From e4620f5124a76145f72c63fddf61c74423647f50 Mon Sep 17 00:00:00 2001 From: Maxim Pimenov Date: Tue, 2 Jul 2019 01:04:18 +0300 Subject: [PATCH] [indexer] DebugPrint for the feature's Metadata. --- indexer/feature_meta.cpp | 29 ++++++++++++++++++++--- indexer/feature_meta.hpp | 51 +++++++++++++++++++++++----------------- 2 files changed, 56 insertions(+), 24 deletions(-) diff --git a/indexer/feature_meta.cpp b/indexer/feature_meta.cpp index 420637eb7b..ff229379c3 100644 --- a/indexer/feature_meta.cpp +++ b/indexer/feature_meta.cpp @@ -2,6 +2,8 @@ #include "std/target_os.hpp" +#include + using namespace std; namespace feature @@ -156,12 +158,10 @@ void RegionData::AddPublicHoliday(int8_t month, int8_t offset) value.push_back(offset); Set(RegionData::Type::RD_PUBLIC_HOLIDAYS, value); } -} // namespace feature // Warning: exact osm tag keys should be returned for valid enum values. -string ToString(feature::Metadata::EType type) +string ToString(Metadata::EType type) { - using feature::Metadata; switch (type) { case Metadata::FMD_CUISINE: return "cuisine"; @@ -198,3 +198,26 @@ string ToString(feature::Metadata::EType type) return string(); } + +string DebugPrint(Metadata const & metadata) +{ + ostringstream oss; + bool first = true; + oss << "Metadata ["; + for (uint8_t i = 0; i < static_cast(Metadata::FMD_COUNT); ++i) + { + auto const t = static_cast(i); + string s; + if (metadata.Get(t, s)) + { + if (!first) + oss << "; "; + first = false; + + oss << DebugPrint(t) << "=" << s; + } + } + oss << "]"; + return oss.str(); +} +} // namespace feature diff --git a/indexer/feature_meta.hpp b/indexer/feature_meta.hpp index 2890ef7db2..1f40c89c3c 100644 --- a/indexer/feature_meta.hpp +++ b/indexer/feature_meta.hpp @@ -8,30 +8,10 @@ #include #include - namespace feature { class MetadataBase { -protected: - // TODO: Change uint8_t to appropriate type when FMD_COUNT reaches 256. - void Set(uint8_t type, std::string const & value) - { - auto found = m_metadata.find(type); - if (found == m_metadata.end()) - { - if (!value.empty()) - m_metadata[type] = value; - } - else - { - if (value.empty()) - m_metadata.erase(found); - else - found->second = value; - } - } - public: bool Has(uint8_t type) const { @@ -45,6 +25,15 @@ public: return (it == m_metadata.end()) ? std::string() : it->second; } + bool Get(uint8_t type, std::string & value) const + { + auto const it = m_metadata.find(type); + if (it == m_metadata.end()) + return false; + value = it->second; + return true; + } + std::vector GetPresentTypes() const { std::vector types; @@ -88,6 +77,24 @@ public: } protected: + // TODO: Change uint8_t to appropriate type when FMD_COUNT reaches 256. + void Set(uint8_t type, std::string const & value) + { + auto found = m_metadata.find(type); + if (found == m_metadata.end()) + { + if (!value.empty()) + m_metadata[type] = value; + } + else + { + if (value.empty()) + m_metadata.erase(found); + else + found->second = value; + } + } + std::map m_metadata; }; @@ -224,8 +231,10 @@ public: void AddPublicHoliday(int8_t month, int8_t offset); // No public holidays getters until we know what to do with these. }; -} // namespace feature // Prints types in osm-friendly format. std::string ToString(feature::Metadata::EType type); inline std::string DebugPrint(feature::Metadata::EType type) { return ToString(type); } + +std::string DebugPrint(feature::Metadata const & metadata); +} // namespace feature