Libosmium  2.15.4
Fast and flexible C++ library for working with OpenStreetMap data
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 
6 This file is part of Osmium (https://osmcode.org/libosmium).
7 
8 Copyright 2013-2019 Jochen Topf <jochen@topf.org> and others (see README).
9 
10 Boost Software License - Version 1.0 - August 17th, 2003
11 
12 Permission is hereby granted, free of charge, to any person or organization
13 obtaining a copy of the software and accompanying documentation covered by
14 this license (the "Software") to use, reproduce, display, distribute,
15 execute, and transmit the Software, and to prepare derivative works of the
16 Software, and to permit third-parties to whom the Software is furnished to
17 do so, all subject to the following:
18 
19 The copyright notices in the Software and this entire statement, including
20 the above license grant, this restriction and the following disclaimer,
21 must be included in all copies of the Software, in whole or in part, and
22 all derivative works of the Software, unless such copies or derivative
23 works are solely in the form of machine-executable object code generated by
24 a source language processor.
25 
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 DEALINGS IN THE SOFTWARE.
33 
34 */
35 
36 #include <osmium/fwd.hpp>
37 #include <osmium/handler.hpp>
39 #include <osmium/io/file.hpp>
40 #include <osmium/io/reader.hpp>
41 #include <osmium/memory/buffer.hpp>
44 #include <osmium/visitor.hpp>
45 
46 #include <cstddef>
47 #include <initializer_list>
48 #include <iomanip>
49 #include <utility>
50 
51 namespace osmium {
52 
53  namespace relations {
54 
63  template <typename TManager>
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 
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) {
123  osmium::apply(reader, std::forward<TManager>(managers)...);
124  reader.close();
125  (void)std::initializer_list<int>{
126  (std::forward<TManager>(managers).prepare_for_lookup(), 0)...
127  };
128  }
129 
146  template <typename ...TManager>
147  void read_relations(osmium::ProgressBar& progress_bar, const osmium::io::File& file, TManager&& ...managers) {
149  while (auto buffer = reader.read()) {
150  progress_bar.update(reader.offset());
151  osmium::apply(buffer, std::forward<TManager>(managers)...);
152  }
153  reader.close();
154  (void)std::initializer_list<int>{
155  (std::forward<TManager>(managers).prepare_for_lookup(), 0)...
156  };
157  progress_bar.file_done(file.size());
158  }
159 
165  std::size_t relations_db;
166  std::size_t members_db;
167  std::size_t stash;
168  };
169 
180  template <typename TStream>
181  void print_used_memory(TStream& stream, const relations_manager_memory_usage& mu) {
182  const auto total = mu.relations_db + mu.members_db + mu.stash;
183 
184  stream << " relations: " << std::setw(8) << (mu.relations_db / 1024) << " kB\n"
185  << " members: " << std::setw(8) << (mu.members_db / 1024) << " kB\n"
186  << " stash: " << std::setw(8) << (mu.stash / 1024) << " kB\n"
187  << " total: " << std::setw(8) << (total / 1024) << " kB\n"
188  << " ======================\n";
189  }
190 
191  } // namespace relations
192 
193 } // namespace osmium
194 
195 #endif // OSMIUM_RELATIONS_MANAGER_UTIL_HPP
void print_used_memory(TStream &stream, const relations_manager_memory_usage &mu)
Definition: manager_util.hpp:181
void update(std::size_t current_size)
Definition: progress_bar.hpp:150
Definition: relation.hpp:168
std::size_t members_db
Definition: manager_util.hpp:166
Definition: handler.hpp:71
SecondPassHandler(TManager &manager) noexcept
Definition: manager_util.hpp:70
Definition: way.hpp:72
Definition: manager_util.hpp:64
Definition: file.hpp:72
TManager & m_manager
Definition: manager_util.hpp:66
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
void apply(TIterator it, TIterator end, THandlers &&... handlers)
Definition: visitor.hpp:323
std::size_t stash
Definition: manager_util.hpp:167
void node(const osmium::Node &node)
Definition: manager_util.hpp:77
Definition: reader.hpp:90
Definition: progress_bar.hpp:46
void relation(const osmium::Relation &relation)
Definition: manager_util.hpp:91
void file_done(std::size_t file_size)
Definition: progress_bar.hpp:166
void flush()
Definition: manager_util.hpp:100
Definition: node.hpp:48
void read_relations(const osmium::io::File &file, TManager &&...managers)
Definition: manager_util.hpp:121
Definition: entity_bits.hpp:70
std::size_t relations_db
Definition: manager_util.hpp:165
void way(const osmium::Way &way)
Definition: manager_util.hpp:84