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

Loading...
Searching...
No Matches
relation.hpp
Go to the documentation of this file.
1#ifndef OSMIUM_OSM_RELATION_HPP
2#define OSMIUM_OSM_RELATION_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> // IWYU pragma: keep
37#include <osmium/memory/item.hpp>
38#include <osmium/osm/entity.hpp>
39#include <osmium/osm/item_type.hpp>
40#include <osmium/osm/object.hpp>
41#include <osmium/osm/types.hpp>
42
43#include <cstdint>
44#include <cstdlib>
45#include <iterator>
46
47 namespace osmium {
48
49 namespace builder {
50 template <typename TDerived, typename T>
51 class OSMObjectBuilder;
52
53 class RelationMemberListBuilder;
54 } // namespace builder
55
56 class RelationMember : public osmium::memory::detail::ItemHelper {
57
58 friend class osmium::builder::RelationMemberListBuilder;
59
60 object_id_type m_ref;
61 item_type m_type;
62 uint16_t m_flags;
63 string_size_type m_role_size = 0;
64
65 unsigned char* endpos() {
66 return data() + osmium::memory::padded_length(sizeof(RelationMember) + m_role_size);
67 }
68
69 const unsigned char* endpos() const {
70 return data() + osmium::memory::padded_length(sizeof(RelationMember) + m_role_size);
71 }
72
73 template <typename TMember>
74 friend class osmium::memory::CollectionIterator;
75
76 unsigned char* next() {
77 if (full_member()) {
78 return endpos() + reinterpret_cast<osmium::memory::Item*>(endpos())->byte_size();
79 }
80 return endpos();
81 }
82
83 const unsigned char* next() const {
84 if (full_member()) {
85 return endpos() + reinterpret_cast<const osmium::memory::Item*>(endpos())->byte_size();
86 }
87 return endpos();
88 }
89
90 void set_role_size(string_size_type size) noexcept {
91 m_role_size = size;
92 }
93
94 public:
95
96 static constexpr item_type collection_type = item_type::relation_member_list;
97
98 explicit RelationMember(const object_id_type ref = 0, const item_type type = item_type(), const bool full = false) noexcept :
99 m_ref(ref),
100 m_type(type),
101 m_flags(full ? 1 : 0) {
102 }
103
104 RelationMember(const RelationMember&) = delete;
105 RelationMember& operator=(const RelationMember&) = delete;
106
107 RelationMember(RelationMember&&) = delete;
108 RelationMember& operator=(RelationMember&&) = delete;
109
110 ~RelationMember() noexcept = default;
111
112 object_id_type ref() const noexcept {
113 return m_ref;
114 }
115
116 unsigned_object_id_type positive_ref() const noexcept {
117 return static_cast<unsigned_object_id_type>(std::abs(m_ref));
118 }
119
120 RelationMember& set_ref(const osmium::object_id_type ref) noexcept {
121 m_ref = ref;
122 return *this;
123 }
124
125 item_type type() const noexcept {
126 return m_type;
127 }
128
129 bool full_member() const noexcept {
130 return m_flags == 1;
131 }
132
133 const char* role() const noexcept {
134 return reinterpret_cast<const char*>(data() + sizeof(RelationMember));
135 }
136
137 OSMObject& get_object() {
138 return *reinterpret_cast<OSMObject*>(endpos());
139 }
140
141 const OSMObject& get_object() const {
142 return *reinterpret_cast<const OSMObject*>(endpos());
143 }
144
145 }; // class RelationMember
146
147 class RelationMemberList : public osmium::memory::Collection<RelationMember, osmium::item_type::relation_member_list> {
148
149 public:
150
151 constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
152 return t == osmium::item_type::relation_member_list ||
153 t == osmium::item_type::relation_member_list_with_full_members;
154 }
155
156 RelationMemberList() noexcept = default;
157
158 }; // class RelationMemberList
159
160
161 class Relation : public OSMObject {
162
163 template <typename TDerived, typename T>
164 friend class osmium::builder::OSMObjectBuilder;
165
166 Relation() noexcept :
167 OSMObject(sizeof(Relation), osmium::item_type::relation) {
168 }
169
170 public:
171
172 static constexpr osmium::item_type itemtype = osmium::item_type::relation;
173
174 constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
175 return t == itemtype;
176 }
177
179 RelationMemberList& members() {
180 return osmium::detail::subitem_of_type<RelationMemberList>(begin(), end());
181 }
182
184 const RelationMemberList& members() const {
185 return osmium::detail::subitem_of_type<const RelationMemberList>(cbegin(), cend());
186 }
187
189 const RelationMemberList& cmembers() const {
190 return osmium::detail::subitem_of_type<const RelationMemberList>(cbegin(), cend());
191 }
192
193 }; // class Relation
194
195
196} // namespace osmium
197
198#endif // OSMIUM_OSM_RELATION_HPP
osmium::OSMObject
Definition object.hpp:64
osmium::RelationMemberList
Definition relation.hpp:147
osmium::RelationMemberList::is_compatible_to
static constexpr bool is_compatible_to(osmium::item_type t) noexcept
Definition relation.hpp:151
osmium::RelationMemberList::RelationMemberList
RelationMemberList() noexcept=default
osmium::RelationMember
Definition relation.hpp:56
osmium::RelationMember::m_role_size
string_size_type m_role_size
Definition relation.hpp:63
osmium::RelationMember::get_object
OSMObject & get_object()
Definition relation.hpp:137
osmium::RelationMember::RelationMember
RelationMember(const RelationMember &)=delete
osmium::RelationMember::~RelationMember
~RelationMember() noexcept=default
osmium::RelationMember::m_ref
object_id_type m_ref
Definition relation.hpp:60
osmium::RelationMember::RelationMember
RelationMember(RelationMember &&)=delete
osmium::RelationMember::next
unsigned char * next()
Definition relation.hpp:76
osmium::RelationMember::role
const char * role() const noexcept
Definition relation.hpp:133
osmium::RelationMember::operator=
RelationMember & operator=(const RelationMember &)=delete
osmium::RelationMember::next
const unsigned char * next() const
Definition relation.hpp:83
osmium::RelationMember::set_ref
RelationMember & set_ref(const osmium::object_id_type ref) noexcept
Definition relation.hpp:120
osmium::RelationMember::type
item_type type() const noexcept
Definition relation.hpp:125
osmium::RelationMember::set_role_size
void set_role_size(string_size_type size) noexcept
Definition relation.hpp:90
osmium::RelationMember::endpos
unsigned char * endpos()
Definition relation.hpp:65
osmium::RelationMember::positive_ref
unsigned_object_id_type positive_ref() const noexcept
Definition relation.hpp:116
osmium::RelationMember::RelationMember
RelationMember(const object_id_type ref=0, const item_type type=item_type(), const bool full=false) noexcept
Definition relation.hpp:98
osmium::RelationMember::collection_type
static constexpr item_type collection_type
Definition relation.hpp:96
osmium::RelationMember::operator=
RelationMember & operator=(RelationMember &&)=delete
osmium::RelationMember::get_object
const OSMObject & get_object() const
Definition relation.hpp:141
osmium::RelationMember::m_flags
uint16_t m_flags
Definition relation.hpp:62
osmium::RelationMember::endpos
const unsigned char * endpos() const
Definition relation.hpp:69
osmium::RelationMember::full_member
bool full_member() const noexcept
Definition relation.hpp:129
osmium::RelationMember::m_type
item_type m_type
Definition relation.hpp:61
osmium::RelationMember::ref
object_id_type ref() const noexcept
Definition relation.hpp:112
osmium::Relation
Definition relation.hpp:161
osmium::Relation::members
RelationMemberList & members()
Get a reference to the member list.
Definition relation.hpp:179
osmium::Relation::Relation
Relation() noexcept
Definition relation.hpp:166
osmium::Relation::cmembers
const RelationMemberList & cmembers() const
Get a const reference to the member list.
Definition relation.hpp:189
osmium::Relation::is_compatible_to
static constexpr bool is_compatible_to(osmium::item_type t) noexcept
Definition relation.hpp:174
osmium::Relation::members
const RelationMemberList & members() const
Get a const reference to the member list.
Definition relation.hpp:184
osmium::builder::OSMObjectBuilder
Definition way.hpp:49
osmium::builder::RelationMemberListBuilder
Definition osm_object_builder.hpp:228
osmium::memory::CollectionIterator
Definition collection.hpp:47
osmium::memory::Collection
Definition collection.hpp:181
osmium::memory::Collection< RelationMember, osmium::item_type::relation_member_list >::itemtype
static constexpr osmium::item_type itemtype
Definition collection.hpp:192
osmium::memory::Collection< RelationMember, osmium::item_type::relation_member_list >::end
iterator end() noexcept
Definition collection.hpp:224
osmium::memory::Collection< RelationMember, osmium::item_type::relation_member_list >::cend
const_iterator cend() const noexcept
Definition collection.hpp:232
osmium::memory::Collection< RelationMember, osmium::item_type::relation_member_list >::cbegin
const_iterator cbegin() const noexcept
Definition collection.hpp:228
osmium::memory::Collection< RelationMember, osmium::item_type::relation_member_list >::begin
iterator begin() noexcept
Definition collection.hpp:220
osmium::memory::Item
Definition item.hpp:105
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_size_type
uint16_t string_size_type
Definition types.hpp:59
osmium::unsigned_object_id_type
uint64_t unsigned_object_id_type
Type for OSM object (node, way, or relation) IDs where we only allow positive IDs.
Definition types.hpp:46
osmium::item_type
item_type
Definition item_type.hpp:45
osmium::item_type::relation_member_list
@ relation_member_list
osmium::item_type::relation_member_list_with_full_members
@ relation_member_list_with_full_members
osmium::item_type::relation
@ relation
osmium::object_id_type
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition types.hpp:45
object.hpp
types.hpp