From b4b10b3e7d2bd804ad43b63268f5df62fa413c1c Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Thu, 26 Nov 2015 23:16:26 -0800 Subject: Fixed Metadata interface and implementation, added missing unit tests. --- indexer/feature_meta.hpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'indexer/feature_meta.hpp') diff --git a/indexer/feature_meta.hpp b/indexer/feature_meta.hpp index 363f899ded..3a082f32eb 100644 --- a/indexer/feature_meta.hpp +++ b/indexer/feature_meta.hpp @@ -42,14 +42,28 @@ namespace feature static_assert(FMD_COUNT <= 255, "Meta types count is limited to one byte."); - bool Add(EType type, string const & s) + /// Empty value drops (clears) corresponding type. + void Set(EType type, string const & value) { - string & val = m_metadata[type]; - if (val.empty()) - val = s; + auto found = m_metadata.find(type); + if (found == m_metadata.end()) + { + if (!value.empty()) + m_metadata[type] = value; + } else - val = val + ", " + s; - return true; + { + if (value.empty()) + m_metadata.erase(found); + else + found->second = value; + } + } + + /// Synonym of Set(type, ""). + void Drop(EType type) + { + Set(type, ""); } string Get(EType type) const @@ -69,11 +83,6 @@ namespace feature return types; } - void Drop(EType type) - { - m_metadata.erase(type); - } - inline bool Empty() const { return m_metadata.empty(); } inline size_t Size() const { return m_metadata.size(); } -- cgit v1.2.3