diff --git a/generator/generator_tests/classificator_tests.cpp b/generator/generator_tests/classificator_tests.cpp new file mode 100644 index 0000000000..dc5b7f52b3 --- /dev/null +++ b/generator/generator_tests/classificator_tests.cpp @@ -0,0 +1,30 @@ +#include "../../testing/testing.hpp" + +#include "../../indexer/classificator.hpp" +#include "../../indexer/classificator_loader.hpp" + +#include "../../base/logging.hpp" + + +namespace +{ + class DoCheckConsistency + { + Classificator const & m_c; + public: + DoCheckConsistency() : m_c(classif()) {} + void operator() (ClassifObject const * p, uint32_t type) + { + if (p->IsDrawableAny() && !m_c.IsTypeValid(type)) + TEST(false, ("Inconsistency type", type, m_c.GetFullObjectName(type))); + } + }; +} + +UNIT_TEST(Classificator_CheckConsistency) +{ + classificator::Load(); + + DoCheckConsistency doCheck; + classif().ForEachTree(doCheck); +} diff --git a/generator/generator_tests/generator_tests.pro b/generator/generator_tests/generator_tests.pro index c125655967..5886c62721 100644 --- a/generator/generator_tests/generator_tests.pro +++ b/generator/generator_tests/generator_tests.pro @@ -28,3 +28,4 @@ SOURCES += \ triangles_tree_coding_test.cpp \ coasts_test.cpp \ feature_builder_test.cpp \ + classificator_tests.cpp \ diff --git a/indexer/classificator.hpp b/indexer/classificator.hpp index d77e256614..117aa9f37b 100644 --- a/indexer/classificator.hpp +++ b/indexer/classificator.hpp @@ -98,33 +98,24 @@ public: } template - void ForEachObjectConst(ToDo & toDo) const + void ForEachObjectInTree(ToDo & toDo, uint32_t const start) const { for (size_t i = 0; i < m_objs.size(); ++i) - toDo(m_objs[i]); + { + uint32_t type = start; + + ftype::PushValue(type, static_cast(i)); + + toDo(&m_objs[i], type); + + m_objs[i].ForEachObjectInTree(toDo, type); + } } typedef bitset<18> visible_mask_t; visible_mask_t GetVisibilityMask() const { return m_visibility; } void SetVisibilityMask(visible_mask_t mask) { m_visibility = mask; } - //template void ForEachType(int level, uint32_t type, ToDo & toDo) - //{ - // if (IsCriterion()) return; - - // if ((level > 1) || (level == 1 && m_objs.empty())) // root and first level is skipped - // { - // toDo(type); - // } - - // for (size_t i = 0; i < m_objs.size(); ++i) - // { - // uint32_t t = type; - // ftype::PushValue(t, i); - // m_objs[i].ForEachType(level + 1, t, toDo); - // } - //} - /// @name Policies for classificator tree serialization. //@{ class BasePolicy @@ -238,21 +229,23 @@ public: uint32_t GetIndexForType(uint32_t t) const { return m_mapping.GetIndex(t); } uint32_t GetTypeForIndex(uint32_t i) const { return m_mapping.GetType(i); } + bool IsTypeValid(uint32_t t) const { return m_mapping.HasIndex(t); } inline uint32_t GetCoastType() const { return m_coastType; } - // Iterate for possible objects types - //template void ForEachType(ToDo toDo) - //{ - // m_root.ForEachType(0, ftype::GetEmptyValue(), toDo); - //} - /// @name used in osm2type.cpp, not for public use. //@{ ClassifObject const * GetRoot() const { return &m_root; } ClassifObject * GetMutableRoot() { return &m_root; } //@} + /// Iterate through all classificator tree. + /// Functor receives pointer to object and uint32 type. + template void ForEachTree(ToDo & toDo) const + { + GetRoot()->ForEachObjectInTree(toDo, ftype::GetEmptyValue()); + } + /// @name Used only in feature_visibility.cpp, not for public use. //@{ template typename ToDo::ResultType diff --git a/indexer/types_mapping.hpp b/indexer/types_mapping.hpp index 6a1f9bd496..72dcc1be62 100644 --- a/indexer/types_mapping.hpp +++ b/indexer/types_mapping.hpp @@ -25,4 +25,7 @@ public: } uint32_t GetIndex(uint32_t t) const; + + /// For Debug purposes only. + bool HasIndex(uint32_t t) const { return (m_map.find(t) != m_map.end()); } };