forked from organicmaps/organicmaps-tmp
[new downloader] git-clang-format.
This commit is contained in:
parent
cae77867cc
commit
be86da1fa6
6 changed files with 57 additions and 44 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@ namespace storage
|
|||
using TMapping = map<TCountryId, TCountriesSet>;
|
||||
|
||||
/// 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<TCountryId, Country>;
|
|||
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<string, CountryInfo> & id2info,
|
||||
bool & isSingleMwm);
|
||||
|
|
|
@ -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 <class TFunctor>
|
||||
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<TKey, Node *>;
|
||||
|
||||
public:
|
||||
CountryTree(TValue const & value = TValue(), Node * parent = nullptr)
|
||||
: m_countryTree(make_unique<Node>(value, parent)) {}
|
||||
|
||||
: m_countryTree(make_unique<Node>(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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 <class ToDo>
|
||||
|
@ -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
|
||||
|
|
|
@ -1313,14 +1313,14 @@ UNIT_TEST(StorageTest_ForEachAncestorExceptForTheRoot)
|
|||
Storage storage(kSingleMwmCountriesTxt, make_unique<TestMapFilesDownloader>());
|
||||
|
||||
// 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")
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue