libzypp: zypp-core/base/Iterator.h Source File

libzypp 17.38.9

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-core/base/Iterable.h>
24
26namespace 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
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
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 using MapType = TMap;
215 using KeyType = typename TMap::key_type;
217 using Key_const_iterator = transform_iterator<GetPairFirst<typename MapType::value_type>, typename MapType::const_iterator>;
219 using ValueType = typename TMap::mapped_type;
221 using Value_const_iterator = transform_iterator<GetPairSecond<typename MapType::value_type>, typename MapType::const_iterator>;
222 };
223
225 template<class TMap>
226 inline typename MapKVIteratorTraits<TMap>::Key_const_iterator make_map_key_begin( const TMap & map_r )
227 { return make_transform_iterator( map_r.begin(), GetPairFirst<typename TMap::value_type>() ); }
228
230 template<class TMap>
231 inline typename MapKVIteratorTraits<TMap>::Key_const_iterator make_map_key_end( const TMap & map_r )
232 { return make_transform_iterator( map_r.end(), GetPairFirst<typename TMap::value_type>() ); }
233
235 template<class TMap>
236 inline typename MapKVIteratorTraits<TMap>::Value_const_iterator make_map_value_begin( const TMap & map_r )
237 { return make_transform_iterator( map_r.begin(), GetPairSecond<typename TMap::value_type>() ); }
238
240 template<class TMap>
241 inline typename MapKVIteratorTraits<TMap>::Value_const_iterator make_map_value_end( const TMap & map_r )
242 { return make_transform_iterator( map_r.end(), GetPairSecond<typename TMap::value_type>() ); }
243
245 template<class TMap>
246 inline typename MapKVIteratorTraits<TMap>::Key_const_iterator make_map_key_lower_bound( const TMap & map_r, const typename TMap::key_type & key_r )
247 { return make_transform_iterator( map_r.lower_bound( key_r ), GetPairFirst<typename TMap::value_type>() ); }
248
250 template<class TMap>
251 inline typename MapKVIteratorTraits<TMap>::Key_const_iterator make_map_key_upper_bound( const TMap & map_r, const typename TMap::key_type & key_r )
252 { return make_transform_iterator( map_r.upper_bound( key_r ), GetPairFirst<typename TMap::value_type>() ); }
253
255 template<class TMap>
256 inline typename MapKVIteratorTraits<TMap>::Value_const_iterator make_map_value_lower_bound( const TMap & map_r, const typename TMap::key_type & key_r )
257 { return make_transform_iterator( map_r.lower_bound( key_r ), GetPairSecond<typename TMap::value_type>() ); }
258
260 template<class TMap>
261 inline typename MapKVIteratorTraits<TMap>::Value_const_iterator make_map_value_upper_bound( const TMap & map_r, const typename TMap::key_type & key_r )
262 { return make_transform_iterator( map_r.upper_bound( key_r ), GetPairSecond<typename TMap::value_type>() ); }
263
264
266 template<class TMap>
267 inline Iterable<typename MapKVIteratorTraits<TMap>::Key_const_iterator> make_map_key_Iterable( const TMap & map_r )
268 { return makeIterable( make_map_key_begin( map_r ), make_map_key_end( map_r ) ); }
269
271 template<class TMap>
272 inline Iterable<typename MapKVIteratorTraits<TMap>::Value_const_iterator> make_map_value_Iterable( const TMap & map_r )
273 { return makeIterable( make_map_value_begin( map_r ), make_map_value_end( map_r ) ); }
274
275
290 using boost::function_output_iterator;
291 using boost::make_function_output_iterator;
292
294
295} // namespace zypp
297#endif // ZYPP_BASE_ITERATOR_H
Iterable.h
filter_iterator
An iterator over the subset of elements of some sequence which satisfy a given predicate.
transform_iterator
An iterator over elements which are the result of applying some functional transformation to the elem...
zypp::Iterable
Definition Iterable.h:37
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
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:226
zypp::makeIterable
Iterable< TIterator > makeIterable(TIterator &&begin_r, TIterator &&end_r)
relates: Iterable convenient construction.
Definition Iterable.h:88
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:251
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:256
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:236
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_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:231
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:267
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:241
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:272
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:261
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_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:246
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::Key_const_iterator::Key_const_iterator
transform_iterator< GetPairFirst< typename MapType::value_type >, typename MapType::const_iterator > Key_const_iterator
Definition Iterator.h:217
zypp::Key_const_iterator::KeyType
typename PatternMap::key_type KeyType
Definition Iterator.h:215
zypp::Key_const_iterator::ValueType
typename PatternMap::mapped_type ValueType
Definition Iterator.h:219
zypp::Key_const_iterator::Value_const_iterator
transform_iterator< GetPairSecond< typename MapType::value_type >, typename MapType::const_iterator > Value_const_iterator
Definition Iterator.h:221
zypp::Key_const_iterator::MapType
PatternMap MapType
Definition Iterator.h:213