From a1b0f7bc362faf190be66887cf6f94bdfee5eaa0 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Mon, 11 Feb 2008 13:08:25 +0000 Subject: [PATCH] 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. --- zypp/ResPool.h | 42 +++++++++++++++++++++++++++++++++++--- zypp/base/String.h | 4 ++++ zypp/pool/PoolTraits.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 3 deletions(-) diff --git a/zypp/ResPool.h b/zypp/ResPool.h index 680ea5f..af1f997 100644 --- a/zypp/ResPool.h +++ b/zypp/ResPool.h @@ -51,7 +51,7 @@ namespace zypp 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 @@ namespace zypp /** */ 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 @@ namespace zypp 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 filter_iterator<_Filter,const_iterator> filterBegin( const _Filter & filter_r ) const @@ -109,6 +109,42 @@ namespace zypp //@} 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 + byIdent_iterator byIdentBegin( IdString name_r ) const + { return make_filter_begin( ByIdent(ResTraits<_Res>::kind,name_r), *this ); } + + template + 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 + byIdent_iterator byIdentEnd( IdString name_r ) const + { return make_filter_end( ByIdent(ResTraits<_Res>::kind,name_r), *this ); } + + template + 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; diff --git a/zypp/base/String.h b/zypp/base/String.h index d69b170..7b10138 100644 --- a/zypp/base/String.h +++ b/zypp/base/String.h @@ -89,6 +89,10 @@ namespace zypp 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 diff --git a/zypp/pool/PoolTraits.h b/zypp/pool/PoolTraits.h index 4f99546..e5aa31a 100644 --- a/zypp/pool/PoolTraits.h +++ b/zypp/pool/PoolTraits.h @@ -33,12 +33,67 @@ namespace zypp 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 -- 2.7.4