Libosmium: include/osmium/relations/manager_util.hpp Source File

Libosmium Fast and flexible C++ library for working with OpenStreetMap data

Loading...
Searching...
No Matches
manager_util.hpp
Go to the documentation of this file.
1#ifndef OSMIUM_RELATIONS_MANAGER_UTIL_HPP
2#define OSMIUM_RELATIONS_MANAGER_UTIL_HPP
3
4/*
5
6This file is part of Osmium (https://osmcode.org/libosmium).
7
8Copyright 2013-2026 Jochen Topf <jochen@topf.org> and others (see README).
9
10Boost Software License - Version 1.0 - August 17th, 2003
11
12Permission is hereby granted, free of charge, to any person or organization
13obtaining a copy of the software and accompanying documentation covered by
14this license (the "Software") to use, reproduce, display, distribute,
15execute, and transmit the Software, and to prepare derivative works of the
16Software, and to permit third-parties to whom the Software is furnished to
17do so, all subject to the following:
18
19The copyright notices in the Software and this entire statement, including
20the above license grant, this restriction and the following disclaimer,
21must be included in all copies of the Software, in whole or in part, and
22all derivative works of the Software, unless such copies or derivative
23works are solely in the form of machine-executable object code generated by
24a source language processor.
25
26THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32DEALINGS IN THE SOFTWARE.
33
34*/
35
36#include <osmium/fwd.hpp>
37#include <osmium/handler.hpp>
38#include <osmium/handler/check_order.hpp>
39#include <osmium/io/file.hpp>
40#include <osmium/io/reader.hpp>
41#include <osmium/memory/buffer.hpp>
42#include <osmium/osm/entity_bits.hpp>
43#include <osmium/util/progress_bar.hpp>
44#include <osmium/visitor.hpp>
45
46#include <cstddef>
47#include <initializer_list>
48#include <iomanip>
49#include <utility>
50
51namespace osmium {
52
53 namespace relations {
54
63 template <typename TManager>
64 class SecondPassHandler : public osmium::handler::Handler {
65
66 TManager& m_manager;
67
68 public:
69
70 explicit SecondPassHandler(TManager& manager) noexcept :
71 m_manager(manager) {
72 }
73
77 void node(const osmium::Node& node) {
78 m_manager.handle_node(node);
79 }
80
84 void way(const osmium::Way& way) {
85 m_manager.handle_way(way);
86 }
87
91 void relation(const osmium::Relation& relation) {
92 m_manager.handle_relation(relation);
93 }
94
100 void flush() {
101 m_manager.flush_output();
102 }
103
104 }; // class SecondPassHandler
105
120 template <typename ...TManager>
121 void read_relations(const osmium::io::File& file, TManager& ...managers) {
122 osmium::io::Reader reader{file, osmium::osm_entity_bits::relation};
123 osmium::apply(reader, managers...);
124 reader.close();
125 (void)std::initializer_list<int>{(managers.prepare_for_lookup(), 0)...};
126 }
127
144 template <typename ...TManager>
145 void read_relations(osmium::ProgressBar& progress_bar, const osmium::io::File& file, TManager& ...managers) {
146 osmium::io::Reader reader{file, osmium::osm_entity_bits::relation};
147 while (auto buffer = reader.read()) {
148 progress_bar.update(reader.offset());
149 osmium::apply(buffer, managers...);
150 }
151 reader.close();
152 (void)std::initializer_list<int>{(managers.prepare_for_lookup(), 0)...};
153 progress_bar.file_done(file.size());
154 }
155
160 struct relations_manager_memory_usage {
161 std::size_t relations_db;
162 std::size_t members_db;
163 std::size_t stash;
164 };
165
176 template <typename TStream>
177 void print_used_memory(TStream& stream, const relations_manager_memory_usage& mu) {
178 const auto total = mu.relations_db + mu.members_db + mu.stash;
179
180 stream << " relations: " << std::setw(8) << (mu.relations_db / 1024) << " kB\n"
181 << " members: " << std::setw(8) << (mu.members_db / 1024) << " kB\n"
182 << " stash: " << std::setw(8) << (mu.stash / 1024) << " kB\n"
183 << " total: " << std::setw(8) << (total / 1024) << " kB\n"
184 << " ======================\n";
185 }
186
187 } // namespace relations
188
189} // namespace osmium
190
191#endif // OSMIUM_RELATIONS_MANAGER_UTIL_HPP
buffer.hpp
check_order.hpp
osmium::Node
Definition node.hpp:48
osmium::ProgressBar
Definition progress_bar.hpp:46
osmium::ProgressBar::file_done
void file_done(std::size_t file_size)
Definition progress_bar.hpp:166
osmium::ProgressBar::update
void update(std::size_t current_size)
Definition progress_bar.hpp:150
osmium::Relation
Definition relation.hpp:161
osmium::Way
Definition way.hpp:72
osmium::handler::Handler
Definition handler.hpp:71
osmium::io::File
Definition file.hpp:72
osmium::io::Reader
Definition reader.hpp:90
osmium::io::Reader::read
osmium::memory::Buffer read()
Definition reader.hpp:444
osmium::io::Reader::offset
std::size_t offset() const noexcept
Definition reader.hpp:524
osmium::io::Reader::close
void close()
Definition reader.hpp:384
osmium::relations::SecondPassHandler::relation
void relation(const osmium::Relation &relation)
Definition manager_util.hpp:91
osmium::relations::SecondPassHandler::node
void node(const osmium::Node &node)
Definition manager_util.hpp:77
osmium::relations::SecondPassHandler::way
void way(const osmium::Way &way)
Definition manager_util.hpp:84
osmium::relations::SecondPassHandler::SecondPassHandler
SecondPassHandler(TManager &manager) noexcept
Definition manager_util.hpp:70
osmium::relations::SecondPassHandler::m_manager
TManager & m_manager
Definition manager_util.hpp:66
osmium::relations::SecondPassHandler::flush
void flush()
Definition manager_util.hpp:100
entity_bits.hpp
fwd.hpp
handler.hpp
file.hpp
osmium::osm_entity_bits::relation
@ relation
Definition entity_bits.hpp:73
osmium::relations
Code related to the assembly of OSM relations.
Definition multipolygon_collector.hpp:53
osmium::relations::print_used_memory
void print_used_memory(TStream &stream, const relations_manager_memory_usage &mu)
Definition manager_util.hpp:177
osmium::relations::read_relations
void read_relations(const osmium::io::File &file, TManager &...managers)
Definition manager_util.hpp:121
osmium
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
osmium::apply
void apply(TIterator it, TIterator end, THandlers &&... handlers)
Definition visitor.hpp:326
progress_bar.hpp
reader.hpp
osmium::relations::relations_manager_memory_usage
Definition manager_util.hpp:160
osmium::relations::relations_manager_memory_usage::members_db
std::size_t members_db
Definition manager_util.hpp:162
osmium::relations::relations_manager_memory_usage::relations_db
std::size_t relations_db
Definition manager_util.hpp:161
osmium::relations::relations_manager_memory_usage::stash
std::size_t stash
Definition manager_util.hpp:163
visitor.hpp