Files
comaps/generator/complex_loader.hpp
Konstantin Pastbin e3e4a1985a 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
2025-05-08 21:10:51 +07:00

67 lines
1.8 KiB
C++

#pragma once
#include "generator/hierarchy_entry.hpp"
#include "indexer/complex/tree_node.hpp"
#include "storage/storage_defines.hpp"
#include <functional>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
namespace generator
{
namespace complex
{
// Feature ids.
using Ids = std::vector<uint32_t>;
} // namespace complex
// ComplexLoader loads complexes from hierarchy source file and provides easy access.
class ComplexLoader
{
public:
explicit ComplexLoader(std::string const & filename);
tree_node::Forest<HierarchyEntry> const & GetForest(storage::CountryId const & country) const;
// fn accepts country name and tree.
template <typename Fn>
void ForEach(Fn && fn) const
{
for (auto const & pair : m_forests)
fn(pair.first, pair.second);
}
std::unordered_set<CompositeId> GetIdsSet() const;
private:
std::unordered_map<storage::CountryId, tree_node::Forest<HierarchyEntry>> m_forests;
};
// Returns true if hierarchy tree is complex; otherwise returns false.
// Complex is defined at https://confluence.mail.ru/display/MAPSME/Complexes.
bool IsComplex(tree_node::types::Ptr<HierarchyEntry> const & tree);
// Returns country id of hierarchy.
storage::CountryId GetCountry(tree_node::types::Ptr<HierarchyEntry> const & tree);
// Returns initilized ComplexLoader by filename.
// It loads only at the time of the first call.
ComplexLoader const & GetOrCreateComplexLoader(std::string const & filename);
template <typename Fn>
tree_node::Forest<complex::Ids> TraformToIdsForest(
tree_node::Forest<HierarchyEntry> const & forest, Fn && fn)
{
tree_node::Forest<complex::Ids> res;
forest.ForEachTree([&](auto const & tree) {
res.Append(tree_node::TransformToTree(tree, std::forward<Fn>(fn)));
});
return res;
}
} // namespace generator