diff --git a/storage/country.cpp b/storage/country.cpp index 284a14f7a9..1260fc5fbf 100644 --- a/storage/country.cpp +++ b/storage/country.cpp @@ -148,7 +148,7 @@ class DoStoreCountriesSingleMwms TMapping m_idsMapping; public: - DoStoreCountriesSingleMwms(TCountryTree & cont) : m_countries(cont) {} + DoStoreCountriesSingleMwms(TCountryTree & countries) : m_countries(countries) {} Country * operator()(TCountryId const & id, uint32_t mapSize, int depth, TCountryId const & parent) { @@ -243,7 +243,8 @@ public: }; } // namespace -int64_t LoadCountries(string const & jsonBuffer, TCountryTree & countries, TMapping * mapping /* = nullptr */) +int64_t LoadCountries(string const & jsonBuffer, TCountryTree & countries, + TMapping * mapping /* = nullptr */) { countries.Clear(); diff --git a/storage/country.hpp b/storage/country.hpp index 87b878d69e..96dd19ee79 100644 --- a/storage/country.hpp +++ b/storage/country.hpp @@ -26,7 +26,8 @@ namespace storage using TMapping = map; /// This class keeps all the information about a country in country tree (TCountryTree). -/// It is guaranteed that every node represent a unique region has a unique |m_name| in country tree. +/// It is guaranteed that every node represent a unique region has a unique |m_name| in country +/// tree. /// If several nodes have the same |m_name| they represent the same region. /// It happends in case of disputed territories. /// That means that @@ -79,7 +80,8 @@ using TCountryTree = CountryTree; using TCountryTreeNode = TCountryTree::Node; /// @return version of country file or -1 if error was encountered -int64_t LoadCountries(string const & jsonBuffer, TCountryTree & countries, TMapping * mapping = nullptr); +int64_t LoadCountries(string const & jsonBuffer, TCountryTree & countries, + TMapping * mapping = nullptr); void LoadCountryFile2CountryInfo(string const & jsonBuffer, map & id2info, bool & isSingleMwm); diff --git a/storage/country_tree.hpp b/storage/country_tree.hpp index 5606a55bb5..b469b0fae0 100644 --- a/storage/country_tree.hpp +++ b/storage/country_tree.hpp @@ -6,7 +6,8 @@ #include "std/unique_ptr.hpp" #include "std/vector.hpp" -/// \brief This class is developed for using in Storage. It's a implementation of a tree with ability +/// \brief This class is developed for using in Storage. It's a implementation of a tree with +/// ability /// of access to its nodes in expected constant time with the help of hash table. /// It should be filled with AddAtDepth method. /// This class is used in Storage and filled based on countries.txt (countries_migrate.txt). @@ -110,7 +111,7 @@ public: template void ForEachDescendant(TFunctor && f) const { - for (auto const & child: m_children) + for (auto const & child : m_children) { f(*child); child->ForEachDescendant(f); @@ -121,7 +122,7 @@ public: void ForEachInSubtree(TFunctor && f) { f(*this); - for (auto & child: m_children) + for (auto & child : m_children) child->ForEachInSubtree(f); } @@ -129,7 +130,7 @@ public: void ForEachInSubtree(TFunctor && f) const { f(*this); - for (auto const & child: m_children) + for (auto const & child : m_children) child->ForEachInSubtree(f); } @@ -154,10 +155,12 @@ public: private: using TCountryTreeHashTable = unordered_multimap; + public: CountryTree(TValue const & value = TValue(), Node * parent = nullptr) - : m_countryTree(make_unique(value, parent)) {} - + : m_countryTree(make_unique(value, parent)) + { + } Node const & GetRoot() const { return *m_countryTree; } Node & GetRoot() { return *m_countryTree; } @@ -190,7 +193,10 @@ public: return; for_each(range.first, range.second, - [&found](typename TCountryTreeHashTable::value_type const & node) { found.push_back(&*node.second); }); + [&found](typename TCountryTreeHashTable::value_type const & node) + { + found.push_back(&*node.second); + }); } Node const * const FindFirst(TValue const & value) const diff --git a/storage/storage.cpp b/storage/storage.cpp index bd7b19b747..09effa9449 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -77,7 +77,7 @@ void DeleteFromDiskWithIndexes(LocalCountryFile const & localFile, MapOptions op } TCountryTreeNode const & LeafNodeFromCountryId(TCountryTree const & root, - TCountryId const & countryId) + TCountryId const & countryId) { TCountryTreeNode const * node = root.FindFirstLeaf(Country(countryId)); CHECK(node, ("Node with id =", countryId, "not found in country tree as a leaf.")); @@ -554,7 +554,8 @@ void Storage::NotifyStatusChangedForHierarchy(TCountryId const & countryId) NotifyStatusChanged(countryId); // Notification status changing for ancestors in country tree. - ForEachAncestorExceptForTheRoot(countryId, [&] (TCountryId const & parentId, TCountryTreeNode const &) + ForEachAncestorExceptForTheRoot(countryId, + [&](TCountryId const & parentId, TCountryTreeNode const &) { NotifyStatusChanged(parentId); }); @@ -728,14 +729,13 @@ void Storage::ReportProgressForHierarchy(TCountryId const & countryId, TCountriesSet setQueue; GetQueuedCountries(m_queue, setQueue); - auto calcProgress = [&] - (TCountryId const & parentId, TCountryTreeNode const & parentNode) + auto calcProgress = [&](TCountryId const & parentId, TCountryTreeNode const & parentNode) { TCountriesVec descendants; parentNode.ForEachDescendant([&descendants](TCountryTreeNode const & container) - { - descendants.push_back(container.Value().Name()); - }); + { + descendants.push_back(container.Value().Name()); + }); MapFilesDownloader::TProgress localAndRemoteBytes = CalculateProgress(countryId, descendants, leafProgress, setQueue); @@ -1311,9 +1311,9 @@ void Storage::GetNodeAttrs(TCountryId const & countryId, NodeAttrs & nodeAttrs) // Status and progress. TCountriesVec descendants; node->ForEachDescendant([&descendants](TCountryTreeNode const & d) - { - descendants.push_back(d.Value().Name()); - }); + { + descendants.push_back(d.Value().Name()); + }); TCountryId const & downloadingMwm = IsDownloadInProgress() ? GetCurrentDownloadingCountryId() : kInvalidCountryId; MapFilesDownloader::TProgress downloadingMwmProgress(0, 0); @@ -1330,7 +1330,8 @@ void Storage::GetNodeAttrs(TCountryId const & countryId, NodeAttrs & nodeAttrs) nodeAttrs.m_localMwmSize = 0; node->ForEachInSubtree([this, &nodeAttrs](TCountryTreeNode const & d) { - Storage::TLocalFilePtr const localFile = GetLatestLocalFile(d.Value().Name()); + Storage::TLocalFilePtr const localFile = + GetLatestLocalFile(d.Value().Name()); if (localFile == nullptr) return; diff --git a/storage/storage.hpp b/storage/storage.hpp index 384b1d736c..3dc7d88d7b 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -533,10 +533,11 @@ void Storage::ForEachInSubtree(TCountryId const & root, ToDo && toDo) const return; } rootNode->ForEachInSubtree([&toDo](TCountryTreeNode const & container) - { - Country const & value = container.Value(); - toDo(value.Name(), value.GetSubtreeMwmCounter() != 1 /* groupNode. */); - }); + { + Country const & value = container.Value(); + toDo(value.Name(), + value.GetSubtreeMwmCounter() != 1 /* groupNode. */); + }); } template @@ -575,14 +576,16 @@ void Storage::ForEachAncestorExceptForTheRoot(TCountryId const & countryId, ToDo // may be more than one. It means |childId| is present in the country tree more than once. for (auto const & node : nodes) { - node->ForEachAncestorExceptForTheRoot([&](TCountryTreeNode const & container) - { - TCountryId const ancestorId = container.Value().Name(); - if (visitedAncestors.find(ancestorId) != visitedAncestors.end()) - return; // The node was visited before because countryId is present in the tree more than once. - visitedAncestors.insert(ancestorId); - toDo(ancestorId, container); - }); + node->ForEachAncestorExceptForTheRoot( + [&](TCountryTreeNode const & container) + { + TCountryId const ancestorId = container.Value().Name(); + if (visitedAncestors.find(ancestorId) != visitedAncestors.end()) + return; // The node was visited before because countryId is present in the tree more + // than once. + visitedAncestors.insert(ancestorId); + toDo(ancestorId, container); + }); } } } // storage diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp index ff4ee4091e..30b6e2ee17 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -1313,14 +1313,14 @@ UNIT_TEST(StorageTest_ForEachAncestorExceptForTheRoot) Storage storage(kSingleMwmCountriesTxt, make_unique()); // Two parent case. - auto const forEachParentDisputableTerritory - = [](TCountryId const & parentId, TCountryTreeNode const & parentNode) + auto const forEachParentDisputableTerritory = + [](TCountryId const & parentId, TCountryTreeNode const & parentNode) { TCountriesVec descendants; parentNode.ForEachDescendant([&descendants](TCountryTreeNode const & container) - { - descendants.push_back(container.Value().Name()); - }); + { + descendants.push_back(container.Value().Name()); + }); if (parentId == "Country1") { @@ -1339,14 +1339,14 @@ UNIT_TEST(StorageTest_ForEachAncestorExceptForTheRoot) storage.ForEachAncestorExceptForTheRoot("Disputable Territory", forEachParentDisputableTerritory); // One parent case. - auto const forEachParentIndisputableTerritory - = [](TCountryId const & parentId, TCountryTreeNode const & parentNode) + auto const forEachParentIndisputableTerritory = + [](TCountryId const & parentId, TCountryTreeNode const & parentNode) { TCountriesVec descendants; parentNode.ForEachDescendant([&descendants](TCountryTreeNode const & container) - { - descendants.push_back(container.Value().Name()); - }); + { + descendants.push_back(container.Value().Name()); + }); if (parentId == "Country1") {