#pragma once #include "base/std_serialization.hpp" #include "base/assert.hpp" #include "std/utility.hpp" #include "std/vector.hpp" #include "std/string.hpp" #include "std/algorithm.hpp" #include "std/bind.hpp" #define NODES_FILE "nodes.dat" #define WAYS_FILE "ways.dat" #define RELATIONS_FILE "relations.dat" #define OFFSET_EXT ".offs" #define ID2REL_EXT ".id2rel" #define MAPPED_WAYS "mapped_ways.n2w" class progress_policy { size_t m_count; size_t m_factor; public: size_t GetCount() const { return m_count; } void Begin(string const &, size_t factor); void Inc(size_t i = 1); void End(); }; struct WayElement { vector nodes; uint64_t m_wayOsmId; explicit WayElement(uint64_t osmId) : m_wayOsmId(osmId) {} bool IsValid() const { return !nodes.empty(); } uint64_t GetOtherEndPoint(uint64_t id) const { if (id == nodes.front()) return nodes.back(); else { ASSERT ( id == nodes.back(), () ); return nodes.front(); } } template void ForEachPoint(ToDo & toDo) const { for_each(nodes.begin(), nodes.end(), bind(ref(toDo), _1)); } template void ForEachPointOrdered(uint64_t start, ToDo & toDo) { if (start == nodes.front()) for_each(nodes.begin(), nodes.end(), bind(ref(toDo), _1)); else for_each(nodes.rbegin(), nodes.rend(), bind(ref(toDo), _1)); } }; struct RelationElement { typedef vector > ref_vec_t; ref_vec_t nodes, ways; map tags; bool IsValid() const { return !(nodes.empty() && ways.empty()); } string GetType() const; bool FindWay(uint64_t id, string & role) const; bool FindNode(uint64_t id, string & role) const; template void ForEachWay(ToDo & toDo) const { for (size_t i = 0; i < ways.size(); ++i) toDo(ways[i].first, ways[i].second); } void Swap(RelationElement & rhs) { nodes.swap(rhs.nodes); ways.swap(rhs.ways); tags.swap(rhs.tags); } }; template TArchive & operator << (TArchive & ar, WayElement const & e) { ar << e.nodes; return ar; } template TArchive & operator >> (TArchive & ar, WayElement & e) { ar >> e.nodes; return ar; } template TArchive & operator << (TArchive & ar, RelationElement const & e) { ar << e.nodes << e.ways << e.tags; return ar; } template TArchive & operator >> (TArchive & ar, RelationElement & e) { ar >> e.nodes >> e.ways >> e.tags; return ar; }