libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_UI_SELECTABLE_H 00013 #define ZYPP_UI_SELECTABLE_H 00014 00015 #include <iosfwd> 00016 00017 #include "zypp/base/ReferenceCounted.h" 00018 #include "zypp/base/NonCopyable.h" 00019 #include "zypp/base/PtrTypes.h" 00020 #include "zypp/base/Iterator.h" 00021 00022 #include "zypp/ui/SelectableTraits.h" 00023 #include "zypp/ui/Status.h" 00024 00026 namespace zypp 00027 { 00028 00030 namespace ui 00031 { 00032 00033 DEFINE_PTR_TYPE(Selectable); 00034 00036 // 00037 // CLASS NAME : Selectable 00038 // 00051 class Selectable : public base::ReferenceCounted, private base::NonCopyable 00052 { 00053 friend std::ostream & operator<<( std::ostream & str, const Selectable & obj ); 00054 friend std::ostream & dumpOn( std::ostream & str, const Selectable & obj ); 00055 00056 public: 00057 typedef intrusive_ptr<Selectable> Ptr; 00058 typedef intrusive_ptr<const Selectable> constPtr; 00059 00061 typedef SelectableTraits::available_iterator available_iterator; 00062 typedef SelectableTraits::available_size_type available_size_type; 00063 00064 typedef SelectableTraits::installed_iterator installed_iterator; 00065 typedef SelectableTraits::installed_size_type installed_size_type; 00066 00067 typedef SelectableTraits::picklist_iterator picklist_iterator; 00068 typedef SelectableTraits::picklist_size_type picklist_size_type; 00069 00070 public: 00081 static Ptr get( const pool::ByIdent & ident_r ); 00082 00084 static Ptr get( IdString ident_r ) 00085 { return get( pool::ByIdent( ident_r ) ); } 00086 00088 static Ptr get( ResKind kind_r, const std::string & name_r ) 00089 { return get( pool::ByIdent( kind_r, name_r ) ); } 00090 00092 static Ptr get( const std::string & name_r ) 00093 { return get( pool::ByIdent( ResKind::package, name_r ) ); } 00094 00096 static Ptr get( const sat::Solvable & solv_r ) 00097 { return get( pool::ByIdent( solv_r ) ); } 00098 00100 static Ptr get( const ResObject::constPtr & resolvable_r ) 00101 { return resolvable_r ? get( resolvable_r->satSolvable() ) : Ptr(); } 00102 00104 static Ptr get( const PoolItem & pi_r ) 00105 { return get( pi_r.satSolvable() ); } 00107 00108 public: 00114 IdString ident() const; 00115 00117 ResObject::Kind kind() const; 00118 00120 const std::string & name() const; 00121 00123 PoolItem installedObj() const; 00124 00129 PoolItem candidateObj() const; 00130 00136 PoolItem candidateObjFrom( Repository repo_r ) const; 00137 00144 PoolItem updateCandidateObj() const; 00145 00151 PoolItem highestAvailableVersionObj() const; 00152 00157 bool identicalAvailable( const PoolItem & rhs ) const; 00158 00163 bool identicalInstalled( const PoolItem & rhs ) const; 00164 00168 bool identicalInstalledCandidate() const 00169 { return identicalInstalled( candidateObj() ); } 00170 00174 bool identicalInstalledUpdateCandidate() const 00175 { return identicalInstalled( updateCandidateObj() ); } 00176 00181 PoolItem identicalAvailableObj( const PoolItem & rhs ) const; 00182 00187 PoolItem identicalInstalledObj( const PoolItem & rhs ) const; 00188 00195 template<class _Res> 00196 typename ResTraits<_Res>::constPtrType installedAsKind() const 00197 { return asKind<_Res>( candidateObj() ); } 00198 00205 template<class _Res> 00206 typename ResTraits<_Res>::constPtrType candidateAsKind() const 00207 { return asKind<_Res>( candidateObj() ); } 00208 00217 PoolItem setCandidate( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r = ResStatus::USER ); 00219 PoolItem setCandidate( ResObject::constPtr newCandidate_r, ResStatus::TransactByValue causer_r = ResStatus::USER ); 00220 00227 bool setOnSystem( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r = ResStatus::USER ); 00228 00234 PoolItem theObj() const; 00235 00237 00242 bool availableEmpty() const; 00243 available_size_type availableSize() const; 00244 available_iterator availableBegin() const; 00245 available_iterator availableEnd() const; 00247 00249 00254 bool installedEmpty() const; 00255 installed_size_type installedSize() const; 00256 installed_iterator installedBegin() const; 00257 installed_iterator installedEnd() const; 00258 //} 00259 00261 00267 bool picklistEmpty() const; 00268 picklist_size_type picklistSize() const; 00269 picklist_iterator picklistBegin() const; 00270 picklist_iterator picklistEnd() const; 00271 //} 00272 00274 00275 public: 00280 bool hasObject() const 00281 { return (! installedEmpty()) || candidateObj(); } 00282 00284 bool hasInstalledObj() const 00285 { return ! installedEmpty(); } 00286 00288 bool hasCandidateObj() const 00289 { return candidateObj(); } 00290 00292 bool hasBothObjects() const 00293 { return (! installedEmpty()) && candidateObj(); } 00294 00296 bool hasInstalledObjOnly() const 00297 { return (! installedEmpty()) && ! candidateObj(); } 00298 00300 bool hasCandidateObjOnly() const 00301 { return ( installedEmpty() ) && candidateObj(); } 00303 00308 bool isUnmaintained() const; 00309 00320 bool multiversionInstall() const; 00321 00324 bool pickInstall( const PoolItem & pi_r, ResStatus::TransactByValue causer_r = ResStatus::USER, bool yesno_r = true ); 00325 00328 bool pickNoInstall( const PoolItem & pi_r, ResStatus::TransactByValue causer_r = ResStatus::USER ) 00329 { return pickInstall( pi_r, causer_r, false ); } 00330 00333 bool pickDelete( const PoolItem & pi_r, ResStatus::TransactByValue causer_r = ResStatus::USER, bool yesno_r = true ); 00334 00337 bool pickNoDelete( const PoolItem & pi_r, ResStatus::TransactByValue causer_r = ResStatus::USER ) 00338 { return pickDelete( pi_r, causer_r, false ); } 00339 00363 Status pickStatus( const PoolItem & pi_r ) const; 00364 00366 bool setPickStatus( const PoolItem & pi_r, Status state_r, ResStatus::TransactByValue causer_r = ResStatus::USER ); 00368 00378 bool isUndetermined() const; 00379 00383 bool isRelevant() const; 00384 00386 bool isSatisfied() const; 00387 00389 bool isBroken() const; 00390 00396 bool isNeeded() const; 00397 00399 bool isUnwanted() const; 00401 00402 public: 00406 enum Fate { 00407 TO_DELETE = -1, 00408 UNMODIFIED = 0, 00409 TO_INSTALL = 1 00410 }; 00412 Fate fate() const; 00413 00415 bool unmodified() const 00416 { return fate() == UNMODIFIED; } 00417 00419 bool locked() const 00420 { Status st( status() ); return( st == S_Protected || st == S_Taboo ); } 00421 00423 bool toModify() const 00424 { return fate() != UNMODIFIED; } 00425 00427 bool toDelete() const 00428 { return fate() == TO_DELETE; } 00429 00431 bool toInstall() const 00432 { return fate() == TO_INSTALL; } 00433 00435 bool onSystem() const 00436 { return( ( hasInstalledObj() && !toDelete() ) 00437 ||( hasCandidateObj() && toInstall() ) ); } 00438 00440 bool offSystem() const 00441 { return ! onSystem(); } 00442 00444 bool setFate( Fate fate_r, ResStatus::TransactByValue causer_r = ResStatus::USER ); 00445 00447 bool setToInstall( ResStatus::TransactByValue causer_r = ResStatus::USER ) 00448 { return setFate( TO_INSTALL, causer_r ); } 00449 00451 bool setInstalled( ResStatus::TransactByValue causer_r = ResStatus::USER ); 00452 00454 bool setUpToDate( ResStatus::TransactByValue causer_r = ResStatus::USER ); 00455 00457 bool setToDelete( ResStatus::TransactByValue causer_r = ResStatus::USER ) 00458 { return setFate( TO_DELETE, causer_r ); } 00459 00461 bool setDeleted( ResStatus::TransactByValue causer_r = ResStatus::USER ); 00462 00464 bool unset( ResStatus::TransactByValue causer_r = ResStatus::USER ) 00465 { return setFate( UNMODIFIED, causer_r ); } 00467 00468 public: 00477 Status status() const; 00478 00483 bool setStatus( Status state_r, ResStatus::TransactByValue causer_r = ResStatus::USER ); 00484 00486 ResStatus::TransactByValue modifiedBy() const; 00487 00489 bool hasLicenceConfirmed() const; 00490 00492 void setLicenceConfirmed( bool val_r = true ); 00494 00495 public: 00497 class Impl; 00498 typedef shared_ptr<Impl> Impl_Ptr; 00500 Selectable( Impl_Ptr pimpl_r ); 00501 private: 00503 ~Selectable(); 00504 private: 00506 RW_pointer<Impl> _pimpl; 00507 }; 00509 00511 std::ostream & operator<<( std::ostream & str, const Selectable & obj ); 00512 00514 std::ostream & dumpOn( std::ostream & str, const Selectable & obj ); 00515 00520 struct asSelectable 00521 { 00522 typedef Selectable_Ptr result_type; 00523 00524 Selectable_Ptr operator()( const sat::Solvable & solv_r ) const; 00525 00526 Selectable_Ptr operator()( const PoolItem & pi_r ) const 00527 { return operator()( pi_r.satSolvable() ); } 00528 }; 00529 00531 } // namespace ui 00534 } // namespace zypp 00536 #endif // ZYPP_UI_SELECTABLE_H