Libosmium  2.1.0
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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-2015 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/node_ref.hpp>
43 
44 namespace osmium {
45 
51 
52  public:
53 
54  NodeRefList(osmium::item_type itemtype) noexcept :
55  osmium::memory::Item(sizeof(NodeRefList), itemtype) {
56  }
57 
61  bool empty() const noexcept {
62  return sizeof(NodeRefList) == byte_size();
63  }
64 
68  size_t size() const noexcept {
69  auto size_node_refs = osmium::memory::Item::byte_size() - sizeof(NodeRefList);
70  assert(size_node_refs % sizeof(NodeRef) == 0);
71  return size_node_refs / sizeof(NodeRef);
72  }
73 
80  const NodeRef& operator[](size_t n) const noexcept {
81  assert(n < size());
82  const NodeRef* node_ref = &*(cbegin());
83  return node_ref[n];
84  }
85 
91  const NodeRef& front() const noexcept {
92  assert(!empty());
93  return operator[](0);
94  }
95 
101  const NodeRef& back() const noexcept {
102  assert(!empty());
103  return operator[](size()-1);
104  }
105 
111  bool is_closed() const noexcept {
112  return front().ref() == back().ref();
113  }
114 
120  bool ends_have_same_id() const noexcept {
121  return front().ref() == back().ref();
122  }
123 
131  bool ends_have_same_location() const {
132  assert(front().location() && back().location());
133  return front().location() == back().location();
134  }
135 
136  typedef NodeRef* iterator;
137  typedef const NodeRef* const_iterator;
138  typedef std::reverse_iterator<const NodeRef*> const_reverse_iterator;
139 
141  iterator begin() noexcept {
142  return iterator(data() + sizeof(NodeRefList));
143  }
144 
146  iterator end() noexcept {
147  return iterator(data() + byte_size());
148  }
149 
151  const_iterator cbegin() const noexcept {
152  return const_iterator(data() + sizeof(NodeRefList));
153  }
154 
156  const_iterator cend() const noexcept {
157  return const_iterator(data() + byte_size());
158  }
159 
161  const_iterator begin() const noexcept {
162  return cbegin();
163  }
164 
166  const_iterator end() const noexcept {
167  return cend();
168  }
169 
171  const_reverse_iterator crbegin() const noexcept {
172  return const_reverse_iterator(cend());
173  }
174 
176  const_reverse_iterator crend() const noexcept {
177  return const_reverse_iterator(cbegin());
178  }
179 
180  }; // class NodeRefList
181 
182 } // namespace osmium
183 
184 #endif // OSMIUM_OSM_NODE_REF_LIST_HPP
const_iterator cbegin() const noexcept
Returns an iterator to the beginning.
Definition: node_ref_list.hpp:151
bool is_closed() const noexcept
Definition: node_ref_list.hpp:111
const_reverse_iterator crbegin() const noexcept
Returns a reverse_iterator to the beginning.
Definition: node_ref_list.hpp:171
item_type
Definition: item_type.hpp:42
size_t size() const noexcept
Definition: node_ref_list.hpp:68
bool ends_have_same_location() const
Definition: node_ref_list.hpp:131
bool ends_have_same_id() const noexcept
Definition: node_ref_list.hpp:120
osmium::object_id_type ref() const noexcept
Definition: node_ref.hpp:62
const_iterator cend() const noexcept
Returns an iterator to the end.
Definition: node_ref_list.hpp:156
std::reverse_iterator< const NodeRef * > const_reverse_iterator
Definition: node_ref_list.hpp:138
bool empty() const noexcept
Definition: node_ref_list.hpp:61
Definition: item.hpp:98
Namespace for everything in the Osmium library.
Definition: assembler.hpp:55
const NodeRef * const_iterator
Definition: node_ref_list.hpp:137
const_iterator begin() const noexcept
Returns an iterator to the beginning.
Definition: node_ref_list.hpp:161
osmium::Location & location() noexcept
Definition: node_ref.hpp:73
item_size_type byte_size() const noexcept
Definition: item.hpp:148
const NodeRef & operator[](size_t n) const noexcept
Definition: node_ref_list.hpp:80
iterator begin() noexcept
Returns an iterator to the beginning.
Definition: node_ref_list.hpp:141
NodeRefList(osmium::item_type itemtype) noexcept
Definition: node_ref_list.hpp:54
iterator end() noexcept
Returns an iterator to the end.
Definition: node_ref_list.hpp:146
NodeRef * iterator
Definition: node_ref_list.hpp:136
Definition: node_ref_list.hpp:50
const NodeRef & front() const noexcept
Definition: node_ref_list.hpp:91
const NodeRef & back() const noexcept
Definition: node_ref_list.hpp:101
Definition: node_ref.hpp:50
const_reverse_iterator crend() const noexcept
Returns a reverse_iterator to the end.
Definition: node_ref_list.hpp:176
const_iterator end() const noexcept
Returns an iterator to the end.
Definition: node_ref_list.hpp:166