libzypp  17.3.0
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/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>
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>
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>
229  { return make_transform_iterator( map_r.begin(), GetPairFirst<typename TMap::value_type>() ); }
230 
232  template<class TMap>
234  { return make_transform_iterator( map_r.end(), GetPairFirst<typename TMap::value_type>() ); }
235 
237  template<class TMap>
239  { return make_transform_iterator( map_r.begin(), GetPairSecond<typename TMap::value_type>() ); }
240 
242  template<class TMap>
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 
280  using boost::function_output_iterator;
281  using boost::make_function_output_iterator;
282 
284 } // namespace zypp
287 #endif // ZYPP_BASE_ITERATOR_H
const TPair::second_type & operator()(const TPair &pair_r) const
Definition: Iterator.h:167
TMap MapType
The map type.
Definition: Iterator.h:213
Functor taking a std::pair returning std::pair.second .
Definition: Iterator.h:165
transform_iterator< GetPairSecond< typename MapType::value_type >, typename MapType::const_iterator > Value_const_iterator
The value iterator type.
Definition: Iterator.h:223
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
An iterator over the subset of elements of some sequence which satisfy a given predicate.
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
Functor taking a std::pair returning std::pair.first.
Definition: Iterator.h:155
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
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
TMap::mapped_type ValueType
The maps value (mapped) type.
Definition: Iterator.h:220
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
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
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
transform_iterator< GetPairFirst< typename MapType::value_type >, typename MapType::const_iterator > Key_const_iterator
The key iterator type.
Definition: Iterator.h:218
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
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
TMap::key_type KeyType
The maps key type.
Definition: Iterator.h:215
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
const TPair::first_type & operator()(const TPair &pair_r) const
Definition: Iterator.h:157
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
Traits for std::map key and value iterators.
Definition: Iterator.h:210