mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
63
storage/country_tree_helpers.cpp
Normal file
63
storage/country_tree_helpers.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "storage/country_tree_helpers.hpp"
|
||||
|
||||
#include "base/logging.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
namespace storage
|
||||
{
|
||||
CountryId GetTopmostParentFor(CountryTree const & countries, CountryId const & countryId)
|
||||
{
|
||||
CountryTree::NodesBufferT nodes;
|
||||
countries.Find(countryId, nodes);
|
||||
if (nodes.empty())
|
||||
{
|
||||
LOG(LWARNING, ("CountryId =", countryId, "not found in countries."));
|
||||
return {};
|
||||
}
|
||||
|
||||
if (nodes.size() > 1)
|
||||
{
|
||||
// Disputed territory. Has multiple parents.
|
||||
CHECK(nodes[0]->HasParent(), ());
|
||||
auto const parentId = nodes[0]->Parent().Value().Name();
|
||||
for (size_t i = 1; i < nodes.size(); ++i)
|
||||
{
|
||||
if (nodes[i]->Parent().Value().Name() != parentId)
|
||||
return countryId;
|
||||
}
|
||||
return GetTopmostParentFor(countries, parentId);
|
||||
}
|
||||
|
||||
auto result = nodes[0];
|
||||
|
||||
if (!result->HasParent())
|
||||
return result->Value().Name();
|
||||
|
||||
auto parent = &(result->Parent());
|
||||
while (parent->HasParent())
|
||||
{
|
||||
result = parent;
|
||||
parent = &(result->Parent());
|
||||
}
|
||||
|
||||
return result->Value().Name();
|
||||
}
|
||||
|
||||
std::optional<CountryTree> LoadCountriesFromFile(std::string const & path)
|
||||
{
|
||||
Affiliations affiliations;
|
||||
CountryNameSynonyms countryNameSynonyms;
|
||||
MwmTopCityGeoIds mwmTopCityGeoIds;
|
||||
MwmTopCountryGeoIds mwmTopCountryGeoIds;
|
||||
CountryTree countries;
|
||||
auto const res = LoadCountriesFromFile(path, countries, affiliations, countryNameSynonyms,
|
||||
mwmTopCityGeoIds, mwmTopCountryGeoIds);
|
||||
|
||||
if (res == -1)
|
||||
return {};
|
||||
|
||||
return std::optional<CountryTree>(std::move(countries));
|
||||
}
|
||||
} // namespace storage
|
||||
Reference in New Issue
Block a user