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 (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <cstring>
#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>
namespace osmium {
namespace builder {
class ChangesetDiscussionBuilder;
template <typename T> class ObjectBuilder;
} // 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};
string_size_type m_user_size;
string_size_type m_text_size;
ChangesetComment(const ChangesetComment&) = delete;
ChangesetComment(ChangesetComment&&) = delete;
ChangesetComment& operator=(const ChangesetComment&) = delete;
ChangesetComment& operator=(ChangesetComment&&) = delete;
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();
}
unsigned const char* next() const {
return endpos();
}
void set_user_size(string_size_type size) noexcept {
m_user_size = size;
}
void set_text_size(string_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),
m_user_size(0),
m_text_size(0) {
}
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> {
friend class osmium::builder::ObjectBuilder<osmium::Changeset>;
public:
typedef size_t size_type;
ChangesetDiscussion() :
osmium::memory::Collection<ChangesetComment, osmium::item_type::changeset_discussion>() {
}
size_type size() const noexcept {
return static_cast<size_type>(std::distance(begin(), end()));
}
}; // class ChangesetDiscussion
class Changeset : public osmium::OSMEntity {
friend class osmium::builder::ObjectBuilder<osmium::Changeset>;
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;
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) {
m_user_size = 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:
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) {
return set_uid_from_signed(string_to_user_id(uid));
}
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));
}
const TagList& tags() const {
return osmium::detail::subitem_of_type<const TagList>(cbegin(), cend());
}
void set_attribute(const char* attr, const char* value) {
if (!strcmp(attr, "id")) {
set_id(value);
} else if (!strcmp(attr, "num_changes")) {
set_num_changes(value);
} else if (!strcmp(attr, "comments_count")) {
set_num_comments(value);
} else if (!strcmp(attr, "created_at")) {
set_created_at(osmium::Timestamp(value));
} else if (!strcmp(attr, "closed_at")) {
set_closed_at(osmium::Timestamp(value));
} else if (!strcmp(attr, "uid")) {
set_uid(value);
}
}
typedef osmium::memory::CollectionIterator<Item> iterator;
typedef osmium::memory::CollectionIterator<const Item> const_iterator;
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
collection.hpp
osmium::ChangesetDiscussion
Definition: changeset.hpp:128
osmium::ChangesetComment::text
const char * text() const noexcept
Definition: changeset.hpp:122
osmium::memory::CollectionIterator
Definition: collection.hpp:47
osmium::Changeset::num_comments
num_comments_type num_comments() const noexcept
Get the number of comments in this changeset.
Definition: changeset.hpp:320
osmium::TagList
Definition: tag.hpp:105
osmium::operator<=
bool operator<=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:446
osmium::Changeset::bounds
osmium::Box & bounds() noexcept
Definition: changeset.hpp:340
types_from_string.hpp
osmium::Changeset::open
bool open() const noexcept
Is this changeset open?
Definition: changeset.hpp:272
osmium::Changeset::m_user_size
string_size_type m_user_size
Definition: changeset.hpp:165
osmium::item_type::changeset_discussion
osmium::operator==
constexpr bool operator==(const Box &lhs, const Box &rhs) noexcept
Definition: box.hpp:222
osmium::Changeset::set_attribute
void set_attribute(const char *attr, const char *value)
Definition: changeset.hpp:370
osmium::Changeset::uid
user_id_type uid() const noexcept
Get user id.
Definition: changeset.hpp:214
osmium::ChangesetComment::m_user_size
string_size_type m_user_size
Definition: changeset.hpp:63
osmium::item_type
item_type
Definition: item_type.hpp:43
osmium::Changeset::set_uid_from_signed
Changeset & set_uid_from_signed(signed_user_id_type uid) noexcept
Definition: changeset.hpp:236
osmium::Changeset::tags
const TagList & tags() const
Get the list of tags.
Definition: changeset.hpp:359
osmium::Changeset::user
const char * user() const
Get user name.
Definition: changeset.hpp:354
osmium::Changeset::id
changeset_id_type id() const noexcept
Get ID of this changeset.
Definition: changeset.hpp:188
osmium::OSMEntity
OSMEntity is the abstract base class for the OSMObject and Changeset classes.
Definition: entity.hpp:64
osmium::Changeset::set_num_changes
Changeset & set_num_changes(const char *num_changes)
Set the number of changes in this changeset.
Definition: changeset.hpp:315
osmium::geom::haversine::distance
double distance(const osmium::geom::Coordinates &c1, const osmium::geom::Coordinates &c2)
Definition: haversine.hpp:64
box.hpp
types.hpp
osmium::Changeset::begin
const_iterator begin() const
Definition: changeset.hpp:405
osmium::ChangesetComment
Definition: changeset.hpp:57
osmium::memory::padded_length
T padded_length(T length) noexcept
Definition: item.hpp:56
osmium::builder::ChangesetDiscussionBuilder
Definition: osm_object_builder.hpp:278
item_type.hpp
tag.hpp
osmium::ChangesetComment::m_text_size
string_size_type m_text_size
Definition: changeset.hpp:64
osmium::Changeset::begin
iterator begin()
Definition: changeset.hpp:389
osmium::Changeset::set_id
Changeset & set_id(changeset_id_type id) noexcept
Definition: changeset.hpp:198
osmium::Changeset::closed_at
osmium::Timestamp closed_at() const noexcept
Definition: changeset.hpp:267
osmium::operator<
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:438
osmium
Namespace for everything in the Osmium library.
Definition: assembler.hpp:59
osmium::Changeset::set_uid
Changeset & set_uid(const char *uid)
Definition: changeset.hpp:247
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:309
osmium::ChangesetComment::endpos
const unsigned char * endpos() const
Definition: changeset.hpp:76
osmium::Changeset::set_user_size
void set_user_size(string_size_type size)
Definition: changeset.hpp:173
osmium::Changeset::num_changes
num_changes_type num_changes() const noexcept
Get the number of changes in this changeset.
Definition: changeset.hpp:304
osmium::memory::Collection
Definition: collection.hpp:111
osmium::Changeset::cend
const_iterator cend() const
Definition: changeset.hpp:401
osmium::Timestamp
Definition: timestamp.hpp:56
osmium::string_size_type
uint16_t string_size_type
Definition: types.hpp:59
osmium::ChangesetComment::next
unsigned char * next()
Definition: changeset.hpp:83
std::end
osmium::io::InputIterator< osmium::io::Reader > end(osmium::io::Reader &)
Definition: reader_iterator.hpp:45
osmium::Changeset::end
const_iterator end() const
Definition: changeset.hpp:409
osmium::string_to_changeset_id
changeset_id_type string_to_changeset_id(const char *input)
Definition: types_from_string.hpp:137
osmium::Changeset::user_is_anonymous
bool user_is_anonymous() const noexcept
Is this user anonymous?
Definition: changeset.hpp:252
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:325
osmium::Changeset::iterator
osmium::memory::CollectionIterator< Item > iterator
Definition: changeset.hpp:386
osmium::Changeset::created_at
osmium::Timestamp created_at() const noexcept
Get timestamp when this changeset was created.
Definition: changeset.hpp:257
osmium::signed_user_id_type
int32_t signed_user_id_type
Type for signed OSM user IDs.
Definition: types.hpp:50
osmium::Changeset::Changeset
Changeset()
Definition: changeset.hpp:169
osmium::ChangesetComment::uid
osmium::user_id_type uid() const noexcept
Definition: changeset.hpp:114
osmium::ChangesetDiscussion::size
size_type size() const noexcept
Definition: changeset.hpp:140
osmium::memory::CollectionIterator::data
unsigned char * data() const noexcept
Definition: collection.hpp:85
entity.hpp
osmium::Box
Definition: box.hpp:50
osmium::ChangesetComment::endpos
unsigned char * endpos()
Definition: changeset.hpp:72
osmium::ChangesetComment::set_text_size
void set_text_size(string_size_type size) noexcept
Definition: changeset.hpp:95
osmium::Changeset::end
iterator end()
Definition: changeset.hpp:393
osmium::operator>=
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:450
osmium::string_to_user_id
signed_user_id_type string_to_user_id(const char *input)
Definition: types_from_string.hpp:151
item.hpp
osmium::ChangesetComment::ChangesetComment
ChangesetComment(osmium::Timestamp date, osmium::user_id_type uid) noexcept
Definition: changeset.hpp:103
osmium::Changeset::const_iterator
osmium::memory::CollectionIterator< const Item > const_iterator
Definition: changeset.hpp:387
osmium::Changeset::set_num_comments
Changeset & set_num_comments(const char *num_comments)
Set the number of comments in this changeset.
Definition: changeset.hpp:331
osmium::builder::ObjectBuilder
Definition: builder.hpp:186
osmium::operator>
bool operator>(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:442
osmium::ChangesetComment::set_user_size
void set_user_size(string_size_type size) noexcept
Definition: changeset.hpp:91
osmium::ChangesetComment::date
osmium::Timestamp date() const noexcept
Definition: changeset.hpp:110
osmium::ChangesetComment::next
unsigned const char * next() const
Definition: changeset.hpp:87
osmium::Changeset::subitems_position
unsigned char * subitems_position()
Definition: changeset.hpp:177
osmium::Changeset::discussion
ChangesetDiscussion & discussion()
Definition: changeset.hpp:413
osmium::Changeset::subitems_position
const unsigned char * subitems_position() const
Definition: changeset.hpp:181
osmium::Changeset::set_created_at
Changeset & set_created_at(const osmium::Timestamp &timestamp)
Definition: changeset.hpp:287
osmium::Changeset
An OSM Changeset, a group of changes made by a single user over a short period of time...
Definition: changeset.hpp:154
osmium::Changeset::bounds
const osmium::Box & bounds() const noexcept
Definition: changeset.hpp:349
osmium::num_changes_type
uint32_t num_changes_type
Type for changeset num_changes.
Definition: types.hpp:51
osmium::Changeset::set_closed_at
Changeset & set_closed_at(const osmium::Timestamp &timestamp)
Definition: changeset.hpp:298
osmium::Changeset::closed
bool closed() const noexcept
Is this changeset closed?
Definition: changeset.hpp:277
osmium::changeset_id_type
uint32_t changeset_id_type
Type for OSM changeset IDs.
Definition: types.hpp:48
osmium::ChangesetDiscussion::size_type
size_t size_type
Definition: changeset.hpp:134
std::begin
osmium::io::InputIterator< osmium::io::Reader > begin(osmium::io::Reader &reader)
Definition: reader_iterator.hpp:41
osmium::Changeset::cbegin
const_iterator cbegin() const
Definition: changeset.hpp:397
osmium::num_comments_type
uint32_t num_comments_type
Type for changeset num_comments.
Definition: types.hpp:52
osmium::string_to_num_comments
num_comments_type string_to_num_comments(const char *input)
Definition: types_from_string.hpp:182
osmium::ChangesetComment::m_date
osmium::Timestamp m_date
Definition: changeset.hpp:61
osmium::operator!=
bool operator!=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:431
osmium::Changeset::set_id
Changeset & set_id(const char *id)
Definition: changeset.hpp:209
osmium::string_to_num_changes
num_changes_type string_to_num_changes(const char *input)
Definition: types_from_string.hpp:168
osmium::builder::Builder::operator=
Builder & operator=(const Builder &)=delete
timestamp.hpp
osmium::Changeset::set_uid
Changeset & set_uid(user_id_type uid) noexcept
Definition: changeset.hpp:224
osmium::ChangesetComment::user
const char * user() const noexcept
Definition: changeset.hpp:118
osmium::Changeset::discussion
const ChangesetDiscussion & discussion() const
Definition: changeset.hpp:417
osmium::user_id_type
uint32_t user_id_type
Type for OSM user IDs.
Definition: types.hpp:49