Libosmium  2.20.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
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
37#include <osmium/osm/object.hpp>
39#include <osmium/osm/types.hpp>
40
41#include <cassert>
42
43namespace osmium {
44
45 class Node;
46 class Way;
47 class Relation;
48
66 class DiffObject {
67
68 const osmium::OSMObject* m_prev = nullptr;
69 const osmium::OSMObject* m_curr = nullptr;
70 const osmium::OSMObject* m_next = nullptr;
71
72 public:
73
78 DiffObject() noexcept = default;
79
85 DiffObject(const osmium::OSMObject& prev, const osmium::OSMObject& curr, const osmium::OSMObject& next) noexcept :
86 m_prev(&prev),
87 m_curr(&curr),
88 m_next(&next) {
89 assert(prev.type() == curr.type() && curr.type() == next.type());
90 assert(prev.id() == curr.id() && curr.id() == next.id());
91 }
92
96 bool empty() const noexcept {
97 return m_prev == nullptr;
98 }
99
105 const osmium::OSMObject& prev() const noexcept {
106 assert(m_prev && m_curr && m_next);
107 return *m_prev;
108 }
109
115 const osmium::OSMObject& curr() const noexcept {
116 assert(m_prev && m_curr && m_next);
117 return *m_curr;
118 }
119
125 const osmium::OSMObject& next() const noexcept {
126 assert(m_prev && m_curr && m_next);
127 return *m_next;
128 }
129
135 bool first() const noexcept {
136 assert(m_prev && m_curr && m_next);
137 return m_prev == m_curr;
138 }
139
145 bool last() const noexcept {
146 assert(m_prev && m_curr && m_next);
147 return m_curr == m_next;
148 }
149
155 osmium::item_type type() const noexcept {
156 assert(m_prev && m_curr && m_next);
157 return m_curr->type();
158 }
159
165 osmium::object_id_type id() const noexcept {
166 assert(m_prev && m_curr && m_next);
167 return m_curr->id();
168 }
169
176 assert(m_prev && m_curr && m_next);
177 return m_curr->version();
178 }
179
186 assert(m_prev && m_curr && m_next);
187 return m_curr->changeset();
188 }
189
195 osmium::Timestamp start_time() const noexcept {
196 assert(m_prev && m_curr && m_next);
197 return m_curr->timestamp();
198 }
199
209 osmium::Timestamp end_time() const noexcept {
210 assert(m_prev && m_curr && m_next);
211 return last() ? osmium::end_of_time() : m_next->timestamp();
212 }
213
223 bool is_between(const osmium::Timestamp& from, const osmium::Timestamp& to) const noexcept {
224 assert(m_prev && m_curr && m_next);
225 return start_time() < to &&
226 ((start_time() != end_time() && end_time() > from) ||
227 (start_time() == end_time() && end_time() >= from));
228 }
229
235 bool is_visible_at(const osmium::Timestamp& timestamp) const noexcept {
236 assert(m_prev && m_curr && m_next);
237 return start_time() <= timestamp && end_time() > timestamp && m_curr->visible();
238 }
239
240 }; // class DiffObject
241
242 template <typename T>
244
245 public:
246
247 DiffObjectDerived(const T& prev, const T& curr, const T& next) noexcept :
249 }
250
251 const T& prev() const noexcept {
252 return static_cast<const T&>(DiffObject::prev());
253 }
254
255 const T& curr() const noexcept {
256 return static_cast<const T&>(DiffObject::curr());
257 }
258
259 const T& next() const noexcept {
260 return static_cast<const T&>(DiffObject::next());
261 }
262
263 }; // class DiffObjectDerived
264
268
269} // namespace osmium
270
271#endif // OSMIUM_OSM_DIFF_OBJECT_HPP
Definition: diff_object.hpp:243
const T & prev() const noexcept
Definition: diff_object.hpp:251
DiffObjectDerived(const T &prev, const T &curr, const T &next) noexcept
Definition: diff_object.hpp:247
const T & next() const noexcept
Definition: diff_object.hpp:259
const T & curr() const noexcept
Definition: diff_object.hpp:255
Definition: diff_object.hpp:66
osmium::Timestamp end_time() const noexcept
Definition: diff_object.hpp:209
bool is_visible_at(const osmium::Timestamp &timestamp) const noexcept
Definition: diff_object.hpp:235
osmium::item_type type() const noexcept
Definition: diff_object.hpp:155
bool empty() const noexcept
Definition: diff_object.hpp:96
DiffObject() noexcept=default
osmium::Timestamp start_time() const noexcept
Definition: diff_object.hpp:195
osmium::changeset_id_type changeset() const noexcept
Definition: diff_object.hpp:185
const osmium::OSMObject & next() const noexcept
Definition: diff_object.hpp:125
const osmium::OSMObject * m_curr
Definition: diff_object.hpp:69
const osmium::OSMObject * m_prev
Definition: diff_object.hpp:68
const osmium::OSMObject & curr() const noexcept
Definition: diff_object.hpp:115
osmium::object_id_type id() const noexcept
Definition: diff_object.hpp:165
const osmium::OSMObject * m_next
Definition: diff_object.hpp:70
bool first() const noexcept
Definition: diff_object.hpp:135
const osmium::OSMObject & prev() const noexcept
Definition: diff_object.hpp:105
bool is_between(const osmium::Timestamp &from, const osmium::Timestamp &to) const noexcept
Definition: diff_object.hpp:223
bool last() const noexcept
Definition: diff_object.hpp:145
osmium::object_version_type version() const noexcept
Definition: diff_object.hpp:175
Definition: object.hpp:64
bool visible() const noexcept
Is this object marked visible (ie not deleted)?
Definition: object.hpp:152
object_version_type version() const noexcept
Get version of this object.
Definition: object.hpp:194
osmium::Timestamp timestamp() const noexcept
Get timestamp when this object last changed.
Definition: object.hpp:283
changeset_id_type changeset() const noexcept
Get changeset id of this object.
Definition: object.hpp:218
object_id_type id() const noexcept
Get ID of this object.
Definition: object.hpp:118
Definition: timestamp.hpp:175
item_type type() const noexcept
Definition: item.hpp:171
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
constexpr Timestamp end_of_time() noexcept
Definition: timestamp.hpp:328
uint32_t object_version_type
Type for OSM object version number.
Definition: types.hpp:47
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
item_type
Definition: item_type.hpp:45