From fb87588b3efeb0fedb4bad06172ed5171ff36906 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Tue, 5 Jul 2016 11:02:30 +0300 Subject: [PATCH 1/2] Remove edits when remove the map --- indexer/osm_editor.cpp | 19 +++++++++++++++++++ indexer/osm_editor.hpp | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/indexer/osm_editor.cpp b/indexer/osm_editor.cpp index ecca7cb813..5f420d07ac 100644 --- a/indexer/osm_editor.cpp +++ b/indexer/osm_editor.cpp @@ -339,6 +339,25 @@ void Editor::ClearAllLocalEdits() Invalidate(); } +void Editor::OnMapDeregistered(platform::LocalCountryFile const & localFile) +{ + // TODO: to add some synchronization mechanism for whole Editor class + lock_guard g(m_mapDeregisteredMtx); + + using TFeaturePair = decltype(m_features)::value_type; + // Cannot search by MwmId because country already removed. So, search by country name. + auto const matchedMwm = + find_if(begin(m_features), end(m_features), [&localFile](TFeaturePair const & item) { + return item.first.GetInfo()->GetCountryName() == localFile.GetCountryName(); + }); + + if (m_features.end() != matchedMwm) + { + m_features.erase(matchedMwm); + Save(GetEditorFilePath()); + } +} + Editor::FeatureStatus Editor::GetFeatureStatus(MwmSet::MwmId const & mwmId, uint32_t index) const { // Most popular case optimization. diff --git a/indexer/osm_editor.hpp b/indexer/osm_editor.hpp index e3d3070493..2d5ed2b31d 100644 --- a/indexer/osm_editor.hpp +++ b/indexer/osm_editor.hpp @@ -17,6 +17,7 @@ #include "std/ctime.hpp" #include "std/function.hpp" #include "std/map.hpp" +#include "std/mutex.hpp" #include "std/string.hpp" #include "std/vector.hpp" @@ -71,6 +72,8 @@ public: LoadMapEdits(); } + void OnMapDeregistered(platform::LocalCountryFile const & localFile) override; + using TFeatureIDFunctor = function; void ForEachFeatureInMwmRectAndScale(MwmSet::MwmId const & id, TFeatureIDFunctor const & f, @@ -215,6 +218,8 @@ private: /// Notes to be sent to osm. shared_ptr m_notes; + // Mutex which locks OnMapDeregistered method + mutex m_mapDeregisteredMtx; }; // class Editor string DebugPrint(Editor::FeatureStatus fs); From 00c41b1753b06152fd67c758d463d1916a52209e Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Tue, 5 Jul 2016 13:14:46 +0300 Subject: [PATCH 2/2] review changes --- indexer/osm_editor.cpp | 3 +-- indexer/osm_editor.hpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/indexer/osm_editor.cpp b/indexer/osm_editor.cpp index 5f420d07ac..243b3097c0 100644 --- a/indexer/osm_editor.cpp +++ b/indexer/osm_editor.cpp @@ -32,7 +32,6 @@ #include "std/algorithm.hpp" #include "std/chrono.hpp" #include "std/future.hpp" -#include "std/mutex.hpp" #include "std/target_os.hpp" #include "std/tuple.hpp" #include "std/unordered_map.hpp" @@ -342,7 +341,7 @@ void Editor::ClearAllLocalEdits() void Editor::OnMapDeregistered(platform::LocalCountryFile const & localFile) { // TODO: to add some synchronization mechanism for whole Editor class - lock_guard g(m_mapDeregisteredMtx); + lock_guard g(m_mapDeregisteredMutex); using TFeaturePair = decltype(m_features)::value_type; // Cannot search by MwmId because country already removed. So, search by country name. diff --git a/indexer/osm_editor.hpp b/indexer/osm_editor.hpp index 2d5ed2b31d..e545470051 100644 --- a/indexer/osm_editor.hpp +++ b/indexer/osm_editor.hpp @@ -219,7 +219,7 @@ private: /// Notes to be sent to osm. shared_ptr m_notes; // Mutex which locks OnMapDeregistered method - mutex m_mapDeregisteredMtx; + mutex m_mapDeregisteredMutex; }; // class Editor string DebugPrint(Editor::FeatureStatus fs);