Libosmium  2.15.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-2018 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  ObjectPointerCollection() = default;
78 
82  void osm_object(osmium::OSMObject& object) {
83  m_objects.push_back(&object);
84  }
85 
89  template <typename TCompare>
90  void sort(TCompare&& compare) {
91  std::sort(m_objects.begin(), m_objects.end(), std::forward<TCompare>(compare));
92  }
93 
99  template <typename TEqual>
100  void unique(TEqual&& equal) {
101  const auto last = std::unique(m_objects.begin(), m_objects.end(), std::forward<TEqual>(equal));
102  m_objects.erase(last, m_objects.end());
103  }
104 
110  bool empty() const noexcept {
111  return m_objects.empty();
112  }
113 
119  std::size_t size() const noexcept {
120  return m_objects.size();
121  }
122 
124  void clear() {
125  m_objects.clear();
126  }
127 
129  return {m_objects.begin()};
130  }
131 
133  return {m_objects.end()};
134  }
135 
137  return {m_objects.cbegin()};
138  }
139 
141  return {m_objects.cend()};
142  }
143 
144  }; // class ObjectPointerCollection
145 
146 } // namespace osmium
147 
148 #endif // OSMIUM_OBJECT_POINTER_COLLECTION_HPP
std::size_t size() const noexcept
Definition: object_pointer_collection.hpp:119
boost::indirect_iterator< std::vector< osmium::OSMObject * >::const_iterator, const osmium::OSMObject > const_iterator
Definition: object_pointer_collection.hpp:75
boost::indirect_iterator< std::vector< osmium::OSMObject * >::iterator, osmium::OSMObject > iterator
Definition: object_pointer_collection.hpp:74
iterator begin()
Definition: object_pointer_collection.hpp:128
Definition: handler.hpp:71
void clear()
Clear the collection,.
Definition: object_pointer_collection.hpp:124
Definition: object_pointer_collection.hpp:68
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
void sort(TCompare &&compare)
Definition: object_pointer_collection.hpp:90
void osm_object(osmium::OSMObject &object)
Definition: object_pointer_collection.hpp:82
const_iterator cend() const
Definition: object_pointer_collection.hpp:140
std::vector< osmium::OSMObject * > m_objects
Definition: object_pointer_collection.hpp:70
bool empty() const noexcept
Definition: object_pointer_collection.hpp:110
iterator end()
Definition: object_pointer_collection.hpp:132
const_iterator cbegin() const
Definition: object_pointer_collection.hpp:136
void unique(TEqual &&equal)
Definition: object_pointer_collection.hpp:100
Definition: object.hpp:64