Libosmium  2.5.3
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 <cstring>
37 
39 #include <osmium/memory/item.hpp>
40 #include <osmium/osm/box.hpp>
41 #include <osmium/osm/entity.hpp>
42 #include <osmium/osm/item_type.hpp>
43 #include <osmium/osm/tag.hpp>
44 #include <osmium/osm/timestamp.hpp>
45 #include <osmium/osm/types.hpp>
47 
48 namespace osmium {
49 
50  namespace builder {
51  class ChangesetDiscussionBuilder;
52  template <typename T> class ObjectBuilder;
53  }
54 
55  class Changeset;
56 
57  class ChangesetComment : public osmium::memory::detail::ItemHelper {
58 
60 
65 
66  ChangesetComment(const ChangesetComment&) = delete;
68 
71 
72  unsigned char* endpos() {
73  return data() + osmium::memory::padded_length(sizeof(ChangesetComment) + m_user_size + m_text_size);
74  }
75 
76  const unsigned char* endpos() const {
77  return data() + osmium::memory::padded_length(sizeof(ChangesetComment) + m_user_size + m_text_size);
78  }
79 
80  template <typename TMember>
82 
83  unsigned char* next() {
84  return endpos();
85  }
86 
87  unsigned const char* next() const {
88  return endpos();
89  }
90 
91  void set_user_size(string_size_type size) noexcept {
92  m_user_size = size;
93  }
94 
95  void set_text_size(string_size_type size) noexcept {
96  m_text_size = size;
97  }
98 
99  public:
100 
102 
104  m_date(date),
105  m_uid(uid),
106  m_user_size(0),
107  m_text_size(0) {
108  }
109 
110  osmium::Timestamp date() const noexcept {
111  return m_date;
112  }
113 
114  osmium::user_id_type uid() const noexcept {
115  return m_uid;
116  }
117 
118  const char* user() const noexcept {
119  return reinterpret_cast<const char*>(data() + sizeof(ChangesetComment));
120  }
121 
122  const char* text() const noexcept {
123  return reinterpret_cast<const char*>(data() + sizeof(ChangesetComment) + m_user_size);
124  }
125 
126  }; // class ChangesetComment
127 
128  class ChangesetDiscussion : public osmium::memory::Collection<ChangesetComment, osmium::item_type::changeset_discussion> {
129 
131 
132  public:
133 
134  typedef size_t size_type;
135 
137  osmium::memory::Collection<ChangesetComment, osmium::item_type::changeset_discussion>() {
138  }
139 
140  size_type size() const noexcept {
141  return static_cast<size_type>(std::distance(begin(), end()));
142  }
143 
144  }; // class ChangesetDiscussion
145 
146 
154  class Changeset : public osmium::OSMEntity {
155 
157 
166  int16_t m_padding1 {0};
167  int32_t m_padding2 {0};
168 
171  }
172 
174  m_user_size = size;
175  }
176 
177  unsigned char* subitems_position() {
178  return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
179  }
180 
181  const unsigned char* subitems_position() const {
182  return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
183  }
184 
185  public:
186 
188  changeset_id_type id() const noexcept {
189  return m_id;
190  }
191 
199  m_id = id;
200  return *this;
201  }
202 
209  Changeset& set_id(const char* id) {
211  }
212 
214  user_id_type uid() const noexcept {
215  return m_uid;
216  }
217 
225  m_uid = uid;
226  return *this;
227  }
228 
237  m_uid = uid < 0 ? 0 : static_cast<user_id_type>(uid);
238  return *this;
239  }
240 
247  Changeset& set_uid(const char* uid) {
249  }
250 
252  bool user_is_anonymous() const noexcept {
253  return m_uid == 0;
254  }
255 
257  osmium::Timestamp created_at() const noexcept {
258  return m_created_at;
259  }
260 
267  osmium::Timestamp closed_at() const noexcept {
268  return m_closed_at;
269  }
270 
272  bool open() const noexcept {
273  return m_closed_at == osmium::Timestamp();
274  }
275 
277  bool closed() const noexcept {
278  return !open();
279  }
280 
288  m_created_at = timestamp;
289  return *this;
290  }
291 
299  m_closed_at = timestamp;
300  return *this;
301  }
302 
304  num_changes_type num_changes() const noexcept {
305  return m_num_changes;
306  }
307 
311  return *this;
312  }
313 
316  return set_num_changes(osmium::string_to_num_changes(num_changes));
317  }
318 
320  num_comments_type num_comments() const noexcept {
321  return m_num_comments;
322  }
323 
327  return *this;
328  }
329 
332  return set_num_comments(osmium::string_to_num_comments(num_comments));
333  }
334 
340  osmium::Box& bounds() noexcept {
341  return m_bounds;
342  }
343 
349  const osmium::Box& bounds() const noexcept {
350  return m_bounds;
351  }
352 
354  const char* user() const {
355  return reinterpret_cast<const char*>(data() + sizeof(Changeset));
356  }
357 
359  const TagList& tags() const {
360  return osmium::detail::subitem_of_type<const TagList>(cbegin(), cend());
361  }
362 
370  void set_attribute(const char* attr, const char* value) {
371  if (!strcmp(attr, "id")) {
372  set_id(value);
373  } else if (!strcmp(attr, "num_changes")) {
374  set_num_changes(value);
375  } else if (!strcmp(attr, "comments_count")) {
376  set_num_comments(value);
377  } else if (!strcmp(attr, "created_at")) {
379  } else if (!strcmp(attr, "closed_at")) {
381  } else if (!strcmp(attr, "uid")) {
382  set_uid(value);
383  }
384  }
385 
388 
389  iterator begin() {
390  return iterator(subitems_position());
391  }
392 
393  iterator end() {
394  return iterator(data() + padded_size());
395  }
396 
397  const_iterator cbegin() const {
399  }
400 
401  const_iterator cend() const {
402  return const_iterator(data() + padded_size());
403  }
404 
405  const_iterator begin() const {
406  return cbegin();
407  }
408 
409  const_iterator end() const {
410  return cend();
411  }
412 
414  return osmium::detail::subitem_of_type<ChangesetDiscussion>(begin(), end());
415  }
416 
418  return osmium::detail::subitem_of_type<const ChangesetDiscussion>(cbegin(), cend());
419  }
420 
421  }; // class Changeset
422 
423 
427  inline bool operator==(const Changeset& lhs, const Changeset& rhs) {
428  return lhs.id() == rhs.id();
429  }
430 
431  inline bool operator!=(const Changeset& lhs, const Changeset& rhs) {
432  return ! (lhs == rhs);
433  }
434 
438  inline bool operator<(const Changeset& lhs, const Changeset& rhs) {
439  return lhs.id() < rhs.id();
440  }
441 
442  inline bool operator>(const Changeset& lhs, const Changeset& rhs) {
443  return rhs < lhs;
444  }
445 
446  inline bool operator<=(const Changeset& lhs, const Changeset& rhs) {
447  return ! (rhs < lhs);
448  }
449 
450  inline bool operator>=(const Changeset& lhs, const Changeset& rhs) {
451  return ! (lhs < rhs);
452  }
453 
454 } // namespace osmium
455 
456 #endif // OSMIUM_OSM_CHANGESET_HPP
osmium::Timestamp m_closed_at
Definition: changeset.hpp:160
size_type size() const noexcept
Definition: changeset.hpp:140
Definition: changeset.hpp:128
osmium::user_id_type m_uid
Definition: changeset.hpp:62
Definition: collection.hpp:47
num_changes_type m_num_changes
Definition: changeset.hpp:162
Definition: tag.hpp:105
ChangesetComment(const ChangesetComment &)=delete
static constexpr item_type collection_type
Definition: changeset.hpp:101
bool operator<=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:446
osmium::Box & bounds() noexcept
Definition: changeset.hpp:340
ChangesetComment & operator=(const ChangesetComment &)=delete
unsigned char * data() const noexcept
Definition: collection.hpp:85
osmium::Timestamp created_at() const noexcept
Get timestamp when this changeset was created.
Definition: changeset.hpp:257
bool closed() const noexcept
Is this changeset closed?
Definition: changeset.hpp:277
string_size_type m_user_size
Definition: changeset.hpp:165
user_id_type uid() const noexcept
Get user id.
Definition: changeset.hpp:214
void set_attribute(const char *attr, const char *value)
Definition: changeset.hpp:370
bool open() const noexcept
Is this changeset open?
Definition: changeset.hpp:272
string_size_type m_user_size
Definition: changeset.hpp:63
item_type
Definition: item_type.hpp:43
Changeset & set_uid_from_signed(signed_user_id_type uid) noexcept
Definition: changeset.hpp:236
const TagList & tags() const
Get the list of tags.
Definition: changeset.hpp:359
const char * user() const
Get user name.
Definition: changeset.hpp:354
item_size_type padded_size() const
Definition: item.hpp:151
num_comments_type num_comments() const noexcept
Get the number of comments in this changeset.
Definition: changeset.hpp:320
OSMEntity is the abstract base class for the OSMObject and Changeset classes.
Definition: entity.hpp:64
Changeset & set_num_changes(const char *num_changes)
Set the number of changes in this changeset.
Definition: changeset.hpp:315
num_comments_type m_num_comments
Definition: changeset.hpp:163
double distance(const osmium::geom::Coordinates &c1, const osmium::geom::Coordinates &c2)
Definition: haversine.hpp:64
const_iterator begin() const
Definition: changeset.hpp:405
Definition: changeset.hpp:57
T padded_length(T length) noexcept
Definition: item.hpp:56
Definition: osm_object_builder.hpp:241
string_size_type m_text_size
Definition: changeset.hpp:64
OSMIUM_CONSTEXPR bool operator==(const Box &lhs, const Box &rhs) noexcept
Definition: box.hpp:219
iterator begin()
Definition: changeset.hpp:389
Changeset & set_id(changeset_id_type id) noexcept
Definition: changeset.hpp:198
int32_t m_padding2
Definition: changeset.hpp:167
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:438
user_id_type m_uid
Definition: changeset.hpp:164
Namespace for everything in the Osmium library.
Definition: assembler.hpp:59
Changeset & set_uid(const char *uid)
Definition: changeset.hpp:247
Changeset & set_num_changes(num_changes_type num_changes) noexcept
Set the number of changes in this changeset.
Definition: changeset.hpp:309
const unsigned char * endpos() const
Definition: changeset.hpp:76
changeset_id_type id() const noexcept
Get ID of this changeset.
Definition: changeset.hpp:188
void set_user_size(string_size_type size)
Definition: changeset.hpp:173
Definition: collection.hpp:105
const_iterator cend() const
Definition: changeset.hpp:401
Definition: timestamp.hpp:55
uint16_t string_size_type
Definition: types.hpp:59
unsigned char * next()
Definition: changeset.hpp:83
const_iterator end() const
Definition: changeset.hpp:409
changeset_id_type m_id
Definition: changeset.hpp:161
osmium::Timestamp m_created_at
Definition: changeset.hpp:159
changeset_id_type string_to_changeset_id(const char *input)
Definition: types_from_string.hpp:137
const char * text() const noexcept
Definition: changeset.hpp:122
Changeset & set_num_comments(num_comments_type num_comments) noexcept
Set the number of comments in this changeset.
Definition: changeset.hpp:325
osmium::memory::CollectionIterator< Item > iterator
Definition: changeset.hpp:386
osmium::Box m_bounds
Definition: changeset.hpp:158
int32_t signed_user_id_type
Type for signed OSM user IDs.
Definition: types.hpp:50
Changeset()
Definition: changeset.hpp:169
Definition: box.hpp:50
unsigned char * endpos()
Definition: changeset.hpp:72
void set_text_size(string_size_type size) noexcept
Definition: changeset.hpp:95
iterator end()
Definition: changeset.hpp:393
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:450
signed_user_id_type string_to_user_id(const char *input)
Definition: types_from_string.hpp:151
ChangesetComment(osmium::Timestamp date, osmium::user_id_type uid) noexcept
Definition: changeset.hpp:103
osmium::memory::CollectionIterator< const Item > const_iterator
Definition: changeset.hpp:387
Changeset & set_num_comments(const char *num_comments)
Set the number of comments in this changeset.
Definition: changeset.hpp:331
Definition: builder.hpp:186
bool operator>(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:442
void set_user_size(string_size_type size) noexcept
Definition: changeset.hpp:91
unsigned const char * next() const
Definition: changeset.hpp:87
unsigned char * subitems_position()
Definition: changeset.hpp:177
ChangesetDiscussion & discussion()
Definition: changeset.hpp:413
const unsigned char * subitems_position() const
Definition: changeset.hpp:181
Changeset & set_created_at(const osmium::Timestamp &timestamp)
Definition: changeset.hpp:287
An OSM Changeset, a group of changes made by a single user over a short period of time...
Definition: changeset.hpp:154
uint32_t num_changes_type
Type for changeset num_changes.
Definition: types.hpp:51
int16_t m_padding1
Definition: changeset.hpp:166
Changeset & set_closed_at(const osmium::Timestamp &timestamp)
Definition: changeset.hpp:298
bool user_is_anonymous() const noexcept
Is this user anonymous?
Definition: changeset.hpp:252
uint32_t changeset_id_type
Type for OSM changeset IDs.
Definition: types.hpp:48
size_t size_type
Definition: changeset.hpp:134
const_iterator cbegin() const
Definition: changeset.hpp:397
uint32_t num_comments_type
Type for changeset num_comments.
Definition: types.hpp:52
num_comments_type string_to_num_comments(const char *input)
Definition: types_from_string.hpp:182
osmium::Timestamp m_date
Definition: changeset.hpp:61
const osmium::Box & bounds() const noexcept
Definition: changeset.hpp:349
osmium::user_id_type uid() const noexcept
Definition: changeset.hpp:114
const char * user() const noexcept
Definition: changeset.hpp:118
bool operator!=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:431
Changeset & set_id(const char *id)
Definition: changeset.hpp:209
num_changes_type string_to_num_changes(const char *input)
Definition: types_from_string.hpp:168
Changeset & set_uid(user_id_type uid) noexcept
Definition: changeset.hpp:224
osmium::Timestamp closed_at() const noexcept
Definition: changeset.hpp:267
const ChangesetDiscussion & discussion() const
Definition: changeset.hpp:417
uint32_t user_id_type
Type for OSM user IDs.
Definition: types.hpp:49
osmium::Timestamp date() const noexcept
Definition: changeset.hpp:110
num_changes_type num_changes() const noexcept
Get the number of changes in this changeset.
Definition: changeset.hpp:304