From 4625ad87faa695be11512b116f788e6405636c68 Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Wed, 15 Sep 2021 12:37:31 +0200 Subject: [PATCH] EHN: Add ToString to ProtoMessageWrapper --- include/caosdb/protobuf_helper.h | 16 +++++++++++++--- include/caosdb/value.h | 21 ++++++--------------- src/caosdb/entity.cpp | 13 ++++++------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/caosdb/protobuf_helper.h b/include/caosdb/protobuf_helper.h index 3cfa3d4..9a73c0d 100644 --- a/include/caosdb/protobuf_helper.h +++ b/include/caosdb/protobuf_helper.h @@ -22,9 +22,11 @@ #ifndef CAOSDB_PROTOBUF_HELPER_H #define CAOSDB_PROTOBUF_HELPER_H -#include "caosdb/status_code.h" -#include <google/protobuf/arena.h> // for Arena -#include <google/protobuf/extension_set.h> // for Arena +#include "caosdb/status_code.h" // for StatusCode, SUCCESS +#include <google/protobuf/arena.h> // for Arena +#include <google/protobuf/extension_set.h> // for Arena +#include <google/protobuf/util/json_util.h> // for JsonOptions, MessageToJs... +#include <string> // for string #define CAOSDB_DEBUG_MESSAGE_STRING(message, out) \ std::string out; \ @@ -47,6 +49,14 @@ public: return StatusCode::SUCCESS; } + /** + * Return a json representation of this object. + */ + inline auto ToString() const noexcept -> const std::string { + CAOSDB_DEBUG_MESSAGE_STRING(*wrapped, out) + return out; + } + protected: ProtoMessageWrapper() : ProtoMessageWrapper(Arena::CreateMessage<P>(get_arena())) {} ProtoMessageWrapper(P *wrapped) : wrapped(wrapped) {} diff --git a/include/caosdb/value.h b/include/caosdb/value.h index 20bbead..f6de040 100644 --- a/include/caosdb/value.h +++ b/include/caosdb/value.h @@ -22,17 +22,13 @@ #ifndef CAOSDB_VALUE_H #define CAOSDB_VALUE_H #include "caosdb/protobuf_helper.h" // for ProtoMessageWrapper -#include "caosdb/logging.h" // IWYU pragma: keep #include "caosdb/entity/v1alpha1/main.pb.h" // for RepeatedPtrField, Message - -#include <cstdint> // for int64_t -#include <google/protobuf/arena.h> // for Arena -#include <google/protobuf/generated_message_util.h> // for Arena -#include <google/protobuf/util/json_util.h> // IWYU pragma: keep -#include <memory> // for unique_ptr -#include <string> // for string, operator== -#include <utility> // for move -#include <vector> // for vector +#include <cstdint> // for int64_t +#include <google/protobuf/arena.h> // for Arena +#include <memory> // for unique_ptr +#include <string> // for string, operator== +#include <utility> // for move +#include <vector> // for vector #define LIST_VALUE_CONSTRUCTOR(TYPE, SETTER) \ explicit inline Value(const std::vector<TYPE> &values) : ProtoMessageWrapper<ProtoValue>() { \ @@ -412,11 +408,6 @@ public: return *this; } - inline auto ToString() const noexcept -> const std::string { - CAOSDB_DEBUG_MESSAGE_STRING(*wrapped, out) - return out; - } - friend class Entity; friend class Property; diff --git a/src/caosdb/entity.cpp b/src/caosdb/entity.cpp index 977fb69..8f73760 100644 --- a/src/caosdb/entity.cpp +++ b/src/caosdb/entity.cpp @@ -20,13 +20,12 @@ * */ #include "caosdb/entity.h" -#include "caosdb/data_type.h" // for DataType -#include "caosdb/entity/v1alpha1/main.pb.h" // for Messages -#include "caosdb/protobuf_helper.h" // for get_arena -#include "caosdb/value.h" // for Value -#include <google/protobuf/arena.h> // for Arena -#include <google/protobuf/generated_message_util.h> // for Arena::Create... -#include <new> // for operator new +#include "caosdb/data_type.h" // for DataType +#include "caosdb/entity/v1alpha1/main.pb.h" // for Messages +#include "caosdb/protobuf_helper.h" // for get_arena +#include "caosdb/value.h" // for Value +#include <google/protobuf/arena.h> // for Arena +#include <new> // for operator new namespace caosdb::entity { using ProtoParent = caosdb::entity::v1alpha1::Parent; -- GitLab