1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_SAT_WHATPROVIDES_H
13 #define ZYPP_SAT_WHATPROVIDES_H
17 #include "zypp/base/DefaultIntegral.h"
18 #include "zypp/sat/detail/PoolMember.h"
19 #include "zypp/sat/Solvable.h"
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////
26 { /////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////
30 // CLASS NAME : WhatProvides
32 /** Container of \ref Solvable providing a \ref Capability (read only).
34 * Capability cap("amarok < 1.13");
35 * WhatProvides q( cap );
38 * cout << "Found " << q.size() << " matches for " << cap << ":" << endl;
39 * for_( it, q.begin(), q.end() )
44 class WhatProvides : protected detail::PoolMember
47 typedef Solvable value_type;
48 typedef unsigned size_type;
56 /** Ctor from Id pointer (friend \ref Solvable). */
58 WhatProvides( Capability cap_r );
61 /** Whether the container is empty. */
63 { return ! ( _begin && *_begin ); }
65 /** Number of solvables inside. */
66 size_type size() const;
71 /** Iterator pointing to the first \ref Solvable. */
72 const_iterator begin() const;
74 /** Iterator pointing behind the last \ref Solvable. */
75 const_iterator end() const;
78 const sat::detail::IdType * _begin;
80 ///////////////////////////////////////////////////////////////////
82 /** \relates WhatProvides Stream output */
83 std::ostream & operator<<( std::ostream & str, const WhatProvides & obj );
85 ///////////////////////////////////////////////////////////////////
87 // CLASS NAME : WhatProvides::const_iterator
89 /** \ref WhatProvides iterator.
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
101 : const_iterator::iterator_adaptor_( 0 )
104 explicit const_iterator( const sat::detail::IdType * _idx )
105 : const_iterator::iterator_adaptor_( _idx )
109 friend class boost::iterator_core_access;
111 reference dereference() const
112 { return ( base() ) ? Solvable( *base() ) : Solvable::nosolvable; }
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() ) );
123 { ++base_reference(); }
125 ///////////////////////////////////////////////////////////////////
127 inline WhatProvides::const_iterator WhatProvides::begin() const
128 { return const_iterator( _begin ); }
130 inline WhatProvides::const_iterator WhatProvides::end() const
131 { return const_iterator( 0 ); }
133 /////////////////////////////////////////////////////////////////
135 ///////////////////////////////////////////////////////////////////
136 /////////////////////////////////////////////////////////////////
138 ///////////////////////////////////////////////////////////////////
139 #endif // ZYPP_SAT_WHATPROVIDES_H