Libosmium: include/osmium/osm/node_ref_list.hpp Source File

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

Loading...
Searching...
No Matches
node_ref_list.hpp
Go to the documentation of this file.
1#ifndef OSMIUM_OSM_NODE_REF_LIST_HPP
2#define OSMIUM_OSM_NODE_REF_LIST_HPP
3
4/*
5
6This file is part of Osmium (https://osmcode.org/libosmium).
7
8Copyright 2013-2026 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/item.hpp>
37#include <osmium/osm/box.hpp>
38#include <osmium/osm/item_type.hpp>
39#include <osmium/osm/location.hpp>
40#include <osmium/osm/node_ref.hpp>
41
42#include <cassert>
43#include <cstddef>
44#include <iterator>
45
46namespace osmium {
47
52 class NodeRefList : public osmium::memory::Item {
53
54 public:
55
56 using value_type = NodeRef;
57 using reference = NodeRef&;
58 using const_reference = const NodeRef&;
59 using iterator = NodeRef*;
60 using const_iterator = const NodeRef*;
61 using const_reverse_iterator = std::reverse_iterator<const NodeRef*>;
62 using difference_type = std::ptrdiff_t;
63 using size_type = std::size_t;
64
65 explicit NodeRefList(osmium::item_type itemtype) noexcept :
66 osmium::memory::Item(sizeof(NodeRefList), itemtype) {
67 }
68
74 bool empty() const noexcept {
75 return sizeof(NodeRefList) == byte_size();
76 }
77
83 size_type size() const noexcept {
84 const auto size_node_refs = byte_size() - sizeof(NodeRefList);
85 assert(size_node_refs % sizeof(NodeRef) == 0);
86 return size_node_refs / sizeof(NodeRef);
87 }
88
98 const NodeRef& operator[](size_type n) const noexcept {
99 assert(n < size());
100 const NodeRef* node_ref = &*(cbegin());
101 return node_ref[n];
102 }
103
113 NodeRef& operator[](size_type n) noexcept {
114 assert(n < size());
115 NodeRef* node_ref = &*(begin());
116 return node_ref[n];
117 }
118
126 const NodeRef& front() const noexcept {
127 assert(!empty());
128 return operator[](0);
129 }
130
138 const NodeRef& back() const noexcept {
139 assert(!empty());
140 return operator[](size() - 1);
141 }
142
151 bool is_closed() const noexcept {
152 assert(!empty());
153 return ends_have_same_id();
154 }
155
164 bool ends_have_same_id() const noexcept {
165 assert(!empty());
166 return front().ref() == back().ref();
167 }
168
178 bool ends_have_same_location() const {
179 assert(!empty());
180 assert(front().location() && back().location());
181 return front().location() == back().location();
182 }
183
190 osmium::Box envelope() const noexcept {
191 osmium::Box box;
192 for (const auto& node_ref : *this) {
193 box.extend(node_ref.location());
194 }
195 return box;
196 }
197
199 iterator begin() noexcept {
200 return reinterpret_cast<iterator>(data() + sizeof(NodeRefList));
201 }
202
204 iterator end() noexcept {
205 return reinterpret_cast<iterator>(data() + byte_size());
206 }
207
209 const_iterator cbegin() const noexcept {
210 return reinterpret_cast<const_iterator>(data() + sizeof(NodeRefList));
211 }
212
214 const_iterator cend() const noexcept {
215 return reinterpret_cast<const_iterator>(data() + byte_size());
216 }
217
219 const_iterator begin() const noexcept {
220 return cbegin();
221 }
222
224 const_iterator end() const noexcept {
225 return cend();
226 }
227
229 const_reverse_iterator crbegin() const noexcept {
230 return const_reverse_iterator(cend());
231 }
232
234 const_reverse_iterator crend() const noexcept {
235 return const_reverse_iterator(cbegin());
236 }
237
238 }; // class NodeRefList
239
240} // namespace osmium
241
242#endif // OSMIUM_OSM_NODE_REF_LIST_HPP
box.hpp
osmium::NodeRefList::cbegin
const_iterator cbegin() const noexcept
Returns an iterator to the beginning.
Definition node_ref_list.hpp:209
osmium::NodeRefList::iterator
NodeRef * iterator
Definition node_ref_list.hpp:59
osmium::NodeRefList::envelope
osmium::Box envelope() const noexcept
Definition node_ref_list.hpp:190
osmium::NodeRefList::begin
iterator begin() noexcept
Returns an iterator to the beginning.
Definition node_ref_list.hpp:199
osmium::NodeRefList::size_type
std::size_t size_type
Definition node_ref_list.hpp:63
osmium::NodeRefList::const_reference
const NodeRef & const_reference
Definition node_ref_list.hpp:58
osmium::NodeRefList::operator[]
const NodeRef & operator[](size_type n) const noexcept
Definition node_ref_list.hpp:98
osmium::NodeRefList::front
const NodeRef & front() const noexcept
Definition node_ref_list.hpp:126
osmium::NodeRefList::is_closed
bool is_closed() const noexcept
Definition node_ref_list.hpp:151
osmium::NodeRefList::cend
const_iterator cend() const noexcept
Returns an iterator to the end.
Definition node_ref_list.hpp:214
osmium::NodeRefList::reference
NodeRef & reference
Definition node_ref_list.hpp:57
osmium::NodeRefList::NodeRefList
NodeRefList(osmium::item_type itemtype) noexcept
Definition node_ref_list.hpp:65
osmium::NodeRefList::difference_type
std::ptrdiff_t difference_type
Definition node_ref_list.hpp:62
osmium::NodeRefList::end
iterator end() noexcept
Returns an iterator to the end.
Definition node_ref_list.hpp:204
osmium::NodeRefList::size
size_type size() const noexcept
Definition node_ref_list.hpp:83
osmium::NodeRefList::ends_have_same_location
bool ends_have_same_location() const
Definition node_ref_list.hpp:178
osmium::NodeRefList::crend
const_reverse_iterator crend() const noexcept
Returns a reverse_iterator to the end.
Definition node_ref_list.hpp:234
osmium::NodeRefList::const_reverse_iterator
std::reverse_iterator< const NodeRef * > const_reverse_iterator
Definition node_ref_list.hpp:61
osmium::NodeRefList::ends_have_same_id
bool ends_have_same_id() const noexcept
Definition node_ref_list.hpp:164
osmium::NodeRefList::begin
const_iterator begin() const noexcept
Returns an iterator to the beginning.
Definition node_ref_list.hpp:219
osmium::NodeRefList::crbegin
const_reverse_iterator crbegin() const noexcept
Returns a reverse_iterator to the beginning.
Definition node_ref_list.hpp:229
osmium::NodeRefList::value_type
NodeRef value_type
Definition node_ref_list.hpp:56
osmium::NodeRefList::empty
bool empty() const noexcept
Definition node_ref_list.hpp:74
osmium::NodeRefList::back
const NodeRef & back() const noexcept
Definition node_ref_list.hpp:138
osmium::NodeRefList::const_iterator
const NodeRef * const_iterator
Definition node_ref_list.hpp:60
osmium::NodeRefList::end
const_iterator end() const noexcept
Returns an iterator to the end.
Definition node_ref_list.hpp:224
osmium::NodeRefList::operator[]
NodeRef & operator[](size_type n) noexcept
Definition node_ref_list.hpp:113
osmium::NodeRef
Definition node_ref.hpp:50
osmium::NodeRef::ref
constexpr osmium::object_id_type ref() const noexcept
Definition node_ref.hpp:71
osmium::NodeRef::location
osmium::Location & location() noexcept
Definition node_ref.hpp:85
osmium::memory::Item
Definition item.hpp:105
osmium::memory::Item::byte_size
item_size_type byte_size() const noexcept
Definition item.hpp:163
item.hpp
item_type.hpp
location.hpp
osmium
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
osmium::item_type
item_type
Definition item_type.hpp:45
node_ref.hpp