Libosmium  2.17.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
6This file is part of Osmium (https://osmcode.org/libosmium).
7
8Copyright 2013-2021 Jochen Topf <jochen@topf.org> and others (see README).
9
10Boost Software License - Version 1.0 - August 17th, 2003
11
12Permission is hereby granted, free of charge, to any person or organization
13obtaining a copy of the software and accompanying documentation covered by
14this license (the "Software") to use, reproduce, display, distribute,
15execute, and transmit the Software, and to prepare derivative works of the
16Software, and to permit third-parties to whom the Software is furnished to
17do so, all subject to the following:
18
19The copyright notices in the Software and this entire statement, including
20the above license grant, this restriction and the following disclaimer,
21must be included in all copies of the Software, in whole or in part, and
22all derivative works of the Software, unless such copies or derivative
23works are solely in the form of machine-executable object code generated by
24a source language processor.
25
26THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32DEALINGS IN THE SOFTWARE.
33
34*/
35
36#include <osmium/memory/collection.hpp> // IWYU pragma: keep
38#include <osmium/osm/entity.hpp>
40#include <osmium/osm/object.hpp>
41#include <osmium/osm/types.hpp>
43
44#include <cstdint>
45#include <cstdlib>
46#include <iterator>
47
48namespace osmium {
49
50 namespace builder {
51 template <typename TDerived, typename T>
52 class OSMObjectBuilder;
53
54 class RelationMemberListBuilder;
55 } // namespace builder
56
57 class RelationMember : public osmium::memory::detail::ItemHelper {
58
60
63 uint16_t m_flags;
65
66 unsigned char* endpos() {
68 }
69
70 const unsigned char* endpos() const {
72 }
73
74 template <typename TMember>
76
77 unsigned char* next() {
78 if (full_member()) {
79 return endpos() + reinterpret_cast<osmium::memory::Item*>(endpos())->byte_size();
80 }
81 return endpos();
82 }
83
84 const unsigned char* next() const {
85 if (full_member()) {
86 return endpos() + reinterpret_cast<const osmium::memory::Item*>(endpos())->byte_size();
87 }
88 return endpos();
89 }
90
91 void set_role_size(string_size_type size) noexcept {
92 m_role_size = size;
93 }
94
95 public:
96
98
99 explicit RelationMember(const object_id_type ref = 0, const item_type type = item_type(), const bool full = false) noexcept :
100 m_ref(ref),
101 m_type(type),
102 m_flags(full ? 1 : 0) {
103 }
104
107
110
111 ~RelationMember() noexcept = default;
112
113 object_id_type ref() const noexcept {
114 return m_ref;
115 }
116
119 m_ref = ref;
120 return *this;
121 }
122
124 return static_cast<unsigned_object_id_type>(std::abs(m_ref));
125 }
126
128 m_ref = ref;
129 return *this;
130 }
131
132 item_type type() const noexcept {
133 return m_type;
134 }
135
136 bool full_member() const noexcept {
137 return m_flags == 1;
138 }
139
140 const char* role() const noexcept {
141 return reinterpret_cast<const char*>(data() + sizeof(RelationMember));
142 }
143
145 return *reinterpret_cast<OSMObject*>(endpos());
146 }
147
148 const OSMObject& get_object() const {
149 return *reinterpret_cast<const OSMObject*>(endpos());
150 }
151
152 }; // class RelationMember
153
154 class RelationMemberList : public osmium::memory::Collection<RelationMember, osmium::item_type::relation_member_list> {
155
156 public:
157
158 constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
161 }
162
163 RelationMemberList() noexcept = default;
164
165 }; // class RelationMemberList
166
167
168 class Relation : public OSMObject {
169
170 template <typename TDerived, typename T>
172
173 Relation() noexcept :
175 }
176
177 public:
178
180
181 constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
182 return t == itemtype;
183 }
184
187 return osmium::detail::subitem_of_type<RelationMemberList>(begin(), end());
188 }
189
192 return osmium::detail::subitem_of_type<const RelationMemberList>(cbegin(), cend());
193 }
194
197 return osmium::detail::subitem_of_type<const RelationMemberList>(cbegin(), cend());
198 }
199
200 }; // class Relation
201
202
203} // namespace osmium
204
205#endif // OSMIUM_OSM_RELATION_HPP
Definition: object.hpp:64
Definition: relation.hpp:154
static constexpr bool is_compatible_to(osmium::item_type t) noexcept
Definition: relation.hpp:158
RelationMemberList() noexcept=default
Definition: relation.hpp:57
string_size_type m_role_size
Definition: relation.hpp:64
OSMObject & get_object()
Definition: relation.hpp:144
RelationMember(const RelationMember &)=delete
~RelationMember() noexcept=default
object_id_type m_ref
Definition: relation.hpp:61
RelationMember(RelationMember &&)=delete
unsigned char * next()
Definition: relation.hpp:77
const char * role() const noexcept
Definition: relation.hpp:140
RelationMember & operator=(const RelationMember &)=delete
const unsigned char * next() const
Definition: relation.hpp:84
RelationMember & set_ref(const osmium::object_id_type ref) noexcept
Definition: relation.hpp:127
item_type type() const noexcept
Definition: relation.hpp:132
void set_role_size(string_size_type size) noexcept
Definition: relation.hpp:91
unsigned char * endpos()
Definition: relation.hpp:66
unsigned_object_id_type positive_ref() const noexcept
Definition: relation.hpp:123
RelationMember(const object_id_type ref=0, const item_type type=item_type(), const bool full=false) noexcept
Definition: relation.hpp:99
static constexpr item_type collection_type
Definition: relation.hpp:97
RelationMember & operator=(RelationMember &&)=delete
OSMIUM_DEPRECATED RelationMember & ref(object_id_type ref) noexcept
Definition: relation.hpp:118
const OSMObject & get_object() const
Definition: relation.hpp:148
uint16_t m_flags
Definition: relation.hpp:63
const unsigned char * endpos() const
Definition: relation.hpp:70
bool full_member() const noexcept
Definition: relation.hpp:136
item_type m_type
Definition: relation.hpp:62
object_id_type ref() const noexcept
Definition: relation.hpp:113
Definition: relation.hpp:168
RelationMemberList & members()
Get a reference to the member list.
Definition: relation.hpp:186
Relation() noexcept
Definition: relation.hpp:173
const RelationMemberList & cmembers() const
Get a const reference to the member list.
Definition: relation.hpp:196
static constexpr bool is_compatible_to(osmium::item_type t) noexcept
Definition: relation.hpp:181
const RelationMemberList & members() const
Get a const reference to the member list.
Definition: relation.hpp:191
Definition: osm_object_builder.hpp:402
Definition: osm_object_builder.hpp:229
Definition: collection.hpp:47
Definition: collection.hpp:117
static constexpr osmium::item_type itemtype
Definition: collection.hpp:128
const_iterator cend() const noexcept
Definition: collection.hpp:168
const_iterator cbegin() const noexcept
Definition: collection.hpp:164
Definition: item.hpp:105
#define OSMIUM_DEPRECATED
Definition: compatibility.hpp:51
constexpr std::size_t padded_length(std::size_t length) noexcept
Definition: item.hpp:64
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
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
item_type
Definition: item_type.hpp:43
@ relation_member_list_with_full_members
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