From 590fd5031cf626857ba685b66e58f8a855e031ef Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Tue, 9 Feb 2016 08:16:53 +0300 Subject: [PATCH] [new downloader] Storage. Implementation ForEachInSubtree method which calls a function for each node in a subtree with a defined parent. --- storage/storage.cpp | 15 +++++++++++++++ storage/storage.hpp | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/storage/storage.cpp b/storage/storage.cpp index 6eb9a611d7..a2185985c4 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -1145,4 +1145,19 @@ void Storage::DoClickOnDownloadMap(TCountryId const & countryId) if (m_downloadMapOnTheMap) m_downloadMapOnTheMap(countryId); } + +void Storage::ForEachInSubtree(TCountryId const & parent, TForEachFunction && forEach) const +{ + TCountriesContainer const * parentNode = m_countries.Find(Country(parent)); + if (parentNode == nullptr) + { + ASSERT(false, ("TCountryId =", parent, "not found in m_countries.")); + return; + } + parentNode->ForEachInSubtree([&forEach](TCountriesContainer const & countryContainer) + { + Country const & value = countryContainer.Value(); + forEach(value.Name(), value.GetSubtreeMwmCounter() != 1 /* It's a leaf. */); + }); +} } // namespace storage diff --git a/storage/storage.hpp b/storage/storage.hpp index 79ae7d4147..074e4d6697 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -25,7 +25,8 @@ struct NodeAttrs m_downloadingMwmSize(0), m_downloadingProgress(0), m_status(NodeStatus::Undefined), m_error(NodeErrorCode::NoError) {} /// If the node is expandable (a big country) |m_mwmCounter| is number of mwm files (leaves) - /// belongs to the node. If the node isn't expandable |m_mapsDownloaded| == 1. + /// belongs to the node. If the node isn't expandable |m_mwmCounter| == 1. + /// Note. For every expandable node |m_mwmCounter| >= 2. uint32_t m_mwmCounter; /// Number of mwms belonging to the node which has been donwloaded. @@ -75,6 +76,7 @@ public: using TUpdate = function; using TChangeCountryFunction = function; using TProgressFunction = function; + using TForEachFunction = function; private: /// We support only one simultaneous request at the moment @@ -230,6 +232,9 @@ public: /// a list of available maps. They are all available countries expect for fully downloaded /// countries. That means all mwm of the countries have been downloaded. void GetCountyListToDownload(TCountriesVec & countryList) const; + /// \brief Calls |forEach| for each node for subtree with parent == |parent|. + /// For example GetAllLeavesInSubtree(GetRootId()) calls |forEach| for every node including the root. + void ForEachInSubtree(TCountryId const & parent, TForEachFunction && forEach) const; /// \brief Returns current version for mwms which are available on the server. inline int64_t GetCurrentDataVersion() const { return m_currentVersion; }