Skip to content
Snippets Groups Projects
Commit d5367643 authored by florian's avatar florian
Browse files

DRAFT: Fill property class

parent 705e09d0
No related branches found
No related tags found
1 merge request!4ENH: Allow insertion and deletion of single entities
This commit is part of merge request !4. Comments created here will be created in the context of that merge request.
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
namespace caosdb::entity { namespace caosdb::entity {
using caosdb::entity::v1alpha1::IdResponse; using caosdb::entity::v1alpha1::IdResponse;
using ProtoParent = caosdb::entity::v1alpha1::Parent; using ProtoParent = caosdb::entity::v1alpha1::Parent;
using ProtoProperty = caosdb::entity::v1alpha1::Property;
using ProtoEntity = caosdb::entity::v1alpha1::Entity; using ProtoEntity = caosdb::entity::v1alpha1::Entity;
/** /**
...@@ -246,14 +247,35 @@ class Property { ...@@ -246,14 +247,35 @@ class Property {
public: public:
explicit inline Property(caosdb::entity::v1alpha1::Property *wrapped) explicit inline Property(caosdb::entity::v1alpha1::Property *wrapped)
: wrapped(wrapped){}; : wrapped(wrapped){};
Property();
// TODO(fspreck) All of these methods need implementations. /**
* Return the id of this property
*/
[[nodiscard]] auto GetId() const -> const std::string &; [[nodiscard]] auto GetId() const -> const std::string &;
/**
* Return the name of this property
*/
[[nodiscard]] auto GetName() const -> const std::string &; [[nodiscard]] auto GetName() const -> const std::string &;
/**
* Return the description of this property
*/
[[nodiscard]] auto GetDescription() const -> const std::string &; [[nodiscard]] auto GetDescription() const -> const std::string &;
/**
* Return the importance of this property
*/
[[nodiscard]] auto GetImportance() const -> const std::string &; [[nodiscard]] auto GetImportance() const -> const std::string &;
/**
* Return the value of this property
*/
[[nodiscard]] auto GetValue() const -> const std::string &; [[nodiscard]] auto GetValue() const -> const std::string &;
/**
* Return the unit of this property
*/
[[nodiscard]] auto GetUnit() const -> const std::string &; [[nodiscard]] auto GetUnit() const -> const std::string &;
/**
* Return the datatype of this property
*/
[[nodiscard]] auto GetDatatype() const -> const std::string &; [[nodiscard]] auto GetDatatype() const -> const std::string &;
// TODO(fspreck) Implement these when we have decided how to attach // TODO(fspreck) Implement these when we have decided how to attach
// messages to properties. // messages to properties.
...@@ -261,17 +283,51 @@ public: ...@@ -261,17 +283,51 @@ public:
// [[nodiscard]] auto GetWarnings() const -> const Messages &; // [[nodiscard]] auto GetWarnings() const -> const Messages &;
// [[nodiscard]] auto GetInfos() const -> const Messages &; // [[nodiscard]] auto GetInfos() const -> const Messages &;
/**
* Set the id of this property.
*/
auto SetId(const std::string &id) -> void; auto SetId(const std::string &id) -> void;
/**
* Set the name of this property.
*/
auto SetName(const std::string &name) -> void; auto SetName(const std::string &name) -> void;
/**
* Set the importance of this property.
*/
auto SetImportance(const std::string &importance) -> void; auto SetImportance(const std::string &importance) -> void;
/**
* Set the value of this property.
*/
auto SetValue(const std::string &value) -> void; auto SetValue(const std::string &value) -> void;
/**
* Set the unit of this property.
*/
auto SetUnit(const std::string &unit) -> void; auto SetUnit(const std::string &unit) -> void;
/**
* Set the datatype of this property.
*/
auto SetDatatype(const std::string &datatype) -> void; auto SetDatatype(const std::string &datatype) -> void;
/**
* Return a json string representing this property.
*
* This is intended for debugging
*/
inline auto ToString() const -> const std::string {
google::protobuf::util::JsonOptions options;
std::string out;
google::protobuf::util::MessageToJsonString(*(this->wrapped), &out,
options);
return out;
}
friend class Entity; friend class Entity;
friend class Properties; friend class Properties;
private: private:
static auto CreateProtoProperty() -> ProtoProperty *;
caosdb::entity::v1alpha1::Property *wrapped; caosdb::entity::v1alpha1::Property *wrapped;
}; };
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
namespace caosdb::entity { namespace caosdb::entity {
using caosdb::entity::v1alpha1::IdResponse; using caosdb::entity::v1alpha1::IdResponse;
using ProtoParent = caosdb::entity::v1alpha1::Parent; using ProtoParent = caosdb::entity::v1alpha1::Parent;
using ProtoProperty = caosdb::entity::v1alpha1::Property;
using ProtoEntity = caosdb::entity::v1alpha1::Entity; using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using caosdb::utility::get_arena; using caosdb::utility::get_arena;
...@@ -65,6 +66,64 @@ auto Parents::Append(const Parent &parent) -> void { ...@@ -65,6 +66,64 @@ auto Parents::Append(const Parent &parent) -> void {
parent.wrapped = destination; parent.wrapped = destination;
} }
Property::Property() : wrapped(Property::CreateProtoProperty()) {}
auto Property::CreateProtoProperty() -> ProtoProperty * {
return google::protobuf::Arena::CreateMessage<ProtoProperty>(get_arena());
}
[[nodiscard]] auto Property::GetId() const -> const std::string & {
return this->wrapped->id();
}
[[nodiscard]] auto Property::GetName() const -> const std::string & {
return this->wrapped->name();
}
[[nodiscard]] auto Property::GetDescription() const -> const std::string & {
return this->wrapped->description();
}
[[nodiscard]] auto Property::GetImportance() const -> const std::string & {
return this->wrapped->importance();
}
[[nodiscard]] auto Property::GetValue() const -> const std::string & {
return this->wrapped->value();
}
[[nodiscard]] auto Property::GetUnit() const -> const std::string & {
return this->wrapped->unit();
}
[[nodiscard]] auto Property::GetDatatype() const -> const std::string & {
return this->wrapped->datatype();
}
auto Property::SetId(const std::string &id) -> void {
this->wrapped->set_id(id);
}
auto Property::SetName(const std::string &name) -> void {
this->wrapped->set_name(name);
}
auto Property::SetImportance(const std::string &importance) -> void {
this->wrapped->set_importance(importance);
}
auto Property::SetValue(const std::string &value) -> void {
this->wrapped->set_value(value);
}
auto Property::SetUnit(const std::string &unit) -> void {
this->wrapped->set_unit(unit);
}
auto Property::SetDatatype(const std::string &datatype) -> void {
this->wrapped->set_datatype(datatype);
}
[[nodiscard]] auto Entity::GetParents() const -> const Parents & { [[nodiscard]] auto Entity::GetParents() const -> const Parents & {
return parents; return parents;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment