Libosmium  2.10.3
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  class ChangesetBuilder;
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 
132  public:
133 
136  }
137 
138  }; // class ChangesetDiscussion
139 
140 
148  class Changeset : public osmium::OSMEntity {
149 
151 
160  int16_t m_padding1 {0};
161  int32_t m_padding2 {0};
162 
165  }
166 
168  m_user_size = size;
169  }
170 
171  string_size_type user_size() const noexcept {
172  return m_user_size;
173  }
174 
175  unsigned char* subitems_position() {
176  return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
177  }
178 
179  const unsigned char* subitems_position() const {
180  return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
181  }
182 
183  public:
184 
185  // Dummy to avoid warning because of unused private fields. Do not use.
186  int32_t do_not_use() const noexcept {
187  return m_padding1 + m_padding2;
188  }
189 
191  changeset_id_type id() const noexcept {
192  return m_id;
193  }
194 
202  m_id = id;
203  return *this;
204  }
205 
212  Changeset& set_id(const char* id) {
214  }
215 
217  user_id_type uid() const noexcept {
218  return m_uid;
219  }
220 
228  m_uid = uid;
229  return *this;
230  }
231 
240  m_uid = uid < 0 ? 0 : static_cast<user_id_type>(uid);
241  return *this;
242  }
243 
250  Changeset& set_uid(const char* uid) {
252  }
253 
255  bool user_is_anonymous() const noexcept {
256  return m_uid == 0;
257  }
258 
260  osmium::Timestamp created_at() const noexcept {
261  return m_created_at;
262  }
263 
270  osmium::Timestamp closed_at() const noexcept {
271  return m_closed_at;
272  }
273 
275  bool open() const noexcept {
276  return m_closed_at == osmium::Timestamp();
277  }
278 
280  bool closed() const noexcept {
281  return !open();
282  }
283 
291  m_created_at = timestamp;
292  return *this;
293  }
294 
302  m_closed_at = timestamp;
303  return *this;
304  }
305 
307  num_changes_type num_changes() const noexcept {
308  return m_num_changes;
309  }
310 
314  return *this;
315  }
316 
319  return set_num_changes(osmium::string_to_num_changes(num_changes));
320  }
321 
323  num_comments_type num_comments() const noexcept {
324  return m_num_comments;
325  }
326 
330  return *this;
331  }
332 
335  return set_num_comments(osmium::string_to_num_comments(num_comments));
336  }
337 
343  osmium::Box& bounds() noexcept {
344  return m_bounds;
345  }
346 
352  const osmium::Box& bounds() const noexcept {
353  return m_bounds;
354  }
355 
357  const char* user() const {
358  return reinterpret_cast<const char*>(data() + sizeof(Changeset));
359  }
360 
362  const TagList& tags() const {
363  return osmium::detail::subitem_of_type<const TagList>(cbegin(), cend());
364  }
365 
373  void set_attribute(const char* attr, const char* value) {
374  if (!std::strcmp(attr, "id")) {
375  set_id(value);
376  } else if (!std::strcmp(attr, "num_changes")) {
377  set_num_changes(value);
378  } else if (!std::strcmp(attr, "comments_count")) {
379  set_num_comments(value);
380  } else if (!std::strcmp(attr, "created_at")) {
382  } else if (!std::strcmp(attr, "closed_at")) {
384  } else if (!std::strcmp(attr, "uid")) {
385  set_uid(value);
386  }
387  }
388 
391 
393  return iterator(subitems_position());
394  }
395 
397  return iterator(data() + padded_size());
398  }
399 
402  }
403 
405  return const_iterator(data() + padded_size());
406  }
407 
409  return cbegin();
410  }
411 
412  const_iterator end() const {
413  return cend();
414  }
415 
417  return osmium::detail::subitem_of_type<ChangesetDiscussion>(begin(), end());
418  }
419 
421  return osmium::detail::subitem_of_type<const ChangesetDiscussion>(cbegin(), cend());
422  }
423 
424  }; // class Changeset
425 
426 
430  inline bool operator==(const Changeset& lhs, const Changeset& rhs) {
431  return lhs.id() == rhs.id();
432  }
433 
434  inline bool operator!=(const Changeset& lhs, const Changeset& rhs) {
435  return ! (lhs == rhs);
436  }
437 
441  inline bool operator<(const Changeset& lhs, const Changeset& rhs) {
442  return lhs.id() < rhs.id();
443  }
444 
445  inline bool operator>(const Changeset& lhs, const Changeset& rhs) {
446  return rhs < lhs;
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 ! (lhs < rhs);
455  }
456 
457 } // namespace osmium
458 
459 #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:154
Definition: changeset.hpp:130
osmium::user_id_type m_uid
Definition: changeset.hpp:64
string_size_type user_size() const noexcept
Definition: changeset.hpp:171
const char * text() const noexcept
Definition: changeset.hpp:124
Definition: collection.hpp:47
num_changes_type m_num_changes
Definition: changeset.hpp:156
num_comments_type num_comments() const noexcept
Get the number of comments in this changeset.
Definition: changeset.hpp:323
Definition: tag.hpp:107
ChangesetComment(const ChangesetComment &)=delete
static constexpr item_type collection_type
Definition: changeset.hpp:103
osmium::memory::CollectionIterator< Item > iterator
Definition: changeset.hpp:389
bool operator<=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:449
osmium::Box & bounds() noexcept
Definition: changeset.hpp:343
ChangesetComment & operator=(const ChangesetComment &)=delete
bool open() const noexcept
Is this changeset open?
Definition: changeset.hpp:275
string_size_type m_user_size
Definition: changeset.hpp:159
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:373
user_id_type uid() const noexcept
Get user id.
Definition: changeset.hpp:217
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:239
const TagList & tags() const
Get the list of tags.
Definition: changeset.hpp:362
uint16_t string_size_type
Definition: types.hpp:59
const char * user() const
Get user name.
Definition: changeset.hpp:357
changeset_id_type id() const noexcept
Get ID of this changeset.
Definition: changeset.hpp:191
item_size_type padded_size() const
Definition: item.hpp:161
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:318
num_comments_type m_num_comments
Definition: changeset.hpp:157
constexpr std::size_t padded_length(std::size_t length) noexcept
Definition: item.hpp:64
const_iterator begin() const
Definition: changeset.hpp:408
Definition: changeset.hpp:59
Definition: osm_object_builder.hpp:304
string_size_type m_text_size
Definition: changeset.hpp:66
iterator begin()
Definition: changeset.hpp:392
Changeset & set_id(changeset_id_type id) noexcept
Definition: changeset.hpp:201
osmium::Timestamp closed_at() const noexcept
Definition: changeset.hpp:270
int32_t m_padding2
Definition: changeset.hpp:161
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:441
user_id_type m_uid
Definition: changeset.hpp:158
Namespace for everything in the Osmium library.
Definition: assembler.hpp:73
Changeset & set_uid(const char *uid)
Definition: changeset.hpp:250
void set_user_size(string_size_type size) noexcept
Definition: changeset.hpp:167
Changeset & set_num_changes(num_changes_type num_changes) noexcept
Set the number of changes in this changeset.
Definition: changeset.hpp:312
const unsigned char * endpos() const
Definition: changeset.hpp:78
uint32_t num_comments_type
Type for changeset num_comments.
Definition: types.hpp:52
num_changes_type num_changes() const noexcept
Get the number of changes in this changeset.
Definition: changeset.hpp:307
Definition: collection.hpp:117
const_iterator cend() const
Definition: changeset.hpp:404
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:390
Definition: timestamp.hpp:115
unsigned char * next()
Definition: changeset.hpp:85
const_iterator end() const
Definition: changeset.hpp:412
changeset_id_type m_id
Definition: changeset.hpp:155
osmium::Timestamp m_created_at
Definition: changeset.hpp:153
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:255
Changeset & set_num_comments(num_comments_type num_comments) noexcept
Set the number of comments in this changeset.
Definition: changeset.hpp:328
osmium::Box m_bounds
Definition: changeset.hpp:152
osmium::Timestamp created_at() const noexcept
Get timestamp when this changeset was created.
Definition: changeset.hpp:260
Changeset()
Definition: changeset.hpp:163
osmium::user_id_type uid() const noexcept
Definition: changeset.hpp:116
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:396
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:453
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:334
bool operator>(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:445
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:175
ChangesetDiscussion & discussion()
Definition: changeset.hpp:416
int32_t do_not_use() const noexcept
Definition: changeset.hpp:186
const unsigned char * subitems_position() const
Definition: changeset.hpp:179
uint32_t size() const noexcept
Definition: builder.hpp:141
Changeset & set_created_at(const osmium::Timestamp &timestamp)
Definition: changeset.hpp:290
An OSM Changeset, a group of changes made by a single user over a short period of time...
Definition: changeset.hpp:148
const osmium::Box & bounds() const noexcept
Definition: changeset.hpp:352
int16_t m_padding1
Definition: changeset.hpp:160
Changeset & set_closed_at(const osmium::Timestamp &timestamp)
Definition: changeset.hpp:301
Definition: osm_object_builder.hpp:555
bool closed() const noexcept
Is this changeset closed?
Definition: changeset.hpp:280
ChangesetDiscussion()
Definition: changeset.hpp:134
const_iterator cbegin() const
Definition: changeset.hpp:400
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:434
Changeset & set_id(const char *id)
Definition: changeset.hpp:212
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:227
const char * user() const noexcept
Definition: changeset.hpp:120
const ChangesetDiscussion & discussion() const
Definition: changeset.hpp:420