Libosmium  2.20.0
Fast and flexible C++ library for working with OpenStreetMap data
object_pointer_collection.hpp
Go to the documentation of this file.
1#ifndef OSMIUM_OBJECT_POINTER_COLLECTION_HPP
2#define OSMIUM_OBJECT_POINTER_COLLECTION_HPP
3
4/*
5
6This file is part of Osmium (https://osmcode.org/libosmium).
7
8Copyright 2013-2023 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/handler.hpp>
37#include <osmium/osm/object.hpp>
38
39#include <algorithm>
40#include <utility>
41#include <vector>
42
43// IWYU pragma: no_forward_declare osmium::OSMObject
44
45namespace osmium {
46
47 template <typename TBaseIterator, typename TValue>
48 class indirect_iterator : public TBaseIterator {
49
50 public:
51
52 using iterator_category = std::random_access_iterator_tag;
53 using value_type = TValue;
54 using difference_type = std::ptrdiff_t;
57
58 explicit indirect_iterator(TBaseIterator it) :
59 TBaseIterator(it) {
60 }
61
62 reference operator*() const noexcept {
63 return *TBaseIterator::operator*();
64 }
65
66 pointer operator->() const noexcept {
67 return &*TBaseIterator::operator*();
68 }
69
70 }; // class indirect_iterator
71
92
93 std::vector<osmium::OSMObject*> m_objects{};
94
95 public:
96
99
100 using ptr_iterator = std::vector<osmium::OSMObject*>::iterator;
101
103
108 m_objects.push_back(&object);
109 }
110
115 template <typename TCompare>
116 void sort(TCompare&& compare) {
117 std::stable_sort(m_objects.begin(), m_objects.end(), std::forward<TCompare>(compare));
118 }
119
125 template <typename TEqual>
126 void unique(TEqual&& equal) {
127 const auto last = std::unique(m_objects.begin(), m_objects.end(), std::forward<TEqual>(equal));
128 m_objects.erase(last, m_objects.end());
129 }
130
136 bool empty() const noexcept {
137 return m_objects.empty();
138 }
139
145 std::size_t size() const noexcept {
146 return m_objects.size();
147 }
148
150 void clear() {
151 m_objects.clear();
152 }
153
155 return iterator{m_objects.begin()};
156 }
157
159 return iterator{m_objects.end()};
160 }
161
163 return const_iterator{m_objects.cbegin()};
164 }
165
167 return const_iterator{m_objects.cend()};
168 }
169
172 return m_objects.begin();
173 }
174
177 return m_objects.end();
178 }
179
180 }; // class ObjectPointerCollection
181
182} // namespace osmium
183
184#endif // OSMIUM_OBJECT_POINTER_COLLECTION_HPP
Definition: object.hpp:64
Definition: object_pointer_collection.hpp:91
void sort(TCompare &&compare)
Definition: object_pointer_collection.hpp:116
void osm_object(osmium::OSMObject &object)
Definition: object_pointer_collection.hpp:107
std::vector< osmium::OSMObject * >::iterator ptr_iterator
Definition: object_pointer_collection.hpp:100
iterator end()
Definition: object_pointer_collection.hpp:158
ptr_iterator ptr_end() noexcept
Access to end of pointer vector.
Definition: object_pointer_collection.hpp:176
void unique(TEqual &&equal)
Definition: object_pointer_collection.hpp:126
ptr_iterator ptr_begin() noexcept
Access to begin of pointer vector.
Definition: object_pointer_collection.hpp:171
const_iterator cend() const
Definition: object_pointer_collection.hpp:166
void clear()
Clear the collection,.
Definition: object_pointer_collection.hpp:150
std::size_t size() const noexcept
Definition: object_pointer_collection.hpp:145
const_iterator cbegin() const
Definition: object_pointer_collection.hpp:162
bool empty() const noexcept
Definition: object_pointer_collection.hpp:136
iterator begin()
Definition: object_pointer_collection.hpp:154
std::vector< osmium::OSMObject * > m_objects
Definition: object_pointer_collection.hpp:93
Definition: handler.hpp:71
Definition: object_pointer_collection.hpp:48
TValue value_type
Definition: object_pointer_collection.hpp:53
pointer operator->() const noexcept
Definition: object_pointer_collection.hpp:66
value_type & reference
Definition: object_pointer_collection.hpp:56
value_type * pointer
Definition: object_pointer_collection.hpp:55
std::ptrdiff_t difference_type
Definition: object_pointer_collection.hpp:54
reference operator*() const noexcept
Definition: object_pointer_collection.hpp:62
std::random_access_iterator_tag iterator_category
Definition: object_pointer_collection.hpp:52
indirect_iterator(TBaseIterator it)
Definition: object_pointer_collection.hpp:58
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53