libzypp  10.5.0
Filter.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_FILTER_H
00013 #define ZYPP_FILTER_H
00014 
00015 #include <iosfwd>
00016 
00017 #include "zypp/base/Functional.h"
00018 #include "zypp/base/Function.h"
00019 // #include "zypp/ResFilters.h"  included at the end!
00020 #include "zypp/sat/Pool.h"
00021 #include "zypp/PoolItem.h"
00022 
00024 namespace zypp
00025 { 
00026 
00027   namespace filter
00028   { 
00029 
00055 
00057     //
00058     //  CLASS NAME : ByLocaleSupport
00059     //
00062     class ByLocaleSupport
00063     {
00064       private:
00065         typedef bool (sat::Solvable::*LS1) (const Locale &) const;
00066         typedef bool (sat::Solvable::*LS2) (const LocaleSet &) const;
00067 
00068       public:
00070         ByLocaleSupport()
00071         : _sel( boost::mem_fun_ref( &sat::Solvable::supportsLocales ) )
00072         {}
00073 
00075         explicit ByLocaleSupport( const Locale & locale_r )
00076         : _sel( boost::bind( boost::mem_fun_ref( (LS1)&sat::Solvable::supportsLocale ), _1, locale_r ) )
00077         {}
00078 
00080         explicit ByLocaleSupport( const LocaleSet & locales_r )
00081         : _sel( boost::bind( boost::mem_fun_ref( (LS2)&sat::Solvable::supportsLocale ), _1, locales_r ) )
00082         {}
00083 
00084       public:
00086         bool operator()( const sat::Solvable & solv_r ) const
00087         { return _sel && _sel( solv_r ); }
00088 
00090         template<class _Solv>
00091         bool operator()( const _Solv & solv_r ) const
00092         { return operator()( solv_r.satSolvable() ); }
00093 
00094       private:
00095         function<bool(const sat::Solvable &)> _sel;
00096     };
00098 
00100     //
00101     //  CLASS NAME : ByKind
00102     //
00105     class ByKind
00106     {
00107       public:
00108         ByKind( const ResKind & kind_r )
00109         : _kind( kind_r )
00110         {}
00111 
00112       public:
00114         bool operator()( const sat::Solvable & solv_r ) const
00115         { return solv_r.isKind( _kind ); }
00116 
00118         template<class _Solv>
00119         bool operator()( const _Solv & solv_r ) const
00120         { return operator()( solv_r.satSolvable() ); }
00121 
00122       private:
00123         ResKind _kind;
00124     };
00125 
00127     template<class _Res>
00128     inline ByKind byKind()
00129     { return ByKind( ResTraits<_Res>::kind ); }
00131 
00133     //
00134     //  CLASS NAME : ByStatus
00135     //
00138     class ByStatus
00139     {
00140       public:
00141         typedef bool (ResStatus::*Predicate)() const;
00142 
00143       public:
00144         ByStatus( Predicate pred_r = 0 )
00145         : _pred( pred_r )
00146         {}
00147 
00148       public:
00150         bool operator()( const PoolItem & pi_r ) const
00151         { return _pred && (pi_r.status().*_pred)(); }
00152 
00154         template<class _Solv>
00155         bool operator()( const _Solv & solv_r ) const
00156         { return operator()( PoolItem(solv_r) ); }
00157 
00158       private:
00159         Predicate _pred;
00160     };
00162 
00163 
00165     //
00166     //  CLASS NAME : SameItemAs
00167     //
00172     class SameItemAs
00173     {
00174       public:
00175         SameItemAs( const sat::Solvable & solv_r )
00176         : _item( solv_r )
00177         {}
00178 
00180         template<class _Solv>
00181         SameItemAs( const _Solv & solv_r )
00182         : _item( solv_r.satSolvable() )
00183         {}
00184 
00185       public:
00187         bool operator()( const sat::Solvable & solv_r ) const
00188         {
00189           return solv_r.name()    == _item.name()
00190               && solv_r.edition() == _item.edition()
00191               && solv_r.arch()    == _item.arch()
00192               && solv_r.vendor()  == _item.vendor();
00193         }
00194 
00196         template<class _Solv>
00197         bool operator()( const _Solv & solv_r ) const
00198         { return operator()( solv_r.satSolvable() ); }
00199 
00200       private:
00201         sat::Solvable _item;
00202     };
00204 
00205 
00207   } // namespace filter
00210 } // namespace zypp
00212 
00213 #include "zypp/ResFilters.h"
00214 
00215 #endif // ZYPP_FILTER_H