Libosmium  2.20.0
Fast and flexible C++ library for working with OpenStreetMap data
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-2023 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>
41#include <osmium/osm/node.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
62
64
65 std::size_t m_offset = 0;
67
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
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
Definition: node.hpp:48
Definition: relation.hpp:161
Definition: way.hpp:72
Definition: disk_store.hpp:61
void operator()(const osmium::memory::Buffer &buffer)
Definition: disk_store.hpp:96
offset_index_type & m_way_index
Definition: disk_store.hpp:69
int m_data_fd
Definition: disk_store.hpp:66
DiskStore(int data_fd, offset_index_type &node_index, offset_index_type &way_index, offset_index_type &relation_index)
Definition: disk_store.hpp:74
void way(const osmium::Way &way)
Definition: disk_store.hpp:86
offset_index_type & m_node_index
Definition: disk_store.hpp:68
std::size_t m_offset
Definition: disk_store.hpp:65
void relation(const osmium::Relation &relation)
Definition: disk_store.hpp:91
void node(const osmium::Node &node)
Definition: disk_store.hpp:81
offset_index_type & m_relation_index
Definition: disk_store.hpp:70
Definition: handler.hpp:71
Definition: map.hpp:97
virtual void set(const TId id, const TValue value)=0
Set the field with id to value.
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
void apply(TIterator it, TIterator end, THandlers &&... handlers)
Definition: visitor.hpp:326