Libosmium  2.10.0
Fast and flexible C++ library for working with OpenStreetMap data
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 (http://osmcode.org/libosmium).
7 
8 Copyright 2013-2016 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 <cstdint>
37 #include <cstdlib>
38 #include <iterator>
39 
40 #include <osmium/memory/collection.hpp> // IWYU pragma: keep
41 #include <osmium/memory/item.hpp>
42 #include <osmium/osm/entity.hpp>
43 #include <osmium/osm/item_type.hpp>
44 #include <osmium/osm/object.hpp>
45 #include <osmium/osm/types.hpp>
47 
48 namespace 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;
64  string_size_type m_role_size {0};
65 
66  RelationMember(const RelationMember&) = delete;
67  RelationMember(RelationMember&&) = delete;
68 
69  RelationMember& operator=(const RelationMember&) = delete;
71 
72  unsigned char* endpos() {
73  return data() + osmium::memory::padded_length(sizeof(RelationMember) + m_role_size);
74  }
75 
76  const unsigned char* endpos() const {
77  return data() + osmium::memory::padded_length(sizeof(RelationMember) + m_role_size);
78  }
79 
80  template <typename TMember>
82 
83  unsigned char* next() {
84  if (full_member()) {
85  return endpos() + reinterpret_cast<osmium::memory::Item*>(endpos())->byte_size();
86  }
87  return endpos();
88  }
89 
90  unsigned const char* next() const {
91  if (full_member()) {
92  return endpos() + reinterpret_cast<const osmium::memory::Item*>(endpos())->byte_size();
93  }
94  return endpos();
95  }
96 
97  void set_role_size(string_size_type size) noexcept {
98  m_role_size = size;
99  }
100 
101  public:
102 
103  static constexpr item_type collection_type = item_type::relation_member_list;
104 
105  RelationMember(const object_id_type ref = 0, const item_type type = item_type(), const bool full = false) noexcept :
106  m_ref(ref),
107  m_type(type),
108  m_flags(full ? 1 : 0) {
109  }
110 
111  object_id_type ref() const noexcept {
112  return m_ref;
113  }
114 
117  m_ref = ref;
118  return *this;
119  }
120 
122  return static_cast<unsigned_object_id_type>(std::abs(m_ref));
123  }
124 
126  m_ref = ref;
127  return *this;
128  }
129 
130  item_type type() const noexcept {
131  return m_type;
132  }
133 
134  bool full_member() const noexcept {
135  return m_flags == 1;
136  }
137 
138  const char* role() const noexcept {
139  return reinterpret_cast<const char*>(data() + sizeof(RelationMember));
140  }
141 
143  return *reinterpret_cast<OSMObject*>(endpos());
144  }
145 
146  const OSMObject& get_object() const {
147  return *reinterpret_cast<const OSMObject*>(endpos());
148  }
149 
150  }; // class RelationMember
151 
152  class RelationMemberList : public osmium::memory::Collection<RelationMember, osmium::item_type::relation_member_list> {
153 
154  public:
155 
157  osmium::memory::Collection<RelationMember, osmium::item_type::relation_member_list>() {
158  }
159 
160  }; // class RelationMemberList
161 
162 
163  class Relation : public OSMObject {
164 
165  template <typename TDerived, typename T>
167 
168  Relation() noexcept :
169  OSMObject(sizeof(Relation), osmium::item_type::relation) {
170  }
171 
172  public:
173 
174  static constexpr osmium::item_type itemtype = osmium::item_type::relation;
175 
177  return osmium::detail::subitem_of_type<RelationMemberList>(begin(), end());
178  }
179 
180  const RelationMemberList& members() const {
181  return osmium::detail::subitem_of_type<const RelationMemberList>(cbegin(), cend());
182  }
183 
184  }; // class Relation
185 
186 
187 } // namespace osmium
188 
189 #endif // OSMIUM_OSM_RELATION_HPP
Definition: osm_object_builder.hpp:376
#define OSMIUM_DEPRECATED
Definition: compatibility.hpp:50
Definition: collection.hpp:47
type
Definition: entity_bits.hpp:63
uint16_t m_flags
Definition: relation.hpp:63
RelationMemberList & members()
Definition: relation.hpp:176
RelationMemberList()
Definition: relation.hpp:156
item_type
Definition: item_type.hpp:43
Definition: relation.hpp:163
uint16_t string_size_type
Definition: types.hpp:59
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
OSMObject & get_object()
Definition: relation.hpp:142
Definition: relation.hpp:152
Relation() noexcept
Definition: relation.hpp:168
constexpr std::size_t padded_length(std::size_t length) noexcept
Definition: item.hpp:64
Definition: item.hpp:105
Definition: relation.hpp:57
Namespace for everything in the Osmium library.
Definition: assembler.hpp:73
unsigned_object_id_type positive_ref() const noexcept
Definition: relation.hpp:121
Definition: collection.hpp:117
unsigned char * endpos()
Definition: relation.hpp:72
osmium::io::InputIterator< osmium::io::Reader > end(osmium::io::Reader &)
Definition: reader_iterator.hpp:45
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
item_type m_type
Definition: relation.hpp:62
item_type type() const noexcept
Definition: relation.hpp:130
OSMIUM_DEPRECATED RelationMember & ref(object_id_type ref) noexcept
Definition: relation.hpp:116
bool full_member() const noexcept
Definition: relation.hpp:134
const unsigned char * endpos() const
Definition: relation.hpp:76
unsigned char * data() const noexcept
Definition: collection.hpp:91
void set_role_size(string_size_type size) noexcept
Definition: relation.hpp:97
object_id_type ref() const noexcept
Definition: relation.hpp:111
const char * role() const noexcept
Definition: relation.hpp:138
RelationMember & set_ref(const osmium::object_id_type ref) noexcept
Definition: relation.hpp:125
const RelationMemberList & members() const
Definition: relation.hpp:180
object_id_type m_ref
Definition: relation.hpp:61
RelationMember(const object_id_type ref=0, const item_type type=item_type(), const bool full=false) noexcept
Definition: relation.hpp:105
osmium::io::InputIterator< osmium::io::Reader > begin(osmium::io::Reader &reader)
Definition: reader_iterator.hpp:41
unsigned char * next()
Definition: relation.hpp:83
Builder & operator=(const Builder &)=delete
Definition: osm_object_builder.hpp:213
const OSMObject & get_object() const
Definition: relation.hpp:146
Definition: object.hpp:63
unsigned const char * next() const
Definition: relation.hpp:90