Libosmium  2.9.0
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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>
46 
47 namespace osmium {
48 
49  namespace builder {
50  template <typename> class ObjectBuilder;
51  class RelationMemberListBuilder;
52  } // namespace builder
53 
54  class RelationMember : public osmium::memory::detail::ItemHelper {
55 
57 
60  uint16_t m_flags;
62 
63  RelationMember(const RelationMember&) = delete;
64  RelationMember(RelationMember&&) = delete;
65 
66  RelationMember& operator=(const RelationMember&) = delete;
68 
69  unsigned char* endpos() {
70  return data() + osmium::memory::padded_length(sizeof(RelationMember) + m_role_size);
71  }
72 
73  const unsigned char* endpos() const {
74  return data() + osmium::memory::padded_length(sizeof(RelationMember) + m_role_size);
75  }
76 
77  template <typename TMember>
79 
80  unsigned char* next() {
81  if (full_member()) {
82  return endpos() + reinterpret_cast<osmium::memory::Item*>(endpos())->byte_size();
83  }
84  return endpos();
85  }
86 
87  unsigned const char* next() const {
88  if (full_member()) {
89  return endpos() + reinterpret_cast<const osmium::memory::Item*>(endpos())->byte_size();
90  }
91  return endpos();
92  }
93 
94  void set_role_size(string_size_type size) noexcept {
95  m_role_size = size;
96  }
97 
98  public:
99 
101 
102  RelationMember(const object_id_type ref = 0, const item_type type = item_type(), const bool full = false) noexcept :
103  m_ref(ref),
104  m_type(type),
105  m_flags(full ? 1 : 0) {
106  }
107 
108  object_id_type ref() const noexcept {
109  return m_ref;
110  }
111 
113  m_ref = ref;
114  return *this;
115  }
116 
118  return static_cast<unsigned_object_id_type>(std::abs(m_ref));
119  }
120 
122  m_ref = ref;
123  return *this;
124  }
125 
126  item_type type() const noexcept {
127  return m_type;
128  }
129 
130  bool full_member() const noexcept {
131  return m_flags == 1;
132  }
133 
134  const char* role() const noexcept {
135  return reinterpret_cast<const char*>(data() + sizeof(RelationMember));
136  }
137 
139  return *reinterpret_cast<OSMObject*>(endpos());
140  }
141 
142  const OSMObject& get_object() const {
143  return *reinterpret_cast<const OSMObject*>(endpos());
144  }
145 
146  }; // class RelationMember
147 
148  class RelationMemberList : public osmium::memory::Collection<RelationMember, osmium::item_type::relation_member_list> {
149 
150  public:
151 
152  using size_type = size_t;
153 
156  }
157 
158  size_type size() const noexcept {
159  return static_cast<size_type>(std::distance(begin(), end()));
160  }
161 
162  }; // class RelationMemberList
163 
164 
165  class Relation : public OSMObject {
166 
168 
169  Relation() noexcept :
170  OSMObject(sizeof(Relation), osmium::item_type::relation) {
171  }
172 
173  public:
174 
176 
178  return osmium::detail::subitem_of_type<RelationMemberList>(begin(), end());
179  }
180 
181  const RelationMemberList& members() const {
182  return osmium::detail::subitem_of_type<const RelationMemberList>(cbegin(), cend());
183  }
184 
185  }; // class Relation
186 
187 
188 } // namespace osmium
189 
190 #endif // OSMIUM_OSM_RELATION_HPP
string_size_type m_role_size
Definition: relation.hpp:61
Definition: collection.hpp:47
RelationMember & ref(object_id_type ref) noexcept
Definition: relation.hpp:112
uint16_t m_flags
Definition: relation.hpp:60
RelationMemberList & members()
Definition: relation.hpp:177
const OSMObject & get_object() const
Definition: relation.hpp:142
RelationMemberList()
Definition: relation.hpp:154
item_type
Definition: item_type.hpp:43
Definition: relation.hpp:165
const_iterator cend() const
Definition: object.hpp:363
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:138
std::size_t padded_length(std::size_t length) noexcept
Definition: item.hpp:64
Definition: relation.hpp:148
double distance(const osmium::geom::Coordinates &c1, const osmium::geom::Coordinates &c2)
Definition: haversine.hpp:64
const_iterator cbegin() const
Definition: object.hpp:359
iterator end()
Definition: object.hpp:355
const RelationMemberList & members() const
Definition: relation.hpp:181
static constexpr osmium::item_type itemtype
Definition: relation.hpp:175
Definition: item.hpp:105
Definition: relation.hpp:54
Namespace for everything in the Osmium library.
Definition: assembler.hpp:73
unsigned_object_id_type positive_ref() const noexcept
Definition: relation.hpp:117
Definition: collection.hpp:117
unsigned char * endpos()
Definition: relation.hpp:69
unsigned const char * next() const
Definition: relation.hpp:87
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:59
item_type type() const noexcept
Definition: relation.hpp:126
RelationMember & operator=(const RelationMember &)=delete
bool full_member() const noexcept
Definition: relation.hpp:130
unsigned char * data() const noexcept
Definition: collection.hpp:91
void set_role_size(string_size_type size) noexcept
Definition: relation.hpp:94
object_id_type ref() const noexcept
Definition: relation.hpp:108
const char * role() const noexcept
Definition: relation.hpp:134
Definition: builder.hpp:185
RelationMember & set_ref(const osmium::object_id_type ref) noexcept
Definition: relation.hpp:121
size_t size_type
Definition: relation.hpp:152
object_id_type m_ref
Definition: relation.hpp:58
RelationMember(const object_id_type ref=0, const item_type type=item_type(), const bool full=false) noexcept
Definition: relation.hpp:102
static constexpr item_type collection_type
Definition: relation.hpp:100
const unsigned char * endpos() const
Definition: relation.hpp:73
unsigned char * next()
Definition: relation.hpp:80
Definition: osm_object_builder.hpp:199
RelationMember(const RelationMember &)=delete
Definition: object.hpp:58
size_type size() const noexcept
Definition: relation.hpp:158
iterator begin()
Definition: object.hpp:351