From ca9a367803cc2b27a66bdca52e463d526bc93a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= Date: Mon, 5 Mar 2018 16:44:06 -0500 Subject: [PATCH] value: add TypeStore --- include/opendht/dht.h | 7 +++---- include/opendht/value.h | 13 +++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/opendht/dht.h b/include/opendht/dht.h index 274a34cf..aafd2f56 100644 --- a/include/opendht/dht.h +++ b/include/opendht/dht.h @@ -99,11 +99,10 @@ public: bool isRunning(sa_family_t af = 0) const; virtual void registerType(const ValueType& type) { - types[type.id] = type; + types.registerType(type); } const ValueType& getType(ValueType::Id type_id) const { - const auto& t_it = types.find(type_id); - return (t_it == types.end()) ? ValueType::USER_DATA : t_it->second; + return types.getType(type_id); } /** @@ -350,7 +349,7 @@ private: uint64_t oldsecret {}; // registred types - std::map types; + TypeStore types; // are we a bootstrap node ? // note: Any running node can be used as a bootstrap node. diff --git a/include/opendht/value.h b/include/opendht/value.h index 9c8b155a..514deafc 100644 --- a/include/opendht/value.h +++ b/include/opendht/value.h @@ -109,6 +109,19 @@ struct OPENDHT_PUBLIC ValueType { EditPolicy editPolicy {DEFAULT_EDIT_POLICY}; }; +class TypeStore { +public: + void registerType(const ValueType& type) { + types[type.id] = type; + } + const ValueType& getType(ValueType::Id type_id) const { + const auto& t_it = types.find(type_id); + return (t_it == types.end()) ? ValueType::USER_DATA : t_it->second; + } +private: + std::map types {}; +}; + /** * A "value" is data potentially stored on the Dht, with some metadata. *