Libosmium  2.20.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
6This file is part of Osmium (https://osmcode.org/libosmium).
7
8Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
9
10Boost Software License - Version 1.0 - August 17th, 2003
11
12Permission is hereby granted, free of charge, to any person or organization
13obtaining a copy of the software and accompanying documentation covered by
14this license (the "Software") to use, reproduce, display, distribute,
15execute, and transmit the Software, and to prepare derivative works of the
16Software, and to permit third-parties to whom the Software is furnished to
17do so, all subject to the following:
18
19The copyright notices in the Software and this entire statement, including
20the above license grant, this restriction and the following disclaimer,
21must be included in all copies of the Software, in whole or in part, and
22all derivative works of the Software, unless such copies or derivative
23works are solely in the form of machine-executable object code generated by
24a source language processor.
25
26THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32DEALINGS IN THE SOFTWARE.
33
34*/
35
38#include <osmium/osm/box.hpp>
39#include <osmium/osm/entity.hpp>
41#include <osmium/osm/tag.hpp>
43#include <osmium/osm/types.hpp>
45
46#include <cstdint>
47#include <cstring>
48#include <iterator>
49
50namespace 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 unsigned char* endpos() {
70 }
71
72 const unsigned char* endpos() const {
74 }
75
76 template <typename TMember>
78
79 unsigned char* next() {
80 return endpos();
81 }
82
83 const unsigned char* next() const {
84 return endpos();
85 }
86
87 void set_user_size(string_size_type size) noexcept {
88 m_user_size = size;
89 }
90
92 m_text_size = size;
93 }
94
95 public:
96
98
100 m_date(date),
101 m_uid(uid) {
102 }
103
106
109
110 ~ChangesetComment() noexcept = default;
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
134 ChangesetDiscussion() noexcept = default;
135
136 }; // class ChangesetDiscussion
137
138
146 class Changeset : public osmium::OSMEntity {
147
149
150 osmium::Box m_bounds;
154 num_changes_type m_num_changes = 0;
155 num_comments_type m_num_comments = 0;
156 user_id_type m_uid = 0;
157 string_size_type m_user_size = 0;
158 int16_t m_padding1 = 0;
159 int32_t m_padding2 = 0;
160
162 OSMEntity(sizeof(Changeset), osmium::item_type::changeset) {
163 }
164
166 m_user_size = size;
167 }
168
169 string_size_type user_size() const noexcept {
170 return m_user_size;
171 }
172
173 unsigned char* subitems_position() {
174 return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
175 }
176
177 const unsigned char* subitems_position() const {
178 return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
179 }
180
181 public:
182
184
185 constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
186 return t == itemtype;
187 }
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) {
217 return set_id(osmium::string_to_changeset_id(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) {
255 m_uid = string_to_uid(uid);
256 return *this;
257 }
258
260 bool user_is_anonymous() const noexcept {
261 return m_uid == 0;
262 }
263
265 osmium::Timestamp created_at() const noexcept {
266 return m_created_at;
267 }
268
275 osmium::Timestamp closed_at() const noexcept {
276 return m_closed_at;
277 }
278
280 bool open() const noexcept {
281 return m_closed_at == osmium::Timestamp();
282 }
283
285 bool closed() const noexcept {
286 return !open();
287 }
288
296 m_created_at = timestamp;
297 return *this;
298 }
299
307 m_closed_at = timestamp;
308 return *this;
309 }
310
312 num_changes_type num_changes() const noexcept {
313 return m_num_changes;
314 }
315
318 m_num_changes = num_changes;
319 return *this;
320 }
321
323 Changeset& set_num_changes(const char* num_changes) {
324 return set_num_changes(osmium::string_to_num_changes(num_changes));
325 }
326
329 return m_num_comments;
330 }
331
334 m_num_comments = num_comments;
335 return *this;
336 }
337
339 Changeset& set_num_comments(const char* num_comments) {
340 return set_num_comments(osmium::string_to_num_comments(num_comments));
341 }
342
348 osmium::Box& bounds() noexcept {
349 return m_bounds;
350 }
351
357 const osmium::Box& bounds() const noexcept {
358 return m_bounds;
359 }
360
362 const char* user() const {
363 return reinterpret_cast<const char*>(data() + sizeof(Changeset));
364 }
365
367 void clear_user() noexcept {
368 std::memset(data() + sizeof(Changeset), 0, user_size());
369 }
370
372 const TagList& tags() const {
373 return osmium::detail::subitem_of_type<const TagList>(cbegin(), cend());
374 }
375
383 void set_attribute(const char* attr, const char* value) {
384 if (!std::strcmp(attr, "id")) {
385 set_id(value);
386 } else if (!std::strcmp(attr, "num_changes")) {
387 set_num_changes(value);
388 } else if (!std::strcmp(attr, "comments_count")) {
389 set_num_comments(value);
390 } else if (!std::strcmp(attr, "created_at")) {
391 set_created_at(osmium::Timestamp(value));
392 } else if (!std::strcmp(attr, "closed_at")) {
393 set_closed_at(osmium::Timestamp(value));
394 } else if (!std::strcmp(attr, "uid")) {
395 set_uid(value);
396 }
397 }
398
401
403 return iterator(subitems_position());
404 }
405
407 return iterator(data() + padded_size());
408 }
409
411 return const_iterator(subitems_position());
412 }
413
415 return const_iterator(data() + padded_size());
416 }
417
419 return cbegin();
420 }
421
423 return cend();
424 }
425
427 return osmium::detail::subitem_of_type<ChangesetDiscussion>(begin(), end());
428 }
429
431 return osmium::detail::subitem_of_type<const ChangesetDiscussion>(cbegin(), cend());
432 }
433
434 }; // class Changeset
435
436
440 inline bool operator==(const Changeset& lhs, const Changeset& rhs) {
441 return lhs.id() == rhs.id();
442 }
443
444 inline bool operator!=(const Changeset& lhs, const Changeset& rhs) {
445 return !(lhs == rhs);
446 }
447
451 inline bool operator<(const Changeset& lhs, const Changeset& rhs) {
452 return lhs.id() < rhs.id();
453 }
454
455 inline bool operator>(const Changeset& lhs, const Changeset& rhs) {
456 return rhs < lhs;
457 }
458
459 inline bool operator<=(const Changeset& lhs, const Changeset& rhs) {
460 return !(rhs < lhs);
461 }
462
463 inline bool operator>=(const Changeset& lhs, const Changeset& rhs) {
464 return !(lhs < rhs);
465 }
466
467} // namespace osmium
468
469#endif // OSMIUM_OSM_CHANGESET_HPP
Definition: changeset.hpp:59
ChangesetComment & operator=(ChangesetComment &&)=delete
unsigned char * endpos()
Definition: changeset.hpp:68
void set_text_size(changeset_comment_size_type size) noexcept
Definition: changeset.hpp:91
ChangesetComment(ChangesetComment &&)=delete
osmium::Timestamp m_date
Definition: changeset.hpp:63
osmium::Timestamp date() const noexcept
Definition: changeset.hpp:112
ChangesetComment(const ChangesetComment &)=delete
osmium::user_id_type m_uid
Definition: changeset.hpp:64
const unsigned char * endpos() const
Definition: changeset.hpp:72
string_size_type m_user_size
Definition: changeset.hpp:66
~ChangesetComment() noexcept=default
unsigned char * next()
Definition: changeset.hpp:79
const unsigned char * next() const
Definition: changeset.hpp:83
const char * user() const noexcept
Definition: changeset.hpp:120
ChangesetComment(osmium::Timestamp date, osmium::user_id_type uid) noexcept
Definition: changeset.hpp:99
osmium::user_id_type uid() const noexcept
Definition: changeset.hpp:116
ChangesetComment & operator=(const ChangesetComment &)=delete
void set_user_size(string_size_type size) noexcept
Definition: changeset.hpp:87
changeset_comment_size_type m_text_size
Definition: changeset.hpp:65
static constexpr item_type collection_type
Definition: changeset.hpp:97
const char * text() const noexcept
Definition: changeset.hpp:124
Definition: changeset.hpp:130
ChangesetDiscussion() noexcept=default
An OSM Changeset, a group of changes made by a single user over a short period of time.
Definition: changeset.hpp:146
num_comments_type num_comments() const noexcept
Get the number of comments in this changeset.
Definition: changeset.hpp:328
const ChangesetDiscussion & discussion() const
Definition: changeset.hpp:430
void set_user_size(string_size_type size) noexcept
Definition: changeset.hpp:165
const_iterator end() const
Definition: changeset.hpp:422
user_id_type uid() const noexcept
Get user id.
Definition: changeset.hpp:221
const_iterator cbegin() const
Definition: changeset.hpp:410
osmium::Box m_bounds
Definition: changeset.hpp:150
Changeset & set_id(const char *id)
Definition: changeset.hpp:216
const char * user() const
Get user name.
Definition: changeset.hpp:362
Changeset & set_uid_from_signed(signed_user_id_type uid) noexcept
Definition: changeset.hpp:243
void set_attribute(const char *attr, const char *value)
Definition: changeset.hpp:383
Changeset & set_id(changeset_id_type id) noexcept
Definition: changeset.hpp:205
osmium::Timestamp closed_at() const noexcept
Definition: changeset.hpp:275
int32_t do_not_use() const noexcept
Definition: changeset.hpp:190
const_iterator begin() const
Definition: changeset.hpp:418
Changeset()
Definition: changeset.hpp:161
string_size_type user_size() const noexcept
Definition: changeset.hpp:169
Changeset & set_num_comments(const char *num_comments)
Set the number of comments in this changeset.
Definition: changeset.hpp:339
Changeset & set_num_changes(num_changes_type num_changes) noexcept
Set the number of changes in this changeset.
Definition: changeset.hpp:317
Changeset & set_uid(user_id_type uid) noexcept
Definition: changeset.hpp:231
Changeset & set_created_at(const osmium::Timestamp &timestamp)
Definition: changeset.hpp:295
Changeset & set_num_changes(const char *num_changes)
Set the number of changes in this changeset.
Definition: changeset.hpp:323
bool open() const noexcept
Is this changeset open?
Definition: changeset.hpp:280
static constexpr bool is_compatible_to(osmium::item_type t) noexcept
Definition: changeset.hpp:185
osmium::Timestamp created_at() const noexcept
Get timestamp when this changeset was created.
Definition: changeset.hpp:265
Changeset & set_num_comments(num_comments_type num_comments) noexcept
Set the number of comments in this changeset.
Definition: changeset.hpp:333
iterator begin()
Definition: changeset.hpp:402
osmium::Timestamp m_closed_at
Definition: changeset.hpp:152
osmium::Box & bounds() noexcept
Definition: changeset.hpp:348
bool user_is_anonymous() const noexcept
Is this user anonymous?
Definition: changeset.hpp:260
changeset_id_type id() const noexcept
Get ID of this changeset.
Definition: changeset.hpp:195
const TagList & tags() const
Get the list of tags.
Definition: changeset.hpp:372
void clear_user() noexcept
Clear user name.
Definition: changeset.hpp:367
Changeset & set_closed_at(const osmium::Timestamp &timestamp)
Definition: changeset.hpp:306
const_iterator cend() const
Definition: changeset.hpp:414
ChangesetDiscussion & discussion()
Definition: changeset.hpp:426
Changeset & set_uid(const char *uid)
Definition: changeset.hpp:254
osmium::Timestamp m_created_at
Definition: changeset.hpp:151
const unsigned char * subitems_position() const
Definition: changeset.hpp:177
const osmium::Box & bounds() const noexcept
Definition: changeset.hpp:357
iterator end()
Definition: changeset.hpp:406
unsigned char * subitems_position()
Definition: changeset.hpp:173
bool closed() const noexcept
Is this changeset closed?
Definition: changeset.hpp:285
num_changes_type num_changes() const noexcept
Get the number of changes in this changeset.
Definition: changeset.hpp:312
OSMEntity is the abstract base class for the OSMObject and Changeset classes.
Definition: entity.hpp:64
Definition: tag.hpp:119
Definition: timestamp.hpp:175
Definition: osm_object_builder.hpp:596
Definition: osm_object_builder.hpp:325
Definition: collection.hpp:47
unsigned char * data() const noexcept
Definition: collection.hpp:91
Definition: collection.hpp:181
static constexpr osmium::item_type itemtype
Definition: collection.hpp:192
CollectionIterator< ChangesetComment > iterator
Definition: collection.hpp:188
CollectionIterator< const ChangesetComment > const_iterator
Definition: collection.hpp:189
const_iterator cend() const noexcept
Definition: collection.hpp:232
const_iterator cbegin() const noexcept
Definition: collection.hpp:228
item_size_type padded_size() const
Definition: item.hpp:167
constexpr std::size_t padded_length(std::size_t length) noexcept
Definition: item.hpp:64
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
changeset_id_type string_to_changeset_id(const char *input)
Definition: types_from_string.hpp:148
uint32_t changeset_comment_size_type
Definition: types.hpp:66
user_id_type string_to_uid(const char *input)
Definition: types_from_string.hpp:162
bool operator==(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:440
num_comments_type string_to_num_comments(const char *input)
Definition: types_from_string.hpp:190
int32_t signed_user_id_type
Type for signed OSM user IDs.
Definition: types.hpp:50
uint32_t user_id_type
Type for OSM user IDs.
Definition: types.hpp:49
bool operator<=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:459
uint32_t changeset_id_type
Type for OSM changeset IDs.
Definition: types.hpp:48
bool operator>(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:455
uint16_t string_size_type
Definition: types.hpp:59
item_type
Definition: item_type.hpp:45
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:463
bool operator!=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:444
uint32_t num_comments_type
Type for changeset num_comments.
Definition: types.hpp:52
num_changes_type string_to_num_changes(const char *input)
Definition: types_from_string.hpp:176
uint32_t num_changes_type
Type for changeset num_changes.
Definition: types.hpp:51
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:451