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 +++++++++++++++++++- src/state.h | 1 + src/sync.cpp | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src') 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; diff --git a/src/state.h b/src/state.h index 91dea94..397a906 100644 --- a/src/state.h +++ b/src/state.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "pubkey.h" diff --git a/src/sync.cpp b/src/sync.cpp index cf423ac..85fed96 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -1,5 +1,6 @@ #include +#include #include using namespace erebos; -- cgit v1.2.3