ref: refs/heads/master
commit 30b05371be7cc64a2adf08a6ee1009842a4775ec
Author: Michael Andres
Date: Mon Oct 19 16:13:11 2009 +0200
Add byStatusBegin/End iterator to ResPool.
---
zypp/Filter.h | 32 ++++++++++++++++++++++++++++++++
zypp/ResPool.h | 26 ++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/zypp/Filter.h b/zypp/Filter.h
index 826e157..f19e9c5 100644
--- a/zypp/Filter.h
+++ b/zypp/Filter.h
@@ -131,6 +131,38 @@ namespace zypp
///////////////////////////////////////////////////////////////////
//
+ // CLASS NAME : ByStatus
+ //
+ /** Filter solvables according to their status.
+ */
+ class ByStatus
+ {
+ public:
+ typedef bool (ResStatus::*Predicate)() const;
+
+ public:
+ ByStatus( Predicate pred_r )
+ : _pred( pred_r )
+ {}
+
+ public:
+ /** Filter on \ref PoolItem. */
+ bool operator()( const PoolItem & pi_r ) const
+ { return (pi_r.status().*_pred)(); }
+
+ /** Filter fitting sat::Solvable/ResObject. */
+ template<class _Solv>
+ bool operator()( const _Solv & solv_r ) const
+ { return operator()( PoolItem(solv_r) ); }
+
+ private:
+ Predicate _pred;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+
+ ///////////////////////////////////////////////////////////////////
+ //
// CLASS NAME : SameItemAs
//
/** Filter items with at least same NVRA, vendor.
diff --git a/zypp/ResPool.h b/zypp/ResPool.h
index 76e4baa..2657598 100644
--- a/zypp/ResPool.h
+++ b/zypp/ResPool.h
@@ -108,6 +108,32 @@ namespace zypp
{ return make_filter_end( filter_r, *this ); }
//@}
+ /** \name Iterate over all PoolItems by status.
+ *
+ * Simply pass the \ref ResStatus predicate you want to use as filter:
+ * \code
+ * // iterate over all orphaned items:
+ * for_( it, pool.byStatusBegin(&ResStatus::isOrphaned), pool.byStatusEnd(&ResStatus::isOrphaned) )
+ * {...}
+ * \endcode
+ *
+ * Or use \ref filter::ByStatus in more complex queries:
+ * \code
+ * // iterate over all (orphaned and recommended) items:
+ * functor::Chainfilter::ByStatus,filter::ByStatus myfilter( filter::ByStatus(&ResStatus::isOrphaned),
+ * filter::ByStatus(&ResStatus::isRecommended) );
+ * for_( it, pool.filterBegin(myfilter), pool.filterEnd(myfilter) )
+ * { ... }
+ * \endcode
+ */
+ //@{
+ filter_iteratorfilter::ByStatus,const_iterator byStatusBegin( const filter::ByStatus & filter_r ) const
+ { return make_filter_begin( filter_r, *this ); }
+
+ filter_iteratorfilter::ByStatus,const_iterator byStatusEnd( const filter::ByStatus & filter_r ) const
+ { return make_filter_end( filter_r, *this ); }
+ //@}
+
public:
/** \name Iterate over all PoolItems of a certain name and kind. */
//@{
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org