Loading...
Searching...
No Matches
manager_util.hpp
Go to the documentation of this file.
#ifndef OSMIUM_RELATIONS_MANAGER_UTIL_HPP
#define OSMIUM_RELATIONS_MANAGER_UTIL_HPP
/*
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2026 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <osmium/fwd.hpp>
#include <osmium/handler.hpp>
#include <osmium/handler/check_order.hpp>
#include <osmium/io/file.hpp>
#include <osmium/io/reader.hpp>
#include <osmium/memory/buffer.hpp>
#include <osmium/osm/entity_bits.hpp>
#include <osmium/util/progress_bar.hpp>
#include <osmium/visitor.hpp>
#include <cstddef>
#include <initializer_list>
#include <iomanip>
#include <utility>
namespace osmium {
namespace relations {
template <typename TManager>
class SecondPassHandler : public osmium::handler::Handler {
TManager& m_manager;
public:
explicit SecondPassHandler(TManager& manager) noexcept :
m_manager(manager) {
}
void node(const osmium::Node& node) {
m_manager.handle_node(node);
}
void way(const osmium::Way& way) {
m_manager.handle_way(way);
}
void relation(const osmium::Relation& relation) {
m_manager.handle_relation(relation);
}
void flush() {
m_manager.flush_output();
}
}; // class SecondPassHandler
template <typename ...TManager>
void read_relations(const osmium::io::File& file, TManager& ...managers) {
osmium::io::Reader reader{file, osmium::osm_entity_bits::relation};
osmium::apply(reader, managers...);
reader.close();
(void)std::initializer_list<int>{(managers.prepare_for_lookup(), 0)...};
}
template <typename ...TManager>
void read_relations(osmium::ProgressBar& progress_bar, const osmium::io::File& file, TManager& ...managers) {
osmium::io::Reader reader{file, osmium::osm_entity_bits::relation};
while (auto buffer = reader.read()) {
progress_bar.update(reader.offset());
osmium::apply(buffer, managers...);
}
reader.close();
(void)std::initializer_list<int>{(managers.prepare_for_lookup(), 0)...};
progress_bar.file_done(file.size());
}
struct relations_manager_memory_usage {
std::size_t relations_db;
std::size_t members_db;
std::size_t stash;
};
template <typename TStream>
void print_used_memory(TStream& stream, const relations_manager_memory_usage& mu) {
const auto total = mu.relations_db + mu.members_db + mu.stash;
stream << " relations: " << std::setw(8) << (mu.relations_db / 1024) << " kB\n"
<< " members: " << std::setw(8) << (mu.members_db / 1024) << " kB\n"
<< " stash: " << std::setw(8) << (mu.stash / 1024) << " kB\n"
<< " total: " << std::setw(8) << (total / 1024) << " kB\n"
<< " ======================\n";
}
} // namespace relations
} // namespace osmium
#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