From 17c8837136b877fe4678f49dc8f5cf395d257e93 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Wed, 10 Feb 2016 12:29:55 +0300 Subject: [PATCH] DebugPrint(TypesHolder). --- indexer/feature.hpp | 4 +--- indexer/feature_data.cpp | 32 +++++++++++++++++--------------- indexer/feature_data.hpp | 33 ++++++++++++++++----------------- map/framework.cpp | 4 ++-- 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/indexer/feature.hpp b/indexer/feature.hpp index f6f7e84bbd..8559b15e98 100644 --- a/indexer/feature.hpp +++ b/indexer/feature.hpp @@ -27,8 +27,6 @@ namespace old_101 { namespace feature /// Base feature class for storing common data (without geometry). class FeatureBase { - static const int m_maxTypesCount = feature::max_types_count; - public: using TBuffer = char const *; @@ -131,7 +129,7 @@ protected: uint8_t m_header; - mutable uint32_t m_types[m_maxTypesCount]; + mutable uint32_t m_types[feature::kMaxTypesCount]; mutable FeatureParamsBase m_params; diff --git a/indexer/feature_data.cpp b/indexer/feature_data.cpp index fd5c8c524c..94a459219d 100644 --- a/indexer/feature_data.cpp +++ b/indexer/feature_data.cpp @@ -16,6 +16,18 @@ using namespace feature; // TypesHolder implementation //////////////////////////////////////////////////////////////////////////////////// +namespace feature +{ +string DebugPrint(TypesHolder const & holder) +{ + Classificator const & c = classif(); + string s; + for (uint32_t type : holder) + s += c.GetFullObjectName(type) + " "; + return s; +} +} // namespace feature + TypesHolder::TypesHolder(FeatureBase const & f) : m_size(0), m_geoType(f.GetFeatureType()) { @@ -25,19 +37,9 @@ TypesHolder::TypesHolder(FeatureBase const & f) }); } -string TypesHolder::DebugPrint() const +void TypesHolder::Remove(uint32_t type) { - Classificator const & c = classif(); - - string s; - for (uint32_t t : *this) - s += c.GetFullObjectName(t) + " "; - return s; -} - -void TypesHolder::Remove(uint32_t t) -{ - (void) RemoveIf(EqualFunctor(t)); + UNUSED_VALUE(RemoveIf(EqualFunctor(type))); } bool TypesHolder::Equals(TypesHolder const & other) const @@ -444,8 +446,8 @@ bool FeatureParams::FinishAddingTypes() m_Types.swap(newTypes); - if (m_Types.size() > max_types_count) - m_Types.resize(max_types_count); + if (m_Types.size() > kMaxTypesCount) + m_Types.resize(kMaxTypesCount); return !m_Types.empty(); } @@ -489,7 +491,7 @@ uint32_t FeatureParams::FindType(uint32_t comp, uint8_t level) const bool FeatureParams::CheckValid() const { - CHECK(!m_Types.empty() && m_Types.size() <= max_types_count, ()); + CHECK(!m_Types.empty() && m_Types.size() <= kMaxTypesCount, ()); CHECK_NOT_EQUAL(m_geomType, 0xFF, ()); return FeatureParamsBase::CheckValid(); diff --git a/indexer/feature_data.hpp b/indexer/feature_data.hpp index 09be7b6556..75e6d07e4c 100644 --- a/indexer/feature_data.hpp +++ b/indexer/feature_data.hpp @@ -1,17 +1,17 @@ #pragma once #include "indexer/feature_decl.hpp" +#include "indexer/feature_meta.hpp" #include "geometry/point2d.hpp" #include "coding/multilang_utf8_string.hpp" -#include "coding/value_opt_string.hpp" #include "coding/reader.hpp" +#include "coding/value_opt_string.hpp" +#include "std/algorithm.hpp" #include "std/string.hpp" #include "std/vector.hpp" -#include "std/algorithm.hpp" - -#include "indexer/feature_meta.hpp" +#include "std/utility.hpp" struct FeatureParamsBase; class FeatureBase; @@ -36,7 +36,7 @@ namespace feature HEADER_GEOM_POINT_EX = 3U << 5 /// point feature (addinfo = house) }; - static const int max_types_count = HEADER_TYPE_MASK + 1; + static constexpr int kMaxTypesCount = HEADER_TYPE_MASK + 1; enum ELayerFlags { @@ -50,7 +50,7 @@ namespace feature class TypesHolder { - uint32_t m_types[max_types_count]; + uint32_t m_types[kMaxTypesCount]; size_t m_size; EGeomType m_geoType; @@ -66,7 +66,11 @@ namespace feature } /// Accumulation function. - inline void operator() (uint32_t t) { m_types[m_size++] = t; } + inline void operator() (uint32_t type) + { + ASSERT_LESS(m_size, kMaxTypesCount, ()); + m_types[m_size++] = type; + } /// @name Selectors. //@{ @@ -89,13 +93,13 @@ namespace feature } //@} - template bool RemoveIf(FnT fn) + template bool RemoveIf(TFn && fn) { if (m_size > 0) { size_t const oldSize = m_size; - uint32_t * e = remove_if(m_types, m_types + m_size, fn); + uint32_t * e = remove_if(m_types, m_types + m_size, forward(fn)); m_size = distance(m_types, e); return (m_size != oldSize); @@ -103,9 +107,7 @@ namespace feature return false; } - void Remove(uint32_t t); - - string DebugPrint() const; + void Remove(uint32_t type); /// Sort types by it's specification (more detailed type goes first). void SortBySpec(); @@ -115,14 +117,11 @@ namespace feature bool Equals(TypesHolder const & other) const; }; - inline string DebugPrint(TypesHolder const & t) - { - return t.DebugPrint(); - } + string DebugPrint(TypesHolder const & holder); uint8_t CalculateHeader(uint32_t const typesCount, uint8_t const headerGeomType, FeatureParamsBase const & params); -} +} // namespace feature /// Feature description struct. struct FeatureParamsBase diff --git a/map/framework.cpp b/map/framework.cpp index 83ad22676f..f9cf67ddf3 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -2427,7 +2427,7 @@ namespace feature { string GetPrintableTypes(FeatureType const & ft) { - return feature::TypesHolder(ft).DebugPrint(); + return DebugPrint(feature::TypesHolder(ft)); } uint32_t GetBestType(FeatureType const & ft) { @@ -2451,7 +2451,7 @@ bool Framework::ParseEditorDebugCommand(search::SearchParams const & params) feature::TypesHolder const types(*feature); search::Result::Metadata smd; results.AddResultNoChecks(search::Result(fid, feature::GetCenter(*feature), name, edit.second, - types.DebugPrint(), types.GetBestType(), smd)); + DebugPrint(types), types.GetBestType(), smd)); } params.m_callback(results); params.m_callback(search::Results::GetEndMarker(false));