Libosmium  2.6.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-2016 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 
59 
61 
62  size_t m_offset = 0;
63  int m_data_fd;
64 
65  offset_index_type& m_node_index;
66  offset_index_type& m_way_index;
67  offset_index_type& m_relation_index;
68 
69  public:
70 
71  explicit DiskStore(int data_fd, offset_index_type& node_index, offset_index_type& way_index, offset_index_type& relation_index) :
72  m_data_fd(data_fd),
73  m_node_index(node_index),
74  m_way_index(way_index),
75  m_relation_index(relation_index) {
76  }
77 
78  DiskStore(const DiskStore&) = delete;
79  DiskStore& operator=(const DiskStore&) = delete;
80 
81  ~DiskStore() noexcept = default;
82 
83  void node(const osmium::Node& node) {
84  m_node_index.set(node.positive_id(), m_offset);
85  m_offset += node.byte_size();
86  }
87 
88  void way(const osmium::Way& way) {
89  m_way_index.set(way.positive_id(), m_offset);
90  m_offset += way.byte_size();
91  }
92 
94  m_relation_index.set(relation.positive_id(), m_offset);
95  m_offset += relation.byte_size();
96  }
97 
98  // XXX
99  void operator()(const osmium::memory::Buffer& buffer) {
100  osmium::io::detail::reliable_write(m_data_fd, buffer.data(), buffer.committed());
101 
102  osmium::apply(buffer.begin(), buffer.end(), *this);
103  }
104 
105  }; // class DiskStore
106 
107  } // namespace handler
108 
109 } // namespace osmium
110 
111 #endif // OSMIUM_HANDLER_DISK_STORE_HPP
offset_index_type & m_relation_index
Definition: disk_store.hpp:67
size_t m_offset
Definition: disk_store.hpp:62
offset_index_type & m_node_index
Definition: disk_store.hpp:65
void node(const osmium::Node &node)
Definition: disk_store.hpp:83
int m_data_fd
Definition: disk_store.hpp:63
osmium::index::map::Map< unsigned_object_id_type, size_t > offset_index_type
Definition: disk_store.hpp:60
Definition: relation.hpp:165
Definition: handler.hpp:45
Definition: way.hpp:65
void operator()(const osmium::memory::Buffer &buffer)
Definition: disk_store.hpp:99
void apply(TIterator it, TIterator end, THandlers &...handlers)
Definition: visitor.hpp:234
DiskStore(int data_fd, offset_index_type &node_index, offset_index_type &way_index, offset_index_type &relation_index)
Definition: disk_store.hpp:71
t_iterator< T > end()
Definition: buffer.hpp:585
Definition: disk_store.hpp:58
Namespace for everything in the Osmium library.
Definition: assembler.hpp:59
t_iterator< T > begin()
Definition: buffer.hpp:529
unsigned char * data() const noexcept
Definition: buffer.hpp:224
~DiskStore() noexcept=default
offset_index_type & m_way_index
Definition: disk_store.hpp:66
item_size_type byte_size() const noexcept
Definition: item.hpp:147
size_t committed() const noexcept
Definition: buffer.hpp:241
Definition: buffer.hpp:97
Definition: node.hpp:47
void way(const osmium::Way &way)
Definition: disk_store.hpp:88
unsigned_object_id_type positive_id() const noexcept
Get absolute value of the ID of this object.
Definition: object.hpp:115
void relation(const osmium::Relation &relation)
Definition: disk_store.hpp:93
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:85