#ifndef ZYPP_RESFILTERS_H
#define ZYPP_RESFILTERS_H
+#include <boost/function.hpp>
+
#include "zypp/base/Functional.h"
+#include "zypp/Filter.h"
#include "zypp/Resolvable.h"
-#include "zypp/CapFilters.h"
#include "zypp/PoolItem.h"
+#include "zypp/Repository.h"
///////////////////////////////////////////////////////////////////
namespace zypp
* return true;
* }
*
- * unsigned & _counter;
+ * unsigned _counter;
* };
*
* ResStore store;
*
* // print and count all Packages named "kernel"
* counter = 0;
- * store.forEach( chain( ByKind(ResTraits<Package>::kind),
+ * store.forEach( chain( ByKind(ResKind::package),
* ByName("kernel") ),
* PrintAndCount(counter) );
*
* // print and count all Packages not named "kernel"
* counter = 0;
- * store.forEach( chain( ByKind(ResTraits<Package>::kind),
+ * store.forEach( chain( ByKind(ResKind::package),
* not_c(ByName("kernel")) ),
* PrintAndCount(counter) );
*
* // same as above ;)
* counter = 0;
- * store.forEach( chain( ByKind(ResTraits<Package>::kind),
+ * store.forEach( chain( ByKind(ResKind::package),
* chain( not_c(ByName("kernel")),
* PrintAndCount(counter) ) ),
* true_c() );
* If you look at a functor, you'll see that it contains both, the function
* to call (it's <tt>operator()</tt> ) and the data you'd otherwise pass as
* <tt>void * data</tt>. That's nice and safe.
+ *
+ * \todo migrate to namespace filter and enhance to support Solvables as well.
*/
//@{
///////////////////////////////////////////////////////////////////
/** */
typedef std::unary_function<ResObject::constPtr, bool> ResObjectFilterFunctor;
-
- /** Select ResObject by kind. */
- struct ByKind : public ResObjectFilterFunctor
- {
- ByKind( const ResObject::Kind & kind_r )
- : _kind( kind_r )
- {}
-
- bool operator()( ResObject::constPtr p ) const
- {
- return p->kind() == _kind;
- }
-
- ResObject::Kind _kind;
- };
+ typedef boost::function<bool ( ResObject::constPtr )> ResFilter;
/** */
template<class _Res>
- inline ByKind byKind()
- { return ByKind( ResTraits<_Res>::kind ); }
+ inline filter::ByKind byKind()
+ { return filter::ByKind( ResTraits<_Res>::kind ); }
/** Select ResObject by name. */
struct ByName : public ResObjectFilterFunctor
std::string _name;
};
+ /** Select ResObject by repository or repository alias. */
+ struct ByRepository : public ResObjectFilterFunctor
+ {
+ ByRepository( Repository repository_r )
+ : _alias( repository_r.info().alias() )
+ {}
+
+ ByRepository( const std::string & alias_r )
+ : _alias( alias_r )
+ {}
+
+ bool operator()( ResObject::constPtr p ) const
+ {
+ return p->repoInfo().alias() == _alias;
+ }
+
+ std::string _alias;
+ };
/** Select ResObject by Edition using \a _Compare functor.
*
- * Selects ResObject if <tt>_Compare( ResObject->edition(), _edition )<\tt>
+ * Selects ResObject if <tt>_Compare( ResObject->edition(), _edition )</tt>
* is \c true.
* \code
* // use the convenience funktions to create ByEdition:
{ return byEdition( edition_r, _Compare() ); }
- /** Select ResObject if at least one Capability with
- * index \a index_r was found in dependency \a depType_r.
+ /** Select ResObject by Arch using \a _Compare functor.
+ *
+ * Selects ResObject if <tt>_Compare( ResObject->arch(), _arch )</tt>
+ * is \c true.
+ * \code
+ * // use the convenience funktions to create ByArch:
+ *
+ * byArch( somearch ); // selects ResObjects with arch == somearch
+ *
+ * byArch( somearch, CompareByGT<Arch>() ) // arch > somearch
+ * \endcode
*/
- struct ByCapabilityIndex : public ResObjectFilterFunctor
- {
- ByCapabilityIndex( const std::string & index_r, Dep depType_r )
- : _dep( depType_r )
- , _index( index_r )
- {}
- ByCapabilityIndex( const Capability & cap_r, Dep depType_r )
- : _dep( depType_r )
- , _index( cap_r.index() )
- {}
+ template<class _Compare = CompareByEQ<Arch> >
+ struct ByArch : public ResObjectFilterFunctor
+ {
+ ByArch( const Arch & arch_r,
+ _Compare cmp_r )
+ : _arch( arch_r )
+ , _cmp( cmp_r )
+ {}
- bool operator()( ResObject::constPtr p ) const
+ bool operator()( ResObject::constPtr p ) const
+ {
+ return _cmp( p->arch(), _arch );
+ }
+
+ Arch _arch;
+ _Compare _cmp;
+ };
+
+ /** */
+ template<class _Compare>
+ ByArch<_Compare> byArch( const Arch & arch_r, _Compare cmp_r )
+ { return ByArch<_Compare>( arch_r, cmp_r ); }
+
+ /** */
+ template<class _Compare>
+ ByArch<_Compare> byArch( const Arch & arch_r )
+ { return byArch( arch_r, _Compare() ); }
+
+
+ ///////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // Some PoolItem attributes
+ //
+ ///////////////////////////////////////////////////////////////////
+
+ /** */
+ typedef std::unary_function<PoolItem, bool> PoolItemFilterFunctor;
+
+ /** Select PoolItem by installed. */
+ struct ByInstalled : public PoolItemFilterFunctor
+ {
+ bool operator()( const PoolItem & p ) const
{
- using capfilter::ByIndex;
- return( make_filter_begin( ByIndex(_index), p->dep( _dep ) )
- != make_filter_end( ByIndex(_index), p->dep( _dep ) ) );
+ return p.status().isInstalled();
}
- Dep _dep;
- std::string _index;
};
- ///////////////////////////////////////////////////////////////////
+ /** Select PoolItem by uninstalled. */
+ struct ByUninstalled : public PoolItemFilterFunctor
+ {
+ bool operator()( const PoolItem & p ) const
+ {
+ return p.status().isUninstalled();
+ }
+ };
- typedef std::binary_function<PoolItem,Capability,
- bool> OnCapMatchCallbackFunctor;
+ /** Select PoolItem by transact. */
+ struct ByTransact : public PoolItemFilterFunctor
+ {
+ bool operator()( const PoolItem & p ) const
+ {
+ return p.status().transacts();
+ }
+ };
- /** Find matching Capabilities in a ResObjects dependency and invoke a
- * callback on matches.
- *
- * Iterates through the PoolItem (in fact the ResObject it holds)
- * CapSet denoted by \a dep_r. For each Capability matching the
- * provided \a cap_r the callback functor \a fnc_r is called with
- * the PoolItem and the PoolItem's matching Capability.
- *
- * \returns \c true, unless an invokation of the callback functor
- * returned \c false.
- *
- * \todo Unfortunately a pure PoolItem Filter, but woud be usefull with
- * plain ResObjects too. But the Solver urgently needs the PoolItem in
- * the OnCapMatchCallback.
- */
- template<class _OnCapMatchCallback>
- struct CallOnCapMatchIn
+ /** Select PoolItem by lock. */
+ struct ByLock : public PoolItemFilterFunctor
+ {
+ bool operator()( const PoolItem & p ) const
{
- bool operator()( const PoolItem & p ) const
- {
- const CapSet & depSet( p->dep( _dep ) ); // dependency set in p to iterate
- capfilter::ByCapMatch matching( _cap ); // predicate: true if match with _cap
-
- int res
- = invokeOnEach( depSet.begin(), depSet.end(), // iterate this set
- matching, // Filter: if match
- std::bind1st(_fnc,p) ); // Action: invoke _fnc(p,match)
- // Maybe worth to note: Filter and Action are invoked with the same
- // iterator, thus Action will use the same capability that cause
- // the match in Filter.
- return ( res >= 0 );
- }
+ return p.status().isLocked();
+ }
+ };
- CallOnCapMatchIn( Dep dep_r, const Capability & cap_r,
- _OnCapMatchCallback fnc_r )
- : _dep( dep_r )
- , _cap( cap_r )
- , _fnc( fnc_r )
- {}
- Dep _dep;
- const Capability & _cap;
- _OnCapMatchCallback _fnc;
- };
+ /** Select PoolItem by keep. */
+ struct ByKeep : public PoolItemFilterFunctor
+ {
+ bool operator()( const PoolItem & p ) const
+ {
+ return p.status().isKept();
+ }
+ };
- /** */
- template<class _OnCapMatchCallback>
- inline CallOnCapMatchIn<_OnCapMatchCallback>
- callOnCapMatchIn( Dep dep_r, const Capability & cap_r,
- _OnCapMatchCallback fnc_r )
+ /** PoolItem which is recommended. */
+ struct ByRecommended : public PoolItemFilterFunctor
+ {
+ bool operator()( const PoolItem & p ) const
{
- return CallOnCapMatchIn<_OnCapMatchCallback>( dep_r, cap_r, fnc_r );
+ return p.status().isRecommended();
}
+ };
- ///////////////////////////////////////////////////////////////////
+ /** PoolItem which is suggested. */
+ struct BySuggested : public PoolItemFilterFunctor
+ {
+ bool operator()( const PoolItem & p ) const
+ {
+ return p.status().isSuggested();
+ }
+ };
//@}
/////////////////////////////////////////////////////////////////