diff options
author | tatiana-yan <tatiana.kondakova@gmail.com> | 2018-07-24 13:28:42 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2018-07-30 12:36:04 +0300 |
commit | ffaf23d30763c1167c9b36290eb62fde67c7291c (patch) | |
tree | e4d5c6f8026cbe65cf43b22c858b294470aeff15 /indexer | |
parent | f771f419b43c67a79d786db0c2740effdbe072c6 (diff) |
[indexer] Convert LoaderBase methods to const, do not store FeatureType * in shared feature loader. Remove mutable from FeatureType. Remove methods which use uninitialized FeatureType * LoaderBase::m_pFt from FeatureBase. Remove FeatureBase because noone else uses it.
Diffstat (limited to 'indexer')
29 files changed, 477 insertions, 627 deletions
diff --git a/indexer/data_source.cpp b/indexer/data_source.cpp index 65ff1b3fed..794ae6e706 100644 --- a/indexer/data_source.cpp +++ b/indexer/data_source.cpp @@ -266,8 +266,7 @@ void DataSource::ForEachInRectForMWM(FeatureCallback const & f, m2::RectD const } } -void DataSource::ReadFeatures(FeatureConstCallback const & fn, - vector<FeatureID> const & features) const +void DataSource::ReadFeatures(FeatureCallback const & fn, vector<FeatureID> const & features) const { ASSERT(is_sorted(features.begin(), features.end()), ()); diff --git a/indexer/data_source.hpp b/indexer/data_source.hpp index 40a06b9cbb..c6dc708425 100644 --- a/indexer/data_source.hpp +++ b/indexer/data_source.hpp @@ -25,7 +25,6 @@ class DataSource : public MwmSet { public: - using FeatureConstCallback = std::function<void(FeatureType const &)>; using FeatureCallback = std::function<void(FeatureType &)>; using FeatureIdCallback = std::function<void(FeatureID const &)>; @@ -47,9 +46,9 @@ public: void ForEachInRectForMWM(FeatureCallback const & f, m2::RectD const & rect, int scale, MwmId const & id) const; // "features" must be sorted using FeatureID::operator< as predicate. - void ReadFeatures(FeatureConstCallback const & fn, std::vector<FeatureID> const & features) const; + void ReadFeatures(FeatureCallback const & fn, std::vector<FeatureID> const & features) const; - void ReadFeature(FeatureConstCallback const & fn, FeatureID const & feature) const + void ReadFeature(FeatureCallback const & fn, FeatureID const & feature) const { return ReadFeatures(fn, {feature}); } diff --git a/indexer/displacement_manager.hpp b/indexer/displacement_manager.hpp index 8d0e77cadb..ca7d00f396 100644 --- a/indexer/displacement_manager.hpp +++ b/indexer/displacement_manager.hpp @@ -71,7 +71,7 @@ public: /// Add feature at bucket (zoom) to displaceable queue if possible. Pass to bucket otherwise. template <typename Feature> - void Add(vector<int64_t> const & cells, uint32_t bucket, Feature const & ft, uint32_t index) + void Add(vector<int64_t> const & cells, uint32_t bucket, Feature & ft, uint32_t index) { // Add to displaceable storage if we need to displace POI. if (bucket != scales::GetUpperScale() && IsDisplaceable(ft)) @@ -152,7 +152,7 @@ private: DisplaceableNode() : m_index(0), m_minScale(0), m_maxScale(0), m_priority(0) {} template <typename Feature> - DisplaceableNode(vector<int64_t> const & cells, Feature const & ft, uint32_t index, + DisplaceableNode(vector<int64_t> const & cells, Feature & ft, uint32_t index, int zoomLevel) : m_index(index) , m_fID(ft.GetID()) @@ -166,7 +166,7 @@ private: // Calculate depth field drule::KeysT keys; - feature::GetDrawRule(ft, zoomLevel, keys); + feature::GetDrawRule(feature::TypesHolder(ft), zoomLevel, keys); // While the function has "runtime" in its name, it merely filters by metadata-based rules. feature::FilterRulesByRuntimeSelector(ft, zoomLevel, keys); drule::MakeUnique(keys); @@ -195,7 +195,7 @@ private: }; template <typename Feature> - static bool IsDisplaceable(Feature const & ft) + static bool IsDisplaceable(Feature & ft) { feature::TypesHolder const types(ft); return types.GetGeoType() == feature::GEOM_POINT; diff --git a/indexer/drawing_rules.cpp b/indexer/drawing_rules.cpp index 8b94774c05..bb0211e740 100644 --- a/indexer/drawing_rules.cpp +++ b/indexer/drawing_rules.cpp @@ -100,7 +100,7 @@ ShieldRuleProto const * BaseRule::GetShield() const return nullptr; } -bool BaseRule::TestFeature(FeatureType const & ft, int /* zoom */) const +bool BaseRule::TestFeature(FeatureType & ft, int /* zoom */) const { if (nullptr == m_selector) return true; diff --git a/indexer/drawing_rules.hpp b/indexer/drawing_rules.hpp index a2f941dfcb..3c9335f9ab 100644 --- a/indexer/drawing_rules.hpp +++ b/indexer/drawing_rules.hpp @@ -60,7 +60,7 @@ namespace drule // Test feature by runtime feature style selector // Returns true if rule is applicable for feature, otherwise it returns false - bool TestFeature(FeatureType const & ft, int zoom) const; + bool TestFeature(FeatureType & ft, int zoom) const; // Set runtime feature style selector void SetSelector(unique_ptr<ISelector> && selector); diff --git a/indexer/drules_selector.cpp b/indexer/drules_selector.cpp index b264bbba74..98ebfd9ac0 100644 --- a/indexer/drules_selector.cpp +++ b/indexer/drules_selector.cpp @@ -27,7 +27,7 @@ public: } // ISelector overrides: - bool Test(FeatureType const & ft) const override + bool Test(FeatureType & ft) const override { for (auto const & selector : m_selectors) if (!selector->Test(ft)) @@ -45,7 +45,7 @@ class Selector : public ISelector { public: // Signature of function which takes a property from a feature - typedef bool (*TGetFeatureTagValueFn)(FeatureType const &, TType & value); + typedef bool (*TGetFeatureTagValueFn)(FeatureType &, TType & value); Selector(TGetFeatureTagValueFn fn, SelectorOperatorType op, TType const & value) : m_getFeatureValueFn(fn), m_evalFn(nullptr), m_value(value) @@ -71,7 +71,7 @@ public: } // ISelector overrides: - bool Test(FeatureType const & ft) const override + bool Test(FeatureType & ft) const override { TType tagValue; if (!m_getFeatureValueFn(ft, tagValue)) @@ -112,7 +112,7 @@ public: m_equals = op == SelectorOperatorEqual; } - bool Test(FeatureType const & ft) const override + bool Test(FeatureType & ft) const override { bool found = false; ft.ForEachType([&found, this](uint32_t type) @@ -130,21 +130,21 @@ private: }; // Feature tag value evaluator for tag 'population' -bool GetPopulation(FeatureType const & ft, uint64_t & population) +bool GetPopulation(FeatureType & ft, uint64_t & population) { population = ftypes::GetPopulation(ft); return true; } // Feature tag value evaluator for tag 'name' -bool GetName(FeatureType const & ft, string & name) +bool GetName(FeatureType & ft, string & name) { ft.GetReadableName(name); return true; } // Feature tag value evaluator for tag 'bbox_area' (bounding box area in sq.meters) -bool GetBoundingBoxArea(FeatureType const & ft, double & sqM) +bool GetBoundingBoxArea(FeatureType & ft, double & sqM) { if (feature::GEOM_AREA != ft.GetFeatureType()) return false; @@ -157,7 +157,7 @@ bool GetBoundingBoxArea(FeatureType const & ft, double & sqM) } // Feature tag value evaluator for tag 'rating' -bool GetRating(FeatureType const & ft, double & rating) +bool GetRating(FeatureType & ft, double & rating) { double constexpr kDefaultRating = 0.0; diff --git a/indexer/drules_selector.hpp b/indexer/drules_selector.hpp index a63000a1aa..c321d3482b 100644 --- a/indexer/drules_selector.hpp +++ b/indexer/drules_selector.hpp @@ -17,7 +17,7 @@ public: // If ISelector.Test returns true then style is applicable for the feature, // otherwise, if ISelector.Test returns false, style cannot be applied to the feature. - virtual bool Test(FeatureType const & ft) const = 0; + virtual bool Test(FeatureType & ft) const = 0; }; // Factory method which builds ISelector from a string. diff --git a/indexer/feature.cpp b/indexer/feature.cpp index f91b9262a9..aa50f3c9d3 100644 --- a/indexer/feature.cpp +++ b/indexer/feature.cpp @@ -21,18 +21,63 @@ using namespace feature; using namespace std; -/////////////////////////////////////////////////////////////////////////////////////////////////// -// FeatureBase implementation -/////////////////////////////////////////////////////////////////////////////////////////////////// +feature::EGeomType FeatureType::GetFeatureType() const +{ + switch (m_header & HEADER_GEOTYPE_MASK) + { + case HEADER_GEOM_LINE: return GEOM_LINE; + case HEADER_GEOM_AREA: return GEOM_AREA; + default: return GEOM_POINT; + } +} -void FeatureBase::Deserialize(feature::LoaderBase * pLoader, TBuffer buffer) +void FeatureType::SetTypes(uint32_t const (&types)[feature::kMaxTypesCount], uint32_t count) { - m_pLoader = pLoader; - m_pLoader->Init(buffer); + ASSERT_GREATER_OR_EQUAL(count, 1, ("Must be one type at least.")); + ASSERT_LESS(count, feature::kMaxTypesCount, ("Too many types for feature")); + if (count >= feature::kMaxTypesCount) + count = feature::kMaxTypesCount - 1; + fill(begin(m_types), end(m_types), 0); + copy_n(begin(types), count, begin(m_types)); + auto value = static_cast<uint8_t>((count - 1) & feature::HEADER_TYPE_MASK); + m_header = (m_header & (~feature::HEADER_TYPE_MASK)) | value; +} + +void FeatureType::Deserialize(feature::LoaderBase * loader, Buffer buffer) +{ + m_loader = loader; + m_data = buffer; + m_offsets.m_common = m_offsets.m_header2 = 0; + m_ptsSimpMask = 0; + m_ptsOffsets.clear(); + m_trgOffsets.clear(); m_limitRect = m2::RectD::GetEmptyRect(); - m_typesParsed = m_commonParsed = false; - m_header = m_pLoader->GetHeader(); + m_header = m_loader->GetHeader(*this); + + m_parsed = {}; + + m_innerStats.MakeZero(); +} + +void FeatureType::ParseTypes() +{ + if (!m_parsed.m_types) + { + m_loader->ParseTypes(*this); + m_parsed.m_types = true; + } +} + +void FeatureType::ParseCommon() +{ + if (!m_parsed.m_common) + { + ParseTypes(); + + m_loader->ParseCommon(*this); + m_parsed.m_common = true; + } } void FeatureType::ReplaceBy(osm::EditableMapObject const & emo) @@ -44,12 +89,12 @@ void FeatureType::ReplaceBy(osm::EditableMapObject const & emo) m_center = emo.GetMercator(); m_limitRect.MakeEmpty(); m_limitRect.Add(m_center); - m_pointsParsed = m_trianglesParsed = true; + m_parsed.m_points = m_parsed.m_triangles = true; geoType = feature::GEOM_POINT; } else { - geoType = Header() & HEADER_GEOTYPE_MASK; + geoType = m_header & HEADER_GEOTYPE_MASK; } m_params.name = emo.GetName(); @@ -58,94 +103,22 @@ void FeatureType::ReplaceBy(osm::EditableMapObject const & emo) m_params.house.Clear(); else m_params.house.Set(house); - m_commonParsed = true; + m_parsed.m_common = true; m_metadata = emo.GetMetadata(); - m_metadataParsed = true; + m_parsed.m_metadata = true; uint32_t typesCount = 0; for (uint32_t const type : emo.GetTypes()) m_types[typesCount++] = type; - m_typesParsed = true; + m_parsed.m_types = true; m_header = CalculateHeader(typesCount, geoType, m_params); - m_header2Parsed = true; + m_parsed.m_header2 = true; m_id = emo.GetID(); } -void FeatureBase::ParseTypes() const -{ - if (!m_typesParsed) - { - m_pLoader->ParseTypes(); - m_typesParsed = true; - } -} - -void FeatureBase::ParseCommon() const -{ - if (!m_commonParsed) - { - ParseTypes(); - - m_pLoader->ParseCommon(); - m_commonParsed = true; - } -} - -feature::EGeomType FeatureBase::GetFeatureType() const -{ - switch (Header() & HEADER_GEOTYPE_MASK) - { - case HEADER_GEOM_LINE: return GEOM_LINE; - case HEADER_GEOM_AREA: return GEOM_AREA; - default: return GEOM_POINT; - } -} - -void FeatureBase::SetTypes(uint32_t const (&types)[feature::kMaxTypesCount], uint32_t count) -{ - ASSERT_GREATER_OR_EQUAL(count, 1, ("Must be one type at least.")); - ASSERT_LESS(count, feature::kMaxTypesCount, ("Too many types for feature")); - if (count >= feature::kMaxTypesCount) - count = feature::kMaxTypesCount - 1; - fill(begin(m_types), end(m_types), 0); - copy_n(begin(types), count, begin(m_types)); - auto value = static_cast<uint8_t>((count - 1) & feature::HEADER_TYPE_MASK); - m_header = (m_header & (~feature::HEADER_TYPE_MASK)) | value; -} - -string FeatureBase::DebugString() const -{ - ParseCommon(); - - Classificator const & c = classif(); - - string res = "Types"; - for (size_t i = 0; i < GetTypesCount(); ++i) - res += (" : " + c.GetReadableObjectName(m_types[i])); - res += "\n"; - - return (res + m_params.DebugString()); -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////// -// FeatureType implementation -/////////////////////////////////////////////////////////////////////////////////////////////////// - -void FeatureType::Deserialize(feature::LoaderBase * pLoader, TBuffer buffer) -{ - base_type::Deserialize(pLoader, buffer); - - m_pLoader->InitFeature(this); - - m_header2Parsed = m_pointsParsed = m_trianglesParsed = m_metadataParsed = false; - - m_innerStats.MakeZero(); -} - -void FeatureType::ParseEverything() const +void FeatureType::ParseEverything() { // Also calls ParseCommon() and ParseTypes(). ParseHeader2(); @@ -154,18 +127,18 @@ void FeatureType::ParseEverything() const ParseMetadata(); } -void FeatureType::ParseHeader2() const +void FeatureType::ParseHeader2() { - if (!m_header2Parsed) + if (!m_parsed.m_header2) { ParseCommon(); - m_pLoader->ParseHeader2(); - m_header2Parsed = true; + m_loader->ParseHeader2(*this); + m_parsed.m_header2 = true; } } -void FeatureType::ResetGeometry() const +void FeatureType::ResetGeometry() { m_points.clear(); m_triangles.clear(); @@ -173,47 +146,50 @@ void FeatureType::ResetGeometry() const if (GetFeatureType() != GEOM_POINT) m_limitRect = m2::RectD(); - m_header2Parsed = m_pointsParsed = m_trianglesParsed = false; + m_parsed.m_header2 = m_parsed.m_points = m_parsed.m_triangles = false; + m_ptsSimpMask = 0; - m_pLoader->ResetGeometry(); + m_ptsOffsets.clear(); + m_trgOffsets.clear(); } -uint32_t FeatureType::ParseGeometry(int scale) const +uint32_t FeatureType::ParseGeometry(int scale) { uint32_t sz = 0; - if (!m_pointsParsed) + if (!m_parsed.m_points) { ParseHeader2(); - sz = m_pLoader->ParseGeometry(scale); - m_pointsParsed = true; + sz = m_loader->ParseGeometry(scale, *this); + m_parsed.m_points = true; } return sz; } -uint32_t FeatureType::ParseTriangles(int scale) const +uint32_t FeatureType::ParseTriangles(int scale) { uint32_t sz = 0; - if (!m_trianglesParsed) + if (!m_parsed.m_triangles) { ParseHeader2(); - sz = m_pLoader->ParseTriangles(scale); - m_trianglesParsed = true; + sz = m_loader->ParseTriangles(scale, *this); + m_parsed.m_triangles = true; } return sz; } -void FeatureType::ParseMetadata() const +void FeatureType::ParseMetadata() { - if (m_metadataParsed) return; + if (m_parsed.m_metadata) + return; - m_pLoader->ParseMetadata(); + m_loader->ParseMetadata(*this); - m_metadataParsed = true; + m_parsed.m_metadata = true; } -StringUtf8Multilang const & FeatureType::GetNames() const +StringUtf8Multilang const & FeatureType::GetNames() { ParseCommon(); return m_params.name; @@ -229,21 +205,21 @@ void FeatureType::SetNames(StringUtf8Multilang const & newNames) }); if (m_params.name.IsEmpty()) - SetHeader(~feature::HEADER_HAS_NAME & Header()); + m_header = ~feature::HEADER_HAS_NAME & m_header; else - SetHeader(feature::HEADER_HAS_NAME | Header()); + m_header = feature::HEADER_HAS_NAME | m_header; } void FeatureType::SetMetadata(feature::Metadata const & newMetadata) { - m_metadataParsed = true; + m_parsed.m_metadata = true; m_metadata = newMetadata; } void FeatureType::UpdateHeader(bool commonParsed, bool metadataParsed) { feature::EHeaderTypeMask geomType = - static_cast<feature::EHeaderTypeMask>(Header() & feature::HEADER_GEOTYPE_MASK); + static_cast<feature::EHeaderTypeMask>(m_header & feature::HEADER_GEOTYPE_MASK); if (!geomType) { geomType = m_params.house.IsEmpty() && !m_params.ref.empty() ? feature::HEADER_GEOM_POINT @@ -251,11 +227,11 @@ void FeatureType::UpdateHeader(bool commonParsed, bool metadataParsed) } m_header = feature::CalculateHeader(GetTypesCount(), geomType, m_params); - m_header2Parsed = true; - m_typesParsed = true; + m_parsed.m_header2 = true; + m_parsed.m_types = true; - m_commonParsed = commonParsed; - m_metadataParsed = metadataParsed; + m_parsed.m_common = commonParsed; + m_parsed.m_metadata = metadataParsed; } bool FeatureType::UpdateMetadataValue(string const & key, string const & value) @@ -284,7 +260,7 @@ void FeatureType::SetCenter(m2::PointD const & pt) ASSERT_EQUAL(GetFeatureType(), GEOM_POINT, ("Only for point feature.")); m_center = pt; m_limitRect.Add(m_center); - m_pointsParsed = m_trianglesParsed = true; + m_parsed.m_points = m_parsed.m_triangles = true; } namespace @@ -297,26 +273,32 @@ namespace } } -string FeatureType::DebugString(int scale) const +string FeatureType::DebugString(int scale) { - ParseGeometryAndTriangles(scale); + ParseCommon(); + + Classificator const & c = classif(); + + string res = "Types"; + for (size_t i = 0; i < GetTypesCount(); ++i) + res += (" : " + c.GetReadableObjectName(m_types[i])); + res += "\n"; - string s = base_type::DebugString(); + res += m_params.DebugString(); + ParseGeometryAndTriangles(scale); switch (GetFeatureType()) { - case GEOM_POINT: - s += (" Center:" + DebugPrint(m_center)); - break; + case GEOM_POINT: res += (" Center:" + DebugPrint(m_center)); break; case GEOM_LINE: - s += " Points:"; - Points2String(s, m_points); + res += " Points:"; + Points2String(res, m_points); break; case GEOM_AREA: - s += " Triangles:"; - Points2String(s, m_triangles); + res += " Triangles:"; + Points2String(res, m_triangles); break; case GEOM_UNDEFINED: @@ -324,15 +306,10 @@ string FeatureType::DebugString(int scale) const break; } - return s; + return res; } -string DebugPrint(FeatureType const & ft) -{ - return ft.DebugString(FeatureType::BEST_GEOMETRY); -} - -bool FeatureType::IsEmptyGeometry(int scale) const +bool FeatureType::IsEmptyGeometry(int scale) { ParseGeometryAndTriangles(scale); @@ -344,7 +321,7 @@ bool FeatureType::IsEmptyGeometry(int scale) const } } -m2::RectD FeatureType::GetLimitRect(int scale) const +m2::RectD FeatureType::GetLimitRect(int scale) { ParseGeometryAndTriangles(scale); @@ -359,31 +336,31 @@ m2::RectD FeatureType::GetLimitRect(int scale) const return m_limitRect; } -void FeatureType::ParseGeometryAndTriangles(int scale) const +void FeatureType::ParseGeometryAndTriangles(int scale) { ParseGeometry(scale); ParseTriangles(scale); } -FeatureType::geom_stat_t FeatureType::GetGeometrySize(int scale) const +FeatureType::GeomStat FeatureType::GetGeometrySize(int scale) { uint32_t sz = ParseGeometry(scale); if (sz == 0 && !m_points.empty()) sz = m_innerStats.m_points; - return geom_stat_t(sz, m_points.size()); + return GeomStat(sz, m_points.size()); } -FeatureType::geom_stat_t FeatureType::GetTrianglesSize(int scale) const +FeatureType::GeomStat FeatureType::GetTrianglesSize(int scale) { uint32_t sz = ParseTriangles(scale); if (sz == 0 && !m_triangles.empty()) sz = m_innerStats.m_strips; - return geom_stat_t(sz, m_triangles.size()); + return GeomStat(sz, m_triangles.size()); } -void FeatureType::GetPreferredNames(string & primary, string & secondary) const +void FeatureType::GetPreferredNames(string & primary, string & secondary) { if (!HasName()) return; @@ -400,7 +377,8 @@ void FeatureType::GetPreferredNames(string & primary, string & secondary) const primary, secondary); } -void FeatureType::GetPreferredNames(bool allowTranslit, int8_t deviceLang, string & primary, string & secondary) const +void FeatureType::GetPreferredNames(bool allowTranslit, int8_t deviceLang, string & primary, + string & secondary) { if (!HasName()) return; @@ -416,7 +394,7 @@ void FeatureType::GetPreferredNames(bool allowTranslit, int8_t deviceLang, strin primary, secondary); } -void FeatureType::GetReadableName(string & name) const +void FeatureType::GetReadableName(string & name) { if (!HasName()) return; @@ -433,7 +411,7 @@ void FeatureType::GetReadableName(string & name) const name); } -void FeatureType::GetReadableName(bool allowTranslit, int8_t deviceLang, string & name) const +void FeatureType::GetReadableName(bool allowTranslit, int8_t deviceLang, string & name) { if (!HasName()) return; @@ -448,7 +426,7 @@ void FeatureType::GetReadableName(bool allowTranslit, int8_t deviceLang, string ::GetReadableName(mwmInfo->GetRegionData(), GetNames(), deviceLang, allowTranslit, name); } -string FeatureType::GetHouseNumber() const +string FeatureType::GetHouseNumber() { ParseCommon(); return m_params.house.Get(); @@ -462,7 +440,7 @@ void FeatureType::SetHouseNumber(string const & number) m_params.house.Set(number); } -bool FeatureType::GetName(int8_t lang, string & name) const +bool FeatureType::GetName(int8_t lang, string & name) { if (!HasName()) return false; @@ -471,31 +449,16 @@ bool FeatureType::GetName(int8_t lang, string & name) const return m_params.name.GetString(lang, name); } -uint8_t FeatureType::GetRank() const +uint8_t FeatureType::GetRank() { ParseCommon(); return m_params.rank; } -uint64_t FeatureType::GetPopulation() const -{ - return feature::RankToPopulation(GetRank()); -} +uint64_t FeatureType::GetPopulation() { return feature::RankToPopulation(GetRank()); } -string FeatureType::GetRoadNumber() const +string FeatureType::GetRoadNumber() { ParseCommon(); return m_params.ref; } - -void FeatureType::SwapGeometry(FeatureType & r) -{ - ASSERT_EQUAL(m_pointsParsed, r.m_pointsParsed, ()); - ASSERT_EQUAL(m_trianglesParsed, r.m_trianglesParsed, ()); - - if (m_pointsParsed) - m_points.swap(r.m_points); - - if (m_trianglesParsed) - m_triangles.swap(r.m_triangles); -} diff --git a/indexer/feature.hpp b/indexer/feature.hpp index 550473890d..957a204b05 100644 --- a/indexer/feature.hpp +++ b/indexer/feature.hpp @@ -8,10 +8,12 @@ #include "base/buffer_vector.hpp" -#include "std/function.hpp" -#include "std/iterator.hpp" -#include "std/string.hpp" -#include "std/utility.hpp" +#include <cstdint> +#include <functional> +#include <iterator> +#include <string> +#include <utility> +#include <vector> namespace feature { @@ -19,77 +21,40 @@ class LoaderBase; class LoaderCurrent; } -namespace old_101 -{ -namespace feature -{ -class LoaderImpl; -} -} - namespace osm { class EditableMapObject; } -/// Base feature class for storing common data (without geometry). -class FeatureBase +// Lazy feature loader. Loads needed data and caches it. +class FeatureType { public: + using Buffer = char const *; - using TBuffer = char const *; - - void Deserialize(feature::LoaderBase * pLoader, TBuffer buffer); + feature::EGeomType GetFeatureType() const; + FeatureParamsBase & GetParams() { return m_params; } - /// @name Parse functions. Do simple dispatching to m_pLoader. - //@{ - void ParseTypes() const; - void ParseCommon() const; - //@} + uint8_t GetTypesCount() const { return (m_header & feature::HEADER_TYPE_MASK) + 1; } - feature::EGeomType GetFeatureType() const; - FeatureParamsBase & GetParams() {return m_params;} + bool HasName() const { return (m_header & feature::HEADER_HAS_NAME) != 0; } - inline uint8_t GetTypesCount() const - { - return ((Header() & feature::HEADER_TYPE_MASK) + 1); - } + void SetTypes(uint32_t const (&types)[feature::kMaxTypesCount], uint32_t count); - inline int8_t GetLayer() const - { - if (!(Header() & feature::HEADER_HAS_LAYER)) - return 0; + void Deserialize(feature::LoaderBase * loader, Buffer buffer); - ParseCommon(); - return m_params.layer; - } + void ParseTypes(); + void ParseCommon(); - inline bool HasName() const + m2::PointD GetCenter() { - return (Header() & feature::HEADER_HAS_NAME) != 0; + ASSERT_EQUAL(GetFeatureType(), feature::GEOM_POINT, ()); + ParseCommon(); + return m_center; } - // Array with 64 strings ??? Use ForEachName instead! - /* - class GetNamesFn - { - public: - string m_names[64]; - char m_langs[64]; - size_t m_size; - - GetNamesFn() : m_size(0) {} - bool operator() (char lang, string const & name) - { - m_names[m_size++] = name; - m_langs[m_size] = lang; - return true; - } - }; - */ - template <class T> - inline bool ForEachName(T && fn) const + bool ForEachName(T && fn) { if (!HasName()) return false; @@ -99,21 +64,8 @@ public: return true; } - inline m2::RectD GetLimitRect() const - { - ASSERT ( m_limitRect.IsValid(), () ); - return m_limitRect; - } - - inline m2::PointD GetCenter() const - { - ASSERT_EQUAL ( GetFeatureType(), feature::GEOM_POINT, () ); - ParseCommon(); - return m_center; - } - template <typename ToDo> - void ForEachType(ToDo && f) const + void ForEachType(ToDo && f) { ParseTypes(); @@ -122,48 +74,14 @@ public: f(m_types[i]); } - void SetTypes(uint32_t const (&types)[feature::kMaxTypesCount], uint32_t count); - -protected: - /// @name Need for FeatureBuilder. - //@{ - friend class FeatureBuilder1; - inline void SetHeader(uint8_t h) { m_header = h; } - //@} - - string DebugString() const; - - inline uint8_t Header() const { return m_header; } - -protected: - feature::LoaderBase * m_pLoader; - - uint8_t m_header = 0; - - mutable uint32_t m_types[feature::kMaxTypesCount]; - - mutable FeatureParamsBase m_params; - - mutable m2::PointD m_center; - - mutable m2::RectD m_limitRect; - - mutable bool m_typesParsed = false; - mutable bool m_commonParsed = false; - - friend class feature::LoaderCurrent; - friend class old_101::feature::LoaderImpl; -}; - -/// Working feature class with geometry. -class FeatureType : public FeatureBase -{ - typedef FeatureBase base_type; - - FeatureID m_id; + int8_t GetLayer() + { + if (!(m_header & feature::HEADER_HAS_LAYER)) + return 0; -public: - void Deserialize(feature::LoaderBase * pLoader, TBuffer buffer); + ParseCommon(); + return m_params.layer; + } /// @name Editor methods. //@{ @@ -171,32 +89,33 @@ public: /// Replaces all FeatureType's components. void ReplaceBy(osm::EditableMapObject const & ef); - StringUtf8Multilang const & GetNames() const; + StringUtf8Multilang const & GetNames(); void SetNames(StringUtf8Multilang const & newNames); void SetMetadata(feature::Metadata const & newMetadata); void UpdateHeader(bool commonParsed, bool metadataParsed); - bool UpdateMetadataValue(string const & key, string const & value); - void ForEachMetadataItem(bool skipSponsored, - function<void(string const & tag, string const & value)> const & fn) const; + bool UpdateMetadataValue(std::string const & key, std::string const & value); + void ForEachMetadataItem( + bool skipSponsored, + std::function<void(std::string const & tag, std::string const & value)> const & fn) const; void SetCenter(m2::PointD const &pt); //@} - inline void SetID(FeatureID const & id) { m_id = id; } - inline FeatureID const & GetID() const { return m_id; } + void SetID(FeatureID const & id) { m_id = id; } + FeatureID const & GetID() const { return m_id; } - /// @name Parse functions. Do simple dispatching to m_pLoader. + /// @name Parse functions. Do simple dispatching to m_loader. //@{ /// Super-method to call all possible Parse* methods. - void ParseEverything() const; - void ParseHeader2() const; + void ParseEverything(); + void ParseHeader2(); - void ResetGeometry() const; - uint32_t ParseGeometry(int scale) const; - uint32_t ParseTriangles(int scale) const; + void ResetGeometry(); + uint32_t ParseGeometry(int scale); + uint32_t ParseTriangles(int scale); - void ParseMetadata() const; + void ParseMetadata(); //@} /// @name Geometry. @@ -204,12 +123,12 @@ public: /// This constant values should be equal with feature::LoaderBase implementation. enum { BEST_GEOMETRY = -1, WORST_GEOMETRY = -2 }; - m2::RectD GetLimitRect(int scale) const; + m2::RectD GetLimitRect(int scale); - bool IsEmptyGeometry(int scale) const; + bool IsEmptyGeometry(int scale); - template <typename TFunctor> - void ForEachPoint(TFunctor && f, int scale) const + template <typename Functor> + void ForEachPoint(Functor && f, int scale) { ParseGeometry(scale); @@ -226,21 +145,21 @@ public: } } - inline size_t GetPointsCount() const + size_t GetPointsCount() const { - ASSERT(m_pointsParsed, ()); + ASSERT(m_parsed.m_points, ()); return m_points.size(); } - inline m2::PointD const & GetPoint(size_t i) const + m2::PointD const & GetPoint(size_t i) const { ASSERT_LESS(i, m_points.size(), ()); - ASSERT(m_pointsParsed, ()); + ASSERT(m_parsed.m_points, ()); return m_points[i]; } template <typename TFunctor> - void ForEachTriangle(TFunctor && f, int scale) const + void ForEachTriangle(TFunctor && f, int scale) { ParseTriangles(scale); @@ -251,55 +170,48 @@ public: } } - inline vector<m2::PointD> GetTriangesAsPoints(int scale) const + std::vector<m2::PointD> GetTriangesAsPoints(int scale) { ParseTriangles(scale); - return {begin(m_triangles), end(m_triangles)}; + return {std::begin(m_triangles), std::end(m_triangles)}; } - template <typename TFunctor> - void ForEachTriangleEx(TFunctor && f, int scale) const + template <typename Functor> + void ForEachTriangleEx(Functor && f, int scale) const { f.StartPrimitive(m_triangles.size()); - ForEachTriangle(forward<TFunctor>(f), scale); + ForEachTriangle(forward<Functor>(f), scale); f.EndPrimitive(); } //@} - /// For test cases only. - string DebugString(int scale) const; - friend string DebugPrint(FeatureType const & ft); + std::string DebugString(int scale); - string GetHouseNumber() const; + std::string GetHouseNumber(); /// Needed for Editor, to change house numbers in runtime. - void SetHouseNumber(string const & number); + void SetHouseNumber(std::string const & number); /// @name Get names for feature. /// @param[out] defaultName corresponds to osm tag "name" /// @param[out] intName optionally choosen from tags "name:<lang_code>" by the algorithm //@{ /// Just get feature names. - void GetPreferredNames(string & defaultName, string & intName) const; - void GetPreferredNames(bool allowTranslit, int8_t deviceLang, string & defaultName, string & intName) const; + void GetPreferredNames(std::string & defaultName, std::string & intName); + void GetPreferredNames(bool allowTranslit, int8_t deviceLang, std::string & defaultName, + std::string & intName); /// Get one most suitable name for user. - void GetReadableName(string & name) const; - void GetReadableName(bool allowTranslit, int8_t deviceLang, string & name) const; + void GetReadableName(std::string & name); + void GetReadableName(bool allowTranslit, int8_t deviceLang, std::string & name); static int8_t const DEFAULT_LANG = StringUtf8Multilang::kDefaultCode; - bool GetName(int8_t lang, string & name) const; + bool GetName(int8_t lang, std::string & name); //@} - uint8_t GetRank() const; - uint64_t GetPopulation() const; - string GetRoadNumber() const; - - inline feature::Metadata const & GetMetadata() const - { - ParseMetadata(); - return m_metadata; - } + uint8_t GetRank(); + uint64_t GetPopulation(); + std::string GetRoadNumber(); - inline feature::Metadata & GetMetadata() + feature::Metadata & GetMetadata() { ParseMetadata(); return m_metadata; @@ -307,12 +219,9 @@ public: /// @name Statistic functions. //@{ - inline void ParseBeforeStatistic() const - { - ParseHeader2(); - } + void ParseBeforeStatistic() { ParseHeader2(); } - struct inner_geom_stat_t + struct InnerGeomStat { uint32_t m_points, m_strips, m_size; @@ -322,66 +231,85 @@ public: } }; - inner_geom_stat_t GetInnerStatistic() const { return m_innerStats; } + InnerGeomStat GetInnerStatistic() const { return m_innerStats; } - struct geom_stat_t + struct GeomStat { uint32_t m_size, m_count; - geom_stat_t(uint32_t sz, size_t count) - : m_size(sz), m_count(static_cast<uint32_t>(count)) - { - } + GeomStat(uint32_t sz, size_t count) : m_size(sz), m_count(static_cast<uint32_t>(count)) {} - geom_stat_t() : m_size(0), m_count(0) {} + GeomStat() : m_size(0), m_count(0) {} }; - geom_stat_t GetGeometrySize(int scale) const; - geom_stat_t GetTrianglesSize(int scale) const; + GeomStat GetGeometrySize(int scale); + GeomStat GetTrianglesSize(int scale); //@} - void SwapGeometry(FeatureType & r); +private: + struct ParsedFlags + { + bool m_types = false; + bool m_common = false; + bool m_header2 = false; + bool m_points = false; + bool m_triangles = false; + bool m_metadata = false; + }; - inline void SwapPoints(buffer_vector<m2::PointD, 32> & points) const + struct Offsets { - ASSERT(m_pointsParsed, ()); - return m_points.swap(points); - } + static uint32_t const m_types = 1; + uint32_t m_common; + uint32_t m_header2; + }; -private: - void ParseGeometryAndTriangles(int scale) const; + void ParseGeometryAndTriangles(int scale); + + feature::LoaderBase * m_loader; + Buffer m_data = 0; + + uint8_t m_header = 0; + + uint32_t m_types[feature::kMaxTypesCount]; + + FeatureID m_id; + FeatureParamsBase m_params; + + m2::PointD m_center; + m2::RectD m_limitRect; // For better result this value should be greater than 17 // (number of points in inner triangle-strips). static const size_t static_buffer = 32; + using Points = buffer_vector<m2::PointD, static_buffer>; + Points m_points, m_triangles; + feature::Metadata m_metadata; - typedef buffer_vector<m2::PointD, static_buffer> points_t; - mutable points_t m_points, m_triangles; - mutable feature::Metadata m_metadata; - - mutable bool m_header2Parsed = false; - mutable bool m_pointsParsed = false; - mutable bool m_trianglesParsed = false; - mutable bool m_metadataParsed = false; + ParsedFlags m_parsed; + Offsets m_offsets; + uint32_t m_ptsSimpMask; + using GeometryOffsets = buffer_vector<uint32_t, feature::DataHeader::MAX_SCALES_COUNT>; + GeometryOffsets m_ptsOffsets, m_trgOffsets; - mutable inner_geom_stat_t m_innerStats; + InnerGeomStat m_innerStats; friend class feature::LoaderCurrent; - friend class old_101::feature::LoaderImpl; + friend class feature::LoaderBase; }; namespace feature { - template <class IterT> - void CalcRect(IterT b, IterT e, m2::RectD & rect) - { - while (b != e) - rect.Add(*b++); - } +template <class Iter> +void CalcRect(Iter b, Iter e, m2::RectD & rect) +{ + while (b != e) + rect.Add(*b++); +} - template <class TCont> - void CalcRect(TCont const & points, m2::RectD & rect) - { - CalcRect(points.begin(), points.end(), rect); - } +template <class Cont> +void CalcRect(Cont const & points, m2::RectD & rect) +{ + CalcRect(points.begin(), points.end(), rect); +} } diff --git a/indexer/feature_algo.cpp b/indexer/feature_algo.cpp index 25d15e9e58..d0b2ef0047 100644 --- a/indexer/feature_algo.cpp +++ b/indexer/feature_algo.cpp @@ -13,7 +13,7 @@ namespace feature /// @returns point on a feature that is the closest to f.GetLimitRect().Center(). /// It is used by many ednities in the core of mapsme. Do not modify it's /// logic if you really-really know what you are doing. -m2::PointD GetCenter(FeatureType const & f, int scale) +m2::PointD GetCenter(FeatureType & f, int scale) { EGeomType const type = f.GetFeatureType(); switch (type) @@ -38,12 +38,9 @@ m2::PointD GetCenter(FeatureType const & f, int scale) } } -m2::PointD GetCenter(FeatureType const & f) -{ - return GetCenter(f, FeatureType::BEST_GEOMETRY); -} +m2::PointD GetCenter(FeatureType & f) { return GetCenter(f, FeatureType::BEST_GEOMETRY); } -double GetMinDistanceMeters(FeatureType const & ft, m2::PointD const & pt, int scale) +double GetMinDistanceMeters(FeatureType & ft, m2::PointD const & pt, int scale) { double res = numeric_limits<double>::max(); auto updateDistanceFn = [&] (m2::PointD const & p) @@ -104,7 +101,7 @@ double GetMinDistanceMeters(FeatureType const & ft, m2::PointD const & pt, int s return res; } -double GetMinDistanceMeters(FeatureType const & ft, m2::PointD const & pt) +double GetMinDistanceMeters(FeatureType & ft, m2::PointD const & pt) { return GetMinDistanceMeters(ft, pt, FeatureType::BEST_GEOMETRY); } diff --git a/indexer/feature_algo.hpp b/indexer/feature_algo.hpp index f30cd010d1..2528436394 100644 --- a/indexer/feature_algo.hpp +++ b/indexer/feature_algo.hpp @@ -6,11 +6,10 @@ class FeatureType; namespace feature { +m2::PointD GetCenter(FeatureType & f, int scale); +m2::PointD GetCenter(FeatureType & f); -m2::PointD GetCenter(FeatureType const & f, int scale); -m2::PointD GetCenter(FeatureType const & f); - -double GetMinDistanceMeters(FeatureType const & ft, m2::PointD const & pt, int scale); -double GetMinDistanceMeters(FeatureType const & ft, m2::PointD const & pt); +double GetMinDistanceMeters(FeatureType & ft, m2::PointD const & pt, int scale); +double GetMinDistanceMeters(FeatureType & ft, m2::PointD const & pt); } // namespace feature diff --git a/indexer/feature_covering.cpp b/indexer/feature_covering.cpp index ce21bc6554..8a0fe0a016 100644 --- a/indexer/feature_covering.cpp +++ b/indexer/feature_covering.cpp @@ -111,7 +111,7 @@ public: }; template <int DEPTH_LEVELS> -void GetIntersection(FeatureType const & f, FeatureIntersector<DEPTH_LEVELS> & fIsect) +void GetIntersection(FeatureType & f, FeatureIntersector<DEPTH_LEVELS> & fIsect) { // We need to cover feature for the best geometry, because it's indexed once for the // first top level scale. Do reset current cached geometry first. @@ -161,7 +161,7 @@ vector<int64_t> CoverLocality(indexer::LocalityObject const & o, int cellDepth) namespace covering { -vector<int64_t> CoverFeature(FeatureType const & f, int cellDepth, uint64_t cellPenaltyArea) +vector<int64_t> CoverFeature(FeatureType & f, int cellDepth, uint64_t cellPenaltyArea) { FeatureIntersector<RectId::DEPTH_LEVELS> fIsect; GetIntersection(f, fIsect); diff --git a/indexer/feature_covering.hpp b/indexer/feature_covering.hpp index aa7abb55e9..a5c7a87a5e 100644 --- a/indexer/feature_covering.hpp +++ b/indexer/feature_covering.hpp @@ -28,8 +28,7 @@ typedef std::pair<int64_t, int64_t> Interval; typedef std::vector<Interval> Intervals; // Cover feature with RectIds and return their integer representations. -std::vector<int64_t> CoverFeature(FeatureType const & feature, int cellDepth, - uint64_t cellPenaltyArea); +std::vector<int64_t> CoverFeature(FeatureType & feature, int cellDepth, uint64_t cellPenaltyArea); std::vector<int64_t> CoverGeoObject(indexer::LocalityObject const & o, int cellDepth); diff --git a/indexer/feature_data.cpp b/indexer/feature_data.cpp index fb5ed1f571..9fc472137d 100644 --- a/indexer/feature_data.cpp +++ b/indexer/feature_data.cpp @@ -6,14 +6,16 @@ #include "indexer/ftypes_matcher.hpp" #include "base/assert.hpp" +#include "base/macros.hpp" #include "base/stl_add.hpp" #include "base/string_utils.hpp" -#include "std/algorithm.hpp" -#include "std/bind.hpp" -#include "std/vector.hpp" +#include <algorithm> +#include <functional> +#include <vector> using namespace feature; +using namespace std; //////////////////////////////////////////////////////////////////////////////////// // TypesHolder implementation @@ -32,8 +34,7 @@ string DebugPrint(TypesHolder const & holder) return s; } -TypesHolder::TypesHolder(FeatureBase const & f) -: m_size(0), m_geoType(f.GetFeatureType()) +TypesHolder::TypesHolder(FeatureType & f) : m_size(0), m_geoType(f.GetFeatureType()) { f.ForEachType([this](uint32_t type) { @@ -171,7 +172,7 @@ void TypesHolder::SortBySpec() // Put "very common" types to the end of possible PP-description types. static UselessTypesChecker checker; - (void) RemoveIfKeepValid(m_types, m_types + m_size, bind<bool>(cref(checker), _1)); + UNUSED_VALUE(RemoveIfKeepValid(m_types, m_types + m_size, [](uint32_t t) { return checker(t); })); } vector<string> TypesHolder::ToObjectNames() const diff --git a/indexer/feature_data.hpp b/indexer/feature_data.hpp index 3ddbc36096..b6761bbdcb 100644 --- a/indexer/feature_data.hpp +++ b/indexer/feature_data.hpp @@ -14,7 +14,7 @@ #include "std/utility.hpp" struct FeatureParamsBase; -class FeatureBase; +class FeatureType; namespace feature { @@ -50,14 +50,10 @@ namespace feature class TypesHolder { - uint32_t m_types[kMaxTypesCount]; - size_t m_size; - - EGeomType m_geoType; - public: - TypesHolder(EGeomType geoType = GEOM_UNDEFINED) : m_size(0), m_geoType(geoType) {} - TypesHolder(FeatureBase const & f); + TypesHolder() = default; + explicit TypesHolder(EGeomType geoType) : m_geoType(geoType) {} + explicit TypesHolder(FeatureType & f); void Assign(uint32_t type) { @@ -119,6 +115,12 @@ namespace feature bool Equals(TypesHolder const & other) const; vector<string> ToObjectNames() const; + + private: + uint32_t m_types[kMaxTypesCount]; + size_t m_size = 0; + + EGeomType m_geoType = GEOM_UNDEFINED; }; string DebugPrint(TypesHolder const & holder); diff --git a/indexer/feature_loader.cpp b/indexer/feature_loader.cpp index 57c25819ee..ba5dd40ffb 100644 --- a/indexer/feature_loader.cpp +++ b/indexer/feature_loader.cpp @@ -1,7 +1,6 @@ #include "indexer/feature_loader.hpp" #include "indexer/classificator.hpp" -#include "indexer/feature.hpp" #include "indexer/scales.hpp" #include "coding/byte_stream.hpp" @@ -18,53 +17,49 @@ namespace feature { -uint8_t LoaderCurrent::GetHeader() -{ - return Header(); -} +uint8_t LoaderCurrent::GetHeader(FeatureType const & ft) const { return Header(ft.m_data); } -void LoaderCurrent::ParseTypes() +void LoaderCurrent::ParseTypes(FeatureType & ft) const { Classificator & c = classif(); - ArrayByteSource source(DataPtr() + m_TypesOffset); + ArrayByteSource source(ft.m_data + ft.m_offsets.m_types); - size_t const count = m_pF->GetTypesCount(); + size_t const count = ft.GetTypesCount(); uint32_t index = 0; try { for (size_t i = 0; i < count; ++i) { index = ReadVarUint<uint32_t>(source); - m_pF->m_types[i] = c.GetTypeForIndex(index); + ft.m_types[i] = c.GetTypeForIndex(index); } } catch (std::out_of_range const & ex) { - LOG(LERROR, ("Incorrect type index for feature. FeatureID:", m_pF->m_id, - ". Incorrect index:", index, ". Loaded feature types:", m_pF->m_types, - ". Total count of types:", count, ". Header:", m_pF->m_header, - ". Exception:", ex.what())); + LOG(LERROR, ("Incorrect type index for feature.FeatureID:", ft.m_id, ". Incorrect index:", + index, ". Loaded feature types:", ft.m_types, ". Total count of types:", count, + ". Header:", ft.m_header, ". Exception:", ex.what())); throw; } - m_CommonOffset = CalcOffset(source); + ft.m_offsets.m_common = CalcOffset(source, ft.m_data); } -void LoaderCurrent::ParseCommon() +void LoaderCurrent::ParseCommon(FeatureType & ft) const { - ArrayByteSource source(DataPtr() + m_CommonOffset); + ArrayByteSource source(ft.m_data + ft.m_offsets.m_common); - uint8_t const h = Header(); - m_pF->m_params.Read(source, h); + uint8_t const h = Header(ft.m_data); + ft.m_params.Read(source, h); - if (m_pF->GetFeatureType() == GEOM_POINT) + if (ft.GetFeatureType() == GEOM_POINT) { - m_pF->m_center = serial::LoadPoint(source, GetDefGeometryCodingParams()); - m_pF->m_limitRect.Add(m_pF->m_center); + ft.m_center = serial::LoadPoint(source, GetDefGeometryCodingParams()); + ft.m_limitRect.Add(ft.m_center); } - m_Header2Offset = CalcOffset(source); + ft.m_offsets.m_header2 = CalcOffset(source, ft.m_data); } namespace @@ -113,13 +108,13 @@ namespace } } -void LoaderCurrent::ParseHeader2() +void LoaderCurrent::ParseHeader2(FeatureType & ft) const { uint8_t ptsCount = 0, ptsMask = 0, trgCount = 0, trgMask = 0; - BitSource bitSource(DataPtr() + m_Header2Offset); + BitSource bitSource(ft.m_data + ft.m_offsets.m_header2); - uint8_t const typeMask = Header() & HEADER_GEOTYPE_MASK; + uint8_t const typeMask = Header(ft.m_data) & HEADER_GEOTYPE_MASK; if (typeMask == HEADER_GEOM_LINE) { ptsCount = bitSource.Read(4); @@ -149,20 +144,20 @@ void LoaderCurrent::ParseHeader2() for (int i = 0; i < count; ++i) { uint32_t mask = ReadByte(src); - m_ptsSimpMask += (mask << (i << 3)); + ft.m_ptsSimpMask += (mask << (i << 3)); } char const * start = src.PtrC(); - src = ArrayByteSource(serial::LoadInnerPath(start, ptsCount, cp, m_pF->m_points)); + src = ArrayByteSource(serial::LoadInnerPath(start, ptsCount, cp, ft.m_points)); - m_pF->m_innerStats.m_points = static_cast<uint32_t>(src.PtrC() - start); + ft.m_innerStats.m_points = static_cast<uint32_t>(src.PtrC() - start); } else { - m_pF->m_points.push_back(serial::LoadPoint(src, cp)); + ft.m_points.push_back(serial::LoadPoint(src, cp)); - ReadOffsets(src, ptsMask, m_ptsOffsets); + ReadOffsets(src, ptsMask, ft.m_ptsOffsets); } } else if (typeMask == HEADER_GEOM_AREA) @@ -172,95 +167,95 @@ void LoaderCurrent::ParseHeader2() trgCount += 2; char const * start = static_cast<char const *>(src.PtrC()); - src = ArrayByteSource(serial::LoadInnerTriangles(start, trgCount, cp, m_pF->m_triangles)); - m_pF->m_innerStats.m_strips = static_cast<uint32_t>(src.PtrC() - start); + src = ArrayByteSource(serial::LoadInnerTriangles(start, trgCount, cp, ft.m_triangles)); + ft.m_innerStats.m_strips = static_cast<uint32_t>(src.PtrC() - start); } else { - ReadOffsets(src, trgMask, m_trgOffsets); + ReadOffsets(src, trgMask, ft.m_trgOffsets); } } - m_pF->m_innerStats.m_size = static_cast<uint32_t>(src.PtrC() - DataPtr()); + ft.m_innerStats.m_size = static_cast<uint32_t>(src.PtrC() - ft.m_data); } -uint32_t LoaderCurrent::ParseGeometry(int scale) +uint32_t LoaderCurrent::ParseGeometry(int scale, FeatureType & ft) const { uint32_t sz = 0; - if ((Header() & HEADER_GEOTYPE_MASK) == HEADER_GEOM_LINE) + if ((Header(ft.m_data) & HEADER_GEOTYPE_MASK) == HEADER_GEOM_LINE) { - size_t const count = m_pF->m_points.size(); + size_t const count = ft.m_points.size(); if (count < 2) { ASSERT_EQUAL ( count, 1, () ); // outer geometry - int const ind = GetScaleIndex(scale, m_ptsOffsets); + int const ind = GetScaleIndex(scale, ft.m_ptsOffsets); if (ind != -1) { ReaderSource<FilesContainerR::TReader> src(m_Info.GetGeometryReader(ind)); - src.Skip(m_ptsOffsets[ind]); + src.Skip(ft.m_ptsOffsets[ind]); serial::GeometryCodingParams cp = GetGeometryCodingParams(ind); - cp.SetBasePoint(m_pF->m_points[0]); - serial::LoadOuterPath(src, cp, m_pF->m_points); + cp.SetBasePoint(ft.m_points[0]); + serial::LoadOuterPath(src, cp, ft.m_points); - sz = static_cast<uint32_t>(src.Pos() - m_ptsOffsets[ind]); + sz = static_cast<uint32_t>(src.Pos() - ft.m_ptsOffsets[ind]); } } else { // filter inner geometry - FeatureType::points_t points; + FeatureType::Points points; points.reserve(count); int const scaleIndex = GetScaleIndex(scale); ASSERT_LESS ( scaleIndex, m_Info.GetScalesCount(), () ); - points.push_back(m_pF->m_points.front()); + points.push_back(ft.m_points.front()); for (size_t i = 1; i + 1 < count; ++i) { // check for point visibility in needed scaleIndex - if (static_cast<int>((m_ptsSimpMask >> (2 * (i - 1))) & 0x3) <= scaleIndex) - points.push_back(m_pF->m_points[i]); + if (static_cast<int>((ft.m_ptsSimpMask >> (2 * (i - 1))) & 0x3) <= scaleIndex) + points.push_back(ft.m_points[i]); } - points.push_back(m_pF->m_points.back()); + points.push_back(ft.m_points.back()); - m_pF->m_points.swap(points); + ft.m_points.swap(points); } - CalcRect(m_pF->m_points, m_pF->m_limitRect); + CalcRect(ft.m_points, ft.m_limitRect); } return sz; } -uint32_t LoaderCurrent::ParseTriangles(int scale) +uint32_t LoaderCurrent::ParseTriangles(int scale, FeatureType & ft) const { uint32_t sz = 0; - if ((Header() & HEADER_GEOTYPE_MASK) == HEADER_GEOM_AREA) + if ((Header(ft.m_data) & HEADER_GEOTYPE_MASK) == HEADER_GEOM_AREA) { - if (m_pF->m_triangles.empty()) + if (ft.m_triangles.empty()) { - auto const ind = GetScaleIndex(scale, m_trgOffsets); + auto const ind = GetScaleIndex(scale, ft.m_trgOffsets); if (ind != -1) { ReaderSource<FilesContainerR::TReader> src(m_Info.GetTrianglesReader(ind)); - src.Skip(m_trgOffsets[ind]); - serial::LoadOuterTriangles(src, GetGeometryCodingParams(ind), m_pF->m_triangles); + src.Skip(ft.m_trgOffsets[ind]); + serial::LoadOuterTriangles(src, GetGeometryCodingParams(ind), ft.m_triangles); - sz = static_cast<uint32_t>(src.Pos() - m_trgOffsets[ind]); + sz = static_cast<uint32_t>(src.Pos() - ft.m_trgOffsets[ind]); } } - CalcRect(m_pF->m_triangles, m_pF->m_limitRect); + CalcRect(ft.m_triangles, ft.m_limitRect); } return sz; } -void LoaderCurrent::ParseMetadata() +void LoaderCurrent::ParseMetadata(FeatureType & ft) const { try { @@ -271,22 +266,20 @@ void LoaderCurrent::ParseMetadata() }; DDVector<TMetadataIndexEntry, FilesContainerR::TReader> idx(m_Info.GetMetadataIndexReader()); - auto it = lower_bound( - idx.begin(), idx.end(), - TMetadataIndexEntry{static_cast<uint32_t>(m_pF->m_id.m_index), 0}, - [](TMetadataIndexEntry const & v1, TMetadataIndexEntry const & v2) - { - return v1.key < v2.key; - }); + auto it = lower_bound(idx.begin(), idx.end(), + TMetadataIndexEntry{static_cast<uint32_t>(ft.m_id.m_index), 0}, + [](TMetadataIndexEntry const & v1, TMetadataIndexEntry const & v2) { + return v1.key < v2.key; + }); - if (it != idx.end() && m_pF->m_id.m_index == it->key) + if (it != idx.end() && ft.m_id.m_index == it->key) { ReaderSource<FilesContainerR::TReader> src(m_Info.GetMetadataReader()); src.Skip(it->value); if (m_Info.GetMWMFormat() >= version::Format::v8) - m_pF->m_metadata.Deserialize(src); + ft.m_metadata.Deserialize(src); else - m_pF->m_metadata.DeserializeFromMWMv7OrLower(src); + ft.m_metadata.DeserializeFromMWMv7OrLower(src); } } catch (Reader::OpenException const &) @@ -316,7 +309,7 @@ int LoaderCurrent::GetScaleIndex(int scale) const } } -int LoaderCurrent::GetScaleIndex(int scale, offsets_t const & offsets) const +int LoaderCurrent::GetScaleIndex(int scale, FeatureType::GeometryOffsets const & offsets) const { int ind = -1; int const count = static_cast<int>(offsets.size()); diff --git a/indexer/feature_loader.hpp b/indexer/feature_loader.hpp index f10ad707a0..789643d5b3 100644 --- a/indexer/feature_loader.hpp +++ b/indexer/feature_loader.hpp @@ -1,13 +1,12 @@ #pragma once #include "indexer/feature_loader_base.hpp" +#include "indexer/feature.hpp" namespace feature { class LoaderCurrent : public LoaderBase { - typedef LoaderBase BaseT; - /// Get the index for geometry serialization. /// @param[in] scale: /// -1 : index for the best geometry @@ -15,18 +14,18 @@ namespace feature /// default : needed geometry //@{ int GetScaleIndex(int scale) const; - int GetScaleIndex(int scale, offsets_t const & offsets) const; + int GetScaleIndex(int scale, FeatureType::GeometryOffsets const & offsets) const; //@} public: - LoaderCurrent(SharedLoadInfo const & info) : BaseT(info) {} + LoaderCurrent(SharedLoadInfo const & info) : LoaderBase(info) {} /// LoaderBase overrides: - virtual uint8_t GetHeader() override; - void ParseTypes() override; - void ParseCommon() override; - void ParseHeader2() override; - uint32_t ParseGeometry(int scale) override; - uint32_t ParseTriangles(int scale) override; - void ParseMetadata() override; + uint8_t GetHeader(FeatureType const & ft) const override; + void ParseTypes(FeatureType & ft) const override; + void ParseCommon(FeatureType & ft) const override; + void ParseHeader2(FeatureType & ft) const override; + uint32_t ParseGeometry(int scale, FeatureType & ft) const override; + uint32_t ParseTriangles(int scale, FeatureType & ft) const override; + void ParseMetadata(FeatureType & ft) const override; }; } diff --git a/indexer/feature_loader_base.cpp b/indexer/feature_loader_base.cpp index 6abe4de1d4..f4c7a91d38 100644 --- a/indexer/feature_loader_base.cpp +++ b/indexer/feature_loader_base.cpp @@ -1,4 +1,5 @@ #include "indexer/feature_loader_base.hpp" + #include "indexer/feature_loader.hpp" #include "indexer/feature_impl.hpp" @@ -65,35 +66,20 @@ void SharedLoadInfo::CreateLoader() // LoaderBase implementation. //////////////////////////////////////////////////////////////////////////////////////////// -LoaderBase::LoaderBase(SharedLoadInfo const & info) - : m_Info(info), m_pF(0), m_Data(0) -{ -} +LoaderBase::LoaderBase(SharedLoadInfo const & info) : m_Info(info) {} -void LoaderBase::Init(TBuffer data) +uint32_t LoaderBase::GetTypesSize(FeatureType const & ft) const { - m_Data = data; - m_pF = 0; - - m_CommonOffset = m_Header2Offset = 0; - - ResetGeometry(); -} - -void LoaderBase::ResetGeometry() -{ - m_ptsSimpMask = 0; - - m_ptsOffsets.clear(); - m_trgOffsets.clear(); + return ft.m_offsets.m_common - ft.m_offsets.m_types; } -uint32_t LoaderBase::CalcOffset(ArrayByteSource const & source) const +uint32_t LoaderBase::CalcOffset(ArrayByteSource const & source, Buffer const data) const { - return static_cast<uint32_t>(source.PtrC() - DataPtr()); + return static_cast<uint32_t>(source.PtrC() - data); } -void LoaderBase::ReadOffsets(ArrayByteSource & src, uint8_t mask, offsets_t & offsets) const +void LoaderBase::ReadOffsets(ArrayByteSource & src, uint8_t mask, + FeatureType::GeometryOffsets & offsets) const { ASSERT ( offsets.empty(), () ); ASSERT_GREATER ( mask, 0, () ); diff --git a/indexer/feature_loader_base.hpp b/indexer/feature_loader_base.hpp index 3b5d40b25a..9a6ef2ab76 100644 --- a/indexer/feature_loader_base.hpp +++ b/indexer/feature_loader_base.hpp @@ -1,13 +1,13 @@ #pragma once #include "indexer/data_header.hpp" +#include "indexer/feature.hpp" #include "coding/file_container.hpp" #include "coding/geometry_coding.hpp" #include "std/noncopyable.hpp" -class FeatureType; class ArrayByteSource; namespace feature @@ -38,82 +38,60 @@ namespace feature LoaderBase * GetLoader() const { return m_loader; } - inline version::Format GetMWMFormat() const { return m_header.GetFormat(); } + version::Format GetMWMFormat() const { return m_header.GetFormat(); } - inline serial::GeometryCodingParams const & GetDefGeometryCodingParams() const + serial::GeometryCodingParams const & GetDefGeometryCodingParams() const { return m_header.GetDefGeometryCodingParams(); } - inline serial::GeometryCodingParams GetGeometryCodingParams(int scaleIndex) const + serial::GeometryCodingParams GetGeometryCodingParams(int scaleIndex) const { return m_header.GetGeometryCodingParams(scaleIndex); } - inline int GetScalesCount() const { return static_cast<int>(m_header.GetScalesCount()); } - inline int GetScale(int i) const { return m_header.GetScale(i); } - inline int GetLastScale() const { return m_header.GetLastScale(); } + int GetScalesCount() const { return static_cast<int>(m_header.GetScalesCount()); } + int GetScale(int i) const { return m_header.GetScale(i); } + int GetLastScale() const { return m_header.GetLastScale(); } }; class LoaderBase { public: LoaderBase(SharedLoadInfo const & info); - virtual ~LoaderBase() {} + virtual ~LoaderBase() = default; // It seems like no need to store a copy of buffer (see FeaturesVector). - using TBuffer = char const * ; + using Buffer = char const *; - /// @name Initialize functions. - //@{ - void Init(TBuffer data); - inline void InitFeature(FeatureType * p) { m_pF = p; } + virtual uint8_t GetHeader(FeatureType const & ft) const = 0; - void ResetGeometry(); - //@} + virtual void ParseTypes(FeatureType & ft) const = 0; + virtual void ParseCommon(FeatureType & ft) const = 0; + virtual void ParseHeader2(FeatureType & ft) const = 0; + virtual uint32_t ParseGeometry(int scale, FeatureType & ft) const = 0; + virtual uint32_t ParseTriangles(int scale, FeatureType & ft) const = 0; + virtual void ParseMetadata(FeatureType & ft) const = 0; - virtual uint8_t GetHeader() = 0; - - virtual void ParseTypes() = 0; - virtual void ParseCommon() = 0; - virtual void ParseHeader2() = 0; - virtual uint32_t ParseGeometry(int scale) = 0; - virtual uint32_t ParseTriangles(int scale) = 0; - virtual void ParseMetadata() = 0; - - inline uint32_t GetTypesSize() const { return m_CommonOffset - m_TypesOffset; } + uint32_t GetTypesSize(FeatureType const & ft) const; protected: - inline char const * DataPtr() const { return m_Data; } - - uint32_t CalcOffset(ArrayByteSource const & source) const; + uint32_t CalcOffset(ArrayByteSource const & source, Buffer const data) const; - inline serial::GeometryCodingParams const & GetDefGeometryCodingParams() const + serial::GeometryCodingParams const & GetDefGeometryCodingParams() const { return m_Info.GetDefGeometryCodingParams(); } - inline serial::GeometryCodingParams GetGeometryCodingParams(int scaleIndex) const + serial::GeometryCodingParams GetGeometryCodingParams(int scaleIndex) const { return m_Info.GetGeometryCodingParams(scaleIndex); } - uint8_t Header() const { return static_cast<uint8_t>(*DataPtr()); } - - protected: - SharedLoadInfo const & m_Info; - FeatureType * m_pF; + uint8_t Header(Buffer const data) const { return static_cast<uint8_t>(*data); } - TBuffer m_Data; - - static uint32_t const m_TypesOffset = 1; - uint32_t m_CommonOffset, m_Header2Offset; - - uint32_t m_ptsSimpMask; - - typedef buffer_vector<uint32_t, DataHeader::MAX_SCALES_COUNT> offsets_t; - offsets_t m_ptsOffsets, m_trgOffsets; + void ReadOffsets(ArrayByteSource & src, uint8_t mask, + FeatureType::GeometryOffsets & offsets) const; + SharedLoadInfo const & m_Info; static uint32_t const s_InvalidOffset = uint32_t(-1); - - void ReadOffsets(ArrayByteSource & src, uint8_t mask, offsets_t & offsets) const; }; } diff --git a/indexer/feature_visibility.cpp b/indexer/feature_visibility.cpp index 7161d8cf45..0d105456bf 100644 --- a/indexer/feature_visibility.cpp +++ b/indexer/feature_visibility.cpp @@ -1,6 +1,9 @@ #include "indexer/feature_visibility.hpp" + #include "indexer/classificator.hpp" #include "indexer/drawing_rules.hpp" +#include "indexer/feature.hpp" +#include "indexer/feature_data.hpp" #include "indexer/scales.hpp" #include "base/assert.hpp" @@ -114,7 +117,7 @@ void GetDrawRule(vector<uint32_t> const & types, int level, int geoType, (void)c.ProcessObjects(t, doRules); } -void FilterRulesByRuntimeSelector(FeatureType const & f, int zoomLevel, drule::KeysT & keys) +void FilterRulesByRuntimeSelector(FeatureType & f, int zoomLevel, drule::KeysT & keys) { keys.erase_if([&f, zoomLevel](drule::Key const & key)->bool { @@ -279,33 +282,39 @@ bool IsDrawableLike(vector<uint32_t> const & types, EGeomType geomType) return false; } -bool IsDrawableForIndex(FeatureBase const & f, int level) +bool IsDrawableForIndex(FeatureType & ft, int level) +{ + return IsDrawableForIndexGeometryOnly(ft, level) && + IsDrawableForIndexClassifOnly(TypesHolder(ft), level); +} + +bool IsDrawableForIndex(TypesHolder const & types, m2::RectD limitRect, int level) { - return IsDrawableForIndexGeometryOnly(f, level) && IsDrawableForIndexClassifOnly(f, level); + return IsDrawableForIndexGeometryOnly(types, limitRect, level) && + IsDrawableForIndexClassifOnly(types, level); } -bool IsDrawableForIndexGeometryOnly(FeatureBase const & f, int level) +bool IsDrawableForIndexGeometryOnly(FeatureType & ft, int level) +{ + return IsDrawableForIndexGeometryOnly(TypesHolder(ft), + ft.GetLimitRect(FeatureType::BEST_GEOMETRY), level); +} +bool IsDrawableForIndexGeometryOnly(TypesHolder const & types, m2::RectD limitRect, int level) { Classificator const & c = classif(); static uint32_t const buildingPartType = c.GetTypeByPath({"building:part"}); - TypesHolder const types(f); - - if (types.GetGeoType() == GEOM_AREA - && !types.Has(c.GetCoastType()) && !types.Has(buildingPartType) - && !scales::IsGoodForLevel(level, f.GetLimitRect())) + if (types.GetGeoType() == GEOM_AREA && !types.Has(c.GetCoastType()) && + !types.Has(buildingPartType) && !scales::IsGoodForLevel(level, limitRect)) return false; return true; } -bool IsDrawableForIndexClassifOnly(FeatureBase const & f, int level) +bool IsDrawableForIndexClassifOnly(TypesHolder const & types, int level) { Classificator const & c = classif(); - - TypesHolder const types(f); - IsDrawableChecker doCheck(level); for (uint32_t t : types) { @@ -344,23 +353,28 @@ bool RemoveNoDrawableTypes(vector<uint32_t> & types, EGeomType geomType, bool em return !types.empty(); } -int GetMinDrawableScale(FeatureBase const & f) +int GetMinDrawableScale(FeatureType & ft) +{ + return GetMinDrawableScale(TypesHolder(ft), ft.GetLimitRect(FeatureType::BEST_GEOMETRY)); +} + +int GetMinDrawableScale(TypesHolder const & types, m2::RectD limitRect) { int const upBound = scales::GetUpperStyleScale(); for (int level = 0; level <= upBound; ++level) - if (IsDrawableForIndex(f, level)) + if (IsDrawableForIndex(types, limitRect, level)) return level; return -1; } -int GetMinDrawableScaleClassifOnly(FeatureBase const & f) +int GetMinDrawableScaleClassifOnly(TypesHolder const & types) { int const upBound = scales::GetUpperStyleScale(); for (int level = 0; level <= upBound; ++level) - if (IsDrawableForIndexClassifOnly(f, level)) + if (IsDrawableForIndexClassifOnly(types, level)) return level; return -1; @@ -482,11 +496,6 @@ pair<int, int> GetDrawableScaleRangeForRules(TypesHolder const & types, int rule return make_pair(lowL, highL); } -pair<int, int> GetDrawableScaleRangeForRules(FeatureBase const & f, int rules) -{ - return GetDrawableScaleRangeForRules(TypesHolder(f), rules); -} - TypeSetChecker::TypeSetChecker(initializer_list<char const *> const & lst) { m_type = classif().GetTypeByPath(lst); diff --git a/indexer/feature_visibility.hpp b/indexer/feature_visibility.hpp index 09011303a2..65031d5420 100644 --- a/indexer/feature_visibility.hpp +++ b/indexer/feature_visibility.hpp @@ -11,22 +11,23 @@ #include "std/utility.hpp" #include "std/initializer_list.hpp" - -class FeatureBase; +class FeatureType; namespace feature { class TypesHolder; bool IsDrawableAny(uint32_t type); - bool IsDrawableForIndex(FeatureBase const & f, int level); + bool IsDrawableForIndex(FeatureType & ft, int level); + bool IsDrawableForIndex(TypesHolder const & types, m2::RectD limitRect, int level); // The separation into ClassifOnly and GeometryOnly versions is needed to speed up // the geometrical index (see indexer/scale_index_builder.hpp). // Technically, the GeometryOnly version uses the classificator, but it only does // so when checking against coastlines. - bool IsDrawableForIndexClassifOnly(FeatureBase const & f, int level); - bool IsDrawableForIndexGeometryOnly(FeatureBase const & f, int level); + bool IsDrawableForIndexClassifOnly(TypesHolder const & types, int level); + bool IsDrawableForIndexGeometryOnly(FeatureType & ft, int level); + bool IsDrawableForIndexGeometryOnly(TypesHolder const & types, m2::RectD limitRect, int level); /// For FEATURE_TYPE_AREA need to have at least one area-filling type. bool IsDrawableLike(vector<uint32_t> const & types, EGeomType geomType); @@ -34,8 +35,9 @@ namespace feature bool RemoveNoDrawableTypes(vector<uint32_t> & types, EGeomType geomType, bool emptyName = false); //@} - int GetMinDrawableScale(FeatureBase const & f); - int GetMinDrawableScaleClassifOnly(FeatureBase const & f); + int GetMinDrawableScale(FeatureType & ft); + int GetMinDrawableScale(TypesHolder const & types, m2::RectD limitRect); + int GetMinDrawableScaleClassifOnly(TypesHolder const & types); /// @return [-1, -1] if range is not drawable //@{ @@ -54,7 +56,6 @@ namespace feature }; pair<int, int> GetDrawableScaleRangeForRules(TypesHolder const & types, int rules); - pair<int, int> GetDrawableScaleRangeForRules(FeatureBase const & f, int rules); //@} /// @return (geometry type, is coastline) @@ -62,7 +63,7 @@ namespace feature drule::KeysT & keys); void GetDrawRule(vector<uint32_t> const & types, int level, int geoType, drule::KeysT & keys); - void FilterRulesByRuntimeSelector(FeatureType const & f, int zoomLevel, drule::KeysT & keys); + void FilterRulesByRuntimeSelector(FeatureType & f, int zoomLevel, drule::KeysT & keys); /// Used to check whether user types belong to particular classificator set. class TypeSetChecker diff --git a/indexer/ftypes_matcher.cpp b/indexer/ftypes_matcher.cpp index f8b9dc09a1..76c52444ec 100644 --- a/indexer/ftypes_matcher.cpp +++ b/indexer/ftypes_matcher.cpp @@ -135,7 +135,7 @@ bool BaseChecker::operator()(feature::TypesHolder const & types) const return false; } -bool BaseChecker::operator()(FeatureType const & ft) const +bool BaseChecker::operator()(FeatureType & ft) const { return this->operator()(feature::TypesHolder(ft)); } @@ -292,7 +292,7 @@ IsHotelChecker::IsHotelChecker() sort(m_sortedTypes.begin(), m_sortedTypes.end()); } -unsigned IsHotelChecker::GetHotelTypesMask(FeatureType const & ft) const +unsigned IsHotelChecker::GetHotelTypesMask(FeatureType & ft) const { feature::TypesHolder types(ft); buffer_vector<uint32_t, feature::kMaxTypesCount> sortedTypes(types.begin(), types.end()); @@ -322,7 +322,7 @@ unsigned IsHotelChecker::GetHotelTypesMask(FeatureType const & ft) const return mask; } -boost::optional<IsHotelChecker::Type> IsHotelChecker::GetHotelType(FeatureType const & ft) const +boost::optional<IsHotelChecker::Type> IsHotelChecker::GetHotelType(FeatureType & ft) const { feature::TypesHolder types(ft); buffer_vector<uint32_t, feature::kMaxTypesCount> sortedTypes(types.begin(), types.end()); @@ -435,13 +435,13 @@ Type IsLocalityChecker::GetType(feature::TypesHolder const & types) const return NONE; } -Type IsLocalityChecker::GetType(FeatureType const & f) const +Type IsLocalityChecker::GetType(FeatureType & f) const { feature::TypesHolder types(f); return GetType(types); } -uint64_t GetPopulation(FeatureType const & ft) +uint64_t GetPopulation(FeatureType & ft) { uint64_t population = ft.GetPopulation(); diff --git a/indexer/ftypes_matcher.hpp b/indexer/ftypes_matcher.hpp index 620f7e5ee8..f43466acb6 100644 --- a/indexer/ftypes_matcher.hpp +++ b/indexer/ftypes_matcher.hpp @@ -39,7 +39,7 @@ public: virtual bool IsMatched(uint32_t type) const; bool operator() (feature::TypesHolder const & types) const; - bool operator() (FeatureType const & ft) const; + bool operator()(FeatureType & ft) const; bool operator() (std::vector<uint32_t> const & types) const; static uint32_t PrepareToMatch(uint32_t type, uint8_t level); @@ -178,9 +178,9 @@ public: static char const * GetHotelTypeTag(Type type); - unsigned GetHotelTypesMask(FeatureType const & ft) const; + unsigned GetHotelTypesMask(FeatureType & ft) const; - boost::optional<Type> GetHotelType(FeatureType const & ft) const; + boost::optional<Type> GetHotelType(FeatureType & ft) const; DECLARE_CHECKER_INSTANCE(IsHotelChecker); private: @@ -229,7 +229,7 @@ class IsLocalityChecker : public BaseChecker public: Type GetType(uint32_t t) const; Type GetType(feature::TypesHolder const & types) const; - Type GetType(FeatureType const & f) const; + Type GetType(FeatureType & f) const; DECLARE_CHECKER_INSTANCE(IsLocalityChecker); }; @@ -247,7 +247,7 @@ bool IsTownOrCity(Types const & types) /// @name Get city radius and population. /// @param r Radius in meters. //@{ -uint64_t GetPopulation(FeatureType const & ft); +uint64_t GetPopulation(FeatureType & ft); double GetRadiusByPopulation(uint64_t p); uint64_t GetPopulationByRadius(double r); //@} diff --git a/indexer/map_object.cpp b/indexer/map_object.cpp index 58a9b1595c..bd3ce0460d 100644 --- a/indexer/map_object.cpp +++ b/indexer/map_object.cpp @@ -21,7 +21,7 @@ constexpr char const * kWired = "wired"; constexpr char const * kYes = "yes"; constexpr char const * kNo = "no"; -void SetInetIfNeeded(FeatureType const & ft, feature::Metadata & metadata) +void SetInetIfNeeded(FeatureType & ft, feature::Metadata & metadata) { if (!ftypes::IsWifiChecker::Instance()(ft) || metadata.Has(feature::Metadata::FMD_INTERNET)) return; @@ -66,7 +66,7 @@ string DebugPrint(Props props) return k; } -void MapObject::SetFromFeatureType(FeatureType const & ft) +void MapObject::SetFromFeatureType(FeatureType & ft) { m_mercator = feature::GetCenter(ft); m_name = ft.GetNames(); diff --git a/indexer/map_object.hpp b/indexer/map_object.hpp index 5d62d542e1..3de3a0ebaa 100644 --- a/indexer/map_object.hpp +++ b/indexer/map_object.hpp @@ -54,7 +54,7 @@ string DebugPrint(Props props); class MapObject { public: - void SetFromFeatureType(FeatureType const & ft); + void SetFromFeatureType(FeatureType & ft); FeatureID const & GetID() const; diff --git a/indexer/rank_table.cpp b/indexer/rank_table.cpp index 0424462d8f..a7c640f2b7 100644 --- a/indexer/rank_table.cpp +++ b/indexer/rank_table.cpp @@ -220,7 +220,7 @@ unique_ptr<RankTable> LoadRankTable(unique_ptr<TRegion> && region) return unique_ptr<RankTable>(); } -uint8_t CalcEventRank(FeatureType const & ft) +uint8_t CalcEventRank(FeatureType & ft) { // |fc2018Rank| value was adjusted for cases: // - fc2018 objects should be in thetop for "stadium" query iff fc2018 mwm is in viewport. @@ -242,7 +242,7 @@ uint8_t CalcEventRank(FeatureType const & ft) } // Calculates search rank for a feature. -uint8_t CalcSearchRank(FeatureType const & ft) +uint8_t CalcSearchRank(FeatureType & ft) { auto const eventRank = CalcEventRank(ft); auto const populationRank = feature::PopulationToRank(ftypes::GetPopulation(ft)); @@ -313,10 +313,8 @@ void SearchRankTableBuilder::CalcSearchRanks(FilesContainerR & rcont, vector<uin feature::DataHeader header(rcont); FeaturesVector featuresVector(rcont, header, nullptr /* features offsets table */); - featuresVector.ForEach([&ranks](FeatureType const & ft, uint32_t /* index */) - { - ranks.push_back(CalcSearchRank(ft)); - }); + featuresVector.ForEach( + [&ranks](FeatureType & ft, uint32_t /* index */) { ranks.push_back(CalcSearchRank(ft)); }); } // static diff --git a/indexer/road_shields_parser.cpp b/indexer/road_shields_parser.cpp index 718ba17f99..50bfe9aaa4 100644 --- a/indexer/road_shields_parser.cpp +++ b/indexer/road_shields_parser.cpp @@ -470,7 +470,7 @@ public: namespace ftypes { -std::set<RoadShield> GetRoadShields(FeatureType const & f) +std::set<RoadShield> GetRoadShields(FeatureType & f) { std::string const roadNumber = f.GetRoadNumber(); if (roadNumber.empty()) diff --git a/indexer/road_shields_parser.hpp b/indexer/road_shields_parser.hpp index d68691b2f9..0d406e2a7c 100644 --- a/indexer/road_shields_parser.hpp +++ b/indexer/road_shields_parser.hpp @@ -52,7 +52,7 @@ struct RoadShield } }; -std::set<RoadShield> GetRoadShields(FeatureType const & f); +std::set<RoadShield> GetRoadShields(FeatureType & f); std::string DebugPrint(RoadShieldType shieldType); std::string DebugPrint(RoadShield const & shield); } // namespace ftypes diff --git a/indexer/scale_index_builder.hpp b/indexer/scale_index_builder.hpp index 5629dd25a9..78c74eca24 100644 --- a/indexer/scale_index_builder.hpp +++ b/indexer/scale_index_builder.hpp @@ -4,6 +4,7 @@ #include "indexer/displacement_manager.hpp" #include "indexer/feature.hpp" #include "indexer/feature_covering.hpp" +#include "indexer/feature_data.hpp" #include "indexer/feature_visibility.hpp" #include "indexer/interval_index_builder.hpp" @@ -45,12 +46,12 @@ public: m_cellsInBucket.resize(m_bucketsCount); } - template <class TFeature> - void operator() (TFeature const & ft, uint32_t index) const + template <class Feature> + void operator()(Feature & ft, uint32_t index) const { m_scalesIdx = 0; - uint32_t const minScaleClassif = min(scales::GetUpperScale(), - feature::GetMinDrawableScaleClassifOnly(ft)); + uint32_t const minScaleClassif = min( + scales::GetUpperScale(), feature::GetMinDrawableScaleClassifOnly(feature::TypesHolder(ft))); // The classificator won't allow this feature to be drawable for smaller // scales so the first buckets can be safely skipped. // todo(@pimenov) Parallelizing this loop may be helpful. @@ -81,8 +82,8 @@ private: // -- it is visible; // -- it is allowed by the classificator. // If the feature is invisible at all scales, do not index it. - template <class TFeature> - bool FeatureShouldBeIndexed(TFeature const & ft, int scale, bool needReset) const + template <class Feature> + bool FeatureShouldBeIndexed(Feature & ft, int scale, bool needReset) const { while (m_scalesIdx < m_header.GetScalesCount() && m_header.GetScale(m_scalesIdx) < scale) { @@ -98,8 +99,6 @@ private: return false; // This function assumes that geometry rect for the needed scale is already initialized. - // Note: it works with FeatureBase so in fact it does not use the information about - // the feature's geometry except for the type and the LimitRect. return feature::IsDrawableForIndexGeometryOnly(ft, scale); } @@ -120,9 +119,9 @@ private: vector<uint32_t> & m_cellsInBucket; }; -template <class TFeaturesVector, class TWriter> -void IndexScales(feature::DataHeader const & header, TFeaturesVector const & features, - TWriter & writer, string const & tmpFilePrefix) +template <class FeaturesVector, class Writer> +void IndexScales(feature::DataHeader const & header, FeaturesVector const & features, + Writer & writer, string const & tmpFilePrefix) { // TODO: Make scale bucketing dynamic. @@ -164,7 +163,7 @@ void IndexScales(feature::DataHeader const & header, TFeaturesVector const & fea FileReader reader(cellsToFeatureAllBucketsFile); DDVector<CellFeatureBucketTuple, FileReader, uint64_t> cellsToFeaturesAllBuckets(reader); - VarSerialVectorWriter<TWriter> recordWriter(writer, bucketsCount); + VarSerialVectorWriter<Writer> recordWriter(writer, bucketsCount); auto it = cellsToFeaturesAllBuckets.begin(); for (uint32_t bucket = 0; bucket < bucketsCount; ++bucket) @@ -185,7 +184,7 @@ void IndexScales(feature::DataHeader const & header, TFeaturesVector const & fea FileReader reader(cellsToFeatureFile); DDVector<CellFeatureBucketTuple::CellFeaturePair, FileReader, uint64_t> cellsToFeatures( reader); - SubWriter<TWriter> subWriter(writer); + SubWriter<Writer> subWriter(writer); LOG(LINFO, ("Building interval index for bucket:", bucket)); BuildIntervalIndex(cellsToFeatures.begin(), cellsToFeatures.end(), subWriter, RectId::DEPTH_LEVELS * 2 + 1); |