diff options
author | VladiMihaylenko <vxmihaylenko@gmail.com> | 2019-03-01 18:48:04 +0300 |
---|---|---|
committer | VladiMihaylenko <vxmihaylenko@gmail.com> | 2019-03-25 17:48:13 +0300 |
commit | 4e9b3238e8aff0fdbc43f3e66b20992ce79a1f64 (patch) | |
tree | 960d4c675a457247e973040d5bd548c53a488b25 /storage | |
parent | 44d8610e1c6d3d45a40f2ca55e66f655e8cec3f3 (diff) |
Added method for getting topmost country id
Diffstat (limited to 'storage')
-rw-r--r-- | storage/storage.cpp | 14 | ||||
-rw-r--r-- | storage/storage.hpp | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/storage/storage.cpp b/storage/storage.cpp index ea4b7d4089..8145e140ce 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -2107,6 +2107,20 @@ CountryId const Storage::GetParentIdFor(CountryId const & countryId) const return nodes[0]->Value().GetParent(); } +CountryId const Storage::GetTopmostParentFor(CountryId const & countryId) const +{ + auto const rootId = GetRootId(); + auto result = countryId; + auto parent = GetParentIdFor(result); + while (!parent.empty() && parent != rootId) + { + result = move(parent); + parent = GetParentIdFor(result); + } + + return result; +} + MwmSize Storage::GetRemoteSize(CountryFile const & file, MapOptions opt, int64_t version) const { if (version::IsSingleMwm(version)) diff --git a/storage/storage.hpp b/storage/storage.hpp index 80fa46fcd7..2ef7f808a1 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -401,6 +401,9 @@ public: void GetTopmostNodesFor(CountryId const & countryId, CountriesVec & nodes, size_t level = 0) const; + /// \brief Returns topmost country id prior root id or |countryId| itself, if it's already + /// a topmost node or it's a disputed territory. + CountryId const GetTopmostParentFor(CountryId const & countryId) const; /// \brief Returns parent id for node if node has single parent. Otherwise (if node is disputed /// territory and has multiple parents or does not exist) returns empty CountryId CountryId const GetParentIdFor(CountryId const & countryId) const; |