Libosmium  2.13.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-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 <cassert>
37 
38 #include <osmium/osm/item_type.hpp>
39 #include <osmium/osm/object.hpp>
40 #include <osmium/osm/timestamp.hpp>
41 #include <osmium/osm/types.hpp>
42 
43 namespace osmium {
44 
45  class Node;
46  class Way;
47  class Relation;
48 
66  class DiffObject {
67 
71 
72  public:
73 
78  DiffObject() noexcept :
79  m_prev(nullptr),
80  m_curr(nullptr),
81  m_next(nullptr) {
82  }
83 
90  m_prev(&prev),
91  m_curr(&curr),
92  m_next(&next) {
93  assert(prev.type() == curr.type() && curr.type() == next.type());
94  assert(prev.id() == curr.id() && curr.id() == next.id());
95  }
96 
100  bool empty() const noexcept {
101  return m_prev == nullptr;
102  }
103 
109  const osmium::OSMObject& prev() const noexcept {
110  assert(m_prev && m_curr && m_next);
111  return *m_prev;
112  }
113 
119  const osmium::OSMObject& curr() const noexcept {
120  assert(m_prev && m_curr && m_next);
121  return *m_curr;
122  }
123 
129  const osmium::OSMObject& next() const noexcept {
130  assert(m_prev && m_curr && m_next);
131  return *m_next;
132  }
133 
139  bool first() const noexcept {
140  assert(m_prev && m_curr && m_next);
141  return m_prev == m_curr;
142  }
143 
149  bool last() const noexcept {
150  assert(m_prev && m_curr && m_next);
151  return m_curr == m_next;
152  }
153 
159  osmium::item_type type() const noexcept {
160  assert(m_prev && m_curr && m_next);
161  return m_curr->type();
162  }
163 
169  osmium::object_id_type id() const noexcept {
170  assert(m_prev && m_curr && m_next);
171  return m_curr->id();
172  }
173 
180  assert(m_prev && m_curr && m_next);
181  return m_curr->version();
182  }
183 
190  assert(m_prev && m_curr && m_next);
191  return m_curr->changeset();
192  }
193 
199  const osmium::Timestamp start_time() const noexcept {
200  assert(m_prev && m_curr && m_next);
201  return m_curr->timestamp();
202  }
203 
213  const osmium::Timestamp end_time() const noexcept {
214  assert(m_prev && m_curr && m_next);
215  return last() ? osmium::end_of_time() : m_next->timestamp();
216  }
217 
227  bool is_between(const osmium::Timestamp& from, const osmium::Timestamp& to) const noexcept {
228  assert(m_prev && m_curr && m_next);
229  return start_time() < to &&
230  ((start_time() != end_time() && end_time() > from) ||
231  (start_time() == end_time() && end_time() >= from));
232  }
233 
239  bool is_visible_at(const osmium::Timestamp& timestamp) const noexcept {
240  assert(m_prev && m_curr && m_next);
241  return start_time() <= timestamp && end_time() > timestamp && m_curr->visible();
242  }
243 
244  }; // class DiffObject
245 
246  template <typename T>
247  class DiffObjectDerived : public DiffObject {
248 
249  public:
250 
251  DiffObjectDerived(const T& prev, const T& curr, const T& next) noexcept :
252  DiffObject(prev, curr, next) {
253  }
254 
255  const T& prev() const noexcept {
256  return static_cast<const T&>(DiffObject::prev());
257  }
258 
259  const T& curr() const noexcept {
260  return static_cast<const T&>(DiffObject::curr());
261  }
262 
263  const T& next() const noexcept {
264  return static_cast<const T&>(DiffObject::next());
265  }
266 
267  }; // class DiffObjectDerived
268 
272 
273 } // namespace osmium
274 
275 #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:179
DiffObjectDerived(const T &prev, const T &curr, const T &next) noexcept
Definition: diff_object.hpp:251
const osmium::OSMObject & prev() const noexcept
Definition: diff_object.hpp:109
Definition: diff_object.hpp:66
osmium::item_type type() const noexcept
Definition: diff_object.hpp:159
item_type
Definition: item_type.hpp:43
bool last() const noexcept
Definition: diff_object.hpp:149
const T & next() const noexcept
Definition: diff_object.hpp:263
DiffObject() noexcept
Definition: diff_object.hpp:78
const osmium::Timestamp start_time() const noexcept
Definition: diff_object.hpp:199
osmium::changeset_id_type changeset() const noexcept
Definition: diff_object.hpp:189
bool is_visible_at(const osmium::Timestamp &timestamp) const noexcept
Definition: diff_object.hpp:239
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
const T & curr() const noexcept
Definition: diff_object.hpp:259
const osmium::Timestamp end_time() const noexcept
Definition: diff_object.hpp:213
const osmium::OSMObject * m_next
Definition: diff_object.hpp:70
Definition: timestamp.hpp:115
const osmium::OSMObject * m_prev
Definition: diff_object.hpp:68
bool empty() const noexcept
Definition: diff_object.hpp:100
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:226
Definition: diff_object.hpp:247
osmium::object_id_type id() const noexcept
Definition: diff_object.hpp:169
const osmium::OSMObject & curr() const noexcept
Definition: diff_object.hpp:119
DiffObject(const osmium::OSMObject &prev, const osmium::OSMObject &curr, const osmium::OSMObject &next) noexcept
Definition: diff_object.hpp:89
object_id_type id() const noexcept
Get ID of this object.
Definition: object.hpp:126
object_version_type version() const noexcept
Get version of this object.
Definition: object.hpp:202
const T & prev() const noexcept
Definition: diff_object.hpp:255
bool visible() const noexcept
Is this object marked visible (ie not deleted)?
Definition: object.hpp:160
bool first() const noexcept
Definition: diff_object.hpp:139
const osmium::OSMObject * m_curr
Definition: diff_object.hpp:69
constexpr Timestamp end_of_time() noexcept
Definition: timestamp.hpp:267
item_type type() const noexcept
Definition: item.hpp:169
osmium::Timestamp timestamp() const noexcept
Get timestamp when this object last changed.
Definition: object.hpp:290
const osmium::OSMObject & next() const noexcept
Definition: diff_object.hpp:129
Definition: object.hpp:64
bool is_between(const osmium::Timestamp &from, const osmium::Timestamp &to) const noexcept
Definition: diff_object.hpp:227