#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/CapAndItem.h"
+#include "zypp/Repository.h"
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
- class Repository;
///////////////////////////////////////////////////////////////////
namespace resfilter
{ /////////////////////////////////////////////////////////////////
*
* // 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;
typedef boost::function<bool ( ResObject::constPtr )> ResFilter;
- /** 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;
- };
-
/** */
- template<class _Res>
- inline ByKind byKind()
- { return ByKind( ResTraits<_Res>::kind ); }
+ template<class TRes>
+ inline filter::ByKind byKind()
+ { return filter::ByKind( ResTraits<TRes>::kind ); }
/** Select ResObject by name. */
struct ByName : public ResObjectFilterFunctor
{
+ ByName()
+ {}
+
ByName( const std::string & name_r )
: _name( name_r )
{}
std::string _name;
};
-
/** Select ResObject by repository or repository alias. */
struct ByRepository : public ResObjectFilterFunctor
{
std::string _alias;
};
-
- /** Select ResObject by Edition using \a _Compare functor.
+ /** Select ResObject by Edition using \a TCompare functor.
*
- * Selects ResObject if <tt>_Compare( ResObject->edition(), _edition )</tt>
+ * Selects ResObject if <tt>TCompare( ResObject->edition(), _edition )</tt>
* is \c true.
* \code
* // use the convenience funktions to create ByEdition:
* byEdition( someedition, CompareByGT<Edition>() ) // edition > someedition
* \endcode
*/
- template<class _Compare = CompareByEQ<Edition> >
+ template<class TCompare = CompareByEQ<Edition> >
struct ByEdition : public ResObjectFilterFunctor
{
- ByEdition( const Edition & edition_r,
- _Compare cmp_r )
+ ByEdition( const Edition & edition_r, TCompare cmp_r )
: _edition( edition_r )
, _cmp( cmp_r )
{}
}
Edition _edition;
- _Compare _cmp;
+ TCompare _cmp;
};
/** */
- template<class _Compare>
- ByEdition<_Compare> byEdition( const Edition & edition_r, _Compare cmp_r )
- { return ByEdition<_Compare>( edition_r, cmp_r ); }
+ template<class TCompare>
+ ByEdition<TCompare> byEdition( const Edition & edition_r, TCompare cmp_r )
+ { return ByEdition<TCompare>( edition_r, cmp_r ); }
/** */
- template<class _Compare>
- ByEdition<_Compare> byEdition( const Edition & edition_r )
- { return byEdition( edition_r, _Compare() ); }
+ template<class TCompare>
+ ByEdition<TCompare> byEdition( const Edition & edition_r )
+ { return byEdition( edition_r, TCompare() ); }
- /** Select ResObject by Arch using \a _Compare functor.
+ /** Select ResObject by Arch using \a TCompare functor.
*
- * Selects ResObject if <tt>_Compare( ResObject->arch(), _arch )</tt>
+ * Selects ResObject if <tt>TCompare( ResObject->arch(), _arch )</tt>
* is \c true.
* \code
* // use the convenience funktions to create ByArch:
* byArch( somearch, CompareByGT<Arch>() ) // arch > somearch
* \endcode
*/
- template<class _Compare = CompareByEQ<Arch> >
+ template<class TCompare = CompareByEQ<Arch> >
struct ByArch : public ResObjectFilterFunctor
{
- ByArch( const Arch & arch_r,
- _Compare cmp_r )
+ ByArch( const Arch & arch_r, TCompare cmp_r )
: _arch( arch_r )
, _cmp( cmp_r )
{}
}
Arch _arch;
- _Compare _cmp;
+ TCompare _cmp;
};
/** */
- template<class _Compare>
- ByArch<_Compare> byArch( const Arch & arch_r, _Compare cmp_r )
- { return ByArch<_Compare>( arch_r, cmp_r ); }
+ template<class TCompare>
+ ByArch<TCompare> byArch( const Arch & arch_r, TCompare cmp_r )
+ { return ByArch<TCompare>( arch_r, cmp_r ); }
/** */
- template<class _Compare>
- ByArch<_Compare> byArch( const Arch & arch_r )
- { return byArch( arch_r, _Compare() ); }
+ template<class TCompare>
+ ByArch<TCompare> byArch( const Arch & arch_r )
+ { return byArch( arch_r, TCompare() ); }
///////////////////////////////////////////////////////////////////
{
return p.status().isInstalled();
}
-
};
/** Select PoolItem by uninstalled. */
}
};
-
-
- ///////////////////////////////////////////////////////////////////
-
- /** Select ResObject if at least one Capability with
- * index \a index_r was found in dependency \a depType_r.
- */
- struct ByCapabilityIndex
- {
- bool operator()( const CapAndItem & /*cai*/ ) const
- {
- return true; // its all in the PoolImpl !
- }
- };
-
-
- /** Select ResObject if at least one Capability with
- * index \a index_r was found in dependency \a depType_r.
- */
- struct ByCapMatch
- {
- bool operator()( const CapAndItem & cai ) const
- {
- return cai.cap.matches( _cap ) == CapMatch::yes;
- }
- ByCapMatch( const Capability & cap_r )
- : _cap( cap_r )
- {}
- Capability _cap;
- };
-
-
- /** Select PoolItem by uninstalled. */
- struct ByCaIUninstalled
- {
- bool operator()( const CapAndItem & cai ) const
- {
- return cai.item.status().isUninstalled();
- }
- };
-
- /** Select PoolItem by installed. */
- struct ByCaIInstalled
- {
- bool operator()( const CapAndItem & cai ) const
- {
- return cai.item.status().isInstalled();
- }
- };
-
- /** Select PoolItem by transact. */
- struct ByCaITransact
+ /** PoolItem which is recommended. */
+ struct ByRecommended : public PoolItemFilterFunctor
{
- bool operator()( const CapAndItem & cai ) const
- {
- return cai.item.status().transacts();
- }
- };
-
- /** Select PoolItem by not transact. */
- struct ByCaINotTransact
- {
- bool operator()( const CapAndItem & cai ) const
+ bool operator()( const PoolItem & p ) const
{
- return !(cai.item.status().transacts());
+ return p.status().isRecommended();
}
};
-
- /** Select CapAndItem by kind. */
- struct ByCaIKind
+ /** PoolItem which is suggested. */
+ struct BySuggested : public PoolItemFilterFunctor
{
- ByCaIKind( const ResObject::Kind & kind_r )
- : _kind( kind_r )
- {}
-
- bool operator()( const CapAndItem & cai ) const
+ bool operator()( const PoolItem & p ) const
{
- return cai.item->kind() == _kind;
+ return p.status().isSuggested();
}
-
- ResObject::Kind _kind;
};
- /** */
- template<class _Res>
- inline ByCaIKind byCaIKind()
- { return ByCaIKind( ResTraits<_Res>::kind ); }
-
- ///////////////////////////////////////////////////////////////////
-
//@}
/////////////////////////////////////////////////////////////////
} // namespace resfilter