Libosmium  2.8.0
Fast and flexible C++ library for working with OpenStreetMap data
diff_object.hpp
Go to the documentation of this file.
1 #ifndef OSMIUM_OSM_DIFF_OBJECT_HPP
2 #define OSMIUM_OSM_DIFF_OBJECT_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 <cassert>
37 
38 #include <osmium/fwd.hpp>
39 #include <osmium/osm/item_type.hpp>
40 #include <osmium/osm/object.hpp>
41 #include <osmium/osm/timestamp.hpp>
42 #include <osmium/osm/types.hpp>
43 
44 namespace osmium {
45 
63  class DiffObject {
64 
68 
69  public:
70 
75  DiffObject() noexcept :
76  m_prev(nullptr),
77  m_curr(nullptr),
78  m_next(nullptr) {
79  }
80 
87  m_prev(&prev),
88  m_curr(&curr),
89  m_next(&next) {
90  assert(prev.type() == curr.type() && curr.type() == next.type());
91  assert(prev.id() == curr.id() && curr.id() == next.id());
92  }
93 
97  bool empty() const noexcept {
98  return m_prev == nullptr;
99  }
100 
106  const osmium::OSMObject& prev() const noexcept {
107  assert(m_prev && m_curr && m_next);
108  return *m_prev;
109  }
110 
116  const osmium::OSMObject& curr() const noexcept {
117  assert(m_prev && m_curr && m_next);
118  return *m_curr;
119  }
120 
126  const osmium::OSMObject& next() const noexcept {
127  assert(m_prev && m_curr && m_next);
128  return *m_next;
129  }
130 
136  bool first() const noexcept {
137  assert(m_prev && m_curr && m_next);
138  return m_prev == m_curr;
139  }
140 
146  bool last() const noexcept {
147  assert(m_prev && m_curr && m_next);
148  return m_curr == m_next;
149  }
150 
156  osmium::item_type type() const noexcept {
157  assert(m_prev && m_curr && m_next);
158  return m_curr->type();
159  }
160 
166  osmium::object_id_type id() const noexcept {
167  assert(m_prev && m_curr && m_next);
168  return m_curr->id();
169  }
170 
177  assert(m_prev && m_curr && m_next);
178  return m_curr->version();
179  }
180 
187  assert(m_prev && m_curr && m_next);
188  return m_curr->changeset();
189  }
190 
196  const osmium::Timestamp start_time() const noexcept {
197  assert(m_prev && m_curr && m_next);
198  return m_curr->timestamp();
199  }
200 
210  const osmium::Timestamp end_time() const noexcept {
211  assert(m_prev && m_curr && m_next);
212  return last() ? osmium::end_of_time() : m_next->timestamp();
213  }
214 
224  bool is_between(const osmium::Timestamp& from, const osmium::Timestamp& to) const noexcept {
225  assert(m_prev && m_curr && m_next);
226  return start_time() < to &&
227  ((start_time() != end_time() && end_time() > from) ||
228  (start_time() == end_time() && end_time() >= from));
229  }
230 
236  bool is_visible_at(const osmium::Timestamp& timestamp) const noexcept {
237  assert(m_prev && m_curr && m_next);
238  return start_time() <= timestamp && end_time() > timestamp && m_curr->visible();
239  }
240 
241  }; // class DiffObject
242 
243  template <typename T>
244  class DiffObjectDerived : public DiffObject {
245 
246  public:
247 
248  DiffObjectDerived(const T& prev, const T& curr, const T& next) noexcept :
249  DiffObject(prev, curr, next) {
250  }
251 
252  const T& prev() const noexcept {
253  return static_cast<const T&>(DiffObject::prev());
254  }
255 
256  const T& curr() const noexcept {
257  return static_cast<const T&>(DiffObject::curr());
258  }
259 
260  const T& next() const noexcept {
261  return static_cast<const T&>(DiffObject::next());
262  }
263 
264  }; // class DiffObjectDerived
265 
269 
270 } // namespace osmium
271 
272 #endif // OSMIUM_OSM_DIFF_OBJECT_HPP
uint32_t object_version_type
Type for OSM object version number.
Definition: types.hpp:47
osmium::object_version_type version() const noexcept
Definition: diff_object.hpp:176
DiffObjectDerived(const T &prev, const T &curr, const T &next) noexcept
Definition: diff_object.hpp:248
const osmium::OSMObject & prev() const noexcept
Definition: diff_object.hpp:106
Definition: diff_object.hpp:63
osmium::item_type type() const noexcept
Definition: diff_object.hpp:156
item_type
Definition: item_type.hpp:43
bool last() const noexcept
Definition: diff_object.hpp:146
const T & next() const noexcept
Definition: diff_object.hpp:260
DiffObject() noexcept
Definition: diff_object.hpp:75
const osmium::Timestamp start_time() const noexcept
Definition: diff_object.hpp:196
osmium::changeset_id_type changeset() const noexcept
Definition: diff_object.hpp:186
bool is_visible_at(const osmium::Timestamp &timestamp) const noexcept
Definition: diff_object.hpp:236
Namespace for everything in the Osmium library.
Definition: assembler.hpp:66
const T & curr() const noexcept
Definition: diff_object.hpp:256
const osmium::Timestamp end_time() const noexcept
Definition: diff_object.hpp:210
const osmium::OSMObject * m_next
Definition: diff_object.hpp:67
Definition: timestamp.hpp:56
const osmium::OSMObject * m_prev
Definition: diff_object.hpp:65
bool empty() const noexcept
Definition: diff_object.hpp:97
uint32_t changeset_id_type
Type for OSM changeset IDs.
Definition: types.hpp:48
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
changeset_id_type changeset() const noexcept
Get changeset id of this object.
Definition: object.hpp:212
Definition: diff_object.hpp:244
osmium::object_id_type id() const noexcept
Definition: diff_object.hpp:166
const osmium::OSMObject & curr() const noexcept
Definition: diff_object.hpp:116
DiffObject(const osmium::OSMObject &prev, const osmium::OSMObject &curr, const osmium::OSMObject &next) noexcept
Definition: diff_object.hpp:86
object_id_type id() const noexcept
Get ID of this object.
Definition: object.hpp:112
object_version_type version() const noexcept
Get version of this object.
Definition: object.hpp:188
const T & prev() const noexcept
Definition: diff_object.hpp:252
bool visible() const noexcept
Is this object marked visible (ie not deleted)?
Definition: object.hpp:146
bool first() const noexcept
Definition: diff_object.hpp:136
const osmium::OSMObject * m_curr
Definition: diff_object.hpp:66
constexpr Timestamp end_of_time() noexcept
Definition: timestamp.hpp:228
item_type type() const noexcept
Definition: item.hpp:155
osmium::Timestamp timestamp() const noexcept
Get timestamp when this object last changed.
Definition: object.hpp:276
const osmium::OSMObject & next() const noexcept
Definition: diff_object.hpp:126
Definition: object.hpp:60
bool is_between(const osmium::Timestamp &from, const osmium::Timestamp &to) const noexcept
Definition: diff_object.hpp:224