Loading...
Searching...
No Matches
changeset.hpp
Go to the documentation of this file.
#ifndef OSMIUM_OSM_CHANGESET_HPP
#define OSMIUM_OSM_CHANGESET_HPP
/*
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2025 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <osmium/memory/collection.hpp>
#include <osmium/memory/item.hpp>
#include <osmium/osm/box.hpp>
#include <osmium/osm/entity.hpp>
#include <osmium/osm/item_type.hpp>
#include <osmium/osm/tag.hpp>
#include <osmium/osm/timestamp.hpp>
#include <osmium/osm/types.hpp>
#include <osmium/osm/types_from_string.hpp>
#include <cstdint>
#include <cstring>
#include <iterator>
namespace osmium {
namespace builder {
class ChangesetDiscussionBuilder;
class ChangesetBuilder;
} // namespace builder
class Changeset;
class ChangesetComment : public osmium::memory::detail::ItemHelper {
friend class osmium::builder::ChangesetDiscussionBuilder;
osmium::Timestamp m_date;
osmium::user_id_type m_uid = 0;
changeset_comment_size_type m_text_size = 0;
string_size_type m_user_size = 0;
unsigned char* endpos() {
return data() + osmium::memory::padded_length(sizeof(ChangesetComment) + m_user_size + m_text_size);
}
const unsigned char* endpos() const {
return data() + osmium::memory::padded_length(sizeof(ChangesetComment) + m_user_size + m_text_size);
}
template <typename TMember>
friend class osmium::memory::CollectionIterator;
unsigned char* next() {
return endpos();
}
const unsigned char* next() const {
return endpos();
}
void set_user_size(string_size_type size) noexcept {
m_user_size = size;
}
void set_text_size(changeset_comment_size_type size) noexcept {
m_text_size = size;
}
public:
static constexpr item_type collection_type = item_type::changeset_discussion;
ChangesetComment(osmium::Timestamp date, osmium::user_id_type uid) noexcept :
m_date(date),
m_uid(uid) {
}
ChangesetComment(const ChangesetComment&) = delete;
ChangesetComment& operator=(const ChangesetComment&) = delete;
ChangesetComment(ChangesetComment&&) = delete;
ChangesetComment& operator=(ChangesetComment&&) = delete;
~ChangesetComment() noexcept = default;
osmium::Timestamp date() const noexcept {
return m_date;
}
osmium::user_id_type uid() const noexcept {
return m_uid;
}
const char* user() const noexcept {
return reinterpret_cast<const char*>(data() + sizeof(ChangesetComment));
}
const char* text() const noexcept {
return reinterpret_cast<const char*>(data() + sizeof(ChangesetComment) + m_user_size);
}
}; // class ChangesetComment
class ChangesetDiscussion : public osmium::memory::Collection<ChangesetComment, osmium::item_type::changeset_discussion> {
public:
ChangesetDiscussion() noexcept = default;
}; // class ChangesetDiscussion
class Changeset : public osmium::OSMEntity {
friend class osmium::builder::ChangesetBuilder;
osmium::Box m_bounds;
osmium::Timestamp m_created_at;
osmium::Timestamp m_closed_at;
changeset_id_type m_id = 0;
num_changes_type m_num_changes = 0;
num_comments_type m_num_comments = 0;
user_id_type m_uid = 0;
string_size_type m_user_size = 0;
int16_t m_padding1 = 0;
int32_t m_padding2 = 0;
Changeset() :
OSMEntity(sizeof(Changeset), osmium::item_type::changeset) {
}
void set_user_size(string_size_type size) noexcept {
m_user_size = size;
}
string_size_type user_size() const noexcept {
return m_user_size;
}
unsigned char* subitems_position() {
return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
}
const unsigned char* subitems_position() const {
return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
}
public:
static constexpr osmium::item_type itemtype = osmium::item_type::changeset;
constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
return t == itemtype;
}
// Dummy to avoid warning because of unused private fields. Do not use.
int32_t do_not_use() const noexcept {
return m_padding1 + m_padding2;
}
changeset_id_type id() const noexcept {
return m_id;
}
Changeset& set_id(changeset_id_type id) noexcept {
m_id = id;
return *this;
}
Changeset& set_id(const char* id) {
return set_id(osmium::string_to_changeset_id(id));
}
user_id_type uid() const noexcept {
return m_uid;
}
Changeset& set_uid(user_id_type uid) noexcept {
m_uid = uid;
return *this;
}
Changeset& set_uid_from_signed(signed_user_id_type uid) noexcept {
m_uid = uid < 0 ? 0 : static_cast<user_id_type>(uid);
return *this;
}
Changeset& set_uid(const char* uid) {
m_uid = string_to_uid(uid);
return *this;
}
bool user_is_anonymous() const noexcept {
return m_uid == 0;
}
osmium::Timestamp created_at() const noexcept {
return m_created_at;
}
osmium::Timestamp closed_at() const noexcept {
return m_closed_at;
}
bool open() const noexcept {
return m_closed_at == osmium::Timestamp();
}
bool closed() const noexcept {
return !open();
}
Changeset& set_created_at(const osmium::Timestamp& timestamp) {
m_created_at = timestamp;
return *this;
}
Changeset& set_closed_at(const osmium::Timestamp& timestamp) {
m_closed_at = timestamp;
return *this;
}
num_changes_type num_changes() const noexcept {
return m_num_changes;
}
Changeset& set_num_changes(num_changes_type num_changes) noexcept {
m_num_changes = num_changes;
return *this;
}
Changeset& set_num_changes(const char* num_changes) {
return set_num_changes(osmium::string_to_num_changes(num_changes));
}
num_comments_type num_comments() const noexcept {
return m_num_comments;
}
Changeset& set_num_comments(num_comments_type num_comments) noexcept {
m_num_comments = num_comments;
return *this;
}
Changeset& set_num_comments(const char* num_comments) {
return set_num_comments(osmium::string_to_num_comments(num_comments));
}
osmium::Box& bounds() noexcept {
return m_bounds;
}
const osmium::Box& bounds() const noexcept {
return m_bounds;
}
const char* user() const {
return reinterpret_cast<const char*>(data() + sizeof(Changeset));
}
void clear_user() noexcept {
std::memset(data() + sizeof(Changeset), 0, user_size());
}
const TagList& tags() const {
return osmium::detail::subitem_of_type<const TagList>(cbegin(), cend());
}
void set_attribute(const char* attr, const char* value) {
if (!std::strcmp(attr, "id")) {
set_id(value);
} else if (!std::strcmp(attr, "num_changes")) {
set_num_changes(value);
} else if (!std::strcmp(attr, "comments_count")) {
set_num_comments(value);
} else if (!std::strcmp(attr, "created_at")) {
set_created_at(osmium::Timestamp(value));
} else if (!std::strcmp(attr, "closed_at")) {
set_closed_at(osmium::Timestamp(value));
} else if (!std::strcmp(attr, "uid")) {
set_uid(value);
}
}
using iterator = osmium::memory::CollectionIterator<Item>;
using const_iterator = osmium::memory::CollectionIterator<const Item>;
iterator begin() {
return iterator(subitems_position());
}
iterator end() {
return iterator(data() + padded_size());
}
const_iterator cbegin() const {
return const_iterator(subitems_position());
}
const_iterator cend() const {
return const_iterator(data() + padded_size());
}
const_iterator begin() const {
return cbegin();
}
const_iterator end() const {
return cend();
}
ChangesetDiscussion& discussion() {
return osmium::detail::subitem_of_type<ChangesetDiscussion>(begin(), end());
}
const ChangesetDiscussion& discussion() const {
return osmium::detail::subitem_of_type<const ChangesetDiscussion>(cbegin(), cend());
}
}; // class Changeset
inline bool operator==(const Changeset& lhs, const Changeset& rhs) {
return lhs.id() == rhs.id();
}
inline bool operator!=(const Changeset& lhs, const Changeset& rhs) {
return !(lhs == rhs);
}
inline bool operator<(const Changeset& lhs, const Changeset& rhs) {
return lhs.id() < rhs.id();
}
inline bool operator>(const Changeset& lhs, const Changeset& rhs) {
return rhs < lhs;
}
inline bool operator<=(const Changeset& lhs, const Changeset& rhs) {
return !(rhs < lhs);
}
inline bool operator>=(const Changeset& lhs, const Changeset& rhs) {
return !(lhs < rhs);
}
} // namespace osmium
#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::changeset_comment_size_type
uint32_t changeset_comment_size_type
Definition types.hpp:66
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::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:459
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:455
osmium::string_size_type
uint16_t string_size_type
Definition types.hpp:59
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::string_to_num_changes
num_changes_type string_to_num_changes(const char *input)
Definition types_from_string.hpp:176
osmium::num_changes_type
uint32_t num_changes_type
Type for changeset num_changes.
Definition types.hpp:51
osmium::operator<
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition changeset.hpp:451
tag.hpp
timestamp.hpp
types.hpp
types_from_string.hpp