diff options
author | Sergey Magidovich <mgsergio@mapswithme.com> | 2015-12-15 21:12:40 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-03-23 16:04:00 +0300 |
commit | 4c3355a1454707bf96487674e37ad0b7ebd0b880 (patch) | |
tree | 8ff4a4ff3baa36497c7d073d4876120c797ae17b /editor/xml_feature.hpp | |
parent | a2b10e7042ec97a186a3cd76638ca43b2986440b (diff) |
FeatureType from/to XMLFeature.
Diffstat (limited to 'editor/xml_feature.hpp')
-rw-r--r-- | editor/xml_feature.hpp | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/editor/xml_feature.hpp b/editor/xml_feature.hpp index d5b4369ea4..da7f12a011 100644 --- a/editor/xml_feature.hpp +++ b/editor/xml_feature.hpp @@ -2,18 +2,17 @@ #include "geometry/point2d.hpp" +#include "coding/multilang_utf8_string.hpp" + +#include "base/string_utils.hpp" + #include "std/ctime.hpp" #include "std/iostream.hpp" -#include "std/map.hpp" - -#include "coding/multilang_utf8_string.hpp" #include "3party/pugixml/src/pugixml.hpp" - namespace editor { - DECLARE_EXCEPTION(XMLFeatureError, RootException); DECLARE_EXCEPTION(XMLFeatureNoNodeError, XMLFeatureError); DECLARE_EXCEPTION(XMLFeatureNoLatLonError, XMLFeatureError); @@ -22,12 +21,18 @@ DECLARE_EXCEPTION(XMLFeatureNoHeaderError, XMLFeatureError); class XMLFeature { + static char const * const kLastModified; + static char const * const kHouseNumber; + static char const * const kDefaultName; + static char const * const kLocalName; + static char const * const kDefaultLang; + public: XMLFeature(); XMLFeature(string const & xml); XMLFeature(pugi::xml_document const & xml); XMLFeature(pugi::xml_node const & xml); - + XMLFeature(XMLFeature const & feature) : XMLFeature(feature.m_document) {} void Save(ostream & ost) const; m2::PointD GetCenter() const; @@ -36,16 +41,23 @@ public: string GetType() const; void SetType(string const & type); - uint8_t GetHeader() const; - void SetHeader(uint8_t const header); - string GetName(string const & lang) const; string GetName(uint8_t const langCode = StringUtf8Multilang::DEFAULT_CODE) const; template <typename TFunc> void ForEachName(TFunc && func) const { - //TODO(mgsergio): implement me :) + static auto const kPrefixLen = strlen(kLocalName); + auto const tags = GetRootNode().select_nodes("tag"); + for (auto const & tag : tags) + { + string const & key = tag.node().attribute("k").value(); + + if (strings::StartsWith(key, kLocalName)) + func(key.substr(kPrefixLen), tag.node().attribute("v").value()); + else if (key == kDefaultName) + func(kDefaultLang, tag.node().attribute("v").value()); + } } void SetName(string const & name); @@ -62,6 +74,12 @@ public: bool HasAttribute(string const & key) const; bool HasKey(string const & key) const; + template <typename TFunc> + void ForEachTag(TFunc && func) const + { + // TODO(mgsergio): implement me. + } + string GetTagValue(string const & key) const; void SetTagValue(string const & key, string const value); |