SelectableImpl.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_UI_SELECTABLEIMPL_H
00013 #define ZYPP_UI_SELECTABLEIMPL_H
00014 
00015 #include <iosfwd>
00016 
00017 #include "zypp/base/PtrTypes.h"
00018 
00019 #include "zypp/ui/Selectable.h"
00020 #include "zypp/ui/SelectableTraits.h"
00021 
00023 namespace zypp
00024 { 
00025 
00026   namespace ui
00027   { 
00028 
00030     //
00031     //  CLASS NAME : Selectable::Impl
00032     //
00037     struct Selectable::Impl
00038     {
00039       friend std::ostream & operator<<( std::ostream & str, const Selectable::Impl & obj );
00040 
00041     public:
00042 
00043       typedef SelectableTraits::AvialableItemSet             AvialableItemSet;
00044       typedef SelectableTraits::availableItem_iterator       availableItem_iterator;
00045       typedef SelectableTraits::availableItem_const_iterator availableItem_const_iterator;
00046       typedef SelectableTraits::availableItem_size_type      availableItem_size_type;
00047 
00048     public:
00049       Impl( const ResObject::Kind & kind_r,
00050             const std::string & name_r,
00051             const PoolItem & installedItem_r,
00052             availableItem_const_iterator availableBegin_r,
00053             availableItem_const_iterator availableEnd_r )
00054       : _kind( kind_r )
00055       , _name( name_r )
00056       , _installedItem( installedItem_r )
00057       , _availableItems( availableBegin_r, availableEnd_r )
00058       {
00059         setCandidate( NULL );
00060       }
00061 
00062     public:
00064       ResObject::Kind kind() const
00065       { return _kind; }
00066 
00068       const std::string & name() const
00069       { return _name; }
00070 
00072       Status status() const;
00073 
00075       bool set_status( const Status state_r );
00076 
00078       PoolItem installedObj() const
00079       { return _installedItem; }
00080 
00085       PoolItem candidateObj() const
00086       {
00087         PoolItem ret( transactingCandidate() );
00088         if ( ret )
00089           return ret;
00090 
00091         if ( _candidate )
00092           return _candidate;
00093         return defaultCandidate();
00094       }
00095 
00100       PoolItem setCandidate( ResObject::constPtr byUser_r );
00101 
00103       PoolItem theObj() const
00104       {
00105         PoolItem ret( candidateObj() );
00106         return( ret ? ret : _installedItem );
00107       }
00108 
00110       availableItem_size_type availableObjs() const
00111       { return _availableItems.size(); }
00112 
00114       availableItem_const_iterator availableBegin() const
00115       { return _availableItems.begin(); }
00116 
00118       availableItem_const_iterator availableEnd() const
00119       { return _availableItems.end(); }
00120 
00122       ResStatus::TransactByValue modifiedBy() const;
00123 
00125       bool hasLicenceConfirmed() const
00126       { return candidateObj() && candidateObj().status().isLicenceConfirmed(); }
00127 
00129       void setLicenceConfirmed( bool val_r )
00130       { if ( candidateObj() ) candidateObj().status().setLicenceConfirmed( val_r ); }
00131 
00132     private:
00133       PoolItem transactingCandidate() const
00134       {
00135         for ( availableItem_const_iterator it = availableBegin();
00136               it != availableEnd(); ++it )
00137           {
00138             if ( (*it).status().transacts() )
00139               return (*it);
00140           }
00141         return PoolItem();
00142       }
00143 
00144       PoolItem defaultCandidate() const
00145       {
00146         if ( installedObj() )
00147           {
00148             // prefer the installed objects arch.
00149             for ( availableItem_const_iterator it = availableBegin();
00150                   it != availableEnd(); ++it )
00151               {
00152                 if ( installedObj()->arch() == (*it)->arch() )
00153                   {
00154                     return (*it);
00155                   }
00156               }
00157           }
00158         if ( _availableItems.empty() )
00159           {
00160             return PoolItem();
00161           }
00162         return *_availableItems.begin();
00163       }
00164 
00165       bool allCandidatesLocked() const
00166       {
00167         for ( availableItem_const_iterator it = availableBegin();
00168               it != availableEnd(); ++it )
00169           {
00170             if ( ! (*it).status().isLocked() )
00171               return false;
00172           }
00173         return( ! _availableItems.empty() );
00174       }
00175 
00176     private:
00177       ResObject::Kind  _kind;
00178       std::string      _name;
00179       PoolItem         _installedItem;
00180       AvialableItemSet _availableItems;
00181       PoolItem         _candidate;
00182     };
00184 
00186     inline std::ostream & operator<<( std::ostream & str, const Selectable::Impl & obj )
00187     {
00188       return str << '[' << obj.kind() << ']' << obj.name() << ": " << obj.status()
00189                  << " (I " << obj._installedItem << ")"
00190                  << " (A " << obj._availableItems.size() << ")"
00191                  << obj.candidateObj();
00192     }
00193 
00195   } // namespace ui
00198 } // namespace zypp
00200 #endif // ZYPP_UI_SELECTABLEIMPL_H

Generated on Tue Sep 25 19:23:11 2007 for libzypp by  doxygen 1.5.3