Libosmium  2.16.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 
6 This file is part of Osmium (https://osmcode.org/libosmium).
7 
8 Copyright 2013-2021 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 <osmium/handler.hpp>
37 #include <osmium/osm/object.hpp>
38 
39 #include <boost/iterator/indirect_iterator.hpp>
40 
41 #include <algorithm>
42 #include <utility>
43 #include <vector>
44 
45 // IWYU pragma: no_forward_declare osmium::OSMObject
46 
47 namespace osmium {
48 
69 
70  std::vector<osmium::OSMObject*> m_objects{};
71 
72  public:
73 
74  using iterator = boost::indirect_iterator<std::vector<osmium::OSMObject*>::iterator, osmium::OSMObject>;
75  using const_iterator = boost::indirect_iterator<std::vector<osmium::OSMObject*>::const_iterator, const osmium::OSMObject>;
76 
77  using ptr_iterator = std::vector<osmium::OSMObject*>::iterator;
78 
80 
84  void osm_object(osmium::OSMObject& object) {
85  m_objects.push_back(&object);
86  }
87 
92  template <typename TCompare>
93  void sort(TCompare&& compare) {
94  std::stable_sort(m_objects.begin(), m_objects.end(), std::forward<TCompare>(compare));
95  }
96 
102  template <typename TEqual>
103  void unique(TEqual&& equal) {
104  const auto last = std::unique(m_objects.begin(), m_objects.end(), std::forward<TEqual>(equal));
105  m_objects.erase(last, m_objects.end());
106  }
107 
113  bool empty() const noexcept {
114  return m_objects.empty();
115  }
116 
122  std::size_t size() const noexcept {
123  return m_objects.size();
124  }
125 
127  void clear() {
128  m_objects.clear();
129  }
130 
132  return {m_objects.begin()};
133  }
134 
136  return {m_objects.end()};
137  }
138 
140  return {m_objects.cbegin()};
141  }
142 
144  return {m_objects.cend()};
145  }
146 
148  ptr_iterator ptr_begin() noexcept {
149  return m_objects.begin();
150  }
151 
153  ptr_iterator ptr_end() noexcept {
154  return m_objects.end();
155  }
156 
157  }; // class ObjectPointerCollection
158 
159 } // namespace osmium
160 
161 #endif // OSMIUM_OBJECT_POINTER_COLLECTION_HPP
osmium::ObjectPointerCollection::empty
bool empty() const noexcept
Definition: object_pointer_collection.hpp:113
osmium::ObjectPointerCollection::iterator
boost::indirect_iterator< std::vector< osmium::OSMObject * >::iterator, osmium::OSMObject > iterator
Definition: object_pointer_collection.hpp:74
osmium::OSMObject
Definition: object.hpp:64
osmium::ObjectPointerCollection::ptr_end
ptr_iterator ptr_end() noexcept
Access to end of pointer vector.
Definition: object_pointer_collection.hpp:153
osmium::ObjectPointerCollection::ptr_begin
ptr_iterator ptr_begin() noexcept
Access to begin of pointer vector.
Definition: object_pointer_collection.hpp:148
osmium::ObjectPointerCollection::ptr_iterator
std::vector< osmium::OSMObject * >::iterator ptr_iterator
Definition: object_pointer_collection.hpp:77
osmium::handler::Handler
Definition: handler.hpp:71
osmium::ObjectPointerCollection::end
iterator end()
Definition: object_pointer_collection.hpp:135
osmium::ObjectPointerCollection::cbegin
const_iterator cbegin() const
Definition: object_pointer_collection.hpp:139
osmium::ObjectPointerCollection::cend
const_iterator cend() const
Definition: object_pointer_collection.hpp:143
osmium::ObjectPointerCollection::m_objects
std::vector< osmium::OSMObject * > m_objects
Definition: object_pointer_collection.hpp:70
osmium
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
osmium::ObjectPointerCollection::begin
iterator begin()
Definition: object_pointer_collection.hpp:131
osmium::ObjectPointerCollection::ObjectPointerCollection
ObjectPointerCollection()=default
osmium::ObjectPointerCollection::size
std::size_t size() const noexcept
Definition: object_pointer_collection.hpp:122
osmium::ObjectPointerCollection::const_iterator
boost::indirect_iterator< std::vector< osmium::OSMObject * >::const_iterator, const osmium::OSMObject > const_iterator
Definition: object_pointer_collection.hpp:75
osmium::ObjectPointerCollection
Definition: object_pointer_collection.hpp:68
osmium::ObjectPointerCollection::osm_object
void osm_object(osmium::OSMObject &object)
Definition: object_pointer_collection.hpp:84
handler.hpp
osmium::ObjectPointerCollection::clear
void clear()
Clear the collection,.
Definition: object_pointer_collection.hpp:127
osmium::ObjectPointerCollection::sort
void sort(TCompare &&compare)
Definition: object_pointer_collection.hpp:93
object.hpp
osmium::ObjectPointerCollection::unique
void unique(TEqual &&equal)
Definition: object_pointer_collection.hpp:103