diff options
author | Alex Zolotarev <alex@maps.me> | 2015-11-18 11:23:13 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-03-23 16:03:52 +0300 |
commit | 8f4f450aec9c8f2ee5a81d75c657a11e069c8a5d (patch) | |
tree | 86752c0ed84113a1048fd591700ca159db8fa673 /indexer/index.hpp | |
parent | 2eb1db0912e600f64730891f7868942820e85d52 (diff) |
Edited features support in the Index.
Diffstat (limited to 'indexer/index.hpp')
-rw-r--r-- | indexer/index.hpp | 73 |
1 files changed, 57 insertions, 16 deletions
diff --git a/indexer/index.hpp b/indexer/index.hpp index 5e01ce068a..d1d0080a21 100644 --- a/indexer/index.hpp +++ b/indexer/index.hpp @@ -5,6 +5,7 @@ #include "indexer/features_offsets_table.hpp" #include "indexer/features_vector.hpp" #include "indexer/mwm_set.hpp" +#include "indexer/osm_editor.hpp" #include "indexer/scale_index.hpp" #include "indexer/unique_index.hpp" @@ -92,9 +93,16 @@ private: template <typename F> class ReadMWMFunctor { F & m_f; + osm::Editor & m_editor = osm::Editor::Instance(); public: ReadMWMFunctor(F & f) : m_f(f) {} + /// Used by Editor to inject new features. + void operator()(FeatureType & feature) + { + m_f(feature); + } + void operator()(MwmHandle const & handle, covering::CoveringGetter & cov, uint32_t scale) const { MwmValue const * pValue = handle.GetValue<MwmValue>(); @@ -122,18 +130,26 @@ private: for (auto const & i : interval) { - index.ForEachInIntervalAndScale([&] (uint32_t index) - { - if (checkUnique(index)) - { - FeatureType feature; - - fv.GetByIndex(index, feature); - feature.SetID(FeatureID(mwmID, index)); - - m_f(feature); - } - }, i.first, i.second, scale); + index.ForEachInIntervalAndScale( + [&](uint32_t index) + { + FeatureID const fid(mwmID, index); + if (m_editor.IsFeatureDeleted(fid)) + return; + FeatureType feature; + if (m_editor.GetEditedFeature(fid, feature)) + { + m_f(feature); + return; + } + if (checkUnique(index)) + { + fv.GetByIndex(index, feature); + feature.SetID(fid); + m_f(feature); + } + }, + i.first, i.second, scale); } } } @@ -142,9 +158,16 @@ private: template <typename F> class ReadFeatureIndexFunctor { F & m_f; + osm::Editor & m_editor = osm::Editor::Instance(); public: ReadFeatureIndexFunctor(F & f) : m_f(f) {} + /// Used by Editor to inject new features. + void operator()(FeatureID const & fid) const + { + m_f(fid); + } + void operator()(MwmHandle const & handle, covering::CoveringGetter & cov, uint32_t scale) const { MwmValue const * pValue = handle.GetValue<MwmValue>(); @@ -171,8 +194,9 @@ private: { index.ForEachInIntervalAndScale([&] (uint32_t index) { - if (checkUnique(index)) - m_f(FeatureID(mwmID, index)); + FeatureID const fid(mwmID, index); + if (!m_editor.IsFeatureDeleted(fid) && checkUnique(index)) + m_f(fid); }, i.first, i.second, scale); } } @@ -215,6 +239,7 @@ public: { auto fidIter = features.begin(); auto const endIter = features.end(); + auto & editor = osm::Editor::Instance(); while (fidIter != endIter) { MwmId const & id = fidIter->m_mwmId; @@ -225,9 +250,13 @@ public: FeaturesVector const featureReader(pValue->m_cont, pValue->GetHeader(), pValue->m_table); do { + ASSERT(!editor.IsFeatureDeleted(*fidIter), ("Deleted feature was cached. Please review your code.")); FeatureType featureType; - featureReader.GetByIndex(fidIter->m_index, featureType); - featureType.SetID(*fidIter); + if (!editor.GetEditedFeature(*fidIter, featureType)) + { + featureReader.GetByIndex(fidIter->m_index, featureType); + featureType.SetID(*fidIter); + } f(featureType); } while (++fidIter != endIter && id == fidIter->m_mwmId); @@ -255,6 +284,7 @@ public: private: MwmHandle m_handle; FeaturesVector m_vector; + osm::Editor & m_editor = osm::Editor::Instance(); }; template <typename F> @@ -282,6 +312,8 @@ private: MwmId worldID[2]; + osm::Editor & editor = osm::Editor::Instance(); + for (shared_ptr<MwmInfo> const & info : mwms) { if (info->m_minScale <= scale && scale <= info->m_maxScale && @@ -294,6 +326,9 @@ private: { MwmHandle const handle = GetMwmHandleById(id); f(handle, cov, scale); + // Check created features container. + // Need to do it on a per-mwm basis, because Drape relies on features in a sorted order. + editor.ForEachFeatureInMwmRectAndScale(id, f, rect, scale); } break; @@ -312,12 +347,18 @@ private: { MwmHandle const handle = GetMwmHandleById(worldID[0]); f(handle, cov, scale); + // Check edited/created features container. + // Need to do it on a per-mwm basis, because Drape relies on features in a sorted order. + editor.ForEachFeatureInMwmRectAndScale(worldID[0], f, rect, scale); } if (worldID[1].IsAlive()) { MwmHandle const handle = GetMwmHandleById(worldID[1]); f(handle, cov, scale); + // Check edited/created features container. + // Need to do it on a per-mwm basis, because Drape relies on features in a sorted order. + editor.ForEachFeatureInMwmRectAndScale(worldID[1], f, rect, scale); } } |