Libosmium 2.22.0 Fast and flexible C++ library for working with OpenStreetMap data

Loading...
Searching...
No Matches
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 (https://osmcode.org/libosmium).
7
8 Copyright 2013-2025 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 <osmium/osm/item_type.hpp>
37#include <osmium/osm/object.hpp>
38#include <osmium/osm/timestamp.hpp>
39#include <osmium/osm/types.hpp>
40
41#include <cassert>
42
43 namespace 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
175 osmium::object_version_type version() const noexcept {
176 assert(m_prev && m_curr && m_next);
177 return m_curr->version();
178 }
179
185 osmium::changeset_id_type changeset() const noexcept {
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>
243 class DiffObjectDerived : public DiffObject {
244
245 public:
246
247 DiffObjectDerived(const T& prev, const T& curr, const T& next) noexcept :
248 DiffObject(prev, curr, next) {
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
265 using DiffNode = DiffObjectDerived<osmium::Node>;
266 using DiffWay = DiffObjectDerived<osmium::Way>;
267 using DiffRelation = DiffObjectDerived<osmium::Relation>;
268
269} // namespace osmium
270
271#endif // OSMIUM_OSM_DIFF_OBJECT_HPP
osmium::DiffObjectDerived
Definition diff_object.hpp:243
osmium::DiffObjectDerived::prev
const T & prev() const noexcept
Definition diff_object.hpp:251
osmium::DiffObjectDerived::DiffObjectDerived
DiffObjectDerived(const T &prev, const T &curr, const T &next) noexcept
Definition diff_object.hpp:247
osmium::DiffObjectDerived::next
const T & next() const noexcept
Definition diff_object.hpp:259
osmium::DiffObjectDerived::curr
const T & curr() const noexcept
Definition diff_object.hpp:255
osmium::DiffObject
Definition diff_object.hpp:66
osmium::DiffObject::end_time
osmium::Timestamp end_time() const noexcept
Definition diff_object.hpp:209
osmium::DiffObject::is_visible_at
bool is_visible_at(const osmium::Timestamp &timestamp) const noexcept
Definition diff_object.hpp:235
osmium::DiffObject::type
osmium::item_type type() const noexcept
Definition diff_object.hpp:155
osmium::DiffObject::empty
bool empty() const noexcept
Definition diff_object.hpp:96
osmium::DiffObject::DiffObject
DiffObject() noexcept=default
osmium::DiffObject::start_time
osmium::Timestamp start_time() const noexcept
Definition diff_object.hpp:195
osmium::DiffObject::changeset
osmium::changeset_id_type changeset() const noexcept
Definition diff_object.hpp:185
osmium::DiffObject::next
const osmium::OSMObject & next() const noexcept
Definition diff_object.hpp:125
osmium::DiffObject::m_curr
const osmium::OSMObject * m_curr
Definition diff_object.hpp:69
osmium::DiffObject::m_prev
const osmium::OSMObject * m_prev
Definition diff_object.hpp:68
osmium::DiffObject::curr
const osmium::OSMObject & curr() const noexcept
Definition diff_object.hpp:115
osmium::DiffObject::id
osmium::object_id_type id() const noexcept
Definition diff_object.hpp:165
osmium::DiffObject::m_next
const osmium::OSMObject * m_next
Definition diff_object.hpp:70
osmium::DiffObject::first
bool first() const noexcept
Definition diff_object.hpp:135
osmium::DiffObject::prev
const osmium::OSMObject & prev() const noexcept
Definition diff_object.hpp:105
osmium::DiffObject::is_between
bool is_between(const osmium::Timestamp &from, const osmium::Timestamp &to) const noexcept
Definition diff_object.hpp:223
osmium::DiffObject::last
bool last() const noexcept
Definition diff_object.hpp:145
osmium::DiffObject::version
osmium::object_version_type version() const noexcept
Definition diff_object.hpp:175
osmium::OSMObject
Definition object.hpp:64
osmium::OSMObject::visible
bool visible() const noexcept
Is this object marked visible (ie not deleted)?
Definition object.hpp:152
osmium::OSMObject::version
object_version_type version() const noexcept
Get version of this object.
Definition object.hpp:194
osmium::OSMObject::timestamp
osmium::Timestamp timestamp() const noexcept
Get timestamp when this object last changed.
Definition object.hpp:283
osmium::OSMObject::changeset
changeset_id_type changeset() const noexcept
Get changeset id of this object.
Definition object.hpp:218
osmium::OSMObject::id
object_id_type id() const noexcept
Get ID of this object.
Definition object.hpp:118
osmium::Timestamp
Definition timestamp.hpp:175
osmium::memory::Item::type
item_type type() const noexcept
Definition item.hpp:171
item_type.hpp
osmium
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
osmium::end_of_time
constexpr Timestamp end_of_time() noexcept
Definition timestamp.hpp:328
osmium::changeset_id_type
uint32_t changeset_id_type
Type for OSM changeset IDs.
Definition types.hpp:48
osmium::item_type
item_type
Definition item_type.hpp:45
osmium::object_id_type
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition types.hpp:45
osmium::object_version_type
uint32_t object_version_type
Type for OSM object version number.
Definition types.hpp:47
object.hpp
timestamp.hpp
types.hpp