libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00011 extern "C" 00012 { 00013 struct _Transaction; 00014 } 00015 #ifndef ZYPP_SAT_TRANSACTION_H 00016 #define ZYPP_SAT_TRANSACTION_H 00017 00018 #include <iosfwd> 00019 00020 #include "zypp/base/PtrTypes.h" 00021 #include "zypp/base/Flags.h" 00022 #include "zypp/base/SafeBool.h" 00023 #include "zypp/base/Iterator.h" 00024 #include "zypp/base/DefaultIntegral.h" 00025 00026 #include "zypp/sat/SolvIterMixin.h" 00027 #include "zypp/sat/Solvable.h" 00028 00029 #include "zypp/PoolItem.h" 00030 00032 namespace zypp 00033 { 00034 00035 namespace sat 00036 { 00037 00038 namespace detail 00039 { 00041 class Transaction_iterator; 00043 class Transaction_const_iterator; 00044 } 00045 00055 class Transaction : public SolvIterMixin<Transaction, detail::Transaction_const_iterator> 00056 , protected base::SafeBool<Transaction> 00057 { 00058 friend std::ostream & operator<<( std::ostream & str, const Transaction & obj ); 00059 friend std::ostream & dumpOn( std::ostream & str, const Transaction & obj ); 00060 friend bool operator==( const Transaction & lhs, const Transaction & rhs ); 00061 00062 public: 00064 class Step; 00065 00067 enum StepType 00068 { 00069 TRANSACTION_IGNORE = 0x00, 00070 TRANSACTION_ERASE = 0x10, 00071 TRANSACTION_INSTALL = 0x20, 00072 TRANSACTION_MULTIINSTALL = 0x30 00073 }; 00074 00076 enum StepStage 00077 { 00078 STEP_TODO = (1 << 0), 00079 STEP_DONE = (1 << 1), 00080 STEP_ERROR = (1 << 2), 00081 }; 00082 00083 ZYPP_DECLARE_FLAGS(StepStages,StepStage); 00084 00085 public: 00087 Transaction(); 00088 00090 Transaction( ::_Transaction & trans_r ); 00091 00093 ~Transaction(); 00094 00095 public: 00097 bool valid() const; 00098 00100 using base::SafeBool<Transaction>::operator bool_type; 00101 00107 bool order(); 00108 00110 bool empty() const; 00111 00113 size_t size() const; 00114 00115 typedef detail::Transaction_iterator iterator; 00116 typedef detail::Transaction_const_iterator const_iterator; 00117 00119 const_iterator begin() const; 00121 iterator begin(); 00122 00124 const_iterator end() const; 00126 iterator end(); 00127 00129 const_iterator find( const sat::Solvable & solv_r ) const; 00130 iterator find( const sat::Solvable & solv_r ); 00132 const_iterator find( const ResObject::constPtr & resolvable_r ) const; 00133 iterator find( const ResObject::constPtr & resolvable_r ); 00135 const_iterator find( const PoolItem & pi_r ) const; 00136 iterator find( const PoolItem & pi_r ); 00137 00138 public: 00153 struct FilterAction; 00154 typedef filter_iterator<FilterAction,const_iterator> action_iterator; 00155 00157 bool actionEmpty( StepStages filter_r = StepStages() ) const; 00158 00160 size_t actionSize( StepStages filter_r = StepStages() ) const; 00161 00163 action_iterator actionBegin( StepStages filter_r = StepStages() ) const; 00164 00166 action_iterator actionEnd() const; 00167 00169 00170 private: 00171 friend base::SafeBool<Transaction>::operator bool_type() const; 00173 bool boolTest() const 00174 { return valid(); } 00175 public: 00177 class Impl; 00178 private: 00180 RW_pointer<Impl> _pimpl; 00181 }; 00182 00183 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Transaction::StepStages); 00184 00186 std::ostream & operator<<( std::ostream & str, const Transaction & obj ); 00187 00189 std::ostream & dumpOn( std::ostream & str, const Transaction & obj ); 00190 00192 bool operator==( const Transaction & lhs, const Transaction & rhs ); 00193 00195 inline bool operator!=( const Transaction & lhs, const Transaction & rhs ) 00196 { return !( lhs == rhs ); } 00197 00198 00209 class Transaction::Step 00210 { 00211 friend std::ostream & operator<<( std::ostream & str, const Step & obj ); 00212 00213 public: 00214 Step(); 00215 Step( const RW_pointer<Impl> & pimpl_r, detail::IdType id_r ) 00216 : _solv( id_r ) 00217 , _pimpl( pimpl_r ) 00218 {} 00219 00220 public: 00222 StepType stepType() const; 00223 00225 StepStage stepStage() const; 00226 00228 void stepStage( StepStage val_r ); 00229 00234 Solvable satSolvable() const 00235 { return _solv; } 00236 00248 IdString ident() const; 00249 00251 Edition edition() const; 00252 00254 Arch arch() const; 00256 00258 operator const Solvable &() const { return _solv; } 00260 operator Solvable &() { return _solv; } 00261 00262 private: 00263 Solvable _solv; 00265 RW_pointer<Impl> _pimpl; 00266 }; 00267 00269 std::ostream & operator<<( std::ostream & str, const Transaction::Step & obj ); 00270 00272 std::ostream & operator<<( std::ostream & str, Transaction::StepType obj ); 00273 00275 std::ostream & operator<<( std::ostream & str, Transaction::StepStage obj ); 00276 00278 namespace detail 00279 { 00280 00283 class Transaction_iterator : public boost::iterator_adaptor< 00284 Transaction_iterator // Derived 00285 , const detail::IdType * // Base 00286 , Transaction::Step // Value 00287 , boost::forward_traversal_tag // CategoryOrTraversal 00288 , Transaction::Step // Reference 00289 > 00290 { 00291 public: 00292 Transaction_iterator(); 00293 Transaction_iterator( const RW_pointer<Transaction::Impl> & pimpl_r, base_type id_r ) 00294 : Transaction_iterator::iterator_adaptor_( id_r ) 00295 , _pimpl( pimpl_r ) 00296 {} 00297 00298 private: 00299 friend class boost::iterator_core_access; 00300 00301 reference dereference() const 00302 { return Transaction::Step( _pimpl, *base() ); } 00303 00304 private: 00305 friend class Transaction_const_iterator; 00307 RW_pointer<Transaction::Impl> _pimpl; 00308 }; 00309 00312 class Transaction_const_iterator : public boost::iterator_adaptor< 00313 Transaction_const_iterator // Derived 00314 , const detail::IdType * // Base 00315 , const Transaction::Step // Value 00316 , boost::forward_traversal_tag // CategoryOrTraversal 00317 , const Transaction::Step // Reference 00318 > 00319 { 00320 public: 00321 Transaction_const_iterator(); 00322 Transaction_const_iterator( const Transaction_iterator & iter_r ); 00323 Transaction_const_iterator( const RW_pointer<Transaction::Impl> & pimpl_r, base_type id_r ) 00324 : Transaction_const_iterator::iterator_adaptor_( id_r ) 00325 , _pimpl( pimpl_r ) 00326 {} 00327 00328 private: 00329 friend class boost::iterator_core_access; 00330 00331 reference dereference() const 00332 { return Transaction::Step( _pimpl, *base() ); } 00333 00334 private: 00336 RW_pointer<Transaction::Impl> _pimpl; 00337 }; 00338 00340 } // namespace detail 00342 00343 inline Transaction::const_iterator Transaction::find( const ResObject::constPtr & resolvable_r ) const 00344 { return( resolvable_r ? find( resolvable_r->satSolvable() ) : end() ); } 00345 00346 inline Transaction::iterator Transaction::find( const ResObject::constPtr & resolvable_r ) 00347 { return( resolvable_r ? find( resolvable_r->satSolvable() ) : end() ); } 00348 00349 inline Transaction::const_iterator Transaction::find( const PoolItem & pi_r ) const 00350 { return find( pi_r.satSolvable() ); } 00351 00352 inline Transaction::iterator Transaction::find( const PoolItem & pi_r ) 00353 { return find( pi_r.satSolvable() ); } 00354 00355 00356 struct Transaction::FilterAction 00357 { 00358 FilterAction() {} 00359 FilterAction( StepStages filter_r ) : _filter( filter_r ) {} 00360 00361 bool operator()( const Transaction::Step & step_r ) const 00362 { 00363 if ( step_r.stepType() == Transaction::TRANSACTION_IGNORE ) 00364 return false; // no action 00365 return !_filter || _filter.testFlag( step_r.stepStage() ); 00366 } 00367 00368 StepStages _filter; 00369 }; 00370 00371 inline Transaction::action_iterator Transaction::actionBegin( StepStages filter_r ) const 00372 { return make_filter_begin( FilterAction( filter_r ), *this ); } 00373 00374 inline Transaction::action_iterator Transaction::actionEnd() const 00375 { return make_filter_end( FilterAction(), *this ); } 00376 00377 inline bool Transaction::actionEmpty( StepStages filter_r ) const 00378 { return( actionBegin( filter_r ) == actionEnd() ); } 00379 00380 inline size_t Transaction::actionSize( StepStages filter_r ) const 00381 { 00382 size_t cnt = 0; 00383 for_( it, actionBegin( filter_r ), actionEnd() ) 00384 ++cnt; 00385 return cnt; 00386 } 00387 00389 } // namespace sat 00392 } // namespace zypp 00394 #endif // ZYPP_SAT_TRANSACTION_H