1#ifndef OSMIUM_BUILDER_OSM_OBJECT_BUILDER_HPP
2#define OSMIUM_BUILDER_OSM_OBJECT_BUILDER_HPP
57#include <initializer_list>
102 void add_tag(
const char* key,
const char* value) {
104 throw std::length_error{
"OSM tag key is too long"};
107 throw std::length_error{
"OSM tag value is too long"};
121 void add_tag(
const char* key,
const std::size_t key_length,
const char* value,
const std::size_t value_length) {
123 throw std::length_error{
"OSM tag key is too long"};
126 throw std::length_error{
"OSM tag value is too long"};
138 void add_tag(
const std::string& key,
const std::string& value) {
140 throw std::length_error{
"OSM tag key is too long"};
143 throw std::length_error{
"OSM tag value is too long"};
164 void add_tag(
const std::pair<const char* const, const char* const>& tag) {
165 add_tag(tag.first, tag.second);
167 void add_tag(
const std::pair<const char* const, const char*>& tag) {
168 add_tag(tag.first, tag.second);
170 void add_tag(
const std::pair<const char*, const char* const>& tag) {
171 add_tag(tag.first, tag.second);
173 void add_tag(
const std::pair<const char*, const char*>& tag) {
174 add_tag(tag.first, tag.second);
182 void add_tag(
const std::pair<const std::string&, const std::string&>& tag) {
183 add_tag(tag.first, tag.second);
188 template <
typename T>
241 throw std::length_error{
"OSM relation member role is too long"};
284 auto* member = reserve_space_for<osmium::RelationMember>();
287 add_role(*member, role, role_length);
331 throw std::length_error{
"OSM user name is too long"};
338 if (length > std::numeric_limits<osmium::changeset_comment_size_type>::max() - 1) {
339 throw std::length_error{
"OSM changeset comment is too long"};
365 assert(!
m_comment &&
"You have to always call both add_comment() and then add_comment_text() in that order for each comment!");
370 assert(!
m_comment &&
"You have to always call both add_comment() and then add_comment_text() in that order for each comment!");
371 m_comment = reserve_space_for<osmium::ChangesetComment>();
378 assert(
m_comment &&
"You have to always call both add_comment() and then add_comment_text() in that order for each comment!");
381 add_text(comment, text, std::strlen(text));
385 assert(
m_comment &&
"You have to always call both add_comment() and then add_comment_text() in that order for each comment!");
388 add_text(comment, text.c_str(), text.size());
393#define OSMIUM_FORWARD(setter) \
394 template <typename... TArgs> \
395 type& setter(TArgs&&... args) { \
396 object().setter(std::forward<TArgs>(args)...); \
397 return static_cast<type&>(*this); \
400 template <
typename TDerived,
typename T>
429 return static_cast<T&
>(
item());
440 return static_cast<const T&
>(
item());
452 &&
"set_user() must be called at most once and before any sub-builders");
454 if (length > available_space) {
457 add_size(
static_cast<uint32_t
>(space_needed));
459 std::memcpy(
object().data() + size_of_object, user, length);
462 return static_cast<TDerived&
>(*this);
473 const auto len = std::strlen(user);
474 assert(len < std::numeric_limits<string_size_type>::max());
486 assert(user.size() < std::numeric_limits<string_size_type>::max());
501 void
add_tags(const
std::initializer_list<
std::pair<const
char*, const
char*>>& tags) {
503 for (
const auto& p : tags) {
504 tl_builder.add_tag(p.first, p.second);
544 for (
const auto& node_ref : nodes) {
545 builder.add_node_ref(node_ref);
590 set_uid(source.
uid());
657 &&
"set_user() must be called at most once and before any sub-builders");
659 if (length > available_space) {
662 add_size(
static_cast<uint32_t
>(space_needed));
664 std::memcpy(
object().data() +
sizeof(
Changeset), user, length);
678 const auto len = std::strlen(user);
679 assert(len <= std::numeric_limits<string_size_type>::max());
691 assert(user.size() < std::numeric_limits<string_size_type>::max());
Definition: changeset.hpp:130
An OSM Changeset, a group of changes made by a single user over a short period of time.
Definition: changeset.hpp:146
void set_user_size(string_size_type size) noexcept
Definition: changeset.hpp:165
osmium::Box & bounds() noexcept
Definition: changeset.hpp:348
Definition: location.hpp:271
Definition: node_ref.hpp:50
Definition: object.hpp:64
const char * user() const noexcept
Get user name for this object.
Definition: object.hpp:319
bool visible() const noexcept
Is this object marked visible (ie not deleted)?
Definition: object.hpp:152
object_version_type version() const noexcept
Get version of this object.
Definition: object.hpp:194
osmium::Timestamp timestamp() const noexcept
Get timestamp when this object last changed.
Definition: object.hpp:283
user_id_type uid() const noexcept
Get user id of this object.
Definition: object.hpp:242
changeset_id_type changeset() const noexcept
Get changeset id of this object.
Definition: object.hpp:218
object_id_type id() const noexcept
Get ID of this object.
Definition: object.hpp:118
Definition: relation.hpp:147
Definition: relation.hpp:56
void set_role_size(string_size_type size) noexcept
Definition: relation.hpp:90
Definition: relation.hpp:161
const char * key() const noexcept
Definition: tag.hpp:86
const char * value() const noexcept
Definition: tag.hpp:95
Definition: timestamp.hpp:175
Definition: osm_object_builder.hpp:567
AreaBuilder(osmium::memory::Buffer &buffer, Builder *parent=nullptr)
Definition: osm_object_builder.hpp:573
void initialize_from_object(const osmium::OSMObject &source)
Definition: osm_object_builder.hpp:584
AreaBuilder(Builder &parent)
Definition: osm_object_builder.hpp:577
Definition: builder.hpp:56
unsigned char * reserve_space(std::size_t size)
Definition: builder.hpp:97
osmium::memory::item_size_type append(const char *data, const osmium::memory::item_size_type length)
Definition: builder.hpp:159
uint32_t size() const noexcept
Definition: builder.hpp:136
void add_padding(bool self=false)
Definition: builder.hpp:114
void add_size(osmium::memory::item_size_type size)
Definition: builder.hpp:129
unsigned char * item_pos() const noexcept
Definition: builder.hpp:89
osmium::memory::Buffer & buffer() noexcept
Return the buffer this builder is using.
Definition: builder.hpp:198
osmium::memory::Item & item() const noexcept
Definition: builder.hpp:93
osmium::memory::item_size_type append_with_zero(const char *data, const osmium::memory::item_size_type length)
Definition: builder.hpp:172
void add_item(const osmium::memory::Item &item)
Definition: builder.hpp:206
Definition: osm_object_builder.hpp:596
ChangesetBuilder & set_user(const char *user)
Definition: osm_object_builder.hpp:677
Changeset & object() noexcept
Definition: osm_object_builder.hpp:619
ChangesetBuilder(osmium::memory::Buffer &buffer, Builder *parent=nullptr)
Definition: osm_object_builder.hpp:604
ChangesetBuilder & set_bounds(const osmium::Box &box) noexcept
Definition: osm_object_builder.hpp:644
ChangesetBuilder & set_user(const std::string &user)
Definition: osm_object_builder.hpp:690
static constexpr const std::size_t min_size_for_user
Definition: osm_object_builder.hpp:600
const Changeset & cobject() const noexcept
Definition: osm_object_builder.hpp:630
ChangesetBuilder & set_user(const char *user, const string_size_type length)
Definition: osm_object_builder.hpp:655
Definition: osm_object_builder.hpp:325
void add_user(osmium::ChangesetComment &comment, const char *user, const std::size_t length)
Definition: osm_object_builder.hpp:329
ChangesetDiscussionBuilder(const ChangesetDiscussionBuilder &)=delete
ChangesetDiscussionBuilder(osmium::memory::Buffer &buffer, Builder *parent=nullptr)
Definition: osm_object_builder.hpp:348
ChangesetDiscussionBuilder & operator=(ChangesetDiscussionBuilder &&)=delete
ChangesetDiscussionBuilder(ChangesetDiscussionBuilder &&)=delete
void add_text(osmium::ChangesetComment &comment, const char *text, const std::size_t length)
Definition: osm_object_builder.hpp:337
ChangesetDiscussionBuilder(Builder &parent)
Definition: osm_object_builder.hpp:353
~ChangesetDiscussionBuilder()
Definition: osm_object_builder.hpp:364
void add_comment(osmium::Timestamp date, osmium::user_id_type uid, const char *user)
Definition: osm_object_builder.hpp:369
void add_comment_text(const char *text)
Definition: osm_object_builder.hpp:377
void add_comment_text(const std::string &text)
Definition: osm_object_builder.hpp:384
ChangesetDiscussionBuilder & operator=(const ChangesetDiscussionBuilder &)=delete
osmium::ChangesetComment * m_comment
Definition: osm_object_builder.hpp:327
Definition: osm_object_builder.hpp:510
NodeBuilder(Builder &parent)
Definition: osm_object_builder.hpp:520
NodeBuilder(osmium::memory::Buffer &buffer, Builder *parent=nullptr)
Definition: osm_object_builder.hpp:516
Definition: osm_object_builder.hpp:189
NodeRefListBuilder(NodeRefListBuilder &&)=delete
~NodeRefListBuilder()
Definition: osm_object_builder.hpp:209
NodeRefListBuilder & operator=(const NodeRefListBuilder &)=delete
NodeRefListBuilder(Builder &parent)
Definition: osm_object_builder.hpp:198
NodeRefListBuilder & operator=(NodeRefListBuilder &&)=delete
void add_node_ref(const NodeRef &node_ref)
Definition: osm_object_builder.hpp:213
NodeRefListBuilder(const NodeRefListBuilder &)=delete
void add_node_ref(const object_id_type ref, const osmium::Location &location=Location{})
Definition: osm_object_builder.hpp:218
NodeRefListBuilder(osmium::memory::Buffer &buffer, Builder *parent=nullptr)
Definition: osm_object_builder.hpp:193
Definition: osm_object_builder.hpp:401
const T & cobject() const noexcept
Definition: osm_object_builder.hpp:439
T & object() noexcept
Definition: osm_object_builder.hpp:428
OSMObjectBuilder(osmium::memory::Buffer &buffer, Builder *parent=nullptr)
Definition: osm_object_builder.hpp:413
void set_user_size(string_size_type size) noexcept
Definition: osm_object_builder.hpp:407
static constexpr const std::size_t min_size_for_user
Definition: osm_object_builder.hpp:405
TDerived type
Definition: osm_object_builder.hpp:403
TDerived & set_user(const std::string &user)
Definition: osm_object_builder.hpp:485
void add_tags(const std::initializer_list< std::pair< const char *, const char * > > &tags)
Definition: osm_object_builder.hpp:501
TDerived & set_user(const char *user)
Definition: osm_object_builder.hpp:472
TDerived & set_user(const char *user, const string_size_type length)
Definition: osm_object_builder.hpp:449
Definition: osm_object_builder.hpp:551
RelationBuilder(Builder &parent)
Definition: osm_object_builder.hpp:561
RelationBuilder(osmium::memory::Buffer &buffer, Builder *parent=nullptr)
Definition: osm_object_builder.hpp:557
Definition: osm_object_builder.hpp:228
RelationMemberListBuilder(RelationMemberListBuilder &&)=delete
~RelationMemberListBuilder()
Definition: osm_object_builder.hpp:266
void add_member(osmium::item_type type, object_id_type ref, const char *role, const std::size_t role_length, const osmium::OSMObject *full_member=nullptr)
Definition: osm_object_builder.hpp:283
RelationMemberListBuilder & operator=(RelationMemberListBuilder &&)=delete
RelationMemberListBuilder(osmium::memory::Buffer &buffer, Builder *parent=nullptr)
Definition: osm_object_builder.hpp:250
void add_role(osmium::RelationMember &member, const char *role, const std::size_t length)
Definition: osm_object_builder.hpp:239
RelationMemberListBuilder(Builder &parent)
Definition: osm_object_builder.hpp:255
RelationMemberListBuilder(const RelationMemberListBuilder &)=delete
RelationMemberListBuilder & operator=(const RelationMemberListBuilder &)=delete
void add_member(osmium::item_type type, object_id_type ref, const char *role, const osmium::OSMObject *full_member=nullptr)
Definition: osm_object_builder.hpp:304
void add_member(osmium::item_type type, object_id_type ref, const std::string &role, const osmium::OSMObject *full_member=nullptr)
Definition: osm_object_builder.hpp:319
Definition: osm_object_builder.hpp:72
TagListBuilder & operator=(TagListBuilder &&)=delete
void add_tag(const std::pair< const std::string &, const std::string & > &tag)
Definition: osm_object_builder.hpp:182
~TagListBuilder()
Definition: osm_object_builder.hpp:92
void add_tag(const std::pair< const char *, const char *const > &tag)
Definition: osm_object_builder.hpp:170
void add_tag(const char *key, const std::size_t key_length, const char *value, const std::size_t value_length)
Definition: osm_object_builder.hpp:121
TagListBuilder(osmium::memory::Buffer &buffer, Builder *parent=nullptr)
Definition: osm_object_builder.hpp:76
void add_tag(const std::pair< const char *, const char * > &tag)
Definition: osm_object_builder.hpp:173
TagListBuilder(const TagListBuilder &)=delete
TagListBuilder & operator=(const TagListBuilder &)=delete
void add_tag(const std::pair< const char *const, const char * > &tag)
Definition: osm_object_builder.hpp:167
void add_tag(const std::pair< const char *const, const char *const > &tag)
Definition: osm_object_builder.hpp:164
void add_tag(const std::string &key, const std::string &value)
Definition: osm_object_builder.hpp:138
TagListBuilder(Builder &parent)
Definition: osm_object_builder.hpp:81
void add_tag(const char *key, const char *value)
Definition: osm_object_builder.hpp:102
TagListBuilder(TagListBuilder &&)=delete
void add_tag(const osmium::Tag &tag)
Definition: osm_object_builder.hpp:154
Definition: osm_object_builder.hpp:528
void add_node_refs(const std::initializer_list< osmium::NodeRef > &nodes)
Definition: osm_object_builder.hpp:542
WayBuilder(osmium::memory::Buffer &buffer, Builder *parent=nullptr)
Definition: osm_object_builder.hpp:534
WayBuilder(Builder &parent)
Definition: osm_object_builder.hpp:538
item_type type() const noexcept
Definition: item.hpp:171
constexpr std::size_t padded_length(std::size_t length) noexcept
Definition: item.hpp:64
uint32_t item_size_type
Definition: item.hpp:57
type
Definition: entity_bits.hpp:63
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
@ max_osm_string_length
Definition: types.hpp:70
uint32_t changeset_comment_size_type
Definition: types.hpp:66
uint32_t user_id_type
Type for OSM user IDs.
Definition: types.hpp:49
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
uint16_t string_size_type
Definition: types.hpp:59
osmium::object_id_type object_id_to_area_id(osmium::object_id_type id, osmium::item_type type) noexcept
Definition: area.hpp:104
item_type
Definition: item_type.hpp:45
Definition: location.hpp:555
#define OSMIUM_FORWARD(setter)
Definition: osm_object_builder.hpp:393