Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvng <viktor.govako@gmail.com>2014-10-30 13:21:52 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:31:55 +0300
commita471524c3f19e1fa20e5e634f7a3933c7f3a039a (patch)
tree8532143f7edccd4fdaffac7f1113aeacf47bd3f5
parent07d95abd471a2f4423b2b473d138d59a1a1085dd (diff)
Minor refactoring - use “initializer_list” for getting classificator types.
-rw-r--r--base/internal/message.hpp7
-rw-r--r--generator/feature_builder.cpp3
-rw-r--r--generator/osm2type.cpp3
-rw-r--r--generator/osm_element.hpp6
-rw-r--r--indexer/classificator.cpp23
-rw-r--r--indexer/classificator.hpp7
-rw-r--r--indexer/feature_visibility.cpp6
-rw-r--r--indexer/feature_visibility.hpp10
-rw-r--r--indexer/ftypes_matcher.cpp6
-rw-r--r--routing/vehicle_model.cpp9
-rw-r--r--std/initializer_list.hpp14
11 files changed, 57 insertions, 37 deletions
diff --git a/base/internal/message.hpp b/base/internal/message.hpp
index e384aa4c8a..d120f28e0e 100644
--- a/base/internal/message.hpp
+++ b/base/internal/message.hpp
@@ -7,6 +7,7 @@
#include "../../std/string.hpp"
#include "../../std/utility.hpp"
#include "../../std/vector.hpp"
+#include "../../std/initializer_list.hpp"
/// @name Declarations.
@@ -22,6 +23,7 @@ template <typename T> inline string DebugPrint(list<T> const & v);
template <typename T> inline string DebugPrint(vector<T> const & v);
template <typename T> inline string DebugPrint(set<T> const & v);
template <typename U, typename V> inline string DebugPrint(map<U,V> const & v);
+template <typename T> inline string DebugPrint(initializer_list<T> const & v);
//@}
@@ -96,6 +98,11 @@ template <typename U, typename V> inline string DebugPrint(map<U,V> const & v)
return ::my::impl::DebugPrintSequence(v.begin(), v.end());
}
+template <typename T> inline string DebugPrint(initializer_list<T> const & v)
+{
+ return ::my::impl::DebugPrintSequence(v.begin(), v.end());
+}
+
template <typename T> inline string DebugPrint(T const & t)
{
ostringstream out;
diff --git a/generator/feature_builder.cpp b/generator/feature_builder.cpp
index a82c51c85b..56b8d3f8ae 100644
--- a/generator/feature_builder.cpp
+++ b/generator/feature_builder.cpp
@@ -243,8 +243,7 @@ void FeatureBuilder1::RemoveUselessNames()
{
using namespace feature;
- char const * arr[] = { "boundary", "administrative" };
- static TypeSetChecker checkBoundary(arr, ARRAY_SIZE(arr));
+ static TypeSetChecker checkBoundary({ "boundary", "administrative" });
TypesHolder types(GetFeatureBase());
if (types.RemoveIf(bind(&TypeSetChecker::IsEqual, cref(checkBoundary), _1)))
diff --git a/generator/osm2type.cpp b/generator/osm2type.cpp
index 64cac52afa..3a2ba86b9f 100644
--- a/generator/osm2type.cpp
+++ b/generator/osm2type.cpp
@@ -539,8 +539,7 @@ namespace ftype
uint32_t GetBoundaryType2()
{
- char const * arr[] = { "boundary", "administrative" };
- return classif().GetTypeByPath(vector<string>(arr, arr + 2));
+ return classif().GetTypeByPath({ "boundary", "administrative" });
}
bool IsValidTypes(FeatureParams const & params)
diff --git a/generator/osm_element.hpp b/generator/osm_element.hpp
index 9564ac6c32..a0782b1c9f 100644
--- a/generator/osm_element.hpp
+++ b/generator/osm_element.hpp
@@ -154,8 +154,8 @@ class SecondPassParser : public BaseOSMParser
~type_processor()
{
- for (typename RelationCacheT::iterator i = m_typeCache.begin(); i != m_typeCache.end(); ++i)
- delete i->second.m_e;
+ for (auto & r : m_typeCache)
+ delete r.second.m_e;
}
/// Start process new feature.
@@ -168,7 +168,7 @@ class SecondPassParser : public BaseOSMParser
/// 1. "initial relation" process
int operator() (uint64_t id)
{
- typename RelationCacheT::const_iterator i = m_typeCache.find(id);
+ auto i = m_typeCache.find(id);
if (i != m_typeCache.end())
{
m_val->AddTypes(i->second.m_p, GetSkipBoundaryType(i->second.m_e));
diff --git a/indexer/classificator.cpp b/indexer/classificator.cpp
index d74ae3d903..092e49c399 100644
--- a/indexer/classificator.cpp
+++ b/indexer/classificator.cpp
@@ -367,35 +367,44 @@ void Classificator::SortClassificator()
GetMutableRoot()->Sort();
}
-uint32_t Classificator::GetTypeByPathSafe(vector<string> const & path) const
+template <class IterT> uint32_t Classificator::GetTypeByPathImpl(IterT beg, IterT end) const
{
ClassifObject const * p = GetRoot();
- size_t i = 0;
uint32_t type = ftype::GetEmptyValue();
- while (i < path.size())
+ while (beg != end)
{
- ClassifObjectPtr ptr = p->BinaryFind(path[i]);
+ ClassifObjectPtr ptr = p->BinaryFind(*beg++);
if (!ptr)
return 0;
ftype::PushValue(type, ptr.GetIndex());
-
- ++i;
p = ptr.get();
}
return type;
}
+uint32_t Classificator::GetTypeByPathSafe(vector<string> const & path) const
+{
+ return GetTypeByPathImpl(path.begin(), path.end());
+}
+
uint32_t Classificator::GetTypeByPath(vector<string> const & path) const
{
- uint32_t const type = GetTypeByPathSafe(path);
+ uint32_t const type = GetTypeByPathImpl(path.begin(), path.end());
ASSERT_NOT_EQUAL(type, 0, (path));
return type;
}
+uint32_t Classificator::GetTypeByPath(initializer_list<char const *> const & lst) const
+{
+ uint32_t const type = GetTypeByPathImpl(lst.begin(), lst.end());
+ ASSERT_NOT_EQUAL(type, 0, (lst));
+ return type;
+}
+
void Classificator::ReadTypesMapping(istream & s)
{
m_mapping.Load(s);
diff --git a/indexer/classificator.hpp b/indexer/classificator.hpp
index 910b5eaa63..05e156e30c 100644
--- a/indexer/classificator.hpp
+++ b/indexer/classificator.hpp
@@ -9,6 +9,7 @@
#include "../std/iostream.hpp"
#include "../std/bitset.hpp"
#include "../std/noncopyable.hpp"
+#include "../std/initializer_list.hpp"
class ClassifObject;
@@ -184,10 +185,14 @@ public:
/// Return type by path in classificator tree, for example
/// path = ["natural", "caostline"].
//@{
+private:
+ template <class IterT> uint32_t GetTypeByPathImpl(IterT beg, IterT end) const;
+public:
/// @return 0 in case of nonexisting type
uint32_t GetTypeByPathSafe(vector<string> const & path) const;
- /// Shows ASSERT in case of nonexisting type
+ /// Invokes ASSERT in case of nonexisting type
uint32_t GetTypeByPath(vector<string> const & path) const;
+ uint32_t GetTypeByPath(initializer_list<char const *> const & lst) const;
//@}
uint32_t GetIndexForType(uint32_t t) const { return m_mapping.GetIndex(t); }
diff --git a/indexer/feature_visibility.cpp b/indexer/feature_visibility.cpp
index 2d119bc3e0..59a941d320 100644
--- a/indexer/feature_visibility.cpp
+++ b/indexer/feature_visibility.cpp
@@ -420,10 +420,10 @@ pair<int, int> GetDrawableScaleRangeForRules(FeatureBase const & f, int rules)
return GetDrawableScaleRangeForRules(TypesHolder(f), rules);
}
-void TypeSetChecker::SetType(StringT * beg, StringT * end)
+TypeSetChecker::TypeSetChecker(initializer_list<char const *> const & lst)
{
- m_type = classif().GetTypeByPath(vector<string>(beg, end));
- m_level = distance(beg, end);
+ m_type = classif().GetTypeByPath(lst);
+ m_level = lst.size();
}
bool TypeSetChecker::IsEqual(uint32_t type) const
diff --git a/indexer/feature_visibility.hpp b/indexer/feature_visibility.hpp
index facb8c6723..266896f254 100644
--- a/indexer/feature_visibility.hpp
+++ b/indexer/feature_visibility.hpp
@@ -8,6 +8,7 @@
#include "../std/vector.hpp"
#include "../std/string.hpp"
#include "../std/utility.hpp"
+#include "../std/initializer_list.hpp"
class FeatureBase;
@@ -58,15 +59,8 @@ namespace feature
uint32_t m_type;
uint8_t m_level;
- typedef char const * StringT;
- void SetType(StringT * beg, StringT * end);
-
public:
- /// Construct by classificator set name.
- //@{
- TypeSetChecker(StringT name) { SetType(&name, &name + 1); }
- TypeSetChecker(StringT arr[], size_t n) { SetType(arr, arr + n); }
- //@}
+ explicit TypeSetChecker(initializer_list<char const *> const & lst);
bool IsEqual(uint32_t type) const;
template <class IterT> bool IsEqualR(IterT beg, IterT end) const
diff --git a/indexer/ftypes_matcher.cpp b/indexer/ftypes_matcher.cpp
index bdee45d5c6..c8dbea352a 100644
--- a/indexer/ftypes_matcher.cpp
+++ b/indexer/ftypes_matcher.cpp
@@ -74,10 +74,8 @@ IsBuildingChecker::IsBuildingChecker()
{
Classificator const & c = classif();
- char const * arr0[] = { "building" };
- m_types.push_back(c.GetTypeByPath(vector<string>(arr0, arr0 + 1)));
- char const * arr1[] = { "building", "address" };
- m_types.push_back(c.GetTypeByPath(vector<string>(arr1, arr1 + 2)));
+ m_types.push_back(c.GetTypeByPath({ "building" }));
+ m_types.push_back(c.GetTypeByPath({ "building", "address" }));
}
IsLocalityChecker::IsLocalityChecker()
diff --git a/routing/vehicle_model.cpp b/routing/vehicle_model.cpp
index 4ef0bed5f6..ed8d884428 100644
--- a/routing/vehicle_model.cpp
+++ b/routing/vehicle_model.cpp
@@ -42,13 +42,8 @@ CarModel::CarModel()
VehicleModel::VehicleModel(Classificator const & c, vector<SpeedForType> const & speedLimits) : m_maxSpeed(0)
{
- {
- char const * arr2[] = { "hwtag", "oneway" };
- m_onewayType = c.GetTypeByPath(vector<string>(arr2, arr2 + 2));
-
- char const * arr3[] = { "route", "ferry", "motorcar" };
- m_ferryType = c.GetTypeByPath(vector<string>(arr3, arr3 + 3));
- }
+ m_onewayType = c.GetTypeByPath({ "hwtag", "oneway" });
+ m_ferryType = c.GetTypeByPath({ "route", "ferry", "motorcar" });
for (size_t i = 0; i < speedLimits.size(); ++i)
{
diff --git a/std/initializer_list.hpp b/std/initializer_list.hpp
new file mode 100644
index 0000000000..4e32ec2e0b
--- /dev/null
+++ b/std/initializer_list.hpp
@@ -0,0 +1,14 @@
+#pragma once
+#include "common_defines.hpp"
+
+#ifdef new
+#undef new
+#endif
+
+#include <initializer_list>
+
+using std::initializer_list;
+
+#ifdef DEBUG_NEW
+#define new DEBUG_NEW
+#endif