ref: refs/heads/master
commit c7f52310fc5179ec4be313751070d8ccafa8d5a8
Author: Michael Andres
Date: Thu Mar 26 15:57:53 2009 +0100
SolvIterMixin: Add default implementation for empty, size and contains.
---
zypp/sat/SolvIterMixin.cc | 13 +++++++++++++
zypp/sat/SolvIterMixin.h | 39 +++++++++++++++++++++++++++++++++++++++
zypp/sat/Solvable.h | 25 ++++++++++++++++++++++++-
zypp/sat/SolvableSet.h | 18 ++++++++++++++++++
4 files changed, 94 insertions(+), 1 deletions(-)
diff --git a/zypp/sat/SolvIterMixin.cc b/zypp/sat/SolvIterMixin.cc
index a10ac53..57bde4a 100644
--- a/zypp/sat/SolvIterMixin.cc
+++ b/zypp/sat/SolvIterMixin.cc
@@ -35,6 +35,19 @@ namespace zypp
}
}
+ ///////////////////////////////////////////////////////////////////
+ // asSolvable
+ ///////////////////////////////////////////////////////////////////
+ Solvable asSolvable::operator()( const PoolItem & pi_r ) const
+ {
+ return pi_r.satSolvable();
+ }
+
+ Solvable asSolvable::operator()( const ResObject_constPtr & res_r ) const
+ {
+ return res_r ? res_r->satSolvable() : Solvable();
+ }
+
/////////////////////////////////////////////////////////////////
} // namespace sat
///////////////////////////////////////////////////////////////////
diff --git a/zypp/sat/SolvIterMixin.h b/zypp/sat/SolvIterMixin.h
index 9bad52f..f5a79ff 100644
--- a/zypp/sat/SolvIterMixin.h
+++ b/zypp/sat/SolvIterMixin.h
@@ -18,10 +18,13 @@
#include "zypp/base/Iterator.h"
#include "zypp/base/Tr1hash.h"
+#include "zypp/sat/Solvable.h"
+
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
+ class PoolItem;
class asPoolItem; // transform functor
namespace ui
@@ -34,6 +37,7 @@ namespace zypp
{ /////////////////////////////////////////////////////////////////
class Solvable;
+ class asSolvable; // transform functor
namespace solvitermixin_detail
{
@@ -52,6 +56,8 @@ namespace zypp
{}
shared_ptr<Uset> _uset;
};
+
+
} // namespace solvitermixin_detail
@@ -67,6 +73,10 @@ namespace zypp
* \ref SolvIterMixin will then provide iterators over the corresponding
* \ref PoolItem and \ref ui::Selectable_Ptr.
*
+ * \ref SolvIterMixin will also provide default implementations for \ref empty
+ * and \ref size by iterating from \c begin to \c end. In case \c Derived is
+ * able to provide a more efficient implementation, the methods should be overloaded.
+ *
* \code
* namespace detail
* {
@@ -106,6 +116,35 @@ namespace zypp
class SolvIterMixin
{
public:
+ typedef size_t size_type;
+
+ public:
+ /** \name Convenience methods.
+ * In case \c Derived is able to provide a more efficient implementation,
+ * the methods should be overloaded.
+ */
+ //@{
+ /** Whether the collection is epmty. */
+ bool empty() const
+ { return( self().begin() == self().end() ); }
+
+ /** Size of the collection. */
+ size_type size() const
+ { size_type s = 0; for_( it, self().begin(), self().end() ) ++s; return s;}
+
+ /** Whether collection contains a specific \ref Solvable. */
+ template<class _Solv>
+ bool contains( const _Solv & solv_r ) const
+ {
+ Solvable solv( asSolvable()( solv_r ) );
+ for_( it, self().begin(), self().end() )
+ if ( *it == solv )
+ return true;
+ return false;
+ }
+ //@}
+
+ public:
/** \name Iterate as Solvable */
//@{
typedef DerivedSolvable_iterator Solvable_iterator;
diff --git a/zypp/sat/Solvable.h b/zypp/sat/Solvable.h
index e68cb17..d0bbd01 100644
--- a/zypp/sat/Solvable.h
+++ b/zypp/sat/Solvable.h
@@ -312,7 +312,7 @@ namespace zypp
} // namespace detail
///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
} // namespace sat
///////////////////////////////////////////////////////////////////
@@ -321,6 +321,29 @@ namespace zypp
inline bool isKind( const sat::Solvable & solvable_r )
{ return solvable_r.isKind( ResTraits<_Res>::kind ); }
+ class PoolItem;
+ ///////////////////////////////////////////////////////////////////
+ namespace sat
+ { /////////////////////////////////////////////////////////////////
+ /** To Solvable transform functor.
+ * \relates Solvable
+ * \relates sat::SolvIterMixin
+ */
+ struct asSolvable
+ {
+ typedef Solvable result_type;
+
+ Solvable operator()( Solvable solv_r ) const
+ { return solv_r; }
+
+ Solvable operator()( const PoolItem & pi_r ) const;
+
+ Solvable operator()( const ResObject_constPtr & res_r ) const;
+ };
+ /////////////////////////////////////////////////////////////////
+ } // namespace sat
+ ///////////////////////////////////////////////////////////////////
+
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
diff --git a/zypp/sat/SolvableSet.h b/zypp/sat/SolvableSet.h
index 74482ad..daa8ebd 100644
--- a/zypp/sat/SolvableSet.h
+++ b/zypp/sat/SolvableSet.h
@@ -63,6 +63,11 @@ namespace zypp
size_type size() const
{ return _pimpl->size(); }
+ /** */
+ template<class _Solv>
+ bool contains( const _Solv & solv_r ) const
+ { return( get().find( asSolvable()( solv_r ) ) != end() ); }
+
/** Iterator pointing to the first \ref Solvable. */
const_iterator begin() const
{ return _pimpl->begin(); }
@@ -72,10 +77,23 @@ namespace zypp
{ return _pimpl->end(); }
public:
+
+ /** Insert a Solvable.
+ * \return \c true if it was actually inserted, or \c false if already present.
+ */
+ template<class _Solv>
+ bool insert( const _Solv & solv_r )
+ { return get().insert( asSolvable()( solv_r ) ).second; }
+
+ public:
/** The set. */
Container & get()
{ return *_pimpl; }
+ /** The set. */
+ const Container & get() const
+ { return *_pimpl; }
+
private:
/** Pointer to implementation */
RWCOW_pointer<Container> _pimpl;
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org