Libosmium  2.11.0
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 (http://osmcode.org/libosmium).
7 
8 Copyright 2013-2017 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 <cstddef>
37 
38 #include <osmium/handler.hpp>
39 #include <osmium/index/map.hpp>
40 #include <osmium/io/detail/read_write.hpp>
41 #include <osmium/memory/buffer.hpp>
43 #include <osmium/osm/node.hpp>
44 #include <osmium/osm/relation.hpp>
45 #include <osmium/osm/types.hpp>
46 #include <osmium/osm/way.hpp>
47 #include <osmium/visitor.hpp>
48 
49 namespace osmium {
50 
51  namespace handler {
52 
62 
64 
65  size_t m_offset = 0;
66  int m_data_fd;
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  DiskStore(const DiskStore&) = delete;
82  DiskStore& operator=(const DiskStore&) = delete;
83 
84  ~DiskStore() noexcept = default;
85 
86  void node(const osmium::Node& node) {
87  m_node_index.set(node.positive_id(), m_offset);
88  m_offset += node.byte_size();
89  }
90 
91  void way(const osmium::Way& way) {
92  m_way_index.set(way.positive_id(), m_offset);
93  m_offset += way.byte_size();
94  }
95 
97  m_relation_index.set(relation.positive_id(), m_offset);
98  m_offset += relation.byte_size();
99  }
100 
101  void operator()(const osmium::memory::Buffer& buffer) {
102  osmium::io::detail::reliable_write(m_data_fd, buffer.data(), buffer.committed());
103  osmium::apply(buffer.begin(), buffer.end(), *this);
104  }
105 
106  }; // class DiskStore
107 
108  } // namespace handler
109 
110 } // namespace osmium
111 
112 #endif // OSMIUM_HANDLER_DISK_STORE_HPP
offset_index_type & m_relation_index
Definition: disk_store.hpp:70
size_t m_offset
Definition: disk_store.hpp:65
offset_index_type & m_node_index
Definition: disk_store.hpp:68
void node(const osmium::Node &node)
Definition: disk_store.hpp:86
int m_data_fd
Definition: disk_store.hpp:66
Definition: relation.hpp:168
Definition: handler.hpp:71
Definition: way.hpp:72
void operator()(const osmium::memory::Buffer &buffer)
Definition: disk_store.hpp:101
DiskStore(int data_fd, offset_index_type &node_index, offset_index_type &way_index, offset_index_type &relation_index)
Definition: disk_store.hpp:74
t_iterator< T > end()
Definition: buffer.hpp:625
Definition: disk_store.hpp:61
Namespace for everything in the Osmium library.
Definition: assembler.hpp:73
t_iterator< T > begin()
Definition: buffer.hpp:569
unsigned char * data() const noexcept
Definition: buffer.hpp:242
~DiskStore() noexcept=default
offset_index_type & m_way_index
Definition: disk_store.hpp:69
item_size_type byte_size() const noexcept
Definition: item.hpp:161
size_t committed() const noexcept
Definition: buffer.hpp:259
void apply(TIterator it, TIterator end, THandlers &&...handlers)
Definition: visitor.hpp:218
Definition: buffer.hpp:97
Definition: node.hpp:48
void way(const osmium::Way &way)
Definition: disk_store.hpp:91
unsigned_object_id_type positive_id() const noexcept
Get absolute value of the ID of this object.
Definition: object.hpp:131
void relation(const osmium::Relation &relation)
Definition: disk_store.hpp:96
DiskStore & operator=(const DiskStore &)=delete
virtual void set(const TId id, const TValue value)=0
Set the field with id to value.
Definition: map.hpp:97