diff options
author | vng <viktor.govako@gmail.com> | 2012-01-27 15:07:33 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:32:31 +0300 |
commit | b84bc9172fdb5ed1ada0820eda43c655d22bf842 (patch) | |
tree | 512dc696db4196285fdddc4eb74062142898a9a2 /indexer | |
parent | f87031f54b1e60a7310efb5c2608fad6b62c27c8 (diff) |
Replace FeatureBase::GetTypesFn with more suitable feature::TypesHolder.
Diffstat (limited to 'indexer')
-rw-r--r-- | indexer/feature.hpp | 19 | ||||
-rw-r--r-- | indexer/feature_data.cpp | 7 | ||||
-rw-r--r-- | indexer/feature_data.hpp | 34 | ||||
-rw-r--r-- | indexer/feature_utils.cpp | 27 | ||||
-rw-r--r-- | indexer/feature_utils.hpp | 1 | ||||
-rw-r--r-- | indexer/feature_visibility.cpp | 39 | ||||
-rw-r--r-- | indexer/search_index_builder.cpp | 7 |
7 files changed, 74 insertions, 60 deletions
diff --git a/indexer/feature.hpp b/indexer/feature.hpp index a28c7ce15a..c2df0e10eb 100644 --- a/indexer/feature.hpp +++ b/indexer/feature.hpp @@ -101,25 +101,6 @@ public: return m_Center; } - class GetTypesFn - { - public: - uint32_t m_types[m_maxTypesCount]; - size_t m_size; - - GetTypesFn() : m_size(0) {} - - inline void operator() (uint32_t t) { m_types[m_size++] = t; } - - inline bool Has(uint32_t t) const - { - for (size_t i = 0; i < m_size; ++i) - if (m_types[i] == t) - return true; - return false; - } - }; - template <typename FunctorT> void ForEachTypeRef(FunctorT & f) const { diff --git a/indexer/feature_data.cpp b/indexer/feature_data.cpp index ce99bed34a..7759370383 100644 --- a/indexer/feature_data.cpp +++ b/indexer/feature_data.cpp @@ -1,11 +1,18 @@ #include "feature_data.hpp" #include "classificator.hpp" +#include "feature.hpp" #include "../std/algorithm.hpp" using namespace feature; +TypesHolder::TypesHolder(FeatureBase const & f) +{ + m_geoType = f.GetFeatureType(); + f.ForEachTypeRef(*this); +} + void FeatureParamsBase::MakeZero() { layer = 0; diff --git a/indexer/feature_data.hpp b/indexer/feature_data.hpp index 1b57d9b117..2c6032611a 100644 --- a/indexer/feature_data.hpp +++ b/indexer/feature_data.hpp @@ -8,6 +8,8 @@ #include "../std/vector.hpp" +class FeatureBase; + namespace feature { enum EGeomType @@ -46,6 +48,38 @@ namespace feature LAYER_HIGH = 12 }; + + class TypesHolder + { + uint32_t m_types[max_types_count]; + size_t m_size; + + EGeomType m_geoType; + + public: + TypesHolder() : m_size(0), m_geoType(GEOM_UNDEFINED) {} + TypesHolder(FeatureBase const & f); + + /// Accumulation function. + inline void operator() (uint32_t t) { m_types[m_size++] = t; } + + /// @name Selectors. + //@{ + inline EGeomType GetGeoType() const { return m_geoType; } + + inline size_t Size() const { return m_size; } + inline uint32_t operator[] (size_t i) const { return m_types[i]; } + + inline bool Has(uint32_t t) const + { + for (size_t i = 0; i < m_size; ++i) + if (t == m_types[i]) + return true; + + return false; + } + //@} + }; } /// Feature description struct. diff --git a/indexer/feature_utils.cpp b/indexer/feature_utils.cpp index 04f5719b73..6c19a577af 100644 --- a/indexer/feature_utils.cpp +++ b/indexer/feature_utils.cpp @@ -77,13 +77,12 @@ public: return limitR; } - FeatureBase::GetTypesFn types; - f.ForEachTypeRef(types); + feature::TypesHolder types(f); int const upperScale = scales::GetUpperScale(); int scale = upperScale; - for (size_t i = 0; i < types.m_size; ++i) - scale = min(scale, GetScaleForType(types.m_types[i], f)); + for (size_t i = 0; i < types.Size(); ++i) + scale = min(scale, GetScaleForType(types[i], f)); CorrectScaleForVisibility(f, scale); @@ -95,23 +94,23 @@ public: { uint32_t population = feature.GetPopulation(); - FeatureBase::GetTypesFn types; - feature.ForEachTypeRef(types); - for (size_t i = 0; i < types.m_size; ++i) + feature::TypesHolder types(feature); + + for (size_t i = 0; i < types.Size(); ++i) { - if (IsEqual(types.m_types[i], m_TypeSmallVillage)) + if (IsEqual(types[i], m_TypeSmallVillage)) population = max(population, static_cast<uint32_t>(100)); - else if (IsEqual(types.m_types[i], m_TypeVillage)) + else if (IsEqual(types[i], m_TypeVillage)) population = max(population, static_cast<uint32_t>(1000)); - else if (types.m_types[i] == m_TypeTown || IsEqual(types.m_types[i], m_TypeCounty)) + else if (types[i] == m_TypeTown || IsEqual(types[i], m_TypeCounty)) population = max(population, static_cast<uint32_t>(10000)); - else if (types.m_types[i] == m_TypeCity || types.m_types[i] == m_TypeState) + else if (types[i] == m_TypeCity || types[i] == m_TypeState) population = max(population, static_cast<uint32_t>(100000)); - else if (types.m_types[i] == m_TypeCityCapital) + else if (types[i] == m_TypeCityCapital) population = max(population, static_cast<uint32_t>(1000000)); - else if (types.m_types[i] == m_TypeCountry) + else if (types[i] == m_TypeCountry) population = max(population, static_cast<uint32_t>(2000000)); - else if (types.m_types[i] == m_TypeContinent) + else if (types[i] == m_TypeContinent) population = max(population, static_cast<uint32_t>(20000000)); } diff --git a/indexer/feature_utils.hpp b/indexer/feature_utils.hpp index ac2bfa14d6..0321f62711 100644 --- a/indexer/feature_utils.hpp +++ b/indexer/feature_utils.hpp @@ -1,6 +1,7 @@ #pragma once #include "../geometry/rect2d.hpp" + #include "../base/base.hpp" class FeatureType; diff --git a/indexer/feature_visibility.cpp b/indexer/feature_visibility.cpp index d5ead6d4bd..1b840595b1 100644 --- a/indexer/feature_visibility.cpp +++ b/indexer/feature_visibility.cpp @@ -130,19 +130,16 @@ namespace pair<int, bool> GetDrawRule(FeatureBase const & f, int level, vector<drule::Key> & keys, string & names) { - feature::EGeomType const geoType = f.GetFeatureType(); - - FeatureBase::GetTypesFn types; - f.ForEachTypeRef(types); + feature::TypesHolder types(f); ASSERT ( keys.empty(), () ); Classificator const & c = classif(); - DrawRuleGetter doRules(level, geoType, keys, names); - for (size_t i = 0; i < types.m_size; ++i) - (void)c.ProcessObjects(types.m_types[i], doRules); + DrawRuleGetter doRules(level, types.GetGeoType(), keys, names); + for (size_t i = 0; i < types.Size(); ++i) + (void)c.ProcessObjects(types[i], doRules); - return make_pair(geoType, types.Has(c.GetCoastType())); + return make_pair(types.GetGeoType(), types.Has(c.GetCoastType())); } namespace @@ -243,16 +240,15 @@ bool IsDrawableForIndex(FeatureBase const & f, int level) { Classificator const & c = classif(); - FeatureBase::GetTypesFn types; - f.ForEachTypeRef(types); + feature::TypesHolder types(f); - if (f.GetFeatureType() == feature::GEOM_AREA && !types.Has(c.GetCoastType())) + if (types.GetGeoType() == feature::GEOM_AREA && !types.Has(c.GetCoastType())) if (!scales::IsGoodForLevel(level, f.GetLimitRect())) return false; IsDrawableChecker doCheck(level); - for (size_t i = 0; i < types.m_size; ++i) - if (c.ProcessObjects(types.m_types[i], doCheck)) + for (size_t i = 0; i < types.Size(); ++i) + if (c.ProcessObjects(types[i], doCheck)) return true; return false; @@ -271,13 +267,13 @@ int MinDrawableScaleForFeature(FeatureBase const & f) namespace { - bool IsDrawable(FeatureBase::GetTypesFn const & types, int level, EGeomType geomType) + bool IsDrawable(feature::TypesHolder const & types, int level) { Classificator const & c = classif(); - TextRulesChecker doCheck(level, geomType); - for (size_t i = 0; i < types.m_size; ++i) - if (c.ProcessObjects(types.m_types[i], doCheck)) + TextRulesChecker doCheck(level, types.GetGeoType()); + for (size_t i = 0; i < types.Size(); ++i) + if (c.ProcessObjects(types[i], doCheck)) return true; return false; @@ -286,16 +282,13 @@ namespace pair<int, int> DrawableScaleRangeForText(FeatureBase const & f) { - FeatureBase::GetTypesFn types; - f.ForEachTypeRef(types); - - feature::EGeomType const geomType = f.GetFeatureType(); + feature::TypesHolder types(f); int const upBound = scales::GetUpperScale(); int lowL = -1; for (int level = 0; level <= upBound; ++level) { - if (IsDrawable(types, level, geomType)) + if (IsDrawable(types, level)) { lowL = level; break; @@ -308,7 +301,7 @@ pair<int, int> DrawableScaleRangeForText(FeatureBase const & f) int highL = lowL; for (int level = upBound; level > lowL; --level) { - if (IsDrawable(types, level, geomType)) + if (IsDrawable(types, level)) { highL = level; break; diff --git a/indexer/search_index_builder.cpp b/indexer/search_index_builder.cpp index c3800a5ac8..21a37d70ac 100644 --- a/indexer/search_index_builder.cpp +++ b/indexer/search_index_builder.cpp @@ -73,10 +73,9 @@ struct FeatureInserter feature.ForEachNameRef(f); // Add names of categories of the feature. - FeatureType::GetTypesFn getTypesFn; - feature.ForEachTypeRef(getTypesFn); - for (size_t i = 0; i < getTypesFn.m_size; ++i) - f.AddToken(0, search::FeatureTypeToString(getTypesFn.m_types[i])); + feature::TypesHolder types(feature); + for (size_t i = 0; i < types.Size(); ++i) + f.AddToken(0, search::FeatureTypeToString(types[i])); } }; |