Libosmium  2.2.0
Fast and flexible C++ library for working with OpenStreetMap data
changeset.hpp
Go to the documentation of this file.
1 #ifndef OSMIUM_OSM_CHANGESET_HPP
2 #define OSMIUM_OSM_CHANGESET_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 <cstdint>
37 #include <cstring>
38 
40 #include <osmium/memory/item.hpp>
41 #include <osmium/osm/box.hpp>
42 #include <osmium/osm/entity.hpp>
43 #include <osmium/osm/item_type.hpp>
44 #include <osmium/osm/tag.hpp>
45 #include <osmium/osm/timestamp.hpp>
46 #include <osmium/osm/types.hpp>
48 
49 namespace osmium {
50 
51  namespace builder {
52  template <class T> class ObjectBuilder;
53  }
54 
62  class Changeset : public osmium::OSMEntity {
63 
65 
73 
76  }
77 
79  m_user_size = size;
80  }
81 
82  unsigned char* subitems_position() {
83  return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
84  }
85 
86  const unsigned char* subitems_position() const {
87  return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
88  }
89 
90  public:
91 
93  changeset_id_type id() const noexcept {
94  return m_id;
95  }
96 
104  m_id = id;
105  return *this;
106  }
107 
114  Changeset& set_id(const char* id) {
116  }
117 
119  user_id_type uid() const noexcept {
120  return m_uid;
121  }
122 
130  m_uid = uid;
131  return *this;
132  }
133 
142  m_uid = uid < 0 ? 0 : static_cast<user_id_type>(uid);
143  return *this;
144  }
145 
152  Changeset& set_uid(const char* uid) {
154  }
155 
157  bool user_is_anonymous() const noexcept {
158  return m_uid == 0;
159  }
160 
162  osmium::Timestamp created_at() const noexcept {
163  return m_created_at;
164  }
165 
172  osmium::Timestamp closed_at() const noexcept {
173  return m_closed_at;
174  }
175 
177  bool open() const noexcept {
178  return m_closed_at == osmium::Timestamp();
179  }
180 
182  bool closed() const noexcept {
183  return !open();
184  }
185 
193  m_created_at = timestamp;
194  return *this;
195  }
196 
204  m_closed_at = timestamp;
205  return *this;
206  }
207 
209  num_changes_type num_changes() const noexcept {
210  return m_num_changes;
211  }
212 
216  return *this;
217  }
218 
220  Changeset& set_num_changes(const char* num_changes) noexcept {
222  }
223 
229  osmium::Box& bounds() noexcept {
230  return m_bounds;
231  }
232 
238  const osmium::Box& bounds() const noexcept {
239  return m_bounds;
240  }
241 
243  const char* user() const {
244  return reinterpret_cast<const char*>(data() + sizeof(Changeset));
245  }
246 
248  const TagList& tags() const {
249  return osmium::detail::subitem_of_type<const TagList>(cbegin(), cend());
250  }
251 
259  void set_attribute(const char* attr, const char* value) {
260  if (!strcmp(attr, "id")) {
261  set_id(value);
262  } else if (!strcmp(attr, "num_changes")) {
263  set_num_changes(value);
264  } else if (!strcmp(attr, "created_at")) {
266  } else if (!strcmp(attr, "closed_at")) {
268  } else if (!strcmp(attr, "uid")) {
269  set_uid(value);
270  }
271  }
272 
275 
276  iterator begin() {
277  return iterator(subitems_position());
278  }
279 
280  iterator end() {
281  return iterator(data() + padded_size());
282  }
283 
284  const_iterator cbegin() const {
286  }
287 
288  const_iterator cend() const {
289  return const_iterator(data() + padded_size());
290  }
291 
292  const_iterator begin() const {
293  return cbegin();
294  }
295 
296  const_iterator end() const {
297  return cend();
298  }
299 
300  }; // class Changeset
301 
302 
306  inline bool operator==(const Changeset& lhs, const Changeset& rhs) {
307  return lhs.id() == rhs.id();
308  }
309 
310  inline bool operator!=(const Changeset& lhs, const Changeset& rhs) {
311  return ! (lhs == rhs);
312  }
313 
317  inline bool operator<(const Changeset& lhs, const Changeset& rhs) {
318  return lhs.id() < rhs.id();
319  }
320 
321  inline bool operator>(const Changeset& lhs, const Changeset& rhs) {
322  return rhs < lhs;
323  }
324 
325  inline bool operator<=(const Changeset& lhs, const Changeset& rhs) {
326  return ! (rhs < lhs);
327  }
328 
329  inline bool operator>=(const Changeset& lhs, const Changeset& rhs) {
330  return ! (lhs < rhs);
331  }
332 
333 } // namespace osmium
334 
335 #endif // OSMIUM_OSM_CHANGESET_HPP
osmium::Timestamp m_closed_at
Definition: changeset.hpp:67
Changeset & set_closed_at(const osmium::Timestamp timestamp)
Definition: changeset.hpp:203
Definition: collection.hpp:48
num_changes_type m_num_changes
Definition: changeset.hpp:70
Definition: tag.hpp:105
bool operator<=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:325
osmium::Box & bounds() noexcept
Definition: changeset.hpp:229
bool open() const noexcept
Is this changeset open?
Definition: changeset.hpp:177
string_size_type m_user_size
Definition: changeset.hpp:72
void set_attribute(const char *attr, const char *value)
Definition: changeset.hpp:259
user_id_type uid() const noexcept
Get user id.
Definition: changeset.hpp:119
item_type
Definition: item_type.hpp:43
Changeset & set_uid_from_signed(signed_user_id_type uid) noexcept
Definition: changeset.hpp:141
const TagList & tags() const
Get the list of tags.
Definition: changeset.hpp:248
const char * user() const
Get user name.
Definition: changeset.hpp:243
changeset_id_type id() const noexcept
Get ID of this changeset.
Definition: changeset.hpp:93
item_size_type padded_size() const
Definition: item.hpp:152
OSMEntity is the abstract base class for the OSMObject and Changeset classes.
Definition: entity.hpp:63
const_iterator begin() const
Definition: changeset.hpp:292
T padded_length(T length) noexcept
Definition: item.hpp:57
OSMIUM_CONSTEXPR bool operator==(const Box &lhs, const Box &rhs) noexcept
Definition: box.hpp:219
iterator begin()
Definition: changeset.hpp:276
Changeset & set_id(changeset_id_type id) noexcept
Definition: changeset.hpp:103
osmium::Timestamp closed_at() const noexcept
Definition: changeset.hpp:172
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:317
user_id_type m_uid
Definition: changeset.hpp:71
Namespace for everything in the Osmium library.
Definition: assembler.hpp:55
Changeset & set_uid(const char *uid)
Definition: changeset.hpp:152
Changeset & set_num_changes(num_changes_type num_changes) noexcept
Set the number of changes in this changeset.
Definition: changeset.hpp:214
void set_user_size(string_size_type size)
Definition: changeset.hpp:78
num_changes_type num_changes() const noexcept
Get the number of changes in this changeset.
Definition: changeset.hpp:209
const_iterator cend() const
Definition: changeset.hpp:288
Definition: timestamp.hpp:53
uint16_t string_size_type
Definition: types.hpp:58
const_iterator end() const
Definition: changeset.hpp:296
changeset_id_type m_id
Definition: changeset.hpp:69
osmium::Timestamp m_created_at
Definition: changeset.hpp:66
changeset_id_type string_to_changeset_id(const char *input)
Definition: types_from_string.hpp:96
bool user_is_anonymous() const noexcept
Is this user anonymous?
Definition: changeset.hpp:157
osmium::memory::CollectionIterator< Item > iterator
Definition: changeset.hpp:273
osmium::Box m_bounds
Definition: changeset.hpp:68
osmium::Timestamp created_at() const noexcept
Get timestamp when this changeset was created.
Definition: changeset.hpp:162
int32_t signed_user_id_type
Type for signed OSM user IDs.
Definition: types.hpp:50
Changeset()
Definition: changeset.hpp:74
Definition: box.hpp:50
Changeset & set_num_changes(const char *num_changes) noexcept
Set the number of changes in this changeset.
Definition: changeset.hpp:220
iterator end()
Definition: changeset.hpp:280
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:329
signed_user_id_type string_to_user_id(const char *input)
Definition: types_from_string.hpp:101
osmium::memory::CollectionIterator< const Item > const_iterator
Definition: changeset.hpp:274
Definition: builder.hpp:172
bool operator>(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:321
Changeset & set_created_at(const osmium::Timestamp timestamp)
Definition: changeset.hpp:192
unsigned char * subitems_position()
Definition: changeset.hpp:82
const unsigned char * subitems_position() const
Definition: changeset.hpp:86
An OSM Changeset, a group of changes made by a single user over a short period of time...
Definition: changeset.hpp:62
const osmium::Box & bounds() const noexcept
Definition: changeset.hpp:238
uint32_t num_changes_type
Type for changeset num_changes.
Definition: types.hpp:51
bool closed() const noexcept
Is this changeset closed?
Definition: changeset.hpp:182
uint32_t changeset_id_type
Type for OSM changeset IDs.
Definition: types.hpp:48
const_iterator cbegin() const
Definition: changeset.hpp:284
bool operator!=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:310
Changeset & set_id(const char *id)
Definition: changeset.hpp:114
num_changes_type string_to_num_changes(const char *input)
Definition: types_from_string.hpp:109
Changeset & set_uid(user_id_type uid) noexcept
Definition: changeset.hpp:129
uint32_t user_id_type
Type for OSM user IDs.
Definition: types.hpp:49