Libosmium: include/osmium/handler/disk_store.hpp Source File

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

Loading...
Searching...
No Matches
disk_store.hpp
Go to the documentation of this file.
1#ifndef OSMIUM_HANDLER_DISK_STORE_HPP
2#define OSMIUM_HANDLER_DISK_STORE_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/handler.hpp>
37#include <osmium/index/map.hpp>
38#include <osmium/io/detail/read_write.hpp>
39#include <osmium/memory/buffer.hpp>
40#include <osmium/memory/item_iterator.hpp>
41#include <osmium/osm/node.hpp>
42#include <osmium/osm/relation.hpp>
43#include <osmium/osm/types.hpp>
44#include <osmium/osm/way.hpp>
45#include <osmium/visitor.hpp>
46
47#include <cstddef>
48
49namespace osmium {
50
51 namespace handler {
52
61 class DiskStore : public osmium::handler::Handler {
62
63 using offset_index_type = osmium::index::map::Map<unsigned_object_id_type, std::size_t>;
64
65 std::size_t m_offset = 0;
66 int m_data_fd;
67
68 offset_index_type& m_node_index;
69 offset_index_type& m_way_index;
70 offset_index_type& m_relation_index;
71
72 public:
73
74 explicit DiskStore(int data_fd, offset_index_type& node_index, offset_index_type& way_index, offset_index_type& relation_index) :
75 m_data_fd(data_fd),
76 m_node_index(node_index),
77 m_way_index(way_index),
78 m_relation_index(relation_index) {
79 }
80
81 void node(const osmium::Node& node) {
82 m_node_index.set(node.positive_id(), m_offset);
83 m_offset += node.byte_size();
84 }
85
86 void way(const osmium::Way& way) {
87 m_way_index.set(way.positive_id(), m_offset);
88 m_offset += way.byte_size();
89 }
90
91 void relation(const osmium::Relation& relation) {
92 m_relation_index.set(relation.positive_id(), m_offset);
93 m_offset += relation.byte_size();
94 }
95
96 void operator()(const osmium::memory::Buffer& buffer) {
97 osmium::io::detail::reliable_write(m_data_fd, buffer.data(), buffer.committed());
98 osmium::apply(buffer.begin(), buffer.end(), *this);
99 }
100
101 }; // class DiskStore
102
103 } // namespace handler
104
105} // namespace osmium
106
107#endif // OSMIUM_HANDLER_DISK_STORE_HPP
buffer.hpp
osmium::Node
Definition node.hpp:48
osmium::Relation
Definition relation.hpp:161
osmium::Way
Definition way.hpp:72
osmium::handler::DiskStore::operator()
void operator()(const osmium::memory::Buffer &buffer)
Definition disk_store.hpp:96
osmium::handler::DiskStore::m_way_index
offset_index_type & m_way_index
Definition disk_store.hpp:69
osmium::handler::DiskStore::m_data_fd
int m_data_fd
Definition disk_store.hpp:66
osmium::handler::DiskStore::DiskStore
DiskStore(int data_fd, offset_index_type &node_index, offset_index_type &way_index, offset_index_type &relation_index)
Definition disk_store.hpp:74
osmium::handler::DiskStore::way
void way(const osmium::Way &way)
Definition disk_store.hpp:86
osmium::handler::DiskStore::m_node_index
offset_index_type & m_node_index
Definition disk_store.hpp:68
osmium::handler::DiskStore::offset_index_type
osmium::index::map::Map< unsigned_object_id_type, std::size_t > offset_index_type
Definition disk_store.hpp:63
osmium::handler::DiskStore::m_offset
std::size_t m_offset
Definition disk_store.hpp:65
osmium::handler::DiskStore::relation
void relation(const osmium::Relation &relation)
Definition disk_store.hpp:91
osmium::handler::DiskStore::node
void node(const osmium::Node &node)
Definition disk_store.hpp:81
osmium::handler::DiskStore::m_relation_index
offset_index_type & m_relation_index
Definition disk_store.hpp:70
osmium::handler::Handler
Definition handler.hpp:71
osmium::index::map::Map
Definition map.hpp:97
handler.hpp
item_iterator.hpp
map.hpp
osmium::handler
Osmium handlers provide callbacks for OSM objects.
Definition dynamic_handler.hpp:49
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
node.hpp
relation.hpp
types.hpp
visitor.hpp
way.hpp