forked from organicmaps/organicmaps
Move xml-feature to editor library.
This commit is contained in:
parent
4d4d5e235b
commit
45320c242e
8 changed files with 69 additions and 78 deletions
|
@ -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 \
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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"(<?xml version="1.0"?>
|
||||
<node
|
||||
FooBar="foofoo">
|
||||
<tag
|
||||
k="opening_hours"
|
||||
v="18:20-19:21" />
|
||||
FooBar="foofoo">
|
||||
<tag
|
||||
k="opening_hours"
|
||||
v="18:20-19:21" />
|
||||
</node>
|
||||
)";
|
||||
|
||||
|
@ -63,23 +62,23 @@ UNIT_TEST(XMLFeature_Setters)
|
|||
|
||||
auto const expectedString = R"(<?xml version="1.0"?>
|
||||
<node
|
||||
center="64.2342340, 53.3124200"
|
||||
timestamp="2015-11-27T21:13:32Z">
|
||||
<tag
|
||||
k="name"
|
||||
v="Gorki Park" />
|
||||
<tag
|
||||
k="name:en"
|
||||
v="Gorki Park" />
|
||||
<tag
|
||||
k="name:ru"
|
||||
v="Парк Горького" />
|
||||
<tag
|
||||
k="addr:housenumber"
|
||||
v="10" />
|
||||
<tag
|
||||
k="opening_hours"
|
||||
v="Mo-Fr 08:15-17:30" />
|
||||
center="64.2342340, 53.3124200"
|
||||
timestamp="2015-11-27T21:13:32Z">
|
||||
<tag
|
||||
k="name"
|
||||
v="Gorki Park" />
|
||||
<tag
|
||||
k="name:en"
|
||||
v="Gorki Park" />
|
||||
<tag
|
||||
k="name:ru"
|
||||
v="Парк Горького" />
|
||||
<tag
|
||||
k="addr:housenumber"
|
||||
v="10" />
|
||||
<tag
|
||||
k="opening_hours"
|
||||
v="Mo-Fr 08:15-17:30" />
|
||||
</node>
|
||||
)";
|
||||
|
||||
|
@ -90,23 +89,23 @@ UNIT_TEST(XMLFeatureFromXml)
|
|||
{
|
||||
auto const srcString = R"(<?xml version="1.0"?>
|
||||
<node
|
||||
center="64.2342340, 53.3124200"
|
||||
timestamp="2015-11-27T21:13:32Z">
|
||||
<tag
|
||||
k="name"
|
||||
v="Gorki Park" />
|
||||
<tag
|
||||
k="name:en"
|
||||
v="Gorki Park" />
|
||||
<tag
|
||||
k="name:ru"
|
||||
v="Парк Горького" />
|
||||
<tag
|
||||
k="addr:housenumber"
|
||||
v="10" />
|
||||
<tag
|
||||
k="opening_hours"
|
||||
v="Mo-Fr 08:15-17:30" />
|
||||
center="64.2342340, 53.3124200"
|
||||
timestamp="2015-11-27T21:13:32Z">
|
||||
<tag
|
||||
k="name"
|
||||
v="Gorki Park" />
|
||||
<tag
|
||||
k="name:en"
|
||||
v="Gorki Park" />
|
||||
<tag
|
||||
k="name:ru"
|
||||
v="Парк Горького" />
|
||||
<tag
|
||||
k="addr:housenumber"
|
||||
v="10" />
|
||||
<tag
|
||||
k="opening_hours"
|
||||
v="Mo-Fr 08:15-17:30" />
|
||||
</node>
|
||||
)";
|
||||
|
|
@ -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
|
|
@ -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<pugi::xml_document> m_documentPtr;
|
||||
pugi::xml_document m_document;
|
||||
};
|
||||
} // namespace indexer
|
|
@ -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
|
||||
|
||||
|
|
|
@ -37,4 +37,3 @@ SOURCES += \
|
|||
test_type.cpp \
|
||||
trie_test.cpp \
|
||||
visibility_test.cpp \
|
||||
xml_feature_test.cpp \
|
||||
|
|
4
omim.pro
4
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
|
||||
|
|
Loading…
Add table
Reference in a new issue