diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h index 5f4c8990ee870c8af51253870263a9ff2b1aa8e7..52dc3e05c69578c41f94af444213bfd878362abf 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 9c12bd18a0528218fa12e5c3376fd272484e9f0d..2c52fe68152143d8cc4571ee44c28c0727fc4cbc 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 e42e526ccd40973f6c10d0e7fe47c08a9f7db2d7..9cde6c61fe427bbd13743933c2b0112041ca2dec 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 102de737a4c49d240e411ddf43be0c92883989e9..afe4b302782a424b98c15b3bd46ad84d2ab679f2 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 ©_entity(entity); EXPECT_EQ(copy_entity.GetDataType().AsReference().GetName(), "src_per"); }