Libosmium 2.22.0 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
6 This file is part of Osmium (https://osmcode.org/libosmium).
7
8 Copyright 2013-2025 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/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
49 namespace 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
Definition disk_store.hpp:61
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::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
osmium::index::map::Map::set
virtual void set(const TId id, const TValue value)=0
Set the field with id to value.
handler.hpp
item_iterator.hpp
map.hpp
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
osmium::item_type::relation
@ relation
osmium::item_type::node
@ node
osmium::item_type::way
@ way
node.hpp
relation.hpp
types.hpp
visitor.hpp
way.hpp