Author: mlandres
Date: Mon Feb 11 14:08:25 2008
New Revision: 8606
URL: http://svn.opensuse.org/viewcvs/zypp?rev=8606&view=rev
Log:
Add pool byIdent iterator: Iterate over all items of a given name and kind.
This is faster than iterating by name and filtering by kind.
Modified:
branches/tmp/ma/jump_sat/libzypp/zypp/ResPool.h
branches/tmp/ma/jump_sat/libzypp/zypp/base/String.h
branches/tmp/ma/jump_sat/libzypp/zypp/pool/PoolTraits.h
Modified: branches/tmp/ma/jump_sat/libzypp/zypp/ResPool.h
URL: http://svn.opensuse.org/viewcvs/zypp/branches/tmp/ma/jump_sat/libzypp/zypp/ResPool.h?rev=8606&r1=8605&r2=8606&view=diff
==============================================================================
--- branches/tmp/ma/jump_sat/libzypp/zypp/ResPool.h (original)
+++ branches/tmp/ma/jump_sat/libzypp/zypp/ResPool.h Mon Feb 11 14:08:25 2008
@@ -51,7 +51,7 @@
public:
/** \ref PoolItem */
typedef PoolItem value_type;
- typedef pool::PoolTraits::size_type size_type;
+ typedef pool::PoolTraits::size_type size_type;
typedef pool::PoolTraits::const_iterator const_iterator;
typedef pool::PoolTraits::byCapabilityIndex_iterator byCapabilityIndex_iterator;
@@ -78,7 +78,7 @@
/** */
size_type size() const;
- /** \name Iterate through all ResObjects (all kinds). */
+ /** \name Iterate through all PoolItems (all kinds). */
//@{
/** */
const_iterator begin() const
@@ -97,7 +97,7 @@
PoolItem find( const sat::Solvable & slv_r ) const;
public:
- /** \name Iterate through all ResObjects of a certain name and kind. */
+ /** \name Iterate through all PoolItems matching a \c _Filter. */
//@{
template<class _Filter>
filter_iterator<_Filter,const_iterator> filterBegin( const _Filter & filter_r ) const
@@ -109,6 +109,42 @@
//@}
public:
+ /** \name Iterate through all PoolItems of a certain name and kind. */
+ //@{
+ typedef pool::ByIdent ByIdent;
+ typedef filter_iterator byIdent_iterator;
+
+ byIdent_iterator byIdentBegin( ResKind kind_r, IdString name_r ) const
+ { return make_filter_begin( ByIdent(kind_r,name_r), *this ); }
+
+ byIdent_iterator byIdentBegin( ResKind kind_r, const C_Str & name_r ) const
+ { return make_filter_begin( ByIdent(kind_r,name_r), *this ); }
+
+ template<class _Res>
+ byIdent_iterator byIdentBegin( IdString name_r ) const
+ { return make_filter_begin( ByIdent(ResTraits<_Res>::kind,name_r), *this ); }
+
+ template<class _Res>
+ byIdent_iterator byIdentBegin( const C_Str & name_r ) const
+ { return make_filter_begin( ByIdent(ResTraits<_Res>::kind,name_r), *this ); }
+
+
+ byIdent_iterator byIdentEnd( ResKind kind_r, IdString name_r ) const
+ { return make_filter_end( ByIdent(kind_r,name_r), *this ); }
+
+ byIdent_iterator byIdentEnd( ResKind kind_r, const C_Str & name_r ) const
+ { return make_filter_end( ByIdent(kind_r,name_r), *this ); }
+
+ template<class _Res>
+ byIdent_iterator byIdentEnd( IdString name_r ) const
+ { return make_filter_end( ByIdent(ResTraits<_Res>::kind,name_r), *this ); }
+
+ template<class _Res>
+ byIdent_iterator byIdentEnd( const C_Str & name_r ) const
+ { return make_filter_end( ByIdent(ResTraits<_Res>::kind,name_r), *this ); }
+ //@}
+
+ public:
/** \name Iterate through all ResObjects of a certain kind. */
//@{
typedef zypp::resfilter::ByKind ByKind;
Modified: branches/tmp/ma/jump_sat/libzypp/zypp/base/String.h
URL: http://svn.opensuse.org/viewcvs/zypp/branches/tmp/ma/jump_sat/libzypp/zypp/base/String.h?rev=8606&r1=8605&r2=8606&view=diff
==============================================================================
--- branches/tmp/ma/jump_sat/libzypp/zypp/base/String.h (original)
+++ branches/tmp/ma/jump_sat/libzypp/zypp/base/String.h Mon Feb 11 14:08:25 2008
@@ -89,6 +89,10 @@
mutable size_type _sze;
};
+ /** \relates C_Str Stream output */
+ inline std::ostream & operator<<( std::ostream & str, const C_Str & obj )
+ { return str << obj.c_str(); }
+
///////////////////////////////////////////////////////////////////
/** String related utilities and \ref ZYPP_STR_REGEX.
\see \ref ZYPP_STR_REGEX
Modified: branches/tmp/ma/jump_sat/libzypp/zypp/pool/PoolTraits.h
URL: http://svn.opensuse.org/viewcvs/zypp/branches/tmp/ma/jump_sat/libzypp/zypp/pool/PoolTraits.h?rev=8606&r1=8605&r2=8606&view=diff
==============================================================================
--- branches/tmp/ma/jump_sat/libzypp/zypp/pool/PoolTraits.h (original)
+++ branches/tmp/ma/jump_sat/libzypp/zypp/pool/PoolTraits.h Mon Feb 11 14:08:25 2008
@@ -33,12 +33,67 @@
class PoolImpl;
+ /** Pool internal filter skiping invalid/unwanted PoolItems. */
struct ByPoolItem
{
bool operator()( const PoolItem & pi ) const
{ return pi; }
};
+ /** Main filter selecting PoolItems bu \c name and \c kind. */
+ class ByIdent //: public ResObjectFilterFunctor
+ {
+ public:
+ ByIdent( ResKind kind_r, IdString name_r )
+ : _id( makeIdent( kind_r, name_r ) )
+ {}
+
+ ByIdent( ResKind kind_r, const C_Str & name_r )
+ : _id( makeIdent( kind_r, name_r ) )
+ {}
+
+ public:
+ bool operator()( sat::Solvable slv_r ) const
+ {
+ return _id >= 0 ? ( slv_r.ident().id() == _id && ! slv_r.isKind( ResKind::srcpackage ) )
+ : ( slv_r.ident().id() == -_id && slv_r.isKind( ResKind::srcpackage ) );
+ }
+
+ bool operator()( const PoolItem & pi_r ) const
+ { return operator()( pi_r.satSolvable() ); }
+
+ bool operator()( ResObject::constPtr p_r ) const
+ { return p_r ? operator()( p_r->satSolvable() ) : !_id; }
+
+ private:
+ sat::detail::IdType makeIdent( ResKind kind_r, IdString name_r )
+ {
+ if ( kind_r == ResKind::package )
+ return name_r.id();
+ else if ( kind_r == ResKind::srcpackage )
+ return -name_r.id();
+ return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
+ }
+
+ sat::detail::IdType makeIdent( ResKind kind_r, const C_Str & name_r )
+ {
+ if ( kind_r == ResKind::package )
+ return IdString( name_r ).id();
+ else if ( kind_r == ResKind::srcpackage )
+ return -(IdString( name_r ).id());
+ return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
+ }
+
+ public:
+ sat::detail::IdType get() const { return _id; }
+
+ private:
+ /** negative \c _id for \c srcpackage, as they use the same \c ident
+ * as \c package.
+ */
+ sat::detail::IdType _id;
+ };
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : PoolTraits
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org