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
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 
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 <cassert>
37 #include <cstddef>
38 #include <iterator>
39 
40 #include <osmium/memory/item.hpp>
41 #include <osmium/osm/item_type.hpp>
42 #include <osmium/osm/location.hpp>
43 #include <osmium/osm/node_ref.hpp>
44 
45 namespace osmium {
46 
52 
53  public:
54 
55  explicit NodeRefList(osmium::item_type itemtype) noexcept :
56  osmium::memory::Item(sizeof(NodeRefList), itemtype) {
57  }
58 
62  bool empty() const noexcept {
63  return sizeof(NodeRefList) == byte_size();
64  }
65 
69  size_t size() const noexcept {
70  const auto size_node_refs = byte_size() - sizeof(NodeRefList);
71  assert(size_node_refs % sizeof(NodeRef) == 0);
72  return size_node_refs / sizeof(NodeRef);
73  }
74 
82  const NodeRef& operator[](size_t n) const noexcept {
83  assert(n < size());
84  const NodeRef* node_ref = &*(cbegin());
85  return node_ref[n];
86  }
87 
93  const NodeRef& front() const noexcept {
94  assert(!empty());
95  return operator[](0);
96  }
97 
103  const NodeRef& back() const noexcept {
104  assert(!empty());
105  return operator[](size()-1);
106  }
107 
114  bool is_closed() const noexcept {
115  return ends_have_same_id();
116  }
117 
124  bool ends_have_same_id() const noexcept {
125  return front().ref() == back().ref();
126  }
127 
135  bool ends_have_same_location() const {
136  assert(front().location() && back().location());
137  return front().location() == back().location();
138  }
139 
140  using iterator = NodeRef*;
141  using const_iterator = const NodeRef*;
142  using const_reverse_iterator = std::reverse_iterator<const NodeRef*>;
143 
145  iterator begin() noexcept {
146  return iterator(data() + sizeof(NodeRefList));
147  }
148 
150  iterator end() noexcept {
151  return iterator(data() + byte_size());
152  }
153 
155  const_iterator cbegin() const noexcept {
156  return const_iterator(data() + sizeof(NodeRefList));
157  }
158 
160  const_iterator cend() const noexcept {
161  return const_iterator(data() + byte_size());
162  }
163 
165  const_iterator begin() const noexcept {
166  return cbegin();
167  }
168 
170  const_iterator end() const noexcept {
171  return cend();
172  }
173 
175  const_reverse_iterator crbegin() const noexcept {
176  return const_reverse_iterator(cend());
177  }
178 
180  const_reverse_iterator crend() const noexcept {
181  return const_reverse_iterator(cbegin());
182  }
183 
184  }; // class NodeRefList
185 
186 } // namespace osmium
187 
188 #endif // OSMIUM_OSM_NODE_REF_LIST_HPP
const_iterator cbegin() const noexcept
Returns an iterator to the beginning.
Definition: node_ref_list.hpp:155
std::reverse_iterator< const NodeRef * > const_reverse_iterator
Definition: node_ref_list.hpp:142
bool is_closed() const noexcept
Definition: node_ref_list.hpp:114
const_reverse_iterator crbegin() const noexcept
Returns a reverse_iterator to the beginning.
Definition: node_ref_list.hpp:175
item_type
Definition: item_type.hpp:43
const NodeRef * const_iterator
Definition: node_ref_list.hpp:141
size_t size() const noexcept
Definition: node_ref_list.hpp:69
bool ends_have_same_location() const
Definition: node_ref_list.hpp:135
bool ends_have_same_id() const noexcept
Definition: node_ref_list.hpp:124
const_iterator cend() const noexcept
Returns an iterator to the end.
Definition: node_ref_list.hpp:160
constexpr osmium::object_id_type ref() const noexcept
Definition: node_ref.hpp:65
bool empty() const noexcept
Definition: node_ref_list.hpp:62
Definition: item.hpp:105
Namespace for everything in the Osmium library.
Definition: assembler.hpp:73
const_iterator begin() const noexcept
Returns an iterator to the beginning.
Definition: node_ref_list.hpp:165
osmium::Location & location() noexcept
Definition: node_ref.hpp:79
item_size_type byte_size() const noexcept
Definition: item.hpp:157
const NodeRef & operator[](size_t n) const noexcept
Definition: node_ref_list.hpp:82
iterator begin() noexcept
Returns an iterator to the beginning.
Definition: node_ref_list.hpp:145
NodeRefList(osmium::item_type itemtype) noexcept
Definition: node_ref_list.hpp:55
iterator end() noexcept
Returns an iterator to the end.
Definition: node_ref_list.hpp:150
Definition: node_ref_list.hpp:51
const NodeRef & front() const noexcept
Definition: node_ref_list.hpp:93
const NodeRef & back() const noexcept
Definition: node_ref_list.hpp:103
NodeRef * iterator
Definition: node_ref_list.hpp:140
Definition: node_ref.hpp:50
const_reverse_iterator crend() const noexcept
Returns a reverse_iterator to the end.
Definition: node_ref_list.hpp:180
const_iterator end() const noexcept
Returns an iterator to the end.
Definition: node_ref_list.hpp:170