Add ByLocaleSupport filter to iterate solvables according to their locale support.
[platform/upstream/libzypp.git] / zypp / sat / WhatProvides.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/.h
10  *
11 */
12 #ifndef ZYPP_SAT_WHATPROVIDES_H
13 #define ZYPP_SAT_WHATPROVIDES_H
14
15 #include <iosfwd>
16
17 #include "zypp/base/DefaultIntegral.h"
18 #include "zypp/sat/detail/PoolMember.h"
19 #include "zypp/sat/Solvable.h"
20
21 ///////////////////////////////////////////////////////////////////
22 namespace zypp
23 { /////////////////////////////////////////////////////////////////
24   ///////////////////////////////////////////////////////////////////
25   namespace sat
26   { /////////////////////////////////////////////////////////////////
27
28     ///////////////////////////////////////////////////////////////////
29     //
30     //  CLASS NAME : WhatProvides
31     //
32     /** Container of \ref Solvable providing a \ref Capability (read only).
33      * \code
34      * Capability cap("amarok < 1.13");
35      * WhatProvides q( cap );
36      * if ( ! q.empty() )
37      * {
38      *   cout << "Found " << q.size() << " matches for " << cap << ":" << endl;
39      *   for_( it, q.begin(), q.end() )
40      *     cout << *it << end;
41      * }
42      * \endcode
43      */
44     class WhatProvides : protected detail::PoolMember
45     {
46       public:
47         typedef Solvable  value_type;
48         typedef unsigned  size_type;
49
50       public:
51         /** Default ctor */
52         WhatProvides()
53         : _begin( 0 )
54         {}
55
56         /** Ctor from Id pointer (friend \ref Solvable). */
57         explicit
58         WhatProvides( Capability cap_r );
59
60       public:
61         /** Whether the container is empty. */
62         bool empty() const
63         { return ! ( _begin && *_begin ); }
64
65         /** Number of solvables inside. */
66         size_type size() const;
67
68       public:
69         class const_iterator;
70
71         /** Iterator pointing to the first \ref Solvable. */
72         const_iterator begin() const;
73
74         /** Iterator pointing behind the last \ref Solvable. */
75         const_iterator end() const;
76
77       private:
78         const sat::detail::IdType * _begin;
79     };
80     ///////////////////////////////////////////////////////////////////
81
82     /** \relates WhatProvides Stream output */
83     std::ostream & operator<<( std::ostream & str, const WhatProvides & obj );
84
85     ///////////////////////////////////////////////////////////////////
86     //
87     //  CLASS NAME : WhatProvides::const_iterator
88     //
89     /** \ref WhatProvides iterator.
90      */
91     class WhatProvides::const_iterator : public boost::iterator_adaptor<
92           const_iterator               // Derived
93         , const detail::IdType *       // Base
94         , const Solvable               // Value
95         , boost::forward_traversal_tag // CategoryOrTraversal
96         , const Solvable               // Reference
97         >
98     {
99       public:
100         const_iterator()
101         : const_iterator::iterator_adaptor_( 0 )
102         {}
103
104         explicit const_iterator( const sat::detail::IdType * _idx )
105         : const_iterator::iterator_adaptor_( _idx )
106         {}
107
108       private:
109         friend class boost::iterator_core_access;
110
111         reference dereference() const
112         { return ( base() ) ? Solvable( *base() ) : Solvable::nosolvable; }
113
114         template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
115         bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
116         { // NULL pointer is eqal pointer to Id 0
117           return ( base() == rhs.base() // includes both NULL...
118               || ( !rhs.base() && !*base()     )
119               || ( !base()     && !*rhs.base() ) );
120         }
121
122         void increment()
123         { ++base_reference(); }
124     };
125     ///////////////////////////////////////////////////////////////////
126
127     inline WhatProvides::const_iterator WhatProvides::begin() const
128     { return const_iterator( _begin ); }
129
130     inline WhatProvides::const_iterator WhatProvides::end() const
131     { return const_iterator( 0 ); }
132
133     /////////////////////////////////////////////////////////////////
134   } // namespace sat
135   ///////////////////////////////////////////////////////////////////
136   /////////////////////////////////////////////////////////////////
137 } // namespace zypp
138 ///////////////////////////////////////////////////////////////////
139 #endif // ZYPP_SAT_WHATPROVIDES_H