Libosmium  2.1.0
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 
115  const osmium::Timestamp end_time() const noexcept {
116  return last() ? osmium::Timestamp() : m_next->timestamp();
117  }
118 
119  }; // class DiffObject
120 
121  template <class T>
122  class DiffObjectDerived : public DiffObject {
123 
124  public:
125 
126  DiffObjectDerived(T& prev, T& curr, T& next) noexcept :
127  DiffObject(prev, curr, next) {
128  }
129 
130  DiffObjectDerived(const DiffObjectDerived&) = default;
131  DiffObjectDerived& operator=(const DiffObjectDerived&) = default;
132 
135 
136  const T& prev() const noexcept {
137  return *static_cast<const T*>(m_prev);
138  }
139 
140  const T& curr() const noexcept {
141  return *static_cast<const T*>(m_curr);
142  }
143 
144  const T& next() const noexcept {
145  return *static_cast<const T*>(m_next);
146  }
147 
148  }; // class DiffObjectDerived
149 
153 
154 } // namespace osmium
155 
156 #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:42
bool last() const noexcept
Definition: diff_object.hpp:91
const T & next() const noexcept
Definition: diff_object.hpp:144
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
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:46
Namespace for everything in the Osmium library.
Definition: assembler.hpp:55
const T & curr() const noexcept
Definition: diff_object.hpp:140
DiffObject & operator=(const DiffObject &)=default
const osmium::Timestamp end_time() const noexcept
Definition: diff_object.hpp:115
DiffObjectDerived(T &prev, T &curr, T &next) noexcept
Definition: diff_object.hpp:126
Definition: timestamp.hpp:52
osmium::OSMObject * m_next
Definition: diff_object.hpp:53
changeset_id_type changeset() const noexcept
Get changeset id of this object.
Definition: object.hpp:209
Definition: diff_object.hpp:122
DiffObjectDerived< osmium::Relation > DiffRelation
Definition: diff_object.hpp:152
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:109
object_version_type version() const noexcept
Get version of this object.
Definition: object.hpp:185
const T & prev() const noexcept
Definition: diff_object.hpp:136
DiffObjectDerived< osmium::Node > DiffNode
Definition: diff_object.hpp:150
uint32_t object_version_type
Type for OSM object version number.
Definition: types.hpp:48
bool first() const noexcept
Definition: diff_object.hpp:87
uint32_t changeset_id_type
Type for OSM changeset IDs.
Definition: types.hpp:49
item_type type() const noexcept
Definition: item.hpp:156
osmium::Timestamp timestamp() const noexcept
Get timestamp when this object last changed.
Definition: object.hpp:273
const osmium::OSMObject & next() const noexcept
Definition: diff_object.hpp:83
DiffObjectDerived< osmium::Way > DiffWay
Definition: diff_object.hpp:151
Definition: object.hpp:57