1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/WhatProvides.h
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"
21 #include "zypp/sat/SolvIterMixin.h"
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
28 { /////////////////////////////////////////////////////////////////
32 class WhatProvidesIterator;
35 ///////////////////////////////////////////////////////////////////
37 // CLASS NAME : WhatProvides
39 /** Container of \ref Solvable providing a \ref Capability (read only).
42 * Capability cap("amarok < 1.13");
44 * WhatProvides q( cap );
45 * Solvable firstMatch;
49 * cout << "Found " << q.size() << " matches for " << cap << ":" << endl;
50 * firstMatch = *q.begin();
52 * for_( it, q.begin(), q.end() )
53 * cout << *it << endl;
58 * WhatProvides req( firstMatch.requires() );
59 * if ( ! req.empty() )
61 * cout << "Found " << req.size() << " items providing requirements of " << firstMatch << ":" << endl;
66 * \note Note that there are capabilities which are not provided by any \ref Solvable,
67 * but are system properties. For example:
69 * rpmlib(PayloadIsBzip2) <= 3.0.5-1
71 * In that case a \ref Solvable::noSolvable is returned, which has \c isSystem set \c true, although
72 * there should never be a \ref Solvable::noSolvable returned with \c isSystem set \c false. If so,
73 * please file a bugreport.
75 * WhatProvides q( Capability("rpmlib(PayloadIsBzip2) <= 3.0.5-1") );
76 * for_( it, q.begin(), q.end() )
79 * cout << "Capability is provided by package " << *it << endl;
80 * else if ( it->isSystem() )
81 * cout << "Capability is a system property" << endl;
83 * ; // never reaching this \c else
87 class WhatProvides : public SolvIterMixin<WhatProvides,detail::WhatProvidesIterator>,
88 protected detail::PoolMember
91 typedef Solvable value_type;
92 typedef unsigned size_type;
100 /** Ctor from \ref Capability. */
102 WhatProvides( Capability cap_r );
104 /** Ctor collecting all providers of capabilities in \c caps_r. */
106 WhatProvides( Capabilities caps_r );
108 /** Ctor collecting all providers of capabilities in \c caps_r. */
110 WhatProvides( const CapabilitySet & caps_r );
113 /** Whether the container is empty. */
115 { return ! ( _begin && *_begin ); }
117 /** Number of solvables inside. */
118 size_type size() const;
121 typedef detail::WhatProvidesIterator const_iterator;
123 /** Iterator pointing to the first \ref Solvable. */
124 const_iterator begin() const;
126 /** Iterator pointing behind the last \ref Solvable. */
127 const_iterator end() const;
130 const sat::detail::IdType * _begin;
131 shared_ptr<void> _private;
133 ///////////////////////////////////////////////////////////////////
135 /** \relates WhatProvides Stream output */
136 std::ostream & operator<<( std::ostream & str, const WhatProvides & obj );
140 ///////////////////////////////////////////////////////////////////
142 // CLASS NAME : WhatProvides::const_iterator
144 /** \ref WhatProvides iterator.
145 * Iterate a NULL terminated sat::detail::IdType array.
147 class WhatProvidesIterator : public boost::iterator_adaptor<
148 WhatProvidesIterator // Derived
149 , const detail::IdType * // Base
150 , const Solvable // Value
151 , boost::forward_traversal_tag // CategoryOrTraversal
152 , const Solvable // Reference
156 WhatProvidesIterator()
157 : iterator_adaptor_( 0 )
160 explicit WhatProvidesIterator( const sat::detail::IdType * _idx )
161 : iterator_adaptor_( _idx )
165 friend class boost::iterator_core_access;
167 reference dereference() const
168 { return ( base() ) ? Solvable( *base() ) : Solvable::noSolvable; }
170 template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
171 bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
172 { // NULL pointer is eqal pointer to Id 0
173 return ( base() == rhs.base() // includes both NULL...
174 || ( !rhs.base() && !*base() )
175 || ( !base() && !*rhs.base() ) );
179 { ++base_reference(); }
181 ///////////////////////////////////////////////////////////////////
184 inline WhatProvides::const_iterator WhatProvides::begin() const
185 { return const_iterator( _begin ); }
187 inline WhatProvides::const_iterator WhatProvides::end() const
188 { return const_iterator( 0 ); }
190 /////////////////////////////////////////////////////////////////
192 ///////////////////////////////////////////////////////////////////
193 /////////////////////////////////////////////////////////////////
195 ///////////////////////////////////////////////////////////////////
196 #endif // ZYPP_SAT_WHATPROVIDES_H