libzypp  10.5.0
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/Filter.h"
00019 #include "zypp/Resolvable.h"
00020 
00021 #include "zypp/PoolItem.h"
00022 #include "zypp/Repository.h"
00023 
00025 namespace zypp
00026 { 
00027 
00028   namespace resfilter
00029   { 
00030 
00144 
00145     //
00146     // Some ResObject attributes
00147     //
00149 
00151     typedef std::unary_function<ResObject::constPtr, bool> ResObjectFilterFunctor;
00152     typedef boost::function<bool ( ResObject::constPtr )> ResFilter;
00153 
00155     ZYPP_DEPRECATED typedef filter::ByKind ByKind;
00157     template<class _Res>
00158       inline filter::ByKind byKind()
00159       { return filter::ByKind( ResTraits<_Res>::kind ); }
00160 
00162     struct ByName : public ResObjectFilterFunctor
00163     {
00164       ByName( const std::string & name_r )
00165       : _name( name_r )
00166       {}
00167 
00168       bool operator()( ResObject::constPtr p ) const
00169       {
00170         return p->name() == _name;
00171       }
00172 
00173       std::string _name;
00174     };
00175 
00177     struct ByRepository : public ResObjectFilterFunctor
00178     {
00179       ByRepository( Repository repository_r )
00180       : _alias( repository_r.info().alias() )
00181       {}
00182 
00183       ByRepository( const std::string & alias_r )
00184       : _alias( alias_r )
00185       {}
00186 
00187       bool operator()( ResObject::constPtr p ) const
00188       {
00189         return p->repoInfo().alias() == _alias;
00190       }
00191 
00192       std::string _alias;
00193     };
00194 
00207     template<class _Compare = CompareByEQ<Edition> >
00208       struct ByEdition : public ResObjectFilterFunctor
00209       {
00210         ByEdition( const Edition & edition_r,
00211                    _Compare cmp_r )
00212         : _edition( edition_r )
00213         , _cmp( cmp_r )
00214         {}
00215 
00216         bool operator()( ResObject::constPtr p ) const
00217         {
00218           return _cmp( p->edition(), _edition );
00219         }
00220 
00221         Edition  _edition;
00222         _Compare _cmp;
00223       };
00224 
00226     template<class _Compare>
00227       ByEdition<_Compare> byEdition( const Edition & edition_r, _Compare cmp_r )
00228       { return ByEdition<_Compare>( edition_r, cmp_r ); }
00229 
00231     template<class _Compare>
00232       ByEdition<_Compare> byEdition( const Edition & edition_r )
00233       { return byEdition( edition_r, _Compare() ); }
00234 
00235 
00248     template<class _Compare = CompareByEQ<Arch> >
00249       struct ByArch : public ResObjectFilterFunctor
00250       {
00251         ByArch( const Arch & arch_r,
00252                    _Compare cmp_r )
00253         : _arch( arch_r )
00254         , _cmp( cmp_r )
00255         {}
00256 
00257         bool operator()( ResObject::constPtr p ) const
00258         {
00259           return _cmp( p->arch(), _arch );
00260         }
00261 
00262         Arch  _arch;
00263         _Compare _cmp;
00264       };
00265 
00267     template<class _Compare>
00268       ByArch<_Compare> byArch( const Arch & arch_r, _Compare cmp_r )
00269       { return ByArch<_Compare>( arch_r, cmp_r ); }
00270 
00272     template<class _Compare>
00273       ByArch<_Compare> byArch( const Arch & arch_r )
00274       { return byArch( arch_r, _Compare() ); }
00275 
00276 
00278 
00280     //
00281     // Some PoolItem attributes
00282     //
00284 
00286     typedef std::unary_function<PoolItem, bool> PoolItemFilterFunctor;
00287 
00289     struct ByInstalled : public PoolItemFilterFunctor
00290     {
00291       bool operator()( const PoolItem & p ) const
00292       {
00293         return p.status().isInstalled();
00294       }
00295 
00296     };
00297 
00299     struct ByUninstalled : public PoolItemFilterFunctor
00300     {
00301       bool operator()( const PoolItem & p ) const
00302       {
00303         return p.status().isUninstalled();
00304       }
00305     };
00306 
00308     struct ByTransact : public PoolItemFilterFunctor
00309     {
00310       bool operator()( const PoolItem & p ) const
00311       {
00312         return p.status().transacts();
00313       }
00314     };
00315 
00317     struct ByLock : public PoolItemFilterFunctor
00318     {
00319       bool operator()( const PoolItem & p ) const
00320       {
00321         return p.status().isLocked();
00322       }
00323     };
00324 
00326     struct ByKeep : public PoolItemFilterFunctor
00327     {
00328       bool operator()( const PoolItem & p ) const
00329       {
00330         return p.status().isKept();
00331       }
00332     };
00333 
00335     struct ByRecommended : public PoolItemFilterFunctor
00336     {
00337       bool operator()( const PoolItem & p ) const
00338       {
00339         return p.status().isRecommended();
00340       }
00341     };
00342 
00344     struct BySuggested : public PoolItemFilterFunctor
00345     {
00346       bool operator()( const PoolItem & p ) const
00347       {
00348         return p.status().isSuggested();
00349       }
00350     };
00351 
00353 
00354   } // namespace resfilter
00357 } // namespace zypp
00359 #endif // ZYPP_RESFILTERS_H