libzypp: zypp/base/Iterator.h Source File

libzypp 17.25.10

Iterator.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_BASE_ITERATOR_H
13 #define ZYPP_BASE_ITERATOR_H
14
15 #include <iterator>
16 #include <utility>
17
18 #include <boost/functional.hpp>
19 #include <boost/iterator/filter_iterator.hpp>
20 #include <boost/iterator/transform_iterator.hpp>
21 #include <boost/iterator/function_output_iterator.hpp>
22
23 #include <zypp/base/Iterable.h>
24
26 namespace zypp
27 {
28
68
95 using boost::filter_iterator;
96 using boost::make_filter_iterator;
97
99 template<class TFilter, class TContainer>
100 filter_iterator<TFilter, typename TContainer::const_iterator>
101 make_filter_begin( TFilter f, const TContainer & c )
102 {
103 return make_filter_iterator( f, c.begin(), c.end() );
104 }
105
107 template<class TFilter, class TContainer>
108 filter_iterator<TFilter, typename TContainer::const_iterator>
109 make_filter_begin( const TContainer & c )
110 {
111 return make_filter_iterator( TFilter(), c.begin(), c.end() );
112 }
113
115 template<class TFilter, class TContainer>
116 filter_iterator<TFilter, typename TContainer::const_iterator>
117 make_filter_end( TFilter f, const TContainer & c )
118 {
119 return make_filter_iterator( f, c.end(), c.end() );
120 }
121
123 template<class TFilter, class TContainer>
124 filter_iterator<TFilter, typename TContainer::const_iterator>
125 make_filter_end( const TContainer & c )
126 {
127 return make_filter_iterator( TFilter(), c.end(), c.end() );
128 }
129
148 using boost::transform_iterator;
149 using boost::make_transform_iterator;
150
154 template<class TPair>
155 struct GetPairFirst : public std::unary_function<TPair, const typename TPair::first_type &>
156 {
157 const typename TPair::first_type & operator()( const TPair & pair_r ) const
158 { return pair_r.first; }
159 };
160
164 template<class TPair>
165 struct GetPairSecond : public std::unary_function<TPair, const typename TPair::second_type &>
166 {
167 const typename TPair::second_type & operator()( const TPair & pair_r ) const
168 { return pair_r.second; }
169 };
170
209 template<class TMap>
210 struct MapKVIteratorTraits
211 {
213 typedef TMap MapType;
215 typedef typename TMap::key_type KeyType;
217 typedef transform_iterator<GetPairFirst<typename MapType::value_type>,
218 typename MapType::const_iterator> Key_const_iterator;
220 typedef typename TMap::mapped_type ValueType;
222 typedef transform_iterator<GetPairSecond<typename MapType::value_type>,
223 typename MapType::const_iterator> Value_const_iterator;
224 };
225
227 template<class TMap>
228 inline typename MapKVIteratorTraits<TMap>::Key_const_iterator make_map_key_begin( const TMap & map_r )
229 { return make_transform_iterator( map_r.begin(), GetPairFirst<typename TMap::value_type>() ); }
230
232 template<class TMap>
233 inline typename MapKVIteratorTraits<TMap>::Key_const_iterator make_map_key_end( const TMap & map_r )
234 { return make_transform_iterator( map_r.end(), GetPairFirst<typename TMap::value_type>() ); }
235
237 template<class TMap>
238 inline typename MapKVIteratorTraits<TMap>::Value_const_iterator make_map_value_begin( const TMap & map_r )
239 { return make_transform_iterator( map_r.begin(), GetPairSecond<typename TMap::value_type>() ); }
240
242 template<class TMap>
243 inline typename MapKVIteratorTraits<TMap>::Value_const_iterator make_map_value_end( const TMap & map_r )
244 { return make_transform_iterator( map_r.end(), GetPairSecond<typename TMap::value_type>() ); }
245
247 template<class TMap>
248 inline typename MapKVIteratorTraits<TMap>::Key_const_iterator make_map_key_lower_bound( const TMap & map_r, const typename TMap::key_type & key_r )
249 { return make_transform_iterator( map_r.lower_bound( key_r ), GetPairFirst<typename TMap::value_type>() ); }
250
252 template<class TMap>
253 inline typename MapKVIteratorTraits<TMap>::Key_const_iterator make_map_key_upper_bound( const TMap & map_r, const typename TMap::key_type & key_r )
254 { return make_transform_iterator( map_r.upper_bound( key_r ), GetPairFirst<typename TMap::value_type>() ); }
255
257 template<class TMap>
258 inline typename MapKVIteratorTraits<TMap>::Value_const_iterator make_map_value_lower_bound( const TMap & map_r, const typename TMap::key_type & key_r )
259 { return make_transform_iterator( map_r.lower_bound( key_r ), GetPairSecond<typename TMap::value_type>() ); }
260
262 template<class TMap>
263 inline typename MapKVIteratorTraits<TMap>::Value_const_iterator make_map_value_upper_bound( const TMap & map_r, const typename TMap::key_type & key_r )
264 { return make_transform_iterator( map_r.upper_bound( key_r ), GetPairSecond<typename TMap::value_type>() ); }
265
266
268 template<class TMap>
269 inline Iterable<typename MapKVIteratorTraits<TMap>::Key_const_iterator> make_map_key_Iterable( const TMap & map_r )
270 { return makeIterable( make_map_key_begin( map_r ), make_map_key_end( map_r ) ); }
271
273 template<class TMap>
274 inline Iterable<typename MapKVIteratorTraits<TMap>::Value_const_iterator> make_map_value_Iterable( const TMap & map_r )
275 { return makeIterable( make_map_value_begin( map_r ), make_map_value_end( map_r ) ); }
276
277
292 using boost::function_output_iterator;
293 using boost::make_function_output_iterator;
294
296
297 } // namespace zypp
299 #endif // ZYPP_BASE_ITERATOR_H
Iterable.h
filter_iterator
An iterator over the subset of elements of some sequence which satisfy a given predicate.
zypp::Iterable
Definition: Iterable.h:37
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::make_map_key_end
MapKVIteratorTraits< TMap >::Key_const_iterator make_map_key_end(const TMap &map_r)
Convenience to create the key iterator from container::end()
Definition: Iterator.h:233
zypp::make_filter_end
filter_iterator< TFilter, typename TContainer::const_iterator > make_filter_end(TFilter f, const TContainer &c)
Convenience to create filter_iterator from container::end().
Definition: Iterator.h:117
zypp::make_map_value_lower_bound
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_lower_bound(const TMap &map_r, const typename TMap::key_type &key_r)
Convenience to create the value iterator from container::lower_bound()
Definition: Iterator.h:258
zypp::make_map_key_begin
MapKVIteratorTraits< TMap >::Key_const_iterator make_map_key_begin(const TMap &map_r)
Convenience to create the key iterator from container::begin()
Definition: Iterator.h:228
zypp::make_map_value_end
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_end(const TMap &map_r)
Convenience to create the value iterator from container::end()
Definition: Iterator.h:243
zypp::make_filter_begin
filter_iterator< TFilter, typename TContainer::const_iterator > make_filter_begin(TFilter f, const TContainer &c)
Convenience to create filter_iterator from container::begin().
Definition: Iterator.h:101
zypp::make_map_value_begin
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_begin(const TMap &map_r)
Convenience to create the value iterator from container::begin()
Definition: Iterator.h:238
zypp::make_map_value_upper_bound
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_upper_bound(const TMap &map_r, const typename TMap::key_type &key_r)
Convenience to create the value iterator from container::upper_bound()
Definition: Iterator.h:263
zypp::make_map_key_lower_bound
MapKVIteratorTraits< TMap >::Key_const_iterator make_map_key_lower_bound(const TMap &map_r, const typename TMap::key_type &key_r)
Convenience to create the key iterator from container::lower_bound()
Definition: Iterator.h:248
zypp::make_map_value_Iterable
Iterable< typename MapKVIteratorTraits< TMap >::Value_const_iterator > make_map_value_Iterable(const TMap &map_r)
Convenience to create an Iterable over the container values.
Definition: Iterator.h:274
zypp::make_map_key_upper_bound
MapKVIteratorTraits< TMap >::Key_const_iterator make_map_key_upper_bound(const TMap &map_r, const typename TMap::key_type &key_r)
Convenience to create the key iterator from container::upper_bound()
Definition: Iterator.h:253
zypp::make_map_key_Iterable
Iterable< typename MapKVIteratorTraits< TMap >::Key_const_iterator > make_map_key_Iterable(const TMap &map_r)
Convenience to create an Iterable over the container keys.
Definition: Iterator.h:269
zypp::GetPairFirst
Functor taking a std::pair returning std::pair.first.
Definition: Iterator.h:156
zypp::GetPairFirst::operator()
const TPair::first_type & operator()(const TPair &pair_r) const
Definition: Iterator.h:157
zypp::GetPairSecond
Functor taking a std::pair returning std::pair.second .
Definition: Iterator.h:166
zypp::GetPairSecond::operator()
const TPair::second_type & operator()(const TPair &pair_r) const
Definition: Iterator.h:167
zypp::MapKVIteratorTraits
Traits for std::map key and value iterators.
Definition: Iterator.h:211
zypp::MapKVIteratorTraits::ValueType
TMap::mapped_type ValueType
The maps value (mapped) type.
Definition: Iterator.h:220
zypp::MapKVIteratorTraits::Key_const_iterator
transform_iterator< GetPairFirst< typename MapType::value_type >, typename MapType::const_iterator > Key_const_iterator
The key iterator type.
Definition: Iterator.h:218
zypp::MapKVIteratorTraits::MapType
TMap MapType
The map type.
Definition: Iterator.h:213
zypp::MapKVIteratorTraits::KeyType
TMap::key_type KeyType
The maps key type.
Definition: Iterator.h:215
zypp::MapKVIteratorTraits::Value_const_iterator
transform_iterator< GetPairSecond< typename MapType::value_type >, typename MapType::const_iterator > Value_const_iterator
The value iterator type.
Definition: Iterator.h:223