From d5367643fa87c113bf836745b425cd396335edb6 Mon Sep 17 00:00:00 2001
From: florian <f.spreckelsen@inidscale.com>
Date: Tue, 3 Aug 2021 10:58:31 +0200
Subject: [PATCH] DRAFT: Fill property class

---
 include/caosdb/entity.h | 58 +++++++++++++++++++++++++++++++++++++++-
 src/caosdb/entity.cpp   | 59 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 116 insertions(+), 1 deletion(-)

diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h
index a64940e..19277cd 100644
--- a/include/caosdb/entity.h
+++ b/include/caosdb/entity.h
@@ -36,6 +36,7 @@
 namespace caosdb::entity {
 using caosdb::entity::v1alpha1::IdResponse;
 using ProtoParent = caosdb::entity::v1alpha1::Parent;
+using ProtoProperty = caosdb::entity::v1alpha1::Property;
 using ProtoEntity = caosdb::entity::v1alpha1::Entity;
 
 /**
@@ -246,14 +247,35 @@ class Property {
 public:
   explicit inline Property(caosdb::entity::v1alpha1::Property *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 &;
+  /**
+   * Return the name of this  property
+   */
   [[nodiscard]] auto GetName() const -> const std::string &;
+  /**
+   * Return the description of this  property
+   */
   [[nodiscard]] auto GetDescription() const -> const std::string &;
+  /**
+   * Return the importance of this  property
+   */
   [[nodiscard]] auto GetImportance() const -> const std::string &;
+  /**
+   * Return the value of this  property
+   */
   [[nodiscard]] auto GetValue() const -> const std::string &;
+  /**
+   * Return the unit of this  property
+   */
   [[nodiscard]] auto GetUnit() const -> const std::string &;
+  /**
+   * Return the datatype of this  property
+   */
   [[nodiscard]] auto GetDatatype() const -> const std::string &;
   // TODO(fspreck) Implement these when we have decided how to attach
   // messages to properties.
@@ -261,17 +283,51 @@ public:
   // [[nodiscard]] auto GetWarnings() const -> const Messages &;
   // [[nodiscard]] auto GetInfos() const -> const Messages &;
 
+  /**
+   * Set the id of this property.
+   */
   auto SetId(const std::string &id) -> void;
+  /**
+   * Set the name of this property.
+   */
   auto SetName(const std::string &name) -> void;
+  /**
+   * Set the importance of this property.
+   */
   auto SetImportance(const std::string &importance) -> void;
+  /**
+   * Set the value of this property.
+   */
   auto SetValue(const std::string &value) -> void;
+  /**
+   * Set the unit of this property.
+   */
   auto SetUnit(const std::string &unit) -> void;
+  /**
+   * Set the datatype of this property.
+   */
   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 Properties;
 
 private:
+  static auto CreateProtoProperty() -> ProtoProperty *;
+
   caosdb::entity::v1alpha1::Property *wrapped;
 };
 
diff --git a/src/caosdb/entity.cpp b/src/caosdb/entity.cpp
index 0e56c68..8e032e4 100644
--- a/src/caosdb/entity.cpp
+++ b/src/caosdb/entity.cpp
@@ -25,6 +25,7 @@
 namespace caosdb::entity {
 using caosdb::entity::v1alpha1::IdResponse;
 using ProtoParent = caosdb::entity::v1alpha1::Parent;
+using ProtoProperty = caosdb::entity::v1alpha1::Property;
 using ProtoEntity = caosdb::entity::v1alpha1::Entity;
 using caosdb::utility::get_arena;
 
@@ -65,6 +66,64 @@ auto Parents::Append(const Parent &parent) -> void {
   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 & {
   return parents;
 }
-- 
GitLab