ResFilters.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_RESFILTERS_H
00013 #define ZYPP_RESFILTERS_H
00014 
00015 #include <boost/function.hpp>
00016 
00017 #include "zypp/base/Functional.h"
00018 #include "zypp/Resolvable.h"
00019 #include "zypp/CapFilters.h"
00020 
00021 #include "zypp/PoolItem.h"
00022 #include "zypp/CapAndItem.h"
00023 
00024 //#include "zypp/Repository.h"
00025 
00027 namespace zypp
00028 { 
00029   class Repository;
00031   namespace resfilter
00032   { 
00033 
00145 
00146     //
00147     // Some ResObject attributes
00148     //
00150 
00152     typedef std::unary_function<ResObject::constPtr, bool> ResObjectFilterFunctor;
00153     typedef boost::function<bool ( ResObject::constPtr )> ResFilter;
00154 
00156     struct ByKind : public ResObjectFilterFunctor
00157     {
00158       ByKind( const ResObject::Kind & kind_r )
00159       : _kind( kind_r )
00160       {}
00161 
00162       bool operator()( ResObject::constPtr p ) const
00163       {
00164         return p->kind() == _kind;
00165       }
00166 
00167       ResObject::Kind _kind;
00168     };
00169 
00171     template<class _Res>
00172       inline ByKind byKind()
00173       { return ByKind( ResTraits<_Res>::kind ); }
00174 
00176     struct ByName : public ResObjectFilterFunctor
00177     {
00178       ByName( const std::string & name_r )
00179       : _name( name_r )
00180       {}
00181 
00182       bool operator()( ResObject::constPtr p ) const
00183       {
00184         return p->name() == _name;
00185       }
00186 
00187       std::string _name;
00188     };
00189 
00190 
00192     struct ByRepository : public ResObjectFilterFunctor
00193     {
00194       ByRepository( Repository repository_r )
00195       : _alias( repository_r.info().alias() )
00196       {}
00197 
00198       ByRepository( const std::string & alias_r )
00199       : _alias( alias_r )
00200       {}
00201 
00202       bool operator()( ResObject::constPtr p ) const
00203       {
00204        return p->repository().info().alias() == _alias;
00205       }
00206 
00207       std::string _alias;
00208     };
00209 
00210 
00223     template<class _Compare = CompareByEQ<Edition> >
00224       struct ByEdition : public ResObjectFilterFunctor
00225       {
00226         ByEdition( const Edition & edition_r,
00227                    _Compare cmp_r )
00228         : _edition( edition_r )
00229         , _cmp( cmp_r )
00230         {}
00231 
00232         bool operator()( ResObject::constPtr p ) const
00233         {
00234           return _cmp( p->edition(), _edition );
00235         }
00236 
00237         Edition  _edition;
00238         _Compare _cmp;
00239       };
00240 
00242     template<class _Compare>
00243       ByEdition<_Compare> byEdition( const Edition & edition_r, _Compare cmp_r )
00244       { return ByEdition<_Compare>( edition_r, cmp_r ); }
00245 
00247     template<class _Compare>
00248       ByEdition<_Compare> byEdition( const Edition & edition_r )
00249       { return byEdition( edition_r, _Compare() ); }
00250 
00251 
00264     template<class _Compare = CompareByEQ<Arch> >
00265       struct ByArch : public ResObjectFilterFunctor
00266       {
00267         ByArch( const Arch & arch_r,
00268                    _Compare cmp_r )
00269         : _arch( arch_r )
00270         , _cmp( cmp_r )
00271         {}
00272 
00273         bool operator()( ResObject::constPtr p ) const
00274         {
00275           return _cmp( p->arch(), _arch );
00276         }
00277 
00278         Arch  _arch;
00279         _Compare _cmp;
00280       };
00281 
00283     template<class _Compare>
00284       ByArch<_Compare> byArch( const Arch & arch_r, _Compare cmp_r )
00285       { return ByArch<_Compare>( arch_r, cmp_r ); }
00286 
00288     template<class _Compare>
00289       ByArch<_Compare> byArch( const Arch & arch_r )
00290       { return byArch( arch_r, _Compare() ); }
00291 
00292 
00294 
00296     //
00297     // Some PoolItem attributes
00298     //
00300 
00302     typedef std::unary_function<PoolItem, bool> PoolItemFilterFunctor;
00303 
00305     struct ByInstalled : public PoolItemFilterFunctor
00306     {
00307       bool operator()( const PoolItem & p ) const
00308       {
00309         return p.status().isInstalled();
00310       }
00311 
00312     };
00313 
00315     struct ByUninstalled : public PoolItemFilterFunctor
00316     {
00317       bool operator()( const PoolItem & p ) const
00318       {
00319         return p.status().isUninstalled();
00320       }
00321     };
00322 
00324     struct ByTransact : public PoolItemFilterFunctor
00325     {
00326       bool operator()( const PoolItem & p ) const
00327       {
00328         return p.status().transacts();
00329       }
00330     };
00331 
00333     struct ByLock : public PoolItemFilterFunctor
00334     {
00335       bool operator()( const PoolItem & p ) const
00336       {
00337         return p.status().isLocked();
00338       }
00339     };
00340 
00342     struct ByKeep : public PoolItemFilterFunctor
00343     {
00344       bool operator()( const PoolItem & p ) const
00345       {
00346         return p.status().isKept();
00347       }
00348     };
00349       
00350 
00351 
00353 
00357     struct ByCapabilityIndex
00358     {
00359       bool operator()( const CapAndItem & /*cai*/ ) const
00360       {
00361         return true;                    // its all in the PoolImpl !
00362       }
00363     };
00364 
00365 
00369     struct ByCapMatch
00370     {
00371       bool operator()( const CapAndItem & cai ) const
00372       {
00373         return cai.cap.matches( _cap ) == CapMatch::yes;
00374       }
00375       ByCapMatch( const Capability & cap_r )
00376         : _cap( cap_r )
00377       {}
00378       Capability _cap;
00379     };
00380 
00381 
00383     struct ByCaIUninstalled
00384     {
00385       bool operator()( const CapAndItem & cai ) const
00386       {
00387         return cai.item.status().isUninstalled();
00388       }
00389     };
00390 
00392     struct ByCaIInstalled
00393     {
00394       bool operator()( const CapAndItem & cai ) const
00395       {
00396         return cai.item.status().isInstalled();
00397       }
00398     };
00399 
00401     struct ByCaITransact
00402     {
00403       bool operator()( const CapAndItem & cai ) const
00404       {
00405         return cai.item.status().transacts();
00406       }
00407     };
00408 
00410     struct ByCaINotTransact
00411     {
00412       bool operator()( const CapAndItem & cai ) const
00413       {
00414         return !(cai.item.status().transacts());
00415       }
00416     };
00417 
00418 
00420     struct ByCaIKind
00421     {
00422       ByCaIKind( const ResObject::Kind & kind_r )
00423       : _kind( kind_r )
00424       {}
00425 
00426       bool operator()( const CapAndItem & cai ) const
00427       {
00428         return cai.item->kind() == _kind;
00429       }
00430 
00431       ResObject::Kind _kind;
00432     };
00433 
00435     template<class _Res>
00436       inline ByCaIKind byCaIKind()
00437       { return ByCaIKind( ResTraits<_Res>::kind ); }
00438 
00440 
00442 
00443   } // namespace resfilter
00446 } // namespace zypp
00448 #endif // ZYPP_RESFILTERS_H

Generated on Tue Sep 25 19:23:06 2007 for libzypp by  doxygen 1.5.3