- Added some more tools for queries.
[platform/upstream/libzypp.git] / zypp / base / Iterator.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/base/Iterator.h
10  *
11 */
12 #ifndef ZYPP_BASE_ITERATOR_H
13 #define ZYPP_BASE_ITERATOR_H
14
15 #include <boost/iterator/filter_iterator.hpp>
16 #include <boost/iterator/transform_iterator.hpp>
17 #include <boost/function_output_iterator.hpp>
18
19 ///////////////////////////////////////////////////////////////////
20 namespace zypp
21 { /////////////////////////////////////////////////////////////////
22
23   /** \defgroup ITERATOR Boost.Iterator Library
24    *
25    * \see http://www.boost.org/libs/iterator/doc/index.html
26    *
27    * \li \b counting_iterator: an iterator over a sequence of
28    *        consecutive values. Implements a "lazy sequence"
29    * \li \b filter_iterator: an iterator over the subset of elements
30    *        of some sequence which satisfy a given predicate
31    * \li \b function_output_iterator: an output iterator wrapping a
32    *        unary function object; each time an element is written into
33    *        the dereferenced iterator, it is passed as a parameter to
34    *        the function object.
35    * \li \b indirect_iterator: an iterator over the objects pointed-to
36    *        by the elements of some sequence.
37    * \li \b permutation_iterator: an iterator over the elements of
38    *        some random-access sequence, rearranged according to some
39    *        sequence of integer indices.
40    * \li \b reverse_iterator: an iterator which traverses the elements
41    *        of some bidirectional sequence in reverse. Corrects many of the shortcomings of C++98's std::reverse_iterator.
42    * \li \b shared_container_iterator: an iterator over elements of
43    *        a container whose lifetime is maintained by a shared_ptr
44    *        stored in the iterator.
45    * \li \b transform_iterator: an iterator over elements which are
46    *        the result of applying some functional transformation to
47    *        the elements of an underlying sequence. This component
48    *        also replaces the old projection_iterator_adaptor.
49    * \li \b zip_iterator: an iterator over tuples of the elements
50    *        at corresponding positions of heterogeneous underlying
51    *        iterators.
52    *
53    * There are in fact more interesting iterator concepts
54    * available than the ones listed above. Have a look at them.
55    *
56    * Some of the iterator types are already dragged into namespace
57    * zypp. Feel free to add what's missing.
58    *
59    * \todo Separate them into individual zypp header files.
60   */
61   //@{
62
63   /** \class filter_iterator
64    * An iterator over the subset of elements of some sequence
65    * which satisfy a given predicate.
66    *
67    * Provides boost::filter_iterator and boost::make_filter_iterator
68    * convenience function.
69    * \see http://www.boost.org/libs/iterator/doc/filter_iterator.html
70    * \code
71    * template <class Predicate, class Iterator>
72    *   filter_iterator<Predicate,Iterator>
73    *   make_filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());
74    *
75    * template <class Predicate, class Iterator>
76    *   filter_iterator<Predicate,Iterator>
77    *   make_filter_iterator(Iterator x, Iterator end = Iterator());
78    * \endcode
79    * Remember the deduction rules for template arguments.
80    * \code
81    * struct MyDefaultConstructibleFilter;
82    * make_filter_iterator<MyDefaultConstructibleFilter>( c.begin(), c.end() );
83    * make_filter_iterator( MyDefaultConstructibleFilter(), c.begin(), c.end() );
84    * ...
85    * make_filter_iterator( resfilter::ByName("foo"), c.begin(), c.end() );
86    *
87    * \endcode
88   */
89   using boost::filter_iterator;
90   using boost::make_filter_iterator;
91
92   /** Convenience to create filter_iterator from container::begin(). */
93   template<class _Filter, class _Container>
94     filter_iterator<_Filter, typename _Container::const_iterator>
95     make_filter_begin( _Filter f, const _Container & c )
96     {
97       return make_filter_iterator( f, c.begin(), c.end() );
98     }
99
100   /** Convenience to create filter_iterator from container::end(). */
101   template<class _Filter, class _Container>
102     filter_iterator<_Filter, typename _Container::const_iterator>
103     make_filter_end( _Filter f, const _Container & c )
104     {
105       return make_filter_iterator( f, c.end(), c.end() );
106     }
107
108   /** \class transform_iterator
109    * An iterator over elements which are the result of applying
110    * some functional transformation to the elements of an underlying
111    * sequence.
112    *
113    * Provides boost::transform_iterator and boost::make_transform_iterator
114    * convenience function.
115    * \see http://www.boost.org/libs/iterator/doc/transform_iterator.html
116    * \code
117    * template <class UnaryFunction, class Iterator>
118    *   transform_iterator<UnaryFunction, Iterator>
119    *   make_transform_iterator(Iterator it, UnaryFunction fun);
120    *
121    * template <class UnaryFunction, class Iterator>
122    *   transform_iterator<UnaryFunction, Iterator>
123    *   make_transform_iterator(Iterator it);
124    * \endcode
125   */
126   using boost::transform_iterator;
127   using boost::make_transform_iterator;
128
129   /** \class function_output_iterator
130    * An output iterator wrapping a unary function object; each time an
131    * element is written into the dereferenced iterator, it is passed as
132    * a parameter to the function object.
133    *
134    * Provides boost::function_output_iterator and boost::make_function_output_iterator
135    * convenience function.
136    * \see http://www.boost.org/libs/iterator/doc/function_output_iterator.html
137    * \code
138    * template <class UnaryFunction>
139    *   function_output_iterator<UnaryFunction>
140    *   make_function_output_iterator(const UnaryFunction& f = UnaryFunction());
141    * \endcode
142   */
143   using boost::function_output_iterator;
144   using boost::make_function_output_iterator;
145
146   //@}
147   /////////////////////////////////////////////////////////////////
148 } // namespace zypp
149 ///////////////////////////////////////////////////////////////////
150 #endif // ZYPP_BASE_ITERATOR_H