From a83e3d29210f017eb24b0a01c075979bc806f9fb Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Tue, 8 Apr 2008 15:40:16 +0000 Subject: [PATCH] - Selectable deserves a cleanup, some consistency. - Having setFoo and set_bar in the same API is worse than killing kittens - Use PoolItems everywhere - add multiple installed support - more coming --- zypp/ResPoolProxy.cc | 19 ++------ zypp/ui/SelFilters.h | 2 +- zypp/ui/Selectable.cc | 59 ++++++++++++++--------- zypp/ui/Selectable.h | 108 +++++++++++++++++++++++++++++++++--------- zypp/ui/SelectableImpl.cc | 12 ++--- zypp/ui/SelectableImpl.h | 108 +++++++++++++++++++++++++++++------------- zypp/ui/SelectableTraits.h | 23 ++++----- zypp/ui/UserWantedPackages.cc | 4 +- 8 files changed, 218 insertions(+), 117 deletions(-) diff --git a/zypp/ResPoolProxy.cc b/zypp/ResPoolProxy.cc index 7b554d8..41b9c30 100644 --- a/zypp/ResPoolProxy.cc +++ b/zypp/ResPoolProxy.cc @@ -96,12 +96,13 @@ namespace zypp ui::Selectable::Ptr buildSelectable( const ResObject::Kind & kind_r, const std::string & name_r, - const PoolItem & installedItem_r, + const ItemC & installed, const ItemC & available ) { return ui::Selectable::Ptr( new ui::Selectable( ui::Selectable::Impl_Ptr( new ui::Selectable::Impl( kind_r, name_r, - installedItem_r, + installed.begin(), + installed.end(), available.begin(), available.end() ) ) ) ); @@ -122,20 +123,10 @@ namespace zypp const ItemC & installed( nameIt->second.installed ); const ItemC & available( nameIt->second.available ); - if ( installed.empty() ) - { - if ( available.empty() ) + if ( installed.empty() && available.empty() ) continue; - _selPool[kindIt->first].insert( buildSelectable( kindIt->first, nameIt->first, PoolItem(), available ) ); - } else - { - // ui want's one Selectable per installed item - for ( ItemC::const_iterator instIt = installed.begin(); instIt != installed.end(); ++instIt ) - { - _selPool[kindIt->first].insert( buildSelectable( kindIt->first, nameIt->first, *instIt, available ) ); - } - } + _selPool[kindIt->first].insert( buildSelectable( kindIt->first, nameIt->first, installed, available ) ); } } } diff --git a/zypp/ui/SelFilters.h b/zypp/ui/SelFilters.h index dd2ec5e..2fcdfc7 100644 --- a/zypp/ui/SelFilters.h +++ b/zypp/ui/SelFilters.h @@ -61,7 +61,7 @@ namespace zypp struct ByHasInstalledObj : public SelectableFilterFunctor { bool operator()( const ui::Selectable::constPtr & obj ) const - { return obj && obj->hasInstalledObj(); } + { return obj && !obj->installedEmpty(); } }; /** */ diff --git a/zypp/ui/Selectable.cc b/zypp/ui/Selectable.cc index 9d24aef..9b46ef4 100644 --- a/zypp/ui/Selectable.cc +++ b/zypp/ui/Selectable.cc @@ -55,44 +55,57 @@ namespace zypp Status Selectable::status() const { return _pimpl->status(); } - bool Selectable::set_status( const Status state_r ) - { return _pimpl->set_status( state_r ); } + bool Selectable::setStatus( const Status state_r ) + { return _pimpl->setStatus( state_r ); } - ResObject::constPtr Selectable::installedObj() const + PoolItem Selectable::installedObj() const { return _pimpl->installedObj(); } - PoolItem Selectable::installedPoolItem() const - { return _pimpl->installedObj(); } - - ResObject::constPtr Selectable::candidateObj() const + PoolItem Selectable::candidateObj() const { return _pimpl->candidateObj(); } - PoolItem Selectable::candidatePoolItem() const - { return _pimpl->candidateObj(); } - - ResObject::constPtr Selectable::setCandidate( ResObject::constPtr byUser_r ) + PoolItem Selectable::setCandidate( ResObject::constPtr byUser_r ) { return _pimpl->setCandidate( byUser_r ); } - ResObject::constPtr Selectable::theObj() const + PoolItem Selectable::theObj() const { return _pimpl->theObj(); } - Selectable::size_type Selectable::availableObjs() const - { return _pimpl->availableObjs(); } + //////////////////////////////////////////////////////////////////////// - Selectable::available_iterator Selectable::availableBegin() const - { return make_transform_iterator( _pimpl->availableBegin(), - SelectableTraits::TransformToResObjectPtr() ); } + bool Selectable::availableEmpty() const + { return _pimpl->availableEmpty(); } - Selectable::available_iterator Selectable::availableEnd() const - { return make_transform_iterator( _pimpl->availableEnd(), - SelectableTraits::TransformToResObjectPtr() ); } + Selectable::available_size_type Selectable::availableSize() const + { return _pimpl->availableSize(); } - Selectable::availablePoolItem_iterator Selectable::availablePoolItemBegin() const + Selectable::available_iterator Selectable::availableBegin() const { return _pimpl->availableBegin(); } - - Selectable::availablePoolItem_iterator Selectable::availablePoolItemEnd() const + + Selectable::available_iterator Selectable::availableEnd() const { return _pimpl->availableEnd(); } + //////////////////////////////////////////////////////////////////////// + + bool Selectable::installedEmpty() const + { return _pimpl->installedEmpty(); } + + Selectable::installed_size_type Selectable::installedSize() const + { return _pimpl->installedSize(); } + + Selectable::installed_iterator Selectable::installedBegin() const + { return _pimpl->installedBegin(); } + + Selectable::installed_iterator Selectable::installedEnd() const + { return _pimpl->installedEnd(); } + + + //////////////////////////////////////////////////////////////////////// + + bool Selectable::isUnmaintained() const + { return _pimpl->isUnmaintained(); } + + + ResStatus::TransactByValue Selectable::modifiedBy() const { return _pimpl->modifiedBy(); } diff --git a/zypp/ui/Selectable.h b/zypp/ui/Selectable.h index df0099f..36231ed 100644 --- a/zypp/ui/Selectable.h +++ b/zypp/ui/Selectable.h @@ -53,8 +53,10 @@ namespace zypp /** Iterates over ResObject::constPtr */ typedef SelectableTraits::available_iterator available_iterator; - typedef SelectableTraits::availableItem_iterator availablePoolItem_iterator; - typedef SelectableTraits::availableItem_size_type size_type; + typedef SelectableTraits::available_size_type available_size_type; + + typedef SelectableTraits::installed_iterator installed_iterator; + typedef SelectableTraits::installed_size_type installed_size_type; public: /** The ResObjects kind. */ @@ -63,32 +65,56 @@ namespace zypp /** The ResObjects name. */ const std::string & name() const; - /** Installed object. */ - ResObject::constPtr installedObj() const; + /** + * return the first Installed object + * of available + */ + PoolItem installedObj() const; - /** PoolItem corresponding to the installed object. */ - PoolItem installedPoolItem() const; + /** + * \deprecated use installedObj + * PoolItem corresponding to the installed object. + */ + ZYPP_DEPRECATED PoolItem installedPoolItem() const + { return installedObj(); } /** Best among available objects. + The user selected candiate, or a default. */ - ResObject::constPtr candidateObj() const; + PoolItem candidateObj() const; /** PoolItem corresponding to the candidate object. */ - PoolItem candidatePoolItem() const; + ZYPP_DEPRECATED PoolItem candidatePoolItem() const + { return candidateObj(); } /** Set a candidate (out of available objects). * \return The new candidate, or NULL if choice was invalid * (NULL or not among availableObjs). An invalid choice * selects the default candidate. */ - ResObject::constPtr setCandidate( ResObject::constPtr byUser_r ); + PoolItem setCandidate( ResObject::constPtr byUser_r ); /** Best among all objects. */ - ResObject::constPtr theObj() const; + PoolItem theObj() const; + + //////////////////////////////////////////////////////////////////////// + + /** + * Are there available objects? + */ + bool availableEmpty() const; + + /** + * Number of available objects. + */ + available_size_type availableSize() const; - /** Number of available objects. */ - size_type availableObjs() const; + /** + * Number of available objects. + * \deprecated Use availableSize + */ + ZYPP_DEPRECATED available_size_type availableObjs() const + { return availableSize(); } /** */ available_iterator availableBegin() const; @@ -96,11 +122,29 @@ namespace zypp /** */ available_iterator availableEnd() const; + //////////////////////////////////////////////////////////////////////// + + /** + * Installed object iterators + */ + + /** + * Are there installed objects? + */ + bool installedEmpty() const; + + /** + * Number of available objects. + */ + installed_size_type installedSize() const; + /** */ - availablePoolItem_iterator availablePoolItemBegin() const; + installed_iterator installedBegin() const; /** */ - availablePoolItem_iterator availablePoolItemEnd() const; + installed_iterator installedEnd() const; + + //////////////////////////////////////////////////////////////////////// public: /** \name Query for objects within this Selectable. @@ -108,11 +152,14 @@ namespace zypp //@{ /** True if either installed or candidate object is present */ bool hasObject() const - { return installedObj() || candidateObj(); } + { return (! installedEmpty()) || candidateObj(); } - /** True if installed object is present. */ - bool hasInstalledObj() const - { return installedObj(); } + /** + * True if installed object is present. + * \deprecated Use ! installedEmpty() + */ + ZYPP_DEPRECATED bool hasInstalledObj() const + { return ! installedEmpty(); } /** True if candidate object is present. */ bool hasCandidateObj() const @@ -120,17 +167,23 @@ namespace zypp /** True if installed and candidate object is present */ bool hasBothObjects() const - { return installedObj() && candidateObj(); } + { return (! installedEmpty()) && candidateObj(); } /** True if installed object is present but no candidate. */ bool hasInstalledObjOnly() const - { return installedObj() && ! candidateObj(); } + { return (! installedEmpty()) && ! candidateObj(); } /** True if candidate object is present but no installed. */ bool hasCandidateObjOnly() const - { return ! installedObj() && candidateObj(); } + { return ( installedEmpty() ) && candidateObj(); } //@} + /** + * True if this package has no replacement from + * the available repositories + */ + bool isUnmaintained() const; + public: /** \name Query objects fate in case of commit. */ @@ -161,7 +214,8 @@ namespace zypp //@} public: - /** \name Special inteface for Y2UI. + /** + * \name Special inteface for Y2UI. * \note This interface acts on \ref ResStatus::USER level. * The \ref Status enum, and allowed state transitions are * tightly related to the Y2UI. It might be not verry usefull @@ -170,10 +224,18 @@ namespace zypp //@{ /** Return the current Status */ Status status() const; + + /** + * Try to set a new Status. + * Returns \c false if the transitions is not allowed. + */ + bool setStatus( const Status state_r ); + /** Try to set a new Status. * Returns \c false if the transitions is not allowed. */ - bool set_status( const Status state_r ); + ZYPP_DEPRECATED bool set_status( const Status state_r ) + { return setStatus( state_r ); } /** Return who caused the modification. */ ResStatus::TransactByValue modifiedBy() const; diff --git a/zypp/ui/SelectableImpl.cc b/zypp/ui/SelectableImpl.cc index fd0977f..f42cad8 100644 --- a/zypp/ui/SelectableImpl.cc +++ b/zypp/ui/SelectableImpl.cc @@ -37,8 +37,6 @@ namespace zypp , cand( impl.candidateObj() ) {} - typedef Selectable::Impl::availableItem_const_iterator availableItem_const_iterator; - // // Queries // @@ -62,7 +60,7 @@ namespace zypp // void resetTransactingCandidates() const { - for ( availableItem_const_iterator it = _impl.availableBegin(); + for ( Selectable::Impl::available_const_iterator it = _impl.availableBegin(); it != _impl.availableEnd(); ++it ) { (*it).status().setTransact( false, ResStatus::USER ); @@ -70,7 +68,7 @@ namespace zypp } void unlockCandidates() const { - for ( availableItem_const_iterator it = _impl.availableBegin(); + for ( Selectable::Impl::available_const_iterator it = _impl.availableBegin(); it != _impl.availableEnd(); ++it ) { (*it).status().setTransact( false, ResStatus::USER ); @@ -79,7 +77,7 @@ namespace zypp } void lockCandidates() const { - for ( availableItem_const_iterator it = _impl.availableBegin(); + for ( Selectable::Impl::available_const_iterator it = _impl.availableBegin(); it != _impl.availableEnd(); ++it ) { (*it).status().setTransact( false, ResStatus::USER ); @@ -188,7 +186,7 @@ namespace zypp return( installedObj() ? S_KeepInstalled : S_NoInst ); } - bool Selectable::Impl::set_status( const Status state_r ) + bool Selectable::Impl::setStatus( const Status state_r ) { StatusHelper self( *this ); @@ -235,7 +233,7 @@ namespace zypp if ( byUser_r ) // must be in available list { - for ( availableItem_const_iterator it = availableBegin(); + for ( available_const_iterator it = availableBegin(); it != availableEnd(); ++it ) { if ( it->resolvable() == byUser_r ) diff --git a/zypp/ui/SelectableImpl.h b/zypp/ui/SelectableImpl.h index 40a2340..536b573 100644 --- a/zypp/ui/SelectableImpl.h +++ b/zypp/ui/SelectableImpl.h @@ -40,20 +40,27 @@ namespace zypp public: - typedef SelectableTraits::AvialableItemSet AvialableItemSet; - typedef SelectableTraits::availableItem_iterator availableItem_iterator; - typedef SelectableTraits::availableItem_const_iterator availableItem_const_iterator; - typedef SelectableTraits::availableItem_size_type availableItem_size_type; + typedef SelectableTraits::AvailableItemSet AvailableItemSet; + typedef SelectableTraits::available_iterator available_iterator; + typedef SelectableTraits::available_const_iterator available_const_iterator; + typedef SelectableTraits::available_size_type available_size_type; + + typedef SelectableTraits::InstalledItemSet InstalledItemSet; + typedef SelectableTraits::installed_iterator installed_iterator; + typedef SelectableTraits::installed_const_iterator installed_const_iterator; + typedef SelectableTraits::installed_size_type installed_size_type; + public: Impl( const ResObject::Kind & kind_r, const std::string & name_r, - const PoolItem & installedItem_r, - availableItem_const_iterator availableBegin_r, - availableItem_const_iterator availableEnd_r ) + installed_const_iterator installedBegin_r, + installed_const_iterator installedEnd_r , + available_const_iterator availableBegin_r, + available_const_iterator availableEnd_r ) : _kind( kind_r ) , _name( name_r ) - , _installedItem( installedItem_r ) + , _installedItems( installedBegin_r, installedEnd_r ) , _availableItems( availableBegin_r, availableEnd_r ) { setCandidate( NULL ); @@ -72,11 +79,15 @@ namespace zypp Status status() const; /** */ - bool set_status( const Status state_r ); + bool setStatus( const Status state_r ); /** Installed object. */ PoolItem installedObj() const - { return _installedItem; } + { + if (!installedEmpty()) + return *_installedItems.begin(); + return PoolItem(); + } /** Best among available objects. * The transacting candidate or the one scheduled to receive @@ -103,21 +114,49 @@ namespace zypp PoolItem theObj() const { PoolItem ret( candidateObj() ); - return( ret ? ret : _installedItem ); + if (ret) + return ret; + + if ( ! _installedItems.empty() ) + return (*_installedItems.begin()); + + return PoolItem(); } - /** */ - availableItem_size_type availableObjs() const + //////////////////////////////////////////////////////////////////////// + + bool availableEmpty() const + { return _availableItems.empty(); } + + available_size_type availableSize() const { return _availableItems.size(); } - /** */ - availableItem_const_iterator availableBegin() const + available_const_iterator availableBegin() const { return _availableItems.begin(); } - /** */ - availableItem_const_iterator availableEnd() const + + available_const_iterator availableEnd() const { return _availableItems.end(); } + //////////////////////////////////////////////////////////////////////// + + bool installedEmpty() const + { return _installedItems.empty(); } + + installed_size_type installedSize() const + { return _installedItems.size(); } + + installed_iterator installedBegin() const + { return _installedItems.begin(); } + + installed_iterator installedEnd() const + { return _installedItems.end(); } + + //////////////////////////////////////////////////////////////////////// + + bool isUnmaintained() const + { return availableEmpty(); } + /** Return who caused the modification. */ ResStatus::TransactByValue modifiedBy() const; @@ -132,7 +171,7 @@ namespace zypp private: PoolItem transactingCandidate() const { - for ( availableItem_const_iterator it = availableBegin(); + for ( available_const_iterator it = availableBegin(); it != availableEnd(); ++it ) { if ( (*it).status().transacts() ) @@ -143,28 +182,31 @@ namespace zypp PoolItem defaultCandidate() const { - if ( installedObj() ) + if ( !installedEmpty() ) { // prefer the installed objects arch. - for ( availableItem_const_iterator it = availableBegin(); - it != availableEnd(); ++it ) - { - if ( installedObj()->arch() == (*it)->arch() ) - { - return (*it); - } - } + for ( installed_const_iterator iit = installedBegin(); + iit != installedEnd(); ++iit ) + { + for ( available_const_iterator it = availableBegin(); + it != availableEnd(); ++it ) + { + if ( (*iit)->arch() == (*it)->arch() ) + { + return (*it); + } + } + } } if ( _availableItems.empty() ) - { return PoolItem(); - } + return *_availableItems.begin(); } bool allCandidatesLocked() const { - for ( availableItem_const_iterator it = availableBegin(); + for ( available_const_iterator it = availableBegin(); it != availableEnd(); ++it ) { if ( ! (*it).status().isLocked() ) @@ -176,8 +218,8 @@ namespace zypp private: ResObject::Kind _kind; std::string _name; - PoolItem _installedItem; - AvialableItemSet _availableItems; + InstalledItemSet _installedItems; + AvailableItemSet _availableItems; PoolItem _candidate; }; /////////////////////////////////////////////////////////////////// @@ -186,7 +228,7 @@ namespace zypp inline std::ostream & operator<<( std::ostream & str, const Selectable::Impl & obj ) { return str << '[' << obj.kind() << ']' << obj.name() << ": " << obj.status() - << " (I " << obj._installedItem << ")" + << " (I " << obj._installedItems.size() << ")" << " (A " << obj._availableItems.size() << ")" << obj.candidateObj(); } diff --git a/zypp/ui/SelectableTraits.h b/zypp/ui/SelectableTraits.h index 413a7fb..6ac9881 100644 --- a/zypp/ui/SelectableTraits.h +++ b/zypp/ui/SelectableTraits.h @@ -32,7 +32,7 @@ namespace zypp /** */ struct SelectableTraits { - /** Oder on AvialableItemSet. + /** Oder on AvalableItemSet. * \li best Arch * \li best Edition * \li ResObject::constPtr as fallback. @@ -60,20 +60,15 @@ namespace zypp } }; - typedef std::set AvialableItemSet; - typedef AvialableItemSet::iterator availableItem_iterator; - typedef AvialableItemSet::const_iterator availableItem_const_iterator; - typedef AvialableItemSet::size_type availableItem_size_type; + typedef std::set AvailableItemSet; + typedef AvailableItemSet::iterator available_iterator; + typedef AvailableItemSet::const_iterator available_const_iterator; + typedef AvailableItemSet::size_type available_size_type; - /** Transform PoolItem to ResObject::constPtr. */ - struct TransformToResObjectPtr : public std::unary_function - { - ResObject::constPtr operator()( const PoolItem & obj ) const - { return obj; } - }; - - typedef transform_iterator - available_iterator; + typedef std::set InstalledItemSet; + typedef AvailableItemSet::iterator installed_iterator; + typedef AvailableItemSet::const_iterator installed_const_iterator; + typedef AvailableItemSet::size_type installed_size_type; }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/ui/UserWantedPackages.cc b/zypp/ui/UserWantedPackages.cc index 33d92f1..2dedea6 100644 --- a/zypp/ui/UserWantedPackages.cc +++ b/zypp/ui/UserWantedPackages.cc @@ -122,7 +122,7 @@ namespace zypp // for that pkg set or if the patterns is required by another // pkg set of the same class - typename PkgSet_T::constPtr pkgSet = dynamic_pointer_cast( (*it)->theObj() ); + typename PkgSet_T::constPtr pkgSet = dynamic_pointer_cast( (*it)->theObj() ? (*it)->theObj().resolvable() : 0L ); if ( pkgSet && (*it)->toModify() ) { @@ -190,7 +190,7 @@ namespace zypp patch_it != patchesEnd(); ++patch_it ) { - Patch::constPtr patch = dynamic_pointer_cast( (*patch_it)->theObj() ); + Patch::constPtr patch = dynamic_pointer_cast( (*patch_it)->theObj() ? (*patch_it)->theObj().resolvable() : 0 ); if ( patch && (*patch_it)->toModify() ) { -- 2.7.4