From 81a4beec96490611a4dca02bfddc7afc239b27b8 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 21 Dec 2011 12:46:28 +0300 Subject: [PATCH] Add Model::RemoveAllCountries function. Minor fixes. --- indexer/index.hpp | 2 +- indexer/mwm_set.cpp | 34 ++++++++++++++++++++++++++++------ indexer/mwm_set.hpp | 18 ++++++++++++++---- map/feature_vec_model.cpp | 11 ++++++++--- map/feature_vec_model.hpp | 4 +++- 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/indexer/index.hpp b/indexer/index.hpp index 3d556401bf..8c4d276f17 100644 --- a/indexer/index.hpp +++ b/indexer/index.hpp @@ -144,7 +144,7 @@ private: { /// @todo It's better to avoid hacks with scale comparison. - if (mwm[id].m_minScale > 0) + if (mwm[id].isCountry()) { // process countries first ProcessMwm(f, id, cov, scale); diff --git a/indexer/mwm_set.cpp b/indexer/mwm_set.cpp index eeb275cdac..e239bfed67 100644 --- a/indexer/mwm_set.cpp +++ b/indexer/mwm_set.cpp @@ -58,6 +58,7 @@ void MwmSet::Cleanup() ClearCacheImpl(m_cache.begin(), m_cache.end()); +#ifdef DEBUG for (size_t i = 0; i < m_info.size(); ++i) { if (m_info[i].m_status == MwmInfo::STATUS_ACTIVE) @@ -66,9 +67,10 @@ void MwmSet::Cleanup() ASSERT_NOT_EQUAL(m_name[i], string(), (i)); } } +#endif } -inline void MwmSet::UpdateMwmInfo(MwmInfo & info) +void MwmSet::UpdateMwmInfo(MwmInfo & info) { if (info.m_status == MwmInfo::STATUS_TO_REMOVE && info.m_lockCount == 0) info.m_status = MwmInfo::STATUS_REMOVED; @@ -132,6 +134,15 @@ int MwmSet::Add(string const & fileName, m2::RectD & r) return version; } +void MwmSet::RemoveImpl(MwmId id) +{ + if (m_info[id].m_lockCount == 0) + m_info[id].m_status = MwmInfo::STATUS_REMOVED; + else + m_info[id].m_status = MwmInfo::STATUS_TO_REMOVE; + m_name[id].clear(); +} + void MwmSet::Remove(string const & fileName) { threads::MutexGuard mutexGuard(m_lock); @@ -142,17 +153,28 @@ void MwmSet::Remove(string const & fileName) MwmId const id = GetIdByName(fileName); if (id != INVALID_MWM_ID) { - if (m_info[id].m_lockCount == 0) - m_info[id].m_status = MwmInfo::STATUS_REMOVED; - else - m_info[id].m_status = MwmInfo::STATUS_TO_REMOVE; - m_name[id].clear(); + RemoveImpl(id); // Update the cache. ClearCacheImpl(RemoveIfKeepValid(m_cache.begin(), m_cache.end(), MwmIdIsEqualTo(id)), m_cache.end()); } } +void MwmSet::RemoveAllCountries() +{ + threads::MutexGuard mutexGuard(m_lock); + UNUSED_VALUE(mutexGuard); + + for (MwmId i = 0; i < m_info.size(); ++i) + { + if (m_info[i].isCountry()) + RemoveImpl(i); + } + + // do not call ClearCache - it's under mutex lock + ClearCacheImpl(m_cache.begin(), m_cache.end()); +} + bool MwmSet::IsLoaded(string const & fName) const { return (const_cast(this)->GetIdByName(fName + DATA_FILE_EXTENSION) != INVALID_MWM_ID); diff --git a/indexer/mwm_set.hpp b/indexer/mwm_set.hpp index c9f30d23fb..72ff5a5a78 100644 --- a/indexer/mwm_set.hpp +++ b/indexer/mwm_set.hpp @@ -18,7 +18,9 @@ public: uint8_t m_maxScale; // Max zoom level of mwm. // Does this MwmInfo represent a valid Mwm? - bool isValid() const { return m_status == STATUS_ACTIVE; } + inline bool isValid() const { return (m_status == STATUS_ACTIVE); } + inline bool isCountry() const { return (m_minScale > 0); } + private: friend class MwmSet; @@ -68,8 +70,16 @@ public: return (-1 != Add(fileName, dummy)); } - // Remove mwm. + /// @name Remove mwm. + //@{ +private: + void RemoveImpl(MwmId id); + +public: void Remove(string const & fileName); + /// Remove all except world boundle mwm's. + void RemoveAllCountries(); + //@} bool IsLoaded(string const & fName) const; @@ -106,8 +116,8 @@ private: // Do the cleaning for [beg, end) without acquiring the mutex. void ClearCacheImpl(CacheType::iterator beg, CacheType::iterator end); - mutable vector m_info; - mutable vector m_name; + mutable vector m_info; // mutable needed for GetMwmInfo + /*mutable*/ vector m_name; mutable CacheType m_cache; size_t m_cacheSize; mutable threads::Mutex m_lock; diff --git a/map/feature_vec_model.cpp b/map/feature_vec_model.cpp index 7bcf90a6aa..16e736f97e 100644 --- a/map/feature_vec_model.cpp +++ b/map/feature_vec_model.cpp @@ -53,12 +53,17 @@ void FeaturesFetcher::RemoveMap(string const & fName) m_multiIndex.Remove(fName); } -void FeaturesFetcher::Clean() +void FeaturesFetcher::RemoveAllCountries() { - m_rect.MakeEmpty(); - // TODO: m_multiIndex.Clear(); - is it needed? + m_multiIndex.RemoveAllCountries(); } +//void FeaturesFetcher::Clean() +//{ +// m_rect.MakeEmpty(); +// // TODO: m_multiIndex.Clear(); - is it needed? +//} + void FeaturesFetcher::ClearCaches() { m_multiIndex.ClearCache(); diff --git a/map/feature_vec_model.hpp b/map/feature_vec_model.hpp index 1d3c47df2f..43fa63b920 100644 --- a/map/feature_vec_model.hpp +++ b/map/feature_vec_model.hpp @@ -36,7 +36,9 @@ namespace model /// @return MWM format version for file or -1 if error and map was not added int AddMap(string const & file); void RemoveMap(string const & fName); - void Clean(); + void RemoveAllCountries(); + + //void Clean(); void ClearCaches(); inline bool IsLoaded(string const & fName) const