diff --git a/indexer/classificator.cpp b/indexer/classificator.cpp index c07ccc88b0..d3655405c2 100644 --- a/indexer/classificator.cpp +++ b/indexer/classificator.cpp @@ -1,16 +1,12 @@ #include "classificator.hpp" #include "tree_structure.hpp" -#include "scales.hpp" -#include "../coding/file_reader.hpp" +#include "../base/macros.hpp" +#include "../base/logging.hpp" -#include "../base/assert.hpp" - -#include "../std/target_os.hpp" #include "../std/bind.hpp" #include "../std/algorithm.hpp" #include "../std/iterator.hpp" -#include "../std/fstream.hpp" ///////////////////////////////////////////////////////////////////////////////////////// @@ -31,11 +27,6 @@ ClassifObject * ClassifObject::Add(string const & s) return (p ? p : AddImpl(s)); } -void ClassifObject::AddCriterion(string const & s) -{ - Add('[' + s + ']'); -} - ClassifObject * ClassifObject::Find(string const & s) { for (iter_t i = m_objs.begin(); i != m_objs.end(); ++i) @@ -53,11 +44,6 @@ void ClassifObject::AddDrawRule(drule::Key const & k) m_drawRule.push_back(k); } -bool ClassifObject::IsCriterion() const -{ - return (m_name[0] == '['); -} - ClassifObjectPtr ClassifObject::BinaryFind(string const & s) const { const_iter_t i = lower_bound(m_objs.begin(), m_objs.end(), s, less_name_t()); @@ -67,30 +53,6 @@ ClassifObjectPtr ClassifObject::BinaryFind(string const & s) const return ClassifObjectPtr(&(*i), distance(m_objs.begin(), i)); } -void ClassifObject::SavePolicy::Serialize(ostream & s) const -{ - ClassifObject const * p = Current(); - for (size_t i = 0; i < p->m_drawRule.size(); ++i) - s << p->m_drawRule[i].toString() << " "; -} - -void ClassifObject::LoadPolicy::Serialize(string const & s) -{ - ClassifObject * p = Current(); - - // load drawing rule - drule::Key key; - key.fromString(s); - - // mark as visible in rule's scale - p->m_visibility[key.m_scale] = true; - - // mark objects visible on higher zooms as visible on upperScale, to get them into .mwm file - int const upperScale = scales::GetUpperScale(); - if (key.m_scale > upperScale) - p->m_visibility[upperScale] = true; -} - void ClassifObject::LoadPolicy::Start(size_t i) { ClassifObject * p = Current(); @@ -116,43 +78,6 @@ void ClassifObject::LoadPolicy::EndChilds() p->m_objs.pop_back(); } -void ClassifObject::VisSavePolicy::Serialize(ostream & s) const -{ - ClassifObject const * p = Current(); - - size_t const count = p->m_visibility.size(); - - string str; - str.resize(count); - for (size_t i = 0; i < count; ++i) - str[i] = p->m_visibility[i] ? '1' : '0'; - - s << str << " "; -} - -void ClassifObject::VisLoadPolicy::Name(string const & name) const -{ - UNUSED_VALUE(name); - // Assume that classificator doesn't changed for saved visibility. - ASSERT_EQUAL ( name, Current()->m_name, () ); -} - -void ClassifObject::VisLoadPolicy::Serialize(string const & s) -{ - ClassifObject * p = Current(); - - for (size_t i = 0; i < s.size(); ++i) - p->m_visibility[i] = (s[i] == '1'); -} - -void ClassifObject::VisLoadPolicy::Start(size_t i) -{ - if (i < Current()->m_objs.size()) - base_type::Start(i); - else - m_stack.push_back(0); // dummy -} - void ClassifObject::Sort() { sort(m_drawRule.begin(), m_drawRule.end(), less_scales()); @@ -424,8 +349,6 @@ pair ClassifObject::GetDrawScaleRange() const void Classificator::ReadClassificator(istream & s) { - m_root.Clear(); - ClassifObject::LoadPolicy policy(&m_root); tree::LoadTreeAsText(s, policy); @@ -435,19 +358,6 @@ void Classificator::ReadClassificator(istream & s) m_coastType = GetTypeByPath(vector(path, path + 2)); } -void Classificator::PrintClassificator(char const * fPath) -{ -#ifndef OMIM_OS_BADA - ofstream file(fPath); - - ClassifObject::SavePolicy policy(&m_root); - tree::SaveTreeAsText(file, policy); - -#else - ASSERT ( false, ("PrintClassificator uses only in indexer_tool") ); -#endif -} - void Classificator::SortClassificator() { GetMutableRoot()->Sort(); @@ -481,7 +391,8 @@ void Classificator::ReadTypesMapping(istream & s) void Classificator::Clear() { - *this = Classificator(); + ClassifObject("world").Swap(m_root); + m_mapping.Clear(); } string Classificator::GetReadableObjectName(uint32_t type) const diff --git a/indexer/classificator.hpp b/indexer/classificator.hpp index dda18d257c..1e36c7ee06 100644 --- a/indexer/classificator.hpp +++ b/indexer/classificator.hpp @@ -3,12 +3,11 @@ #include "types_mapping.hpp" #include "scales.hpp" -#include "../base/base.hpp" - #include "../std/vector.hpp" #include "../std/string.hpp" #include "../std/iostream.hpp" #include "../std/bitset.hpp" +#include "../std/noncopyable.hpp" class ClassifObject; @@ -60,7 +59,6 @@ private: ClassifObject * AddImpl(string const & s); public: ClassifObject * Add(string const & s); - void AddCriterion(string const & s); ClassifObject * Find(string const & s); void AddDrawRule(drule::Key const & k); @@ -71,12 +69,9 @@ public: ClassifObjectPtr BinaryFind(string const & s) const; //@} - void Clear() { m_objs.clear(); } - void Sort(); void Swap(ClassifObject & r); - bool IsCriterion() const; string const & GetName() const { return m_name; } ClassifObject const * GetObject(size_t i) const; @@ -134,17 +129,6 @@ public: void End() { m_stack.pop_back(); } }; - class SavePolicy : public BasePolicy - { - public: - SavePolicy(ClassifObject * pRoot) : BasePolicy(pRoot) {} - - string Name() const { return Current()->m_name; } - void Serialize(ostream & s) const; - - size_t BeginChilds() const { return Current()->m_objs.size(); } - }; - class LoadPolicy : public BasePolicy { typedef BasePolicy base_type; @@ -152,33 +136,9 @@ public: LoadPolicy(ClassifObject * pRoot) : base_type(pRoot) {} void Name(string const & name) { Current()->m_name = name; } - void Serialize(string const & s); - void Start(size_t i); void EndChilds(); }; - - class VisSavePolicy : public SavePolicy - { - public: - VisSavePolicy(ClassifObject * pRoot) : SavePolicy(pRoot) {} - - void Serialize(ostream & s) const; - }; - - class VisLoadPolicy : public BasePolicy - { - typedef BasePolicy base_type; - - public: - VisLoadPolicy(ClassifObject * pRoot) : BasePolicy(pRoot) {} - - void Name(string const & name) const; - void Serialize(string const & s); - - void Start(size_t i); - void EndChilds() {} - }; //@} private: @@ -196,7 +156,7 @@ inline void swap(ClassifObject & r1, ClassifObject & r2) r1.Swap(r2); } -class Classificator +class Classificator : private noncopyable { ClassifObject m_root; @@ -214,8 +174,6 @@ public: /// @name Serialization-like functions. //@{ void ReadClassificator(istream & s); - void PrintClassificator(char const * fPath); - void ReadTypesMapping(istream & s); void SortClassificator(); diff --git a/indexer/classificator_loader.cpp b/indexer/classificator_loader.cpp index 5b16ac1caf..9d3e31f962 100644 --- a/indexer/classificator_loader.cpp +++ b/indexer/classificator_loader.cpp @@ -11,7 +11,6 @@ #include "../base/logging.hpp" #include "../std/iostream.hpp" -#include "../std/fstream.hpp" namespace classificator diff --git a/indexer/drawing_rule_def.cpp b/indexer/drawing_rule_def.cpp index 47dc47dbbe..3b305faa4f 100644 --- a/indexer/drawing_rule_def.cpp +++ b/indexer/drawing_rule_def.cpp @@ -1,45 +1,11 @@ -#include "../base/SRC_FIRST.hpp" - #include "drawing_rule_def.hpp" -#include "../base/macros.hpp" -#include "../base/assert.hpp" -#include "../base/string_utils.hpp" - -#include "../std/cstdio.hpp" #include "../std/iterator.hpp" +#include "../std/algorithm.hpp" namespace drule { - string Key::toString() const - { - char buffer[50]; - sprintf(buffer, "%d|%d|%d|%d", m_scale, m_type, m_index, m_priority); - return buffer; - } - - void Key::fromString(string const & s) - { - int * arrParams[] = { &m_scale, &m_type, &m_index, &m_priority }; - size_t const count = s.size(); - - size_t beg = 0; - size_t i = 0; - do - { - size_t end = s.find_first_of('|', beg); - if (end == string::npos) - end = count; - - ASSERT ( i < ARRAY_SIZE(arrParams), (i) ); - //*(arrParams[i++]) = atoi(s.substr(beg, end - beg).c_str()); - *(arrParams[i++]) = strtol(&s[beg], 0, 10); - - beg = end + 1; - } while (beg < count); - } - namespace { struct less_key diff --git a/indexer/drawing_rule_def.hpp b/indexer/drawing_rule_def.hpp index bf334c0249..3fbc1685fb 100644 --- a/indexer/drawing_rule_def.hpp +++ b/indexer/drawing_rule_def.hpp @@ -2,8 +2,6 @@ #include "../base/buffer_vector.hpp" -#include "../std/string.hpp" - namespace drule { @@ -23,9 +21,6 @@ namespace drule return (m_scale == r.m_scale && m_type == r.m_type && m_index == r.m_index); } - string toString() const; - void fromString(string const & s); - void SetPriority(int pr) { m_priority = pr; } }; diff --git a/indexer/tree_structure.hpp b/indexer/tree_structure.hpp index 6d96d8a645..173178c09e 100644 --- a/indexer/tree_structure.hpp +++ b/indexer/tree_structure.hpp @@ -7,57 +7,6 @@ namespace tree { - namespace detail - { - void PrintOffset(size_t offset, ostream & s) - { - for (size_t i = 0; i < offset; ++i) - s << " "; - } - - template - void PrintTextTree(size_t offset, ostream & s, ToDo & toDo) - { - PrintOffset(offset, s); - - // print name as key - s << toDo.Name() << " "; - - // serialize object - toDo.Serialize(s); - - size_t const count = toDo.BeginChilds(); - bool const isEmpty = (count == 0); - - // put end marker - s << (isEmpty ? "-" : "+") << endl; - - // print chils - if (!isEmpty) - { - offset += 4; - - size_t i = 0; - while (i < count) - { - toDo.Start(i++); - PrintTextTree(offset, s, toDo); - toDo.End(); - } - - // end of structure - PrintOffset(offset, s); - s << "{}" << endl; - } - } - } - - template - void SaveTreeAsText(ostream & s, ToDo & toDo) - { - detail::PrintTextTree(0, s, toDo); - } - template bool LoadTreeAsText(istream & s, ToDo & toDo) { @@ -74,7 +23,6 @@ namespace tree s >> strkey; while (strkey != "+" && strkey != "-") { - toDo.Serialize(strkey); s >> strkey; } diff --git a/indexer/types_mapping.cpp b/indexer/types_mapping.cpp index 12e538d3a1..a97e8b6716 100644 --- a/indexer/types_mapping.cpp +++ b/indexer/types_mapping.cpp @@ -5,6 +5,12 @@ #include "../base/stl_add.hpp" +void IndexAndTypeMapping::Clear() +{ + m_types.clear(); + m_map.clear(); +} + void IndexAndTypeMapping::Load(istream & s) { Classificator const & c = classif(); @@ -31,8 +37,8 @@ void IndexAndTypeMapping::Load(istream & s) void IndexAndTypeMapping::Add(uint32_t ind, uint32_t type) { ASSERT_EQUAL ( ind, m_types.size(), () ); - m_types.push_back(type); + m_types.push_back(type); m_map.insert(make_pair(type, ind)); } diff --git a/indexer/types_mapping.hpp b/indexer/types_mapping.hpp index 72dcc1be62..90192bb329 100644 --- a/indexer/types_mapping.hpp +++ b/indexer/types_mapping.hpp @@ -16,6 +16,7 @@ class IndexAndTypeMapping void Add(uint32_t ind, uint32_t type); public: + void Clear(); void Load(istream & s); uint32_t GetType(uint32_t ind) const