libzypp 8.13.6
|
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 00177 00184 template<class _Res> 00185 typename ResTraits<_Res>::constPtrType installedAsKind() const 00186 { return asKind<_Res>( candidateObj() ); } 00187 00194 template<class _Res> 00195 typename ResTraits<_Res>::constPtrType candidateAsKind() const 00196 { return asKind<_Res>( candidateObj() ); } 00197 00206 PoolItem setCandidate( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r = ResStatus::USER ); 00208 PoolItem setCandidate( ResObject::constPtr newCandidate_r, ResStatus::TransactByValue causer_r = ResStatus::USER ); 00209 00216 bool setOnSystem( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r = ResStatus::USER ); 00217 00223 PoolItem theObj() const; 00224 00226 00231 bool availableEmpty() const; 00232 available_size_type availableSize() const; 00233 available_iterator availableBegin() const; 00234 available_iterator availableEnd() const; 00236 00238 00243 bool installedEmpty() const; 00244 installed_size_type installedSize() const; 00245 installed_iterator installedBegin() const; 00246 installed_iterator installedEnd() const; 00247 //} 00248 00250 00256 bool picklistEmpty() const; 00257 picklist_size_type picklistSize() const; 00258 picklist_iterator picklistBegin() const; 00259 picklist_iterator picklistEnd() const; 00260 //} 00261 00263 00264 public: 00269 bool hasObject() const 00270 { return (! installedEmpty()) || candidateObj(); } 00271 00273 bool hasInstalledObj() const 00274 { return ! installedEmpty(); } 00275 00277 bool hasCandidateObj() const 00278 { return candidateObj(); } 00279 00281 bool hasBothObjects() const 00282 { return (! installedEmpty()) && candidateObj(); } 00283 00285 bool hasInstalledObjOnly() const 00286 { return (! installedEmpty()) && ! candidateObj(); } 00287 00289 bool hasCandidateObjOnly() const 00290 { return ( installedEmpty() ) && candidateObj(); } 00292 00297 bool isUnmaintained() const; 00298 00309 bool multiversionInstall() const; 00310 00313 bool pickInstall( const PoolItem & pi_r, ResStatus::TransactByValue causer_r = ResStatus::USER, bool yesno_r = true ); 00314 00317 bool pickNoInstall( const PoolItem & pi_r, ResStatus::TransactByValue causer_r = ResStatus::USER ) 00318 { return pickInstall( pi_r, causer_r, false ); } 00319 00322 bool pickDelete( const PoolItem & pi_r, ResStatus::TransactByValue causer_r = ResStatus::USER, bool yesno_r = true ); 00323 00326 bool pickNoDelete( const PoolItem & pi_r, ResStatus::TransactByValue causer_r = ResStatus::USER ) 00327 { return pickDelete( pi_r, causer_r, false ); } 00328 00352 Status pickStatus( const PoolItem & pi_r ) const; 00353 00355 bool setPickStatus( const PoolItem & pi_r, Status state_r, ResStatus::TransactByValue causer_r = ResStatus::USER ); 00357 00367 bool isUndetermined() const; 00368 00372 bool isRelevant() const; 00373 00375 bool isSatisfied() const; 00376 00378 bool isBroken() const; 00379 00385 bool isNeeded() const; 00386 00388 bool isUnwanted() const; 00390 00391 public: 00395 enum Fate { 00396 TO_DELETE = -1, 00397 UNMODIFIED = 0, 00398 TO_INSTALL = 1 00399 }; 00401 Fate fate() const; 00402 00404 bool unmodified() const 00405 { return fate() == UNMODIFIED; } 00406 00408 bool locked() const 00409 { Status st( status() ); return( st == S_Protected || st == S_Taboo ); } 00410 00412 bool toModify() const 00413 { return fate() != UNMODIFIED; } 00414 00416 bool toDelete() const 00417 { return fate() == TO_DELETE; } 00418 00420 bool toInstall() const 00421 { return fate() == TO_INSTALL; } 00422 00424 bool onSystem() const 00425 { return( ( hasInstalledObj() && !toDelete() ) 00426 ||( hasCandidateObj() && toInstall() ) ); } 00427 00429 bool offSystem() const 00430 { return ! onSystem(); } 00431 00433 bool setFate( Fate fate_r, ResStatus::TransactByValue causer_r = ResStatus::USER ); 00434 00436 bool setToInstall( ResStatus::TransactByValue causer_r = ResStatus::USER ) 00437 { return setFate( TO_INSTALL, causer_r ); } 00438 00440 bool setInstalled( ResStatus::TransactByValue causer_r = ResStatus::USER ); 00441 00443 bool setUpToDate( ResStatus::TransactByValue causer_r = ResStatus::USER ); 00444 00446 bool setToDelete( ResStatus::TransactByValue causer_r = ResStatus::USER ) 00447 { return setFate( TO_DELETE, causer_r ); } 00448 00450 bool setDeleted( ResStatus::TransactByValue causer_r = ResStatus::USER ); 00451 00453 bool unset( ResStatus::TransactByValue causer_r = ResStatus::USER ) 00454 { return setFate( UNMODIFIED, causer_r ); } 00456 00457 public: 00466 Status status() const; 00467 00472 bool setStatus( Status state_r, ResStatus::TransactByValue causer_r = ResStatus::USER ); 00473 00475 ResStatus::TransactByValue modifiedBy() const; 00476 00478 bool hasLicenceConfirmed() const; 00479 00481 void setLicenceConfirmed( bool val_r = true ); 00483 00484 public: 00486 class Impl; 00487 typedef shared_ptr<Impl> Impl_Ptr; 00489 Selectable( Impl_Ptr pimpl_r ); 00490 private: 00492 ~Selectable(); 00493 private: 00495 RW_pointer<Impl> _pimpl; 00496 }; 00498 00500 std::ostream & operator<<( std::ostream & str, const Selectable & obj ); 00501 00503 std::ostream & dumpOn( std::ostream & str, const Selectable & obj ); 00504 00509 struct asSelectable 00510 { 00511 typedef Selectable_Ptr result_type; 00512 00513 Selectable_Ptr operator()( const sat::Solvable & solv_r ) const; 00514 00515 Selectable_Ptr operator()( const PoolItem & pi_r ) const 00516 { return operator()( pi_r.satSolvable() ); } 00517 }; 00518 00520 } // namespace ui 00523 } // namespace zypp 00525 #endif // ZYPP_UI_SELECTABLE_H