From d563500c915de2f0a652513af03f101c99715db3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 9 May 2021 15:20:30 +0200 Subject: SharedType: type trait instead of member functions and typedef --- src/identity.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/identity.cpp') diff --git a/src/identity.cpp b/src/identity.cpp index a4c12f2..f55f6dd 100644 --- a/src/identity.cpp +++ b/src/identity.cpp @@ -1,5 +1,7 @@ #include "identity.h" +#include + #include #include #include @@ -11,7 +13,14 @@ using std::nullopt; using std::runtime_error; using std::set; -const UUID Identity::sharedTypeId { "0c6c1fe0-f2d7-4891-926b-c332449f7871" }; +DEFINE_SHARED_TYPE(optional, + "0c6c1fe0-f2d7-4891-926b-c332449f7871", + &Identity::load, + [](const optional & id) { + if (id) + return id->store(); + return vector(); + }) Identity::Identity(const Priv * p): p(p) {} Identity::Identity(shared_ptr && p): p(std::move(p)) {} @@ -34,6 +43,15 @@ optional Identity::load(const vector & refs) return nullopt; } +vector Identity::store() const +{ + vector res; + res.reserve(p->data.size()); + for (const auto & x : p->data) + res.push_back(x.ref()); + return res; +} + vector Identity::store(const Storage & st) const { vector res; -- cgit v1.2.3