Libosmium: include/osmium/object_pointer_collection.hpp Source File

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

Loading...
Searching...
No Matches
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-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/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;
55 using pointer = value_type*;
56 using reference = value_type&;
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
91 class ObjectPointerCollection : public osmium::handler::Handler {
92
93 std::vector<osmium::OSMObject*> m_objects;
94
95 public:
96
97 using iterator = indirect_iterator<std::vector<osmium::OSMObject*>::iterator, osmium::OSMObject>;
98 using const_iterator = indirect_iterator<std::vector<osmium::OSMObject*>::const_iterator, const osmium::OSMObject>;
99
100 using ptr_iterator = std::vector<osmium::OSMObject*>::iterator;
101
102 ObjectPointerCollection() = default;
103
107 void osm_object(osmium::OSMObject& object) {
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
154 iterator begin() {
155 return iterator{m_objects.begin()};
156 }
157
158 iterator end() {
159 return iterator{m_objects.end()};
160 }
161
162 const_iterator cbegin() const {
163 return const_iterator{m_objects.cbegin()};
164 }
165
166 const_iterator cend() const {
167 return const_iterator{m_objects.cend()};
168 }
169
171 ptr_iterator ptr_begin() noexcept {
172 return m_objects.begin();
173 }
174
176 ptr_iterator ptr_end() noexcept {
177 return m_objects.end();
178 }
179
180 }; // class ObjectPointerCollection
181
182} // namespace osmium
183
184#endif // OSMIUM_OBJECT_POINTER_COLLECTION_HPP
osmium::OSMObject
Definition object.hpp:64
osmium::ObjectPointerCollection::sort
void sort(TCompare &&compare)
Definition object_pointer_collection.hpp:116
osmium::ObjectPointerCollection::iterator
indirect_iterator< std::vector< osmium::OSMObject * >::iterator, osmium::OSMObject > iterator
Definition object_pointer_collection.hpp:97
osmium::ObjectPointerCollection::osm_object
void osm_object(osmium::OSMObject &object)
Definition object_pointer_collection.hpp:107
osmium::ObjectPointerCollection::ptr_iterator
std::vector< osmium::OSMObject * >::iterator ptr_iterator
Definition object_pointer_collection.hpp:100
osmium::ObjectPointerCollection::end
iterator end()
Definition object_pointer_collection.hpp:158
osmium::ObjectPointerCollection::ptr_end
ptr_iterator ptr_end() noexcept
Access to end of pointer vector.
Definition object_pointer_collection.hpp:176
osmium::ObjectPointerCollection::unique
void unique(TEqual &&equal)
Definition object_pointer_collection.hpp:126
osmium::ObjectPointerCollection::ptr_begin
ptr_iterator ptr_begin() noexcept
Access to begin of pointer vector.
Definition object_pointer_collection.hpp:171
osmium::ObjectPointerCollection::cend
const_iterator cend() const
Definition object_pointer_collection.hpp:166
osmium::ObjectPointerCollection::clear
void clear()
Clear the collection,.
Definition object_pointer_collection.hpp:150
osmium::ObjectPointerCollection::size
std::size_t size() const noexcept
Definition object_pointer_collection.hpp:145
osmium::ObjectPointerCollection::cbegin
const_iterator cbegin() const
Definition object_pointer_collection.hpp:162
osmium::ObjectPointerCollection::const_iterator
indirect_iterator< std::vector< osmium::OSMObject * >::const_iterator, const osmium::OSMObject > const_iterator
Definition object_pointer_collection.hpp:98
osmium::ObjectPointerCollection::empty
bool empty() const noexcept
Definition object_pointer_collection.hpp:136
osmium::ObjectPointerCollection::ObjectPointerCollection
ObjectPointerCollection()=default
osmium::ObjectPointerCollection::begin
iterator begin()
Definition object_pointer_collection.hpp:154
osmium::ObjectPointerCollection::m_objects
std::vector< osmium::OSMObject * > m_objects
Definition object_pointer_collection.hpp:93
osmium::handler::Handler
Definition handler.hpp:71
osmium::indirect_iterator
Definition object_pointer_collection.hpp:48
osmium::indirect_iterator::value_type
TValue value_type
Definition object_pointer_collection.hpp:53
osmium::indirect_iterator::operator->
pointer operator->() const noexcept
Definition object_pointer_collection.hpp:66
osmium::indirect_iterator::reference
value_type & reference
Definition object_pointer_collection.hpp:56
osmium::indirect_iterator::pointer
value_type * pointer
Definition object_pointer_collection.hpp:55
osmium::indirect_iterator::difference_type
std::ptrdiff_t difference_type
Definition object_pointer_collection.hpp:54
osmium::indirect_iterator::operator*
reference operator*() const noexcept
Definition object_pointer_collection.hpp:62
osmium::indirect_iterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition object_pointer_collection.hpp:52
osmium::indirect_iterator::indirect_iterator
indirect_iterator(TBaseIterator it)
Definition object_pointer_collection.hpp:58
handler.hpp
osmium
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
object.hpp