1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Filter.h
17 #include "zypp/base/Functional.h"
18 #include "zypp/base/Function.h"
19 // #include "zypp/ResFilters.h" included at the end!
20 #include "zypp/sat/Pool.h"
21 #include "zypp/PoolItem.h"
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
28 { /////////////////////////////////////////////////////////////////
29 /** \defgroup POOLFILTER Collection solvable filter functors.
31 * All functors should be able to process \ref Solvable as well
35 * // The same filter...
36 * filter::ByLocaleSupport f( Locale("de") );
38 * // ...can be used to iterate the sat::Pool...
39 * sat::Pool satpool( sat::Pool::instance() );
40 * for_( it, satpool.filterBegin(f), satpool.filterEnd(f) )
42 * MIL << *it << endl; // prints sat::Solvable
45 * // ...as well as the ResPool.
46 * ResPool pool ( ResPool::instance() );
47 * for_( it, pool.filterBegin(f), pool.filterEnd(f) )
49 * MIL << *it << endl; // prints PoolItem
56 ///////////////////////////////////////////////////////////////////
58 // CLASS NAME : ByLocaleSupport
60 /** Filter solvables according to their locale support.
65 typedef bool (sat::Solvable::*LS1) (const Locale &) const;
66 typedef bool (sat::Solvable::*LS2) (const LocaleSet &) const;
69 /** Solvables with locale support. */
71 : _sel( boost::mem_fun_ref( &sat::Solvable::supportsLocales ) )
74 /** Solvables supporting \c locale_r. */
75 explicit ByLocaleSupport( const Locale & locale_r )
76 : _sel( boost::bind( boost::mem_fun_ref( (LS1)&sat::Solvable::supportsLocale ), _1, locale_r ) )
79 /** Solvables supporting at least one locale in \c locales_r. */
80 explicit ByLocaleSupport( const LocaleSet & locales_r )
81 : _sel( boost::bind( boost::mem_fun_ref( (LS2)&sat::Solvable::supportsLocale ), _1, locales_r ) )
85 /** Filter on \ref Solvable. */
86 bool operator()( const sat::Solvable & solv_r ) const
87 { return _sel && _sel( solv_r ); }
89 /** Filter fitting PoolItem/ResObject. */
91 bool operator()( const TSolv & solv_r ) const
92 { return operator()( solv_r.satSolvable() ); }
95 function<bool(const sat::Solvable &)> _sel;
97 ///////////////////////////////////////////////////////////////////
99 ///////////////////////////////////////////////////////////////////
101 // CLASS NAME : ByKind
103 /** Filter solvables according to their kind.
111 ByKind( const ResKind & kind_r )
116 /** Filter on \ref Solvable. */
117 bool operator()( const sat::Solvable & solv_r ) const
118 { return solv_r.isKind( _kind ); }
120 /** Filter fitting PoolItem/ResObject. */
121 template<class TSolv>
122 bool operator()( const TSolv & solv_r ) const
123 { return operator()( solv_r.satSolvable() ); }
129 /** \relates ByKind templated convenience ctor. */
131 inline ByKind byKind()
132 { return ByKind( ResTraits<TRes>::kind ); }
133 ///////////////////////////////////////////////////////////////////
135 ///////////////////////////////////////////////////////////////////
137 // CLASS NAME : ByStatus
139 /** Filter solvables according to their status.
144 typedef bool (ResStatus::*Predicate)() const;
147 ByStatus( Predicate pred_r = 0 )
152 /** Filter on \ref PoolItem. */
153 bool operator()( const PoolItem & pi_r ) const
154 { return _pred && (pi_r.status().*_pred)(); }
156 /** Filter fitting sat::Solvable/ResObject. */
157 template<class TSolv>
158 bool operator()( const TSolv & solv_r ) const
159 { return operator()( PoolItem(solv_r) ); }
164 ///////////////////////////////////////////////////////////////////
167 ///////////////////////////////////////////////////////////////////
169 // CLASS NAME : SameItemAs
171 /** Filter items with at least same NVRA, vendor.
172 * This is usually used to find available packages
173 * that matche an insytalled one.
178 SameItemAs( const sat::Solvable & solv_r )
182 /** Fitting PoolItem/ResObject. */
183 template<class TSolv>
184 SameItemAs( const TSolv & solv_r )
185 : _item( solv_r.satSolvable() )
189 /** Filter on \ref Solvable. */
190 bool operator()( const sat::Solvable & solv_r ) const
192 return solv_r.name() == _item.name()
193 && solv_r.edition() == _item.edition()
194 && solv_r.arch() == _item.arch()
195 && solv_r.vendor() == _item.vendor();
198 /** Filter fitting PoolItem/ResObject. */
199 template<class TSolv>
200 bool operator()( const TSolv & solv_r ) const
201 { return operator()( solv_r.satSolvable() ); }
206 ///////////////////////////////////////////////////////////////////
209 /////////////////////////////////////////////////////////////////
210 } // namespace filter
211 ///////////////////////////////////////////////////////////////////
212 /////////////////////////////////////////////////////////////////
214 ///////////////////////////////////////////////////////////////////
216 #include "zypp/ResFilters.h"
218 #endif // ZYPP_FILTER_H