From 45320c242e76fa6ad86b5716a128923b9cb6eb9c Mon Sep 17 00:00:00 2001 From: Sergey Magidovich Date: Wed, 2 Dec 2015 14:18:21 +0300 Subject: [PATCH] Move xml-feature to editor library. --- editor/editor.pro | 2 + editor/editor_tests/editor_tests.pro | 5 +- .../editor_tests}/xml_feature_test.cpp | 81 +++++++++---------- {indexer => editor}/xml_feature.cpp | 32 ++++---- {indexer => editor}/xml_feature.hpp | 20 ++--- indexer/indexer.pro | 2 - indexer/indexer_tests/indexer_tests.pro | 1 - omim.pro | 4 +- 8 files changed, 69 insertions(+), 78 deletions(-) rename {indexer/indexer_tests => editor/editor_tests}/xml_feature_test.cpp (76%) rename {indexer => editor}/xml_feature.cpp (83%) rename {indexer => editor}/xml_feature.hpp (80%) diff --git a/editor/editor.pro b/editor/editor.pro index 70ee317165..a7fde752db 100644 --- a/editor/editor.pro +++ b/editor/editor.pro @@ -11,7 +11,9 @@ include($$ROOT_DIR/common.pri) SOURCES += \ opening_hours_ui.cpp \ ui2oh.cpp + xml_feature.cpp \ HEADERS += \ opening_hours_ui.hpp \ ui2oh.hpp \ + xml_feature.hpp \ diff --git a/editor/editor_tests/editor_tests.pro b/editor/editor_tests/editor_tests.pro index ab68fbc6f6..29690dbf45 100644 --- a/editor/editor_tests/editor_tests.pro +++ b/editor/editor_tests/editor_tests.pro @@ -4,14 +4,13 @@ CONFIG -= app_bundle TEMPLATE = app ROOT_DIR = ../.. -DEPENDENCIES = editor base opening_hours +DEPENDENCIES += editor base opening_hours pugixml include($$ROOT_DIR/common.pri) -QT *= core - HEADERS += \ SOURCES += \ $$ROOT_DIR/testing/testingmain.cpp \ opening_hours_ui_test.cpp \ + xml_feature_test.cpp \ diff --git a/indexer/indexer_tests/xml_feature_test.cpp b/editor/editor_tests/xml_feature_test.cpp similarity index 76% rename from indexer/indexer_tests/xml_feature_test.cpp rename to editor/editor_tests/xml_feature_test.cpp index 6687cf21d6..6f7903f462 100644 --- a/indexer/indexer_tests/xml_feature_test.cpp +++ b/editor/editor_tests/xml_feature_test.cpp @@ -1,13 +1,12 @@ #include "testing/testing.hpp" -#include "indexer/xml_feature.hpp" - -#include "3party/pugixml/src/pugixml.hpp" +#include "editor/xml_feature.hpp" #include "base/timer.hpp" #include "std/sstream.hpp" +#include "3party/pugixml/src/pugixml.hpp" using namespace indexer; @@ -31,10 +30,10 @@ UNIT_TEST(XMLFeature_RawGetSet) auto const expected = R"( - + FooBar="foofoo"> + )"; @@ -63,23 +62,23 @@ UNIT_TEST(XMLFeature_Setters) auto const expectedString = R"( - - - - - + center="64.2342340, 53.3124200" + timestamp="2015-11-27T21:13:32Z"> + + + + + )"; @@ -90,23 +89,23 @@ UNIT_TEST(XMLFeatureFromXml) { auto const srcString = R"( - - - - - + center="64.2342340, 53.3124200" + timestamp="2015-11-27T21:13:32Z"> + + + + + )"; diff --git a/indexer/xml_feature.cpp b/editor/xml_feature.cpp similarity index 83% rename from indexer/xml_feature.cpp rename to editor/xml_feature.cpp index 9544caf7cc..1c39447298 100644 --- a/indexer/xml_feature.cpp +++ b/editor/xml_feature.cpp @@ -1,4 +1,4 @@ -#include "indexer/xml_feature.hpp" +#include "editor/xml_feature.hpp" #include "base/string_utils.hpp" #include "base/timer.hpp" @@ -40,17 +40,16 @@ pugi::xml_node FindTag(pugi::xml_document const & document, string const & key) namespace indexer { -XMLFeature::XMLFeature(): m_documentPtr(new pugi::xml_document) +XMLFeature::XMLFeature() { - m_documentPtr->append_child("node"); + m_document.append_child("node"); } -XMLFeature::XMLFeature(string const & xml): - XMLFeature() +XMLFeature::XMLFeature(string const & xml) { - m_documentPtr->load(xml.data()); + m_document.load(xml.data()); - auto const node = m_documentPtr->child("node"); + auto const node = GetRootNode(); if (!node) MYTHROW(XMLFeatureError, ("Document has no node")); @@ -66,20 +65,19 @@ XMLFeature::XMLFeature(string const & xml): MYTHROW(XMLFeatureError, ("Node has no timestamp attribute")); } -XMLFeature::XMLFeature(pugi::xml_document const & xml): - XMLFeature() +XMLFeature::XMLFeature(pugi::xml_document const & xml) { - m_documentPtr->reset(xml); + m_document.reset(xml); } void XMLFeature::Save(ostream & ost) const { - m_documentPtr->save(ost, "\t", pugi::format_indent_attributes); + m_document.save(ost, " ", pugi::format_indent_attributes); } m2::PointD XMLFeature::GetCenter() const { - auto const node = m_documentPtr->child("node"); + auto const node = m_document.child("node"); m2::PointD center; FromString(node.attribute("center").value(), center); return center; @@ -129,7 +127,7 @@ void XMLFeature::SetHouse(string const & house) time_t XMLFeature::GetModificationTime() const { - auto const node = m_documentPtr->child("node"); + auto const node = GetRootNode(); return my::StringToTimestamp(node.attribute("timestamp").value()); } @@ -140,7 +138,7 @@ void XMLFeature::SetModificationTime(time_t const time) bool XMLFeature::HasTag(string const & key) const { - return FindTag(*m_documentPtr, key); + return FindTag(m_document, key); } bool XMLFeature::HasAttribute(string const & key) const @@ -155,13 +153,13 @@ bool XMLFeature::HasKey(string const & key) const string XMLFeature::GetTagValue(string const & key) const { - auto const tag = FindTag(*m_documentPtr, key); + auto const tag = FindTag(m_document, key); return tag.attribute("v").value(); } void XMLFeature::SetTagValue(string const & key, string const value) { - auto tag = FindTag(*m_documentPtr, key); + auto tag = FindTag(m_document, key); if (!tag) { tag = GetRootNode().append_child("tag"); @@ -190,6 +188,6 @@ void XMLFeature::SetAttribute(string const & key, string const & value) pugi::xml_node XMLFeature::GetRootNode() const { - return m_documentPtr->child("node"); + return m_document.child("node"); } } // namespace indexer diff --git a/indexer/xml_feature.hpp b/editor/xml_feature.hpp similarity index 80% rename from indexer/xml_feature.hpp rename to editor/xml_feature.hpp index 496c285807..067a61273c 100644 --- a/indexer/xml_feature.hpp +++ b/editor/xml_feature.hpp @@ -2,19 +2,13 @@ #include "geometry/point2d.hpp" -#include "coding/multilang_utf8_string.hpp" -#include "coding/value_opt_string.hpp" - #include "std/ctime.hpp" #include "std/iostream.hpp" #include "std/map.hpp" #include "std/unique_ptr.hpp" -namespace pugi -{ -class xml_document; -class xml_node; -} +#include "3party/pugixml/src/pugixml.hpp" + namespace indexer { @@ -33,8 +27,11 @@ public: m2::PointD GetCenter() const; void SetCenter(m2::PointD const & center); - string const GetName(string const & lang = "") const; - string const GetName(uint8_t const langCode) const; + string GetType() const; + void SetType(string const & type); + + string const GetName(string const & lang) const; + string const GetName(uint8_t const langCode = StringUtf8Multilang::DEFAULT_CODE) const; void SetName(string const & name); void SetName(string const & lang, string const & name); @@ -58,7 +55,6 @@ public: private: pugi::xml_node GetRootNode() const; - - unique_ptr m_documentPtr; + pugi::xml_document m_document; }; } // namespace indexer diff --git a/indexer/indexer.pro b/indexer/indexer.pro index 7fd88ebe40..ae7e529cd7 100644 --- a/indexer/indexer.pro +++ b/indexer/indexer.pro @@ -47,7 +47,6 @@ SOURCES += \ scales.cpp \ types_mapping.cpp \ types_skipper.cpp \ - xml_feature.cpp \ HEADERS += \ cell_coverer.hpp \ @@ -105,7 +104,6 @@ HEADERS += \ types_mapping.hpp \ types_skipper.hpp \ unique_index.hpp \ - xml_feature.hpp \ OTHER_FILES += drules_struct.proto diff --git a/indexer/indexer_tests/indexer_tests.pro b/indexer/indexer_tests/indexer_tests.pro index ee88ec97ba..f33620ce69 100644 --- a/indexer/indexer_tests/indexer_tests.pro +++ b/indexer/indexer_tests/indexer_tests.pro @@ -37,4 +37,3 @@ SOURCES += \ test_type.cpp \ trie_test.cpp \ visibility_test.cpp \ - xml_feature_test.cpp \ diff --git a/omim.pro b/omim.pro index b9606e5fe9..5f4c9343de 100644 --- a/omim.pro +++ b/omim.pro @@ -23,7 +23,7 @@ HEADERS += defines.hpp CONFIG *= desktop } -SUBDIRS = 3party base coding geometry indexer search routing editor +SUBDIRS = 3party base coding geometry editor indexer routing search !CONFIG(osrm) { SUBDIRS *= platform stats storage @@ -160,7 +160,7 @@ SUBDIRS = 3party base coding geometry indexer search routing editor SUBDIRS *= generator_tests editor_tests.subdir = editor/editor_tests - editor_tests.depends = 3party editor + editor_tests.depends = 3party base editor geometry SUBDIRS *= editor_tests SUBDIRS *= qt_tstfrm