1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_SAT_WHATPROVIDES_H
13 #define ZYPP_SAT_WHATPROVIDES_H
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/sat/detail/PoolMember.h"
20 #include "zypp/sat/Solvable.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
31 // CLASS NAME : WhatProvides
33 /** Container of \ref Solvable providing a \ref Capability (read only).
36 * Capability cap("amarok < 1.13");
38 * WhatProvides q( cap );
39 * Solvable firstMatch;
43 * cout << "Found " << q.size() << " matches for " << cap << ":" << endl;
44 * firstMatch = *q.begin();
46 * for_( it, q.begin(), q.end() )
47 * cout << *it << endl;
52 * WhatProvides req( firstMatch.requires() );
53 * if ( ! req.empty() )
55 * cout << "Found " << req.size() << " items providing requirements of " << firstMatch << ":" << endl;
60 * \note Note that there are capabilities which are not provided by any \ref Solvable,
61 * but are system properties. For example:
63 * rpmlib(PayloadIsBzip2) <= 3.0.5-1
65 * In that case a \ref Solvable::noSolvable is returned, which has \c isSystem set \c true, although
66 * there should never be a \ref Solvable::noSolvable returned with \c isSystem set \c false. If so,
67 * please file a bugreport.
69 * WhatProvides q( Capability("rpmlib(PayloadIsBzip2) <= 3.0.5-1") );
70 * for_( it, q.begin(), q.end() )
73 * cout << "Capability is provided by package " << *it << endl;
74 * else if ( it->isSystem() )
75 * cout << "Capability is a system property" << endl;
77 * ; // never reaching this \c else
81 class WhatProvides : protected detail::PoolMember
84 typedef Solvable value_type;
85 typedef unsigned size_type;
93 /** Ctor from \ref Capability. */
95 WhatProvides( Capability cap_r );
97 /** Ctor collecting all providers of capabilities in \c caps_r. */
99 WhatProvides( Capabilities caps_r );
101 /** Ctor collecting all providers of capabilities in \c caps_r. */
103 WhatProvides( const CapabilitySet & caps_r );
106 /** Whether the container is empty. */
108 { return ! ( _begin && *_begin ); }
110 /** Number of solvables inside. */
111 size_type size() const;
114 class const_iterator;
116 /** Iterator pointing to the first \ref Solvable. */
117 const_iterator begin() const;
119 /** Iterator pointing behind the last \ref Solvable. */
120 const_iterator end() const;
123 const sat::detail::IdType * _begin;
124 shared_ptr<void> _private;
126 ///////////////////////////////////////////////////////////////////
128 /** \relates WhatProvides Stream output */
129 std::ostream & operator<<( std::ostream & str, const WhatProvides & obj );
131 ///////////////////////////////////////////////////////////////////
133 // CLASS NAME : WhatProvides::const_iterator
135 /** \ref WhatProvides iterator.
137 class WhatProvides::const_iterator : public boost::iterator_adaptor<
138 const_iterator // Derived
139 , const detail::IdType * // Base
140 , const Solvable // Value
141 , boost::forward_traversal_tag // CategoryOrTraversal
142 , const Solvable // Reference
147 : const_iterator::iterator_adaptor_( 0 )
150 explicit const_iterator( const sat::detail::IdType * _idx )
151 : const_iterator::iterator_adaptor_( _idx )
155 friend class boost::iterator_core_access;
157 reference dereference() const
158 { return ( base() ) ? Solvable( *base() ) : Solvable::noSolvable; }
160 template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
161 bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
162 { // NULL pointer is eqal pointer to Id 0
163 return ( base() == rhs.base() // includes both NULL...
164 || ( !rhs.base() && !*base() )
165 || ( !base() && !*rhs.base() ) );
169 { ++base_reference(); }
171 ///////////////////////////////////////////////////////////////////
173 inline WhatProvides::const_iterator WhatProvides::begin() const
174 { return const_iterator( _begin ); }
176 inline WhatProvides::const_iterator WhatProvides::end() const
177 { return const_iterator( 0 ); }
179 /////////////////////////////////////////////////////////////////
181 ///////////////////////////////////////////////////////////////////
182 /////////////////////////////////////////////////////////////////
184 ///////////////////////////////////////////////////////////////////
185 #endif // ZYPP_SAT_WHATPROVIDES_H