Libosmium  2.9.0
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2016 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 #include <iterator>
39 
41 #include <osmium/memory/item.hpp>
42 #include <osmium/osm/box.hpp>
43 #include <osmium/osm/entity.hpp>
44 #include <osmium/osm/item_type.hpp>
45 #include <osmium/osm/tag.hpp>
46 #include <osmium/osm/timestamp.hpp>
47 #include <osmium/osm/types.hpp>
49 
50 namespace osmium {
51 
52  namespace builder {
53  class ChangesetDiscussionBuilder;
54  template <typename T> class ObjectBuilder;
55  } // namespace builder
56 
57  class Changeset;
58 
59  class ChangesetComment : public osmium::memory::detail::ItemHelper {
60 
62 
67 
68  ChangesetComment(const ChangesetComment&) = delete;
70 
73 
74  unsigned char* endpos() {
75  return data() + osmium::memory::padded_length(sizeof(ChangesetComment) + m_user_size + m_text_size);
76  }
77 
78  const unsigned char* endpos() const {
79  return data() + osmium::memory::padded_length(sizeof(ChangesetComment) + m_user_size + m_text_size);
80  }
81 
82  template <typename TMember>
84 
85  unsigned char* next() {
86  return endpos();
87  }
88 
89  unsigned const char* next() const {
90  return endpos();
91  }
92 
93  void set_user_size(string_size_type size) noexcept {
94  m_user_size = size;
95  }
96 
97  void set_text_size(string_size_type size) noexcept {
98  m_text_size = size;
99  }
100 
101  public:
102 
104 
106  m_date(date),
107  m_uid(uid),
108  m_user_size(0),
109  m_text_size(0) {
110  }
111 
112  osmium::Timestamp date() const noexcept {
113  return m_date;
114  }
115 
116  osmium::user_id_type uid() const noexcept {
117  return m_uid;
118  }
119 
120  const char* user() const noexcept {
121  return reinterpret_cast<const char*>(data() + sizeof(ChangesetComment));
122  }
123 
124  const char* text() const noexcept {
125  return reinterpret_cast<const char*>(data() + sizeof(ChangesetComment) + m_user_size);
126  }
127 
128  }; // class ChangesetComment
129 
130  class ChangesetDiscussion : public osmium::memory::Collection<ChangesetComment, osmium::item_type::changeset_discussion> {
131 
133 
134  public:
135 
136  using size_type = size_t;
137 
139  osmium::memory::Collection<ChangesetComment, osmium::item_type::changeset_discussion>() {
140  }
141 
142  size_type size() const noexcept {
143  return static_cast<size_type>(std::distance(begin(), end()));
144  }
145 
146  }; // class ChangesetDiscussion
147 
148 
156  class Changeset : public osmium::OSMEntity {
157 
159 
168  int16_t m_padding1 {0};
169  int32_t m_padding2 {0};
170 
173  }
174 
176  m_user_size = size;
177  }
178 
179  unsigned char* subitems_position() {
180  return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
181  }
182 
183  const unsigned char* subitems_position() const {
184  return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
185  }
186 
187  public:
188 
189  // Dummy to avoid warning because of unused private fields. Do not use.
190  int32_t do_not_use() const noexcept {
191  return m_padding1 + m_padding2;
192  }
193 
195  changeset_id_type id() const noexcept {
196  return m_id;
197  }
198 
206  m_id = id;
207  return *this;
208  }
209 
216  Changeset& set_id(const char* id) {
218  }
219 
221  user_id_type uid() const noexcept {
222  return m_uid;
223  }
224 
232  m_uid = uid;
233  return *this;
234  }
235 
244  m_uid = uid < 0 ? 0 : static_cast<user_id_type>(uid);
245  return *this;
246  }
247 
254  Changeset& set_uid(const char* uid) {
256  }
257 
259  bool user_is_anonymous() const noexcept {
260  return m_uid == 0;
261  }
262 
264  osmium::Timestamp created_at() const noexcept {
265  return m_created_at;
266  }
267 
274  osmium::Timestamp closed_at() const noexcept {
275  return m_closed_at;
276  }
277 
279  bool open() const noexcept {
280  return m_closed_at == osmium::Timestamp();
281  }
282 
284  bool closed() const noexcept {
285  return !open();
286  }
287 
295  m_created_at = timestamp;
296  return *this;
297  }
298 
306  m_closed_at = timestamp;
307  return *this;
308  }
309 
311  num_changes_type num_changes() const noexcept {
312  return m_num_changes;
313  }
314 
318  return *this;
319  }
320 
323  return set_num_changes(osmium::string_to_num_changes(num_changes));
324  }
325 
327  num_comments_type num_comments() const noexcept {
328  return m_num_comments;
329  }
330 
334  return *this;
335  }
336 
339  return set_num_comments(osmium::string_to_num_comments(num_comments));
340  }
341 
347  osmium::Box& bounds() noexcept {
348  return m_bounds;
349  }
350 
356  const osmium::Box& bounds() const noexcept {
357  return m_bounds;
358  }
359 
361  const char* user() const {
362  return reinterpret_cast<const char*>(data() + sizeof(Changeset));
363  }
364 
366  const TagList& tags() const {
367  return osmium::detail::subitem_of_type<const TagList>(cbegin(), cend());
368  }
369 
377  void set_attribute(const char* attr, const char* value) {
378  if (!std::strcmp(attr, "id")) {
379  set_id(value);
380  } else if (!std::strcmp(attr, "num_changes")) {
381  set_num_changes(value);
382  } else if (!std::strcmp(attr, "comments_count")) {
383  set_num_comments(value);
384  } else if (!std::strcmp(attr, "created_at")) {
386  } else if (!std::strcmp(attr, "closed_at")) {
388  } else if (!std::strcmp(attr, "uid")) {
389  set_uid(value);
390  }
391  }
392 
395 
397  return iterator(subitems_position());
398  }
399 
401  return iterator(data() + padded_size());
402  }
403 
406  }
407 
409  return const_iterator(data() + padded_size());
410  }
411 
413  return cbegin();
414  }
415 
416  const_iterator end() const {
417  return cend();
418  }
419 
421  return osmium::detail::subitem_of_type<ChangesetDiscussion>(begin(), end());
422  }
423 
425  return osmium::detail::subitem_of_type<const ChangesetDiscussion>(cbegin(), cend());
426  }
427 
428  }; // class Changeset
429 
430 
434  inline bool operator==(const Changeset& lhs, const Changeset& rhs) {
435  return lhs.id() == rhs.id();
436  }
437 
438  inline bool operator!=(const Changeset& lhs, const Changeset& rhs) {
439  return ! (lhs == rhs);
440  }
441 
445  inline bool operator<(const Changeset& lhs, const Changeset& rhs) {
446  return lhs.id() < rhs.id();
447  }
448 
449  inline bool operator>(const Changeset& lhs, const Changeset& rhs) {
450  return rhs < lhs;
451  }
452 
453  inline bool operator<=(const Changeset& lhs, const Changeset& rhs) {
454  return ! (rhs < lhs);
455  }
456 
457  inline bool operator>=(const Changeset& lhs, const Changeset& rhs) {
458  return ! (lhs < rhs);
459  }
460 
461 } // namespace osmium
462 
463 #endif // OSMIUM_OSM_CHANGESET_HPP
uint32_t user_id_type
Type for OSM user IDs.
Definition: types.hpp:49
osmium::Timestamp m_closed_at
Definition: changeset.hpp:162
Definition: changeset.hpp:130
osmium::user_id_type m_uid
Definition: changeset.hpp:64
const char * text() const noexcept
Definition: changeset.hpp:124
Definition: collection.hpp:47
num_changes_type m_num_changes
Definition: changeset.hpp:164
num_comments_type num_comments() const noexcept
Get the number of comments in this changeset.
Definition: changeset.hpp:327
Definition: tag.hpp:105
ChangesetComment(const ChangesetComment &)=delete
static constexpr item_type collection_type
Definition: changeset.hpp:103
osmium::memory::CollectionIterator< Item > iterator
Definition: changeset.hpp:393
bool operator<=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:453
osmium::Box & bounds() noexcept
Definition: changeset.hpp:347
ChangesetComment & operator=(const ChangesetComment &)=delete
bool open() const noexcept
Is this changeset open?
Definition: changeset.hpp:279
string_size_type m_user_size
Definition: changeset.hpp:167
constexpr bool operator==(const Box &lhs, const Box &rhs) noexcept
Definition: box.hpp:221
void set_attribute(const char *attr, const char *value)
Definition: changeset.hpp:377
user_id_type uid() const noexcept
Get user id.
Definition: changeset.hpp:221
string_size_type m_user_size
Definition: changeset.hpp:65
item_type
Definition: item_type.hpp:43
Changeset & set_uid_from_signed(signed_user_id_type uid) noexcept
Definition: changeset.hpp:243
const TagList & tags() const
Get the list of tags.
Definition: changeset.hpp:366
uint16_t string_size_type
Definition: types.hpp:59
const char * user() const
Get user name.
Definition: changeset.hpp:361
changeset_id_type id() const noexcept
Get ID of this changeset.
Definition: changeset.hpp:195
item_size_type padded_size() const
Definition: item.hpp:161
std::size_t padded_length(std::size_t length) noexcept
Definition: item.hpp:64
OSMEntity is the abstract base class for the OSMObject and Changeset classes.
Definition: entity.hpp:64
uint32_t num_changes_type
Type for changeset num_changes.
Definition: types.hpp:51
Changeset & set_num_changes(const char *num_changes)
Set the number of changes in this changeset.
Definition: changeset.hpp:322
num_comments_type m_num_comments
Definition: changeset.hpp:165
double distance(const osmium::geom::Coordinates &c1, const osmium::geom::Coordinates &c2)
Definition: haversine.hpp:64
const_iterator begin() const
Definition: changeset.hpp:412
Definition: changeset.hpp:59
Definition: osm_object_builder.hpp:284
string_size_type m_text_size
Definition: changeset.hpp:66
iterator begin()
Definition: changeset.hpp:396
Changeset & set_id(changeset_id_type id) noexcept
Definition: changeset.hpp:205
osmium::Timestamp closed_at() const noexcept
Definition: changeset.hpp:274
int32_t m_padding2
Definition: changeset.hpp:169
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:445
user_id_type m_uid
Definition: changeset.hpp:166
Namespace for everything in the Osmium library.
Definition: assembler.hpp:73
Changeset & set_uid(const char *uid)
Definition: changeset.hpp:254
Changeset & set_num_changes(num_changes_type num_changes) noexcept
Set the number of changes in this changeset.
Definition: changeset.hpp:316
const unsigned char * endpos() const
Definition: changeset.hpp:78
uint32_t num_comments_type
Type for changeset num_comments.
Definition: types.hpp:52
void set_user_size(string_size_type size)
Definition: changeset.hpp:175
num_changes_type num_changes() const noexcept
Get the number of changes in this changeset.
Definition: changeset.hpp:311
Definition: collection.hpp:117
const_iterator cend() const
Definition: changeset.hpp:408
int32_t signed_user_id_type
Type for signed OSM user IDs.
Definition: types.hpp:50
osmium::memory::CollectionIterator< const Item > const_iterator
Definition: changeset.hpp:394
Definition: timestamp.hpp:115
unsigned char * next()
Definition: changeset.hpp:85
const_iterator end() const
Definition: changeset.hpp:416
changeset_id_type m_id
Definition: changeset.hpp:163
osmium::Timestamp m_created_at
Definition: changeset.hpp:161
uint32_t changeset_id_type
Type for OSM changeset IDs.
Definition: types.hpp:48
changeset_id_type string_to_changeset_id(const char *input)
Definition: types_from_string.hpp:144
bool user_is_anonymous() const noexcept
Is this user anonymous?
Definition: changeset.hpp:259
Changeset & set_num_comments(num_comments_type num_comments) noexcept
Set the number of comments in this changeset.
Definition: changeset.hpp:332
osmium::Box m_bounds
Definition: changeset.hpp:160
osmium::Timestamp created_at() const noexcept
Get timestamp when this changeset was created.
Definition: changeset.hpp:264
Changeset()
Definition: changeset.hpp:171
osmium::user_id_type uid() const noexcept
Definition: changeset.hpp:116
size_type size() const noexcept
Definition: changeset.hpp:142
unsigned char * data() const noexcept
Definition: collection.hpp:91
Definition: box.hpp:49
unsigned char * endpos()
Definition: changeset.hpp:74
void set_text_size(string_size_type size) noexcept
Definition: changeset.hpp:97
iterator end()
Definition: changeset.hpp:400
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:457
signed_user_id_type string_to_user_id(const char *input)
Definition: types_from_string.hpp:158
ChangesetComment(osmium::Timestamp date, osmium::user_id_type uid) noexcept
Definition: changeset.hpp:105
Changeset & set_num_comments(const char *num_comments)
Set the number of comments in this changeset.
Definition: changeset.hpp:338
Definition: builder.hpp:185
bool operator>(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:449
size_t size_type
Definition: changeset.hpp:136
void set_user_size(string_size_type size) noexcept
Definition: changeset.hpp:93
osmium::Timestamp date() const noexcept
Definition: changeset.hpp:112
unsigned const char * next() const
Definition: changeset.hpp:89
unsigned char * subitems_position()
Definition: changeset.hpp:179
ChangesetDiscussion & discussion()
Definition: changeset.hpp:420
int32_t do_not_use() const noexcept
Definition: changeset.hpp:190
const unsigned char * subitems_position() const
Definition: changeset.hpp:183
Changeset & set_created_at(const osmium::Timestamp &timestamp)
Definition: changeset.hpp:294
An OSM Changeset, a group of changes made by a single user over a short period of time...
Definition: changeset.hpp:156
const osmium::Box & bounds() const noexcept
Definition: changeset.hpp:356
int16_t m_padding1
Definition: changeset.hpp:168
Changeset & set_closed_at(const osmium::Timestamp &timestamp)
Definition: changeset.hpp:305
bool closed() const noexcept
Is this changeset closed?
Definition: changeset.hpp:284
const_iterator cbegin() const
Definition: changeset.hpp:404
num_comments_type string_to_num_comments(const char *input)
Definition: types_from_string.hpp:189
osmium::Timestamp m_date
Definition: changeset.hpp:63
bool operator!=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:438
Changeset & set_id(const char *id)
Definition: changeset.hpp:216
num_changes_type string_to_num_changes(const char *input)
Definition: types_from_string.hpp:175
Changeset & set_uid(user_id_type uid) noexcept
Definition: changeset.hpp:231
const char * user() const noexcept
Definition: changeset.hpp:120
const ChangesetDiscussion & discussion() const
Definition: changeset.hpp:424