From: Michael Andres Date: Fri, 11 Apr 2008 10:51:59 +0000 (+0000) Subject: - Fix SolvIterMixin to avioid multiple visits of the same Selectable. X-Git-Tag: BASE-SuSE-Linux-11_0-Branch~283 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=41a6ddf51d5b5fe5cfb86d14b792de25b80afc2b;p=platform%2Fupstream%2Flibzypp.git - Fix SolvIterMixin to avioid multiple visits of the same Selectable. - Add Resolvable::poolItem() providing access to the corresponding PoolItem. API to query isRelevant/isSatisfied/isBroken was moved to PoolItem. --- diff --git a/zypp/PoolItem.cc b/zypp/PoolItem.cc index 4850edb..2d851f8 100644 --- a/zypp/PoolItem.cc +++ b/zypp/PoolItem.cc @@ -54,20 +54,20 @@ namespace zypp public: - bool isSatisfied() const + bool isRelevant() const { - return _resolvable->isSatisfied(); + return true; } - bool isRelevant() const + bool isSatisfied() const { - return _resolvable->isRelevant(); + return true; } - bool validate() const + bool isBroken() const { - return _resolvable->validate(); - } + return true; + } private: mutable ResStatus _status; @@ -194,11 +194,14 @@ namespace zypp ResStatus & PoolItem::statusReset() const { return _pimpl->statusReset(); } + bool PoolItem::isRelevant() const + { return _pimpl->isSatisfied(); } + bool PoolItem::isSatisfied() const { return _pimpl->isSatisfied(); } - ResObject::constPtr PoolItem::resolvable() const - { return _pimpl->resolvable(); } + bool PoolItem::isBroken() const + { return _pimpl->isSatisfied(); } void PoolItem::saveState() const { _pimpl->saveState(); } @@ -209,6 +212,9 @@ namespace zypp bool PoolItem::sameState() const { return _pimpl->sameState(); } + ResObject::constPtr PoolItem::resolvable() const + { return _pimpl->resolvable(); } + /****************************************************************** ** ** FUNCTION NAME : operator<< diff --git a/zypp/PoolItem.h b/zypp/PoolItem.h index acfc1e7..c01bade 100644 --- a/zypp/PoolItem.h +++ b/zypp/PoolItem.h @@ -69,30 +69,32 @@ namespace zypp ~PoolItem(); public: + /** \name Status related methods. */ + //@{ /** Returns the current status. */ ResStatus & status() const; /** Reset status. */ ResStatus & statusReset() const; - /** Whether the items requirements are met. */ - bool isSatisfied() const; - - /** Whether the items requirements are broken. */ - bool isBroken() const - { return ! isSatisfied(); } - /** Returns true if the solvable is relevant which means e.G. for patches + /** \name Status validation. + * + */ + //@{ + /** Returns true if the solvable is relevant which means e.g. for patches * that at least one package of the patch is installed. */ bool isRelevant() const; - /** Check if the solvable is satisfied,broken or not relevant - * (not important, so it can be ignored) - * \return BROKEN, SATISFIED, NOTRELEVANT - */ - ValidValue validate() const; + /** Whether a relevant items requirements are met. */ + bool isSatisfied() const; + /** Whether a relevant items requirements are broken. */ + bool isBroken() const; + //@} + + //@} public: /** Return the \ref ResPool the item belongs to. */ ResPool pool() const; diff --git a/zypp/Resolvable.cc b/zypp/Resolvable.cc index 628801e..aa8ccad 100644 --- a/zypp/Resolvable.cc +++ b/zypp/Resolvable.cc @@ -11,7 +11,8 @@ */ #include "zypp/Resolvable.h" #include "zypp/ResObject.h" - +#include "zypp/PoolItem.h" + /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// @@ -37,6 +38,14 @@ namespace zypp /////////////////////////////////////////////////////////////////// // + // METHOD NAME : Resolvable::poolItem + // METHOD TYPE : PoolItem + // + PoolItem Resolvable::poolItem() const + { return PoolItem( *this ); } + + /////////////////////////////////////////////////////////////////// + // // METHOD NAME : Resolvable::dumpOn // METHOD TYPE : std::ostream & // diff --git a/zypp/Resolvable.h b/zypp/Resolvable.h index 1be9cb1..f45348f 100644 --- a/zypp/Resolvable.h +++ b/zypp/Resolvable.h @@ -30,6 +30,7 @@ namespace zypp { ///////////////////////////////////////////////////////////////// struct NVRAD; + class PoolItem; /////////////////////////////////////////////////////////////////// // @@ -82,26 +83,12 @@ namespace zypp //@} public: - /** Returns true if the solvable is satisfied */ - using sat::Solvable::isSatisfied; - - /** Returns true if the solvable is satisfied */ - using sat::Solvable::isBroken; - - /** Returns true if the solvable is relevant which means e.G. for patches - * that at least one package of the patch is installed. - */ - using sat::Solvable::isRelevant; - - /** Check if the solvable is satisfied,broken or not relevant - * (not important, so it can be ignored) - * \return BROKEN, SATISFIED, NOTRELEVANT - */ - using sat::Solvable::validate; - - public: + /** Access the corresponding \ref sat:::Solvable. */ const sat::Solvable & satSolvable() const { return *this; } + /** Access the corresponding \ref PoolItem. */ + PoolItem poolItem() const; + protected: /** Ctor */ Resolvable( const sat::Solvable & solvable_r ); diff --git a/zypp/sat/SolvIterMixin.cc b/zypp/sat/SolvIterMixin.cc index cece2e5..7d2340a 100644 --- a/zypp/sat/SolvIterMixin.cc +++ b/zypp/sat/SolvIterMixin.cc @@ -13,6 +13,7 @@ //#include "zypp/base/Logger.h" #include "zypp/sat/SolvIterMixin.h" +#include "zypp/sat/Solvable.h" #include "zypp/ResPoolProxy.h" using std::endl; @@ -21,13 +22,29 @@ using std::endl; namespace zypp { ///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// - namespace ui + namespace sat { ///////////////////////////////////////////////////////////////// - Selectable_Ptr asSelectable::operator()( const sat::Solvable & sov_r ) const + namespace solvitermixin_detail + { + bool UnifyByIdent::operator()( const Solvable & solv_r ) const { - return ResPool::instance().proxy().lookup( sov_r ); + return( solv_r && _uset->insert( solv_r.ident().id() ).second ); } + } + + ///////////////////////////////////////////////////////////////// + } // namespace sat + /////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + namespace ui + { ///////////////////////////////////////////////////////////////// + + Selectable_Ptr asSelectable::operator()( const sat::Solvable & sov_r ) const + { + return ResPool::instance().proxy().lookup( sov_r ); + } ///////////////////////////////////////////////////////////////// } // namespace ui diff --git a/zypp/sat/SolvIterMixin.h b/zypp/sat/SolvIterMixin.h index bd060b9..9bad52f 100644 --- a/zypp/sat/SolvIterMixin.h +++ b/zypp/sat/SolvIterMixin.h @@ -16,6 +16,7 @@ #include "zypp/base/PtrTypes.h" #include "zypp/base/Iterator.h" +#include "zypp/base/Tr1hash.h" /////////////////////////////////////////////////////////////////// namespace zypp @@ -34,6 +35,26 @@ namespace zypp class Solvable; + namespace solvitermixin_detail + { + /** Unify by \c ident \c (kind:name). + * Return true on the 1st appearance of a new \c ident. This is + * used in \ref SolvIterMixin when mapping a Solvable iterator + * to a Selectable iterator. + */ + struct UnifyByIdent + { + bool operator()( const Solvable & solv_r ) const; + + typedef std::tr1::unordered_set Uset; + UnifyByIdent() + : _uset( new Uset ) + {} + shared_ptr _uset; + }; + } // namespace solvitermixin_detail + + /////////////////////////////////////////////////////////////////// // // CLASS NAME : SolvIterMixin @@ -103,16 +124,27 @@ namespace zypp { return make_transform_iterator( solvableEnd(), asPoolItem() ); } //@} + private: + typedef filter_iterator UnifiedSolvable_iterator; + public: /** \name Iterate ui::Selectable::Ptr */ //@{ - typedef transform_iterator Selectable_iterator; + typedef transform_iterator Selectable_iterator; Selectable_iterator selectableBegin() const - { return make_transform_iterator( solvableBegin(), ui::asSelectable() ); } + { return make_transform_iterator( unifiedSolvableBegin(), ui::asSelectable() ); } Selectable_iterator selectableEnd() const - { return make_transform_iterator( solvableEnd(), ui::asSelectable() ); } + { return make_transform_iterator( unifiedSolvableEnd(), ui::asSelectable() ); } //@} private: + /** \name Iterate unified Solbvables to be transformed into Selectable. */ + //@{ + UnifiedSolvable_iterator unifiedSolvableBegin() const + { return make_filter_iterator( solvitermixin_detail::UnifyByIdent(), solvableBegin(), solvableEnd() ); } + UnifiedSolvable_iterator unifiedSolvableEnd() const + { return make_filter_iterator( solvitermixin_detail::UnifyByIdent(), solvableEnd(), solvableEnd() );; } + //@} + private: const Derived & self() const { return *static_cast( this ); } protected: diff --git a/zypp/sat/Solvable.cc b/zypp/sat/Solvable.cc index 77f7739..025e979 100644 --- a/zypp/sat/Solvable.cc +++ b/zypp/sat/Solvable.cc @@ -383,35 +383,6 @@ namespace zypp } /////////////////////////////////////////////////////////////////// - - ValidValue Solvable::validate() const - { - NO_SOLVABLE_RETURN( NOTRELEVANT ); - int ret = solvable_trivial_installable_repo (_solvable, Pool::instance().systemRepo().get()); - if (ret == 0) - return BROKEN; - else if (ret > 0) - return SATISFIED; - else - return NOTRELEVANT; - } - - bool Solvable::isSatisfied() const - { - return validate() == SATISFIED; - } - - bool Solvable::isRelevant() const - { - NO_SOLVABLE_RETURN( false ); - if (isKind (ResKind::package)) - return true; // packages are always relevant - - return validate() == BROKEN; - } - - - /////////////////////////////////////////////////////////////////// namespace { ///////////////////////////////////////////////////////////////// /** Expand \ref Capability and call \c fnc_r for each namescpace:language diff --git a/zypp/sat/Solvable.h b/zypp/sat/Solvable.h index b91ebbc..649e2c0 100644 --- a/zypp/sat/Solvable.h +++ b/zypp/sat/Solvable.h @@ -34,8 +34,6 @@ namespace zypp class CheckSum; class OnMediaLocation; - enum ValidValue { BROKEN, SATISFIED, NOTRELEVANT }; - /////////////////////////////////////////////////////////////////// namespace sat { ///////////////////////////////////////////////////////////////// @@ -180,23 +178,6 @@ namespace zypp //@} public: - /** Returns true if the solvable is satisfied */ - bool isSatisfied() const; - /** Returns true if the solvable is satisfied */ - bool isBroken() const { return !isSatisfied(); } - /** Returns true if the solvable is relevant which means e.G. for patches - * that at least one package of the patch is installed. - */ - bool isRelevant() const; - - /** Check if the solvable is satisfied,broken or not relevant - * (not important, so it can be ignored) - * \return BROKEN, SATISFIED, NOTRELEVANT - */ - - ValidValue validate() const; - - public: /** \name Locale support. */ //@{ /** Whether this \c Solvable claims to support locales. */