linkahead/entity.h
Anything entity-related.
File descriptors are used to represent directories, links and files of the linkahead file system and their meta data.
- Author
Timm Fitchen
- Date
2021-07-07
- Author
Timm Fitchen
- Date
2022-01-21
-
namespace linkahead
-
namespace entity
DataTypes have 2 dimensions: They may be atomic or reference typed, and they may be scalar or list valued. If they are atomic, they have an AtomicDataType. If they are reference typed, the reference name can be obtained with GetName().
MessageCodes for entity messages.
In contrast to the status codes, the message codes are part of the LinkAhead API. Messages (and their codes) represent the state of the entities in a transaction or the server.
For a specification of the message codes, look at the protobuf documentation. The sources and documentation can be found at https://gitlab.indiscale.com/caosdb/src/caosdb-proto.
Typedefs
-
using ProtoParent = caosdb::entity::v1::Parent
-
using ProtoProperty = caosdb::entity::v1::Property
-
using ProtoEntity = caosdb::entity::v1::Entity
-
using ProtoMessage = caosdb::entity::v1::Message
-
typedef caosdb::entity::v1::Value ProtoValue
-
using ProtoImportance = caosdb::entity::v1::Importance
Enums
Variables
-
static const std::string logger_name = "linkahead::entity"
-
const std::map<Importance, std::string> importance_names = {{Importance::UNSPECIFIED, "UNSPECIFIED"}, {Importance::OBLIGATORY, "OBLIGATORY"}, {Importance::RECOMMENDED, "RECOMMENDED"}, {Importance::SUGGESTED, "SUGGESTED"}, {Importance::FIX, "FIX"}}
-
class Entity : public linkahead::utility::ScalarProtoMessageWrapper<ProtoEntity>
- #include <entity.h>
Entity is the central and basic data object of LinkAhead.
This class is a wrapper of the Entity class auto-generated by protobuf (henceforth “ProtoEntity”).
Overview of the Constructors:
Entity() - Calls Entity(ProtoEntity *) with a fresh ProtoEntity Entity(const Entity&) - Copy constructor, calls Entity(ProtoEntity *) after copying wrapped ProtoEntity of the original, then also copies all Messages. Entity(ProtoEntity *) - The workhorse of the constructors. Initializes everything and does not call other Entity constructors. Entity(EntityResponse *) - Constructor which is used by the Transaction class to create an Entity from the server’s response, calls Entity(ProtoEntity). Entity(IdResponse *) - Constructor which is used by the Transaction class to create an Entity from the servers’s response. calls Entity(), then moves the data to the wrapped ProtoEntity. Entity(Entity&&) - Move constructor, calls Entity(ProtoEntity *), then moves the messages and resets the original,
Public Functions
-
inline explicit Entity(ProtoEntity *other)
-
inline explicit Entity(EntityResponse *response)
-
inline explicit Entity(IdResponse *id_response)
-
inline explicit Entity()
-
~Entity() = default
-
inline auto GetId() const noexcept -> const std::string&
-
inline auto HasId() const noexcept -> bool
-
inline auto GetVersionId() const -> const std::string&
-
inline auto GetName() const -> const std::string&
-
inline auto GetDescription() const -> const std::string&
-
inline auto GetUnit() const -> const std::string&
-
auto GetProperties() const -> const Properties&
-
inline auto HasErrors() const -> bool
-
inline auto HasWarnings() const -> bool
-
inline auto HasInfos() const -> bool
-
auto SetName(const std::string &name) -> void
-
auto SetDescription(const std::string &description) -> void
Set the description of this entity.
-
auto SetValue(const AbstractValue &value) -> StatusCode
-
auto SetValue(const Value &value) -> StatusCode
-
auto SetValue(const std::string &value) -> StatusCode
-
auto SetValue(const char *value) -> StatusCode
-
auto SetValue(const double value) -> StatusCode
-
auto SetValue(const std::vector<std::string> &values) -> StatusCode
-
auto SetValue(const std::vector<char*> &values) -> StatusCode
-
auto SetValue(const std::vector<int64_t> &values) -> StatusCode
-
auto SetValue(const std::vector<int> &values) -> StatusCode
-
auto SetValue(const std::vector<double> &values) -> StatusCode
-
auto SetValue(const std::vector<bool> &values) -> StatusCode
-
auto SetValue(const int64_t value) -> StatusCode
-
auto SetValue(const int value) -> StatusCode
-
auto SetValue(const bool value) -> StatusCode
-
auto SetUnit(const std::string &unit) -> void
-
auto SetDataType(const DataType &new_data_type) -> StatusCode
-
auto SetDataType(const AtomicDataType new_data_type, bool list_type = false) -> StatusCode
-
auto SetDataType(const std::string &new_data_type, bool list_type = false) -> StatusCode
-
auto RemoveProperty(int index) -> void
-
auto RemoveParent(int index) -> void
-
auto CopyTo(ProtoEntity *target) -> void
Copy all of this entity’s features to the target ProtoEntity.
-
auto SetFilePath(const std::string &path) -> void
-
inline auto HasFile() const -> bool
-
inline auto SetFileTransmissionId(FileTransmissionId *file_transmission_id) -> void
-
inline auto GetFileDescriptor() -> FileDescriptor&
-
inline auto GetLocalPath() const noexcept -> const std::filesystem::path&
-
inline auto SetLocalPath(const std::filesystem::path &local_path) noexcept -> StatusCode
-
inline auto ClearMessages() noexcept -> void
Private Functions
-
auto SetId(const std::string &id) -> void
-
auto SetVersionId(const std::string &id) -> void
-
inline auto GetArena() const -> Arena*
Private Static Functions
-
static auto CreateMessagesField() -> RepeatedPtrField<ProtoMessage>*
-
inline explicit Entity(ProtoEntity *other)
-
class Message : public linkahead::utility::ScalarProtoMessageWrapper<ProtoMessage>
- #include <entity.h>
Messages convey information about the state of entities and result of transactions.
A Message object can be thought of as kinf of a generalized error object in other frameworks. Please have a look at MessageCodes for more details.
Public Functions
-
inline auto GetCode() const -> MessageCode
Get the code of this message.
The message code is a unique identifier of the type of message and is intended to make it easiert to identify messages in a machine-readable way.
-
inline auto GetDescription() const -> std::string
Get the description of this message.
The description is intended for a human reader.
Private Functions
-
inline explicit Message(ProtoMessage *wrapped)
Friends
- friend class Entity
- friend class Messages
- friend class RepeatedPtrFieldWrapper< Message, ProtoMessage >
-
inline auto GetCode() const -> MessageCode
-
class Messages : public linkahead::entity::RepeatedPtrFieldWrapper<Message, ProtoMessage>
- #include <entity.h>
Container for Messages.
Private Functions
-
inline Messages()
Friends
- friend class Entity
-
inline Messages()
-
class Parent : public linkahead::utility::ScalarProtoMessageWrapper<ProtoParent>
- #include <entity.h>
This implementation uses protobuf messages as storage backends. In other words, this class wraps a protobuf message and provides getter and setter methods.
Public Functions
-
inline explicit Parent(ProtoParent *wrapped)
-
inline Parent()
-
~Parent() = default
-
auto GetId() const -> const std::string&
Return the id of the parent entity.
-
auto GetName() const -> const std::string&
Return the name of the parent entity.
-
auto GetDescription() const -> const std::string&
Return the description of the parent entity.
-
auto SetId(const std::string &id) -> void
Set the id of the parent.
-
auto SetName(const std::string &name) -> void
Set the name of the parent.
Friends
- friend class Entity
- friend class Parents
- friend class RepeatedPtrFieldWrapper< Parent, ProtoParent >
-
inline explicit Parent(ProtoParent *wrapped)
-
class Parents : public linkahead::entity::RepeatedPtrFieldWrapper<Parent, ProtoParent>
- #include <entity.h>
Container for parents of entities.
Should only be instantiated and write-accessed by the owning entity.
Private Functions
-
inline Parents()
-
inline explicit Parents(::google::protobuf::RepeatedPtrField<caosdb::entity::v1::Parent> *wrapped)
Friends
- friend class Entity
-
inline Parents()
-
class Properties : public linkahead::entity::RepeatedPtrFieldWrapper<Property, ProtoProperty>
- #include <entity.h>
Container for Properties of Entities.
Should only be instantiated and write-accessed by the owning entity.
Note that iterating over the Property contents only works via references, since the Property copy constructor is deliberately disabled:
// Accessing single properties as reference auto &property = my_properties.at(0); // Iterating via reference for (auto &property : my_properties) {...}
Private Functions
-
inline Properties()
-
inline explicit Properties(RepeatedPtrField<ProtoProperty> *wrapped)
Friends
- friend class Entity
-
inline Properties()
-
class Property : public linkahead::utility::ScalarProtoMessageWrapper<ProtoProperty>
- #include <entity.h>
This is a property which belongs to another entity. Don’t confuse it with an Entity with the “Property” role.
Public Functions
-
inline explicit Property(ProtoProperty *other)
-
inline Property()
-
~Property() = default
-
auto GetId() const -> const std::string&
Return the id of this property
-
auto GetName() const -> const std::string&
Return the name of this property
-
auto GetDescription() const -> const std::string&
Return the description of this property
-
auto GetImportance() const -> Importance
Return the importance of this property
-
auto GetUnit() const -> const std::string&
Return the unit of this property
-
auto SetId(const std::string &id) -> void
Set the id of this property.
-
auto SetName(const std::string &name) -> void
Set the name of this property.
-
auto SetDescription(const std::string &description) -> void
Set the description of this property.
-
auto SetImportance(Importance importance) -> void
Set the importance of this property.
-
auto SetValue(const Value &value) -> StatusCode
Set the value of this property.
-
auto SetValue(const AbstractValue &value) -> StatusCode
-
auto SetValue(const std::string &value) -> StatusCode
-
auto SetValue(const char *value) -> StatusCode
-
auto SetValue(const double value) -> StatusCode
-
auto SetValue(const std::vector<std::string> &values) -> StatusCode
-
auto SetValue(const std::vector<char*> &values) -> StatusCode
-
auto SetValue(const std::vector<int64_t> &values) -> StatusCode
-
auto SetValue(const std::vector<int> &values) -> StatusCode
-
auto SetValue(const std::vector<double> &values) -> StatusCode
-
auto SetValue(const std::vector<bool> &values) -> StatusCode
-
auto SetValue(const int64_t value) -> StatusCode
-
auto SetValue(const int value) -> StatusCode
-
auto SetValue(const bool value) -> StatusCode
-
auto SetUnit(const std::string &unit) -> void
Set the unit of this property.
-
auto SetDataType(const DataType &new_data_type) -> StatusCode
Set the datatype of this property.
-
auto SetDataType(const AtomicDataType new_data_type, bool list_type = false) -> StatusCode
-
auto SetDataType(const std::string &new_data_type, bool list_type = false) -> StatusCode
Friends
- friend class Entity
- friend class Properties
- friend class RepeatedPtrFieldWrapper< Property, ProtoProperty >
-
inline explicit Property(ProtoProperty *other)
-
template<typename T, typename P>
class RepeatedPtrFieldWrapper : public linkahead::utility::ProtoMessageWrapper<RepeatedPtrField<P>> - #include <entity.h>
Abstract base class for Messages, Properties and Parents container classes.
This is a list-like class.
This class wraps a RepeatedPtrField.
Public Functions
-
inline auto size() const -> int
Return the current size of the container.
-
inline auto at(int index) const -> const T&
Return a const reference to the element at the given index.
-
inline auto mutable_at(int index) const -> T*
Return a mutable pointer to the element at the given index.
-
auto begin() const -> const iterator
Return constant iterator positioned at the beginning of the list.
-
inline virtual ~RepeatedPtrFieldWrapper()
-
inline virtual auto ToString() const noexcept -> const std::string override
Return a json representation of this object.
-
inline auto operator==(const RepeatedPtrFieldWrapper<T, P> &other) const noexcept -> bool
Return true if the underlying Protobuf messages have the same serialization.
-
inline auto operator!=(const RepeatedPtrFieldWrapper<T, P> &other) const noexcept -> bool
Return true if the underlying Protobuf messages have a different serialization.
Protected Functions
-
inline RepeatedPtrFieldWrapper()
-
inline auto Append(const T &element) -> void
Append an element. This adds the element to the end of the wrapped list and increases the size by one.
-
inline auto Remove(int index) -> void
Remove the element at the given index.
-
inline auto Clear() noexcept -> void
Friends
- friend class Entity
-
inline auto size() const -> int
-
using ProtoParent = caosdb::entity::v1::Parent
-
namespace entity