From ac18a98e7014f04ba51bf4c8729ce87bbdc68c8b Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Mon, 16 Aug 2021 21:03:34 +0200
Subject: [PATCH] WIP: consolidation

---
 include/caosdb/entity.h          | 18 +++++++++---------
 include/caosdb/protobuf_helper.h |  1 +
 include/caosdb/value.h           |  6 ++----
 test/test_protobuf.cpp           |  2 +-
 4 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h
index 5f4c899..52dc3e0 100644
--- a/include/caosdb/entity.h
+++ b/include/caosdb/entity.h
@@ -453,9 +453,9 @@ private:
  */
 class Property {
 public:
-  explicit inline Property(ProtoProperty *wrapped)
-    : wrapped(wrapped), data_type(DataType(wrapped->mutable_data_type())),
-      value(Value(wrapped->mutable_value())){};
+  explicit inline Property(ProtoProperty *other)
+    : value(Value(other->mutable_value())),
+      data_type(DataType(other->mutable_data_type())), wrapped(other){};
   Property();
 
   /**
@@ -581,9 +581,9 @@ class Entity {
 public:
   Entity();
   inline Entity(const Entity &original)
-    : wrapped(CreateProtoEntity()),
-      data_type(DataType(wrapped->mutable_data_type())),
-      value(Value(wrapped->mutable_value())) {
+    : wrapped(original.wrapped),
+      value(Value(original.wrapped->mutable_value())),
+      data_type(DataType(original.wrapped->mutable_data_type())) {
     this->wrapped->CopyFrom(*original.wrapped);
     data_type.wrapped = this->wrapped->mutable_data_type();
     value.wrapped = this->wrapped->mutable_value();
@@ -594,9 +594,9 @@ public:
     infos.wrapped = CreateMessagesField();
   };
   explicit Entity(IdResponse *id_response);
-  explicit Entity(ProtoEntity *wrapped)
-    : wrapped(wrapped), data_type(DataType(wrapped->mutable_data_type())),
-      value(Value(wrapped->mutable_value())) {
+  explicit Entity(ProtoEntity *other)
+    : wrapped(other), value(Value(other->mutable_value())),
+      data_type(DataType(other->mutable_data_type())) {
     data_type.wrapped = this->wrapped->mutable_data_type();
     value.wrapped = this->wrapped->mutable_value();
     properties.wrapped = this->wrapped->mutable_properties();
diff --git a/include/caosdb/protobuf_helper.h b/include/caosdb/protobuf_helper.h
index 9c12bd1..2c52fe6 100644
--- a/include/caosdb/protobuf_helper.h
+++ b/include/caosdb/protobuf_helper.h
@@ -41,6 +41,7 @@ auto get_arena() -> Arena *;
 
 template <typename P> class ProtoMessageWrapper {
 public:
+  ProtoMessageWrapper(const ProtoMessageWrapper &other) = default;
   inline auto CopyFrom(const ProtoMessageWrapper &other) noexcept
     -> StatusCode {
     this->wrapped->CopyFrom(*other.wrapped);
diff --git a/include/caosdb/value.h b/include/caosdb/value.h
index e42e526..9cde6c6 100644
--- a/include/caosdb/value.h
+++ b/include/caosdb/value.h
@@ -102,13 +102,11 @@ public:
 
 class Value : public ProtoMessageWrapper<ProtoValue> {
 public:
-  explicit inline Value(const Value &value){
-    this->wrapped = value.wrapped;
-  }
   inline Value() : ProtoMessageWrapper<ProtoValue>() {
     // has NULL_VALUE now
   }
-  explicit inline Value(ProtoValue *wrapped) : ProtoMessageWrapper<ProtoValue>(wrapped) {}
+  explicit inline Value(ProtoValue *wrapped)
+    : ProtoMessageWrapper<ProtoValue>(wrapped) {}
   explicit inline Value(const std::string &value)
     : ProtoMessageWrapper<ProtoValue>() {
     this->wrapped->mutable_scalar_value()->set_string_value(value);
diff --git a/test/test_protobuf.cpp b/test/test_protobuf.cpp
index 102de73..afe4b30 100644
--- a/test/test_protobuf.cpp
+++ b/test/test_protobuf.cpp
@@ -105,7 +105,7 @@ TEST(test_protobuf, test_copy_nested) {
   Entity entity(&entity_destination);
   EXPECT_EQ(entity.GetDataType().AsReference().GetName(), "src_per");
 
-  Entity copy_entity(entity);
+  const Entity &copy_entity(entity);
   EXPECT_EQ(copy_entity.GetDataType().AsReference().GetName(), "src_per");
 }
 
-- 
GitLab