Libosmium  2.2.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-2015 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 namespace osmium {
42 
43  class Node;
44  class Way;
45  class Relation;
46 
47  class DiffObject {
48 
49  protected:
50 
54 
55  public:
56 
57  DiffObject() noexcept :
58  m_prev(nullptr),
59  m_curr(nullptr),
60  m_next(nullptr) {
61  }
62 
64  m_prev(&prev),
65  m_curr(&curr),
66  m_next(&next) {
67  }
68 
69  DiffObject(const DiffObject&) = default;
70  DiffObject& operator=(const DiffObject&) = default;
71 
72  DiffObject(DiffObject&&) = default;
73  DiffObject& operator=(DiffObject&&) = default;
74 
75  const osmium::OSMObject& prev() const noexcept {
76  return *m_prev;
77  }
78 
79  const osmium::OSMObject& curr() const noexcept {
80  return *m_curr;
81  }
82 
83  const osmium::OSMObject& next() const noexcept {
84  return *m_next;
85  }
86 
87  bool first() const noexcept {
88  return m_prev == m_curr;
89  }
90 
91  bool last() const noexcept {
92  return m_curr == m_next;
93  }
94 
95  osmium::item_type type() const noexcept {
96  return m_curr->type();
97  }
98 
99  osmium::object_id_type id() const noexcept {
100  return m_curr->id();
101  }
102 
104  return m_curr->version();
105  }
106 
108  return m_curr->changeset();
109  }
110 
111  const osmium::Timestamp start_time() const noexcept {
112  return m_curr->timestamp();
113  }
114 
122  const osmium::Timestamp end_time() const noexcept {
123  return last() ? osmium::end_of_time() : m_next->timestamp();
124  }
125 
133  bool is_between(const osmium::Timestamp& from, const osmium::Timestamp& to) const noexcept {
134  return start_time() < to &&
135  ((start_time() != end_time() && end_time() > from) ||
136  (start_time() == end_time() && end_time() >= from));
137  }
138 
142  bool is_visible_at(const osmium::Timestamp& timestamp) const noexcept {
143  return start_time() <= timestamp && end_time() > timestamp && m_curr->visible();
144  }
145 
146  }; // class DiffObject
147 
148  template <class T>
149  class DiffObjectDerived : public DiffObject {
150 
151  public:
152 
153  DiffObjectDerived(T& prev, T& curr, T& next) noexcept :
154  DiffObject(prev, curr, next) {
155  }
156 
157  DiffObjectDerived(const DiffObjectDerived&) = default;
158  DiffObjectDerived& operator=(const DiffObjectDerived&) = default;
159 
162 
163  const T& prev() const noexcept {
164  return *static_cast<const T*>(m_prev);
165  }
166 
167  const T& curr() const noexcept {
168  return *static_cast<const T*>(m_curr);
169  }
170 
171  const T& next() const noexcept {
172  return *static_cast<const T*>(m_next);
173  }
174 
175  }; // class DiffObjectDerived
176 
180 
181 } // namespace osmium
182 
183 #endif // OSMIUM_OSM_DIFF_OBJECT_HPP
osmium::object_version_type version() const noexcept
Definition: diff_object.hpp:103
osmium::OSMObject * m_prev
Definition: diff_object.hpp:51
const osmium::OSMObject & prev() const noexcept
Definition: diff_object.hpp:75
Definition: diff_object.hpp:47
osmium::item_type type() const noexcept
Definition: diff_object.hpp:95
item_type
Definition: item_type.hpp:43
bool last() const noexcept
Definition: diff_object.hpp:91
const T & next() const noexcept
Definition: diff_object.hpp:171
osmium::OSMObject * m_curr
Definition: diff_object.hpp:52
DiffObject() noexcept
Definition: diff_object.hpp:57
const osmium::Timestamp start_time() const noexcept
Definition: diff_object.hpp:111
osmium::changeset_id_type changeset() const noexcept
Definition: diff_object.hpp:107
DiffObjectDerived & operator=(const DiffObjectDerived &)=default
bool is_visible_at(const osmium::Timestamp &timestamp) const noexcept
Definition: diff_object.hpp:142
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
Namespace for everything in the Osmium library.
Definition: assembler.hpp:55
const T & curr() const noexcept
Definition: diff_object.hpp:167
DiffObject & operator=(const DiffObject &)=default
const osmium::Timestamp end_time() const noexcept
Definition: diff_object.hpp:122
DiffObjectDerived(T &prev, T &curr, T &next) noexcept
Definition: diff_object.hpp:153
Definition: timestamp.hpp:53
osmium::OSMObject * m_next
Definition: diff_object.hpp:53
OSMIUM_CONSTEXPR Timestamp end_of_time() noexcept
Definition: timestamp.hpp:164
changeset_id_type changeset() const noexcept
Get changeset id of this object.
Definition: object.hpp:210
Definition: diff_object.hpp:149
DiffObjectDerived< osmium::Relation > DiffRelation
Definition: diff_object.hpp:179
osmium::object_id_type id() const noexcept
Definition: diff_object.hpp:99
const osmium::OSMObject & curr() const noexcept
Definition: diff_object.hpp:79
DiffObject(osmium::OSMObject &prev, osmium::OSMObject &curr, osmium::OSMObject &next) noexcept
Definition: diff_object.hpp:63
object_id_type id() const noexcept
Get ID of this object.
Definition: object.hpp:110
object_version_type version() const noexcept
Get version of this object.
Definition: object.hpp:186
const T & prev() const noexcept
Definition: diff_object.hpp:163
DiffObjectDerived< osmium::Node > DiffNode
Definition: diff_object.hpp:177
bool visible() const noexcept
Is this object marked visible (ie not deleted)?
Definition: object.hpp:144
uint32_t object_version_type
Type for OSM object version number.
Definition: types.hpp:47
bool first() const noexcept
Definition: diff_object.hpp:87
uint32_t changeset_id_type
Type for OSM changeset IDs.
Definition: types.hpp:48
item_type type() const noexcept
Definition: item.hpp:156
osmium::Timestamp timestamp() const noexcept
Get timestamp when this object last changed.
Definition: object.hpp:274
const osmium::OSMObject & next() const noexcept
Definition: diff_object.hpp:83
DiffObjectDerived< osmium::Way > DiffWay
Definition: diff_object.hpp:178
Definition: object.hpp:58
bool is_between(const osmium::Timestamp &from, const osmium::Timestamp &to) const noexcept
Definition: diff_object.hpp:133