Filter functors operating on ResObjects.
[Filters and Functors]

A simple filter is a function or functor matching the signature:. More...

Classes

struct  zypp::resfilter::ByKind
 Select ResObject by kind. More...
struct  zypp::resfilter::ByName
 Select ResObject by name. More...
struct  zypp::resfilter::ByRepository
 Select ResObject by repository or repository alias. More...
struct  zypp::resfilter::ByEdition< _Compare >
 Select ResObject by Edition using _Compare functor. More...
struct  zypp::resfilter::ByArch< _Compare >
 Select ResObject by Arch using _Compare functor. More...
struct  zypp::resfilter::ByInstalled
 Select PoolItem by installed. More...
struct  zypp::resfilter::ByUninstalled
 Select PoolItem by uninstalled. More...
struct  zypp::resfilter::ByTransact
 Select PoolItem by transact. More...
struct  zypp::resfilter::ByLock
 Select PoolItem by lock. More...
struct  zypp::resfilter::ByKeep
 Select PoolItem by keep. More...
struct  zypp::resfilter::ByCapabilityIndex
 Select ResObject if at least one Capability with index index_r was found in dependency depType_r. More...
struct  zypp::resfilter::ByCapMatch
 Select ResObject if at least one Capability with index index_r was found in dependency depType_r. More...
struct  zypp::resfilter::ByCaIUninstalled
 Select PoolItem by uninstalled. More...
struct  zypp::resfilter::ByCaIInstalled
 Select PoolItem by installed. More...
struct  zypp::resfilter::ByCaITransact
 Select PoolItem by transact. More...
struct  zypp::resfilter::ByCaINotTransact
 Select PoolItem by not transact. More...
struct  zypp::resfilter::ByCaIKind
 Select CapAndItem by kind. More...

Typedefs

typedef
std::unary_function
< ResObject::constPtr,
bool > 
zypp::resfilter::ResObjectFilterFunctor
typedef
boost::function
< bool(ResObject::constPtr)> 
zypp::resfilter::ResFilter
typedef
std::unary_function
< PoolItem, bool > 
zypp::resfilter::PoolItemFilterFunctor

Functions

template<class _Res>
ByKind zypp::resfilter::byKind ()
template<class _Compare>
ByEdition< _Compare > zypp::resfilter::byEdition (const Edition &edition_r, _Compare cmp_r)
template<class _Compare>
ByEdition< _Compare > zypp::resfilter::byEdition (const Edition &edition_r)
template<class _Compare>
ByArch< _Compare > zypp::resfilter::byArch (const Arch &arch_r, _Compare cmp_r)
template<class _Compare>
ByArch< _Compare > zypp::resfilter::byArch (const Arch &arch_r)
template<class _Res>
ByCaIKind zypp::resfilter::byCaIKind ()

Detailed Description

A simple filter is a function or functor matching the signature:.

   bool simplefilter( ResObject::Ptr );

Note:
It's not neccessary that your function or functor actually returns bool. Anything which is convertible into a bool will do;
Besides basic filter functors which actually evaluate the ResObject (e.g. ByKind, ByName) you may use Functors for building compex queries. to build more complex filters.

 // some 'action' functor, printing and counting
 // ResObjects.
 struct PrintAndCount
 {
   PrintAndCount( unsigned & counter_r )
   : _counter( counter_r )
   {}

   bool operator()( ResObject::Ptr p ) const
   {
     DBG << *p << endl;
     ++_counter;
     return true;
   }

   unsigned _counter;
 };

 ResStore store;
 unsigned counter = 0;

 // print and count all resolvables
 store.forEach( PrintAndCount(counter) );

 // print and count all resolvables named "kernel"
 counter = 0;
 store.forEach( ByName("kernel"), PrintAndCount(counter) );

 // print and count all Packages named "kernel"
 counter = 0;
 store.forEach( chain( ByKind(ResTraits<Package>::kind),
                       ByName("kernel") ),
                PrintAndCount(counter) );

 // print and count all Packages not named "kernel"
 counter = 0;
 store.forEach( chain( ByKind(ResTraits<Package>::kind),
                       not_c(ByName("kernel")) ),
                PrintAndCount(counter) );

 // same as above ;)
 counter = 0;
 store.forEach( chain( ByKind(ResTraits<Package>::kind),
                       chain( not_c(ByName("kernel")),
                              PrintAndCount(counter) ) ),
                true_c() );

As you can see in the last example there is no difference in using a filter or an action functor, as both have the same signature. A difference of course is the way forEach interprets the returned value.

Consequently you can netgate and chain actions as well. Thus PrintAndCount(counter) could be chain(Print(),Count(counter)), if these functors are provided.

Note:
These functors are not limited to be used with ResStore::forEach. You can use them with std::algorithms as well.

In case you already have functions or methods which do what you want, but thet don't perfectly match the required signature: Make yourself familiar with std::ptr_fun, mem_fun, bind1st, bind2nd and compose. They are sometimes quite helpfull.

PrintAndCount is an example how a functor can return data collected during the query. You ca easily write a collector, that takes a std:list<ResObject::Ptr>& and fills it with the matches found.

But as a rule of thumb, a functor should be lightweight. If you want to get data out, pass references to variables in (and assert these variables live as long as the query lasts). Or use FunctorRef.

Internally all functors are passed by value. Thus it would not help you to create an instance of some collecting functor, and pass it to the query. The query will then fill a copy of your functor, you won't get the data back. (Well, you probabely could, by using boosr::ref).

Why functors and not plain functions?

You can use plain functions if they don't have to deliver data back to the application. The C-style approach is having functions that take a void * data as last argument. This data pointer is then passed arround and casted up and down.

If you look at a functor, you'll see that it contains both, the function to call (it's operator() ) and the data you'd otherwise pass as void * data. That's nice and safe.


Typedef Documentation

typedef std::unary_function<ResObject::constPtr, bool> zypp::resfilter::ResObjectFilterFunctor

Definition at line 152 of file ResFilters.h.

typedef boost::function<bool ( ResObject::constPtr )> zypp::resfilter::ResFilter

Definition at line 153 of file ResFilters.h.

typedef std::unary_function<PoolItem, bool> zypp::resfilter::PoolItemFilterFunctor

Definition at line 302 of file ResFilters.h.


Function Documentation

template<class _Res>
ByKind zypp::resfilter::byKind (  )  [inline]

Definition at line 172 of file ResFilters.h.

template<class _Compare>
ByEdition<_Compare> zypp::resfilter::byEdition ( const Edition &  edition_r,
_Compare  cmp_r 
) [inline]

Definition at line 243 of file ResFilters.h.

Referenced by zypp::resfilter::byEdition(), and zypp::solver::detail::QueueItemRequire::process().

template<class _Compare>
ByEdition<_Compare> zypp::resfilter::byEdition ( const Edition &  edition_r  )  [inline]

Definition at line 248 of file ResFilters.h.

References zypp::resfilter::byEdition().

template<class _Compare>
ByArch<_Compare> zypp::resfilter::byArch ( const Arch &  arch_r,
_Compare  cmp_r 
) [inline]

Definition at line 284 of file ResFilters.h.

Referenced by zypp::resfilter::byArch().

template<class _Compare>
ByArch<_Compare> zypp::resfilter::byArch ( const Arch &  arch_r  )  [inline]

Definition at line 289 of file ResFilters.h.

References zypp::resfilter::byArch().

template<class _Res>
ByCaIKind zypp::resfilter::byCaIKind (  )  [inline]

Definition at line 436 of file ResFilters.h.


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