Libosmium 2.22.0 Fast and flexible C++ library for working with OpenStreetMap data

Loading...
Searching...
No Matches
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 (https://osmcode.org/libosmium).
7
8 Copyright 2013-2025 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 <osmium/memory/collection.hpp>
37#include <osmium/memory/item.hpp>
38#include <osmium/osm/box.hpp>
39#include <osmium/osm/entity.hpp>
40#include <osmium/osm/item_type.hpp>
41#include <osmium/osm/tag.hpp>
42#include <osmium/osm/timestamp.hpp>
43#include <osmium/osm/types.hpp>
44#include <osmium/osm/types_from_string.hpp>
45
46#include <cstdint>
47#include <cstring>
48#include <iterator>
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
61 friend class osmium::builder::ChangesetDiscussionBuilder;
62
63 osmium::Timestamp m_date;
64 osmium::user_id_type m_uid = 0;
65 changeset_comment_size_type m_text_size = 0;
66 string_size_type m_user_size = 0;
67
68 unsigned char* endpos() {
69 return data() + osmium::memory::padded_length(sizeof(ChangesetComment) + m_user_size + m_text_size);
70 }
71
72 const unsigned char* endpos() const {
73 return data() + osmium::memory::padded_length(sizeof(ChangesetComment) + m_user_size + m_text_size);
74 }
75
76 template <typename TMember>
77 friend class osmium::memory::CollectionIterator;
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
91 void set_text_size(changeset_comment_size_type size) noexcept {
92 m_text_size = size;
93 }
94
95 public:
96
97 static constexpr item_type collection_type = item_type::changeset_discussion;
98
99 ChangesetComment(osmium::Timestamp date, osmium::user_id_type uid) noexcept :
100 m_date(date),
101 m_uid(uid) {
102 }
103
104 ChangesetComment(const ChangesetComment&) = delete;
105 ChangesetComment& operator=(const ChangesetComment&) = delete;
106
107 ChangesetComment(ChangesetComment&&) = delete;
108 ChangesetComment& operator=(ChangesetComment&&) = delete;
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
148 friend class osmium::builder::ChangesetBuilder;
149
150 osmium::Box m_bounds;
151 osmium::Timestamp m_created_at;
152 osmium::Timestamp m_closed_at;
153 changeset_id_type m_id = 0;
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
161 Changeset() :
162 OSMEntity(sizeof(Changeset), osmium::item_type::changeset) {
163 }
164
165 void set_user_size(string_size_type size) noexcept {
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
183 static constexpr osmium::item_type itemtype = osmium::item_type::changeset;
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
205 Changeset& set_id(changeset_id_type id) noexcept {
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
231 Changeset& set_uid(user_id_type uid) noexcept {
232 m_uid = uid;
233 return *this;
234 }
235
243 Changeset& set_uid_from_signed(signed_user_id_type uid) noexcept {
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
295 Changeset& set_created_at(const osmium::Timestamp& timestamp) {
296 m_created_at = timestamp;
297 return *this;
298 }
299
306 Changeset& set_closed_at(const osmium::Timestamp& timestamp) {
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
317 Changeset& set_num_changes(num_changes_type num_changes) noexcept {
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
328 num_comments_type num_comments() const noexcept {
329 return m_num_comments;
330 }
331
333 Changeset& set_num_comments(num_comments_type num_comments) noexcept {
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
399 using iterator = osmium::memory::CollectionIterator<Item>;
400 using const_iterator = osmium::memory::CollectionIterator<const Item>;
401
402 iterator begin() {
403 return iterator(subitems_position());
404 }
405
406 iterator end() {
407 return iterator(data() + padded_size());
408 }
409
410 const_iterator cbegin() const {
411 return const_iterator(subitems_position());
412 }
413
414 const_iterator cend() const {
415 return const_iterator(data() + padded_size());
416 }
417
418 const_iterator begin() const {
419 return cbegin();
420 }
421
422 const_iterator end() const {
423 return cend();
424 }
425
426 ChangesetDiscussion& discussion() {
427 return osmium::detail::subitem_of_type<ChangesetDiscussion>(begin(), end());
428 }
429
430 const ChangesetDiscussion& discussion() const {
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
box.hpp
osmium::ChangesetComment
Definition changeset.hpp:59
osmium::ChangesetComment::operator=
ChangesetComment & operator=(ChangesetComment &&)=delete
osmium::ChangesetComment::endpos
unsigned char * endpos()
Definition changeset.hpp:68
osmium::ChangesetComment::set_text_size
void set_text_size(changeset_comment_size_type size) noexcept
Definition changeset.hpp:91
osmium::ChangesetComment::ChangesetComment
ChangesetComment(ChangesetComment &&)=delete
osmium::ChangesetComment::m_date
osmium::Timestamp m_date
Definition changeset.hpp:63
osmium::ChangesetComment::date
osmium::Timestamp date() const noexcept
Definition changeset.hpp:112
osmium::ChangesetComment::ChangesetComment
ChangesetComment(const ChangesetComment &)=delete
osmium::ChangesetComment::m_uid
osmium::user_id_type m_uid
Definition changeset.hpp:64
osmium::ChangesetComment::endpos
const unsigned char * endpos() const
Definition changeset.hpp:72
osmium::ChangesetComment::m_user_size
string_size_type m_user_size
Definition changeset.hpp:66
osmium::ChangesetComment::~ChangesetComment
~ChangesetComment() noexcept=default
osmium::ChangesetComment::next
unsigned char * next()
Definition changeset.hpp:79
osmium::ChangesetComment::next
const unsigned char * next() const
Definition changeset.hpp:83
osmium::ChangesetComment::user
const char * user() const noexcept
Definition changeset.hpp:120
osmium::ChangesetComment::ChangesetComment
ChangesetComment(osmium::Timestamp date, osmium::user_id_type uid) noexcept
Definition changeset.hpp:99
osmium::ChangesetComment::uid
osmium::user_id_type uid() const noexcept
Definition changeset.hpp:116
osmium::ChangesetComment::operator=
ChangesetComment & operator=(const ChangesetComment &)=delete
osmium::ChangesetComment::set_user_size
void set_user_size(string_size_type size) noexcept
Definition changeset.hpp:87
osmium::ChangesetComment::m_text_size
changeset_comment_size_type m_text_size
Definition changeset.hpp:65
osmium::ChangesetComment::collection_type
static constexpr item_type collection_type
Definition changeset.hpp:97
osmium::ChangesetComment::text
const char * text() const noexcept
Definition changeset.hpp:124
osmium::ChangesetDiscussion
Definition changeset.hpp:130
osmium::ChangesetDiscussion::ChangesetDiscussion
ChangesetDiscussion() noexcept=default
osmium::Changeset
An OSM Changeset, a group of changes made by a single user over a short period of time.
Definition changeset.hpp:146
osmium::Changeset::num_comments
num_comments_type num_comments() const noexcept
Get the number of comments in this changeset.
Definition changeset.hpp:328
osmium::Changeset::discussion
const ChangesetDiscussion & discussion() const
Definition changeset.hpp:430
osmium::Changeset::set_user_size
void set_user_size(string_size_type size) noexcept
Definition changeset.hpp:165
osmium::Changeset::end
const_iterator end() const
Definition changeset.hpp:422
osmium::Changeset::uid
user_id_type uid() const noexcept
Get user id.
Definition changeset.hpp:221
osmium::Changeset::cbegin
const_iterator cbegin() const
Definition changeset.hpp:410
osmium::Changeset::m_bounds
osmium::Box m_bounds
Definition changeset.hpp:150
osmium::Changeset::set_id
Changeset & set_id(const char *id)
Definition changeset.hpp:216
osmium::Changeset::user
const char * user() const
Get user name.
Definition changeset.hpp:362
osmium::Changeset::set_uid_from_signed
Changeset & set_uid_from_signed(signed_user_id_type uid) noexcept
Definition changeset.hpp:243
osmium::Changeset::set_attribute
void set_attribute(const char *attr, const char *value)
Definition changeset.hpp:383
osmium::Changeset::set_id
Changeset & set_id(changeset_id_type id) noexcept
Definition changeset.hpp:205
osmium::Changeset::closed_at
osmium::Timestamp closed_at() const noexcept
Definition changeset.hpp:275
osmium::Changeset::do_not_use
int32_t do_not_use() const noexcept
Definition changeset.hpp:190
osmium::Changeset::begin
const_iterator begin() const
Definition changeset.hpp:418
osmium::Changeset::Changeset
Changeset()
Definition changeset.hpp:161
osmium::Changeset::user_size
string_size_type user_size() const noexcept
Definition changeset.hpp:169
osmium::Changeset::set_num_comments
Changeset & set_num_comments(const char *num_comments)
Set the number of comments in this changeset.
Definition changeset.hpp:339
osmium::Changeset::set_num_changes
Changeset & set_num_changes(num_changes_type num_changes) noexcept
Set the number of changes in this changeset.
Definition changeset.hpp:317
osmium::Changeset::set_uid
Changeset & set_uid(user_id_type uid) noexcept
Definition changeset.hpp:231
osmium::Changeset::set_created_at
Changeset & set_created_at(const osmium::Timestamp &timestamp)
Definition changeset.hpp:295
osmium::Changeset::set_num_changes
Changeset & set_num_changes(const char *num_changes)
Set the number of changes in this changeset.
Definition changeset.hpp:323
osmium::Changeset::open
bool open() const noexcept
Is this changeset open?
Definition changeset.hpp:280
osmium::Changeset::is_compatible_to
static constexpr bool is_compatible_to(osmium::item_type t) noexcept
Definition changeset.hpp:185
osmium::Changeset::created_at
osmium::Timestamp created_at() const noexcept
Get timestamp when this changeset was created.
Definition changeset.hpp:265
osmium::Changeset::set_num_comments
Changeset & set_num_comments(num_comments_type num_comments) noexcept
Set the number of comments in this changeset.
Definition changeset.hpp:333
osmium::Changeset::begin
iterator begin()
Definition changeset.hpp:402
osmium::Changeset::m_closed_at
osmium::Timestamp m_closed_at
Definition changeset.hpp:152
osmium::Changeset::bounds
osmium::Box & bounds() noexcept
Definition changeset.hpp:348
osmium::Changeset::user_is_anonymous
bool user_is_anonymous() const noexcept
Is this user anonymous?
Definition changeset.hpp:260
osmium::Changeset::id
changeset_id_type id() const noexcept
Get ID of this changeset.
Definition changeset.hpp:195
osmium::Changeset::tags
const TagList & tags() const
Get the list of tags.
Definition changeset.hpp:372
osmium::Changeset::clear_user
void clear_user() noexcept
Clear user name.
Definition changeset.hpp:367
osmium::Changeset::set_closed_at
Changeset & set_closed_at(const osmium::Timestamp &timestamp)
Definition changeset.hpp:306
osmium::Changeset::cend
const_iterator cend() const
Definition changeset.hpp:414
osmium::Changeset::discussion
ChangesetDiscussion & discussion()
Definition changeset.hpp:426
osmium::Changeset::set_uid
Changeset & set_uid(const char *uid)
Definition changeset.hpp:254
osmium::Changeset::m_created_at
osmium::Timestamp m_created_at
Definition changeset.hpp:151
osmium::Changeset::subitems_position
const unsigned char * subitems_position() const
Definition changeset.hpp:177
osmium::Changeset::bounds
const osmium::Box & bounds() const noexcept
Definition changeset.hpp:357
osmium::Changeset::end
iterator end()
Definition changeset.hpp:406
osmium::Changeset::subitems_position
unsigned char * subitems_position()
Definition changeset.hpp:173
osmium::Changeset::closed
bool closed() const noexcept
Is this changeset closed?
Definition changeset.hpp:285
osmium::Changeset::num_changes
num_changes_type num_changes() const noexcept
Get the number of changes in this changeset.
Definition changeset.hpp:312
osmium::OSMEntity
OSMEntity is the abstract base class for the OSMObject and Changeset classes.
Definition entity.hpp:64
osmium::TagList
Definition tag.hpp:119
osmium::Timestamp
Definition timestamp.hpp:175
osmium::builder::ChangesetBuilder
Definition osm_object_builder.hpp:596
osmium::builder::ChangesetDiscussionBuilder
Definition osm_object_builder.hpp:325
osmium::memory::CollectionIterator
Definition collection.hpp:47
osmium::memory::Collection
Definition collection.hpp:181
osmium::memory::Collection< ChangesetComment, osmium::item_type::changeset_discussion >::itemtype
static constexpr osmium::item_type itemtype
Definition collection.hpp:192
osmium::memory::Collection< ChangesetComment, osmium::item_type::changeset_discussion >::iterator
CollectionIterator< ChangesetComment > iterator
Definition collection.hpp:188
osmium::memory::Collection< ChangesetComment, osmium::item_type::changeset_discussion >::end
iterator end() noexcept
Definition collection.hpp:224
osmium::memory::Collection< ChangesetComment, osmium::item_type::changeset_discussion >::size
size_type size() const noexcept
Definition collection.hpp:216
osmium::memory::Collection< ChangesetComment, osmium::item_type::changeset_discussion >::const_iterator
CollectionIterator< const ChangesetComment > const_iterator
Definition collection.hpp:189
osmium::memory::Collection< ChangesetComment, osmium::item_type::changeset_discussion >::cend
const_iterator cend() const noexcept
Definition collection.hpp:232
osmium::memory::Collection< ChangesetComment, osmium::item_type::changeset_discussion >::cbegin
const_iterator cbegin() const noexcept
Definition collection.hpp:228
osmium::memory::Collection< ChangesetComment, osmium::item_type::changeset_discussion >::begin
iterator begin() noexcept
Definition collection.hpp:220
osmium::memory::Item::padded_size
item_size_type padded_size() const
Definition item.hpp:167
collection.hpp
entity.hpp
item.hpp
item_type.hpp
osmium::memory::padded_length
constexpr std::size_t padded_length(std::size_t length) noexcept
Definition item.hpp:64
osmium
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
osmium::string_to_changeset_id
changeset_id_type string_to_changeset_id(const char *input)
Definition types_from_string.hpp:148
osmium::string_to_uid
user_id_type string_to_uid(const char *input)
Definition types_from_string.hpp:162
osmium::operator==
bool operator==(const Changeset &lhs, const Changeset &rhs)
Definition changeset.hpp:440
osmium::string_to_num_comments
num_comments_type string_to_num_comments(const char *input)
Definition types_from_string.hpp:190
osmium::signed_user_id_type
int32_t signed_user_id_type
Type for signed OSM user IDs.
Definition types.hpp:50
osmium::changeset_id_type
uint32_t changeset_id_type
Type for OSM changeset IDs.
Definition types.hpp:48
osmium::operator<=
bool operator<=(const Changeset &lhs, const Changeset &rhs)
Definition changeset.hpp:459
osmium::operator>
bool operator>(const Changeset &lhs, const Changeset &rhs)
Definition changeset.hpp:455
osmium::string_size_type
uint16_t string_size_type
Definition types.hpp:59
osmium::num_changes_type
uint32_t num_changes_type
Type for changeset num_changes.
Definition types.hpp:51
osmium::item_type
item_type
Definition item_type.hpp:45
osmium::item_type::changeset_discussion
@ changeset_discussion
osmium::item_type::changeset
@ changeset
osmium::operator>=
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition changeset.hpp:463
osmium::operator!=
bool operator!=(const Changeset &lhs, const Changeset &rhs)
Definition changeset.hpp:444
osmium::num_comments_type
uint32_t num_comments_type
Type for changeset num_comments.
Definition types.hpp:52
osmium::changeset_comment_size_type
uint32_t changeset_comment_size_type
Definition types.hpp:66
osmium::string_to_num_changes
num_changes_type string_to_num_changes(const char *input)
Definition types_from_string.hpp:176
osmium::user_id_type
uint32_t user_id_type
Type for OSM user IDs.
Definition types.hpp:49
osmium::operator<
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition changeset.hpp:451
tag.hpp
timestamp.hpp
types.hpp
types_from_string.hpp