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 _Solv & 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.
108 ByKind( const ResKind & kind_r )
113 /** Filter on \ref Solvable. */
114 bool operator()( const sat::Solvable & solv_r ) const
115 { return solv_r.isKind( _kind ); }
117 /** Filter fitting PoolItem/ResObject. */
118 template<class _Solv>
119 bool operator()( const _Solv & solv_r ) const
120 { return operator()( solv_r.satSolvable() ); }
126 /** \relates ByKind templated convenience ctor. */
128 inline ByKind byKind()
129 { return ByKind( ResTraits<_Res>::kind ); }
130 ///////////////////////////////////////////////////////////////////
132 ///////////////////////////////////////////////////////////////////
134 // CLASS NAME : SameItemAs
136 /** Filter items with at least same NVRA, vendor.
137 * This is usually used to find available packages
138 * that matche an insytalled one.
143 SameItemAs( const sat::Solvable & solv_r )
147 /** Fitting PoolItem/ResObject. */
148 template<class _Solv>
149 SameItemAs( const _Solv & solv_r )
150 : _item( solv_r.satSolvable() )
154 /** Filter on \ref Solvable. */
155 bool operator()( const sat::Solvable & solv_r ) const
157 return solv_r.name() == _item.name()
158 && solv_r.edition() == _item.edition()
159 && solv_r.arch() == _item.arch()
160 && solv_r.vendor() == _item.vendor();
163 /** Filter fitting PoolItem/ResObject. */
164 template<class _Solv>
165 bool operator()( const _Solv & solv_r ) const
166 { return operator()( solv_r.satSolvable() ); }
171 ///////////////////////////////////////////////////////////////////
174 /////////////////////////////////////////////////////////////////
175 } // namespace filter
176 ///////////////////////////////////////////////////////////////////
177 /////////////////////////////////////////////////////////////////
179 ///////////////////////////////////////////////////////////////////
181 #include "zypp/ResFilters.h"
183 #endif // ZYPP_FILTER_H