libzypp  17.23.5
Transaction.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
11 #ifndef ZYPP_SAT_TRANSACTION_H
12 #define ZYPP_SAT_TRANSACTION_H
13 
14 #include <iosfwd>
15 
16 #include <zypp/base/PtrTypes.h>
17 #include <zypp/base/Flags.h>
18 #include <zypp/base/Iterator.h>
20 
21 #include <zypp/sat/SolvIterMixin.h>
22 #include <zypp/sat/Solvable.h>
23 #include <zypp/sat/Queue.h>
24 
25 #include <zypp/PoolItem.h>
26 
28 namespace zypp
29 {
30  namespace sat
32  {
33 
34  namespace detail
35  {
37  class Transaction_iterator;
39  class Transaction_const_iterator;
40  }
41 
51  class Transaction : public SolvIterMixin<Transaction, detail::Transaction_const_iterator>
52  {
53  friend std::ostream & operator<<( std::ostream & str, const Transaction & obj );
54  friend std::ostream & dumpOn( std::ostream & str, const Transaction & obj );
55  friend bool operator==( const Transaction & lhs, const Transaction & rhs );
56 
57  public:
59  class Step;
60 
62  enum StepType
63  {
68  };
69 
71  enum StepStage
72  {
73  STEP_TODO = (1 << 0),
74  STEP_DONE = (1 << 1),
75  STEP_ERROR = (1 << 2),
76  };
77 
78  ZYPP_DECLARE_FLAGS(StepStages,StepStage);
79 
80  public:
81  struct LoadFromPoolType {};
83 
84  public:
86  Transaction();
87 
90 
92  ~Transaction();
93 
94  public:
96  bool valid() const;
97 
99  explicit operator bool() const
100  { return valid(); }
101 
107  bool order();
108 
110  bool empty() const;
111 
113  size_t size() const;
114 
117 
119  const_iterator begin() const;
121  iterator begin();
122 
124  const_iterator end() const;
126  iterator end();
127 
129  const_iterator find( const sat::Solvable & solv_r ) const;
130  iterator find( const sat::Solvable & solv_r );
132  const_iterator find( const ResObject::constPtr & resolvable_r ) const;
133  iterator find( const ResObject::constPtr & resolvable_r );
135  const_iterator find( const PoolItem & pi_r ) const;
136  iterator find( const PoolItem & pi_r );
137 
138  public:
153  struct FilterAction;
154  typedef filter_iterator<FilterAction,const_iterator> action_iterator;
155 
157  bool actionEmpty( StepStages filter_r = StepStages() ) const;
158 
160  size_t actionSize( StepStages filter_r = StepStages() ) const;
161 
163  action_iterator actionBegin( StepStages filter_r = StepStages() ) const;
164 
166  action_iterator actionEnd() const;
167 
169  Iterable<action_iterator> action( StepStages filter_r = StepStages() ) const;
171 
172  public:
176  int installedResult( Queue & result_r ) const;
177 
179  StringQueue autoInstalled() const;
180 
182  void autoInstalled( const StringQueue & queue_r );
183 
184  public:
186  struct Impl;
187  private:
190  };
191 
192  ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Transaction::StepStages);
193 
195  std::ostream & operator<<( std::ostream & str, const Transaction & obj );
196 
198  std::ostream & dumpOn( std::ostream & str, const Transaction & obj );
199 
201  bool operator==( const Transaction & lhs, const Transaction & rhs );
202 
204  inline bool operator!=( const Transaction & lhs, const Transaction & rhs )
205  { return !( lhs == rhs ); }
206 
207 
219  {
220  friend std::ostream & operator<<( std::ostream & str, const Step & obj );
221 
222  public:
223  Step();
224  Step( const RW_pointer<Impl> & pimpl_r, detail::IdType id_r )
225  : _solv( id_r )
226  , _pimpl( pimpl_r )
227  {}
228 
229  public:
231  StepType stepType() const;
232 
234  StepStage stepStage() const;
235 
237  void stepStage( StepStage val_r );
238 
244  { return _solv; }
245 
257  IdString ident() const;
258 
260  Edition edition() const;
261 
263  Arch arch() const;
265 
267  operator const Solvable &() const { return _solv; }
269  operator Solvable &() { return _solv; }
270 
271  private:
275  };
276 
278  std::ostream & operator<<( std::ostream & str, const Transaction::Step & obj );
279 
281  std::ostream & operator<<( std::ostream & str, Transaction::StepType obj );
282 
284  std::ostream & operator<<( std::ostream & str, Transaction::StepStage obj );
285 
287  namespace detail
288  {
289 
292  class Transaction_iterator : public boost::iterator_adaptor<
293  Transaction_iterator // Derived
294  , const detail::IdType * // Base
295  , Transaction::Step // Value
296  , boost::forward_traversal_tag // CategoryOrTraversal
297  , Transaction::Step // Reference
298  >
299  {
300  public:
302  Transaction_iterator( const RW_pointer<Transaction::Impl> & pimpl_r, base_type id_r )
303  : Transaction_iterator::iterator_adaptor_( id_r )
304  , _pimpl( pimpl_r )
305  {}
306 
307  private:
309 
310  reference dereference() const
311  { return Transaction::Step( _pimpl, *base() ); }
312 
313  private:
317  };
318 
321  class Transaction_const_iterator : public boost::iterator_adaptor<
322  Transaction_const_iterator // Derived
323  , const detail::IdType * // Base
324  , const Transaction::Step // Value
325  , boost::forward_traversal_tag // CategoryOrTraversal
326  , const Transaction::Step // Reference
327  >
328  {
329  public:
333  : Transaction_const_iterator::iterator_adaptor_( id_r )
334  , _pimpl( pimpl_r )
335  {}
336 
337  private:
339 
340  reference dereference() const
341  { return Transaction::Step( _pimpl, *base() ); }
342 
343  private:
346  };
347 
349  } // namespace detail
351 
353  { return( resolvable_r ? find( resolvable_r->satSolvable() ) : end() ); }
354 
356  { return( resolvable_r ? find( resolvable_r->satSolvable() ) : end() ); }
357 
359  { return find( pi_r.satSolvable() ); }
360 
362  { return find( pi_r.satSolvable() ); }
363 
364 
366  {
368  FilterAction( StepStages filter_r ) : _filter( filter_r ) {}
369 
370  bool operator()( const Transaction::Step & step_r ) const
371  {
372  if ( step_r.stepType() == Transaction::TRANSACTION_IGNORE )
373  return false; // no action
374  return !_filter || _filter.testFlag( step_r.stepStage() );
375  }
376 
377  StepStages _filter;
378  };
379 
380  inline Transaction::action_iterator Transaction::actionBegin( StepStages filter_r ) const
381  { return make_filter_begin( FilterAction( filter_r ), *this ); }
382 
384  { return make_filter_end( FilterAction(), *this ); }
385 
386  inline bool Transaction::actionEmpty( StepStages filter_r ) const
387  { return( actionBegin( filter_r ) == actionEnd() ); }
388 
389  inline size_t Transaction::actionSize( StepStages filter_r ) const
390  {
391  size_t cnt = 0;
392  for_( it, actionBegin( filter_r ), actionEnd() )
393  ++cnt;
394  return cnt;
395  }
396 
398  { return makeIterable( actionBegin( filter_r ), actionEnd() ); }
399 
401  } // namespace sat
404 } // namespace zypp
406 #endif // ZYPP_SAT_TRANSACTION_H
zypp::sat::Transaction::Step::arch
Arch arch() const
Definition: Transaction.cc:403
zypp::sat::Transaction::TRANSACTION_IGNORE
[ ] Nothing (includes implicit deletes due to obsoletes and non-package actions)
Definition: Transaction.h:64
zypp::sat::Transaction::_pimpl
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: Transaction.h:186
zypp::sat::Transaction::Step::satSolvable
Solvable satSolvable() const
Return the corresponding Solvable.
Definition: Transaction.h:243
zypp::sat::Transaction::Step::stepStage
StepStage stepStage() const
Step action result.
Definition: Transaction.cc:391
zypp::sat::Transaction::FilterAction::FilterAction
FilterAction()
Definition: Transaction.h:367
zypp::PoolItem
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
zypp::sat::Transaction::empty
bool empty() const
Whether the transaction contains any steps.
Definition: Transaction.cc:331
zypp::sat::Transaction::Step
A single step within a Transaction.
Definition: Transaction.h:218
zypp::sat::Transaction::TRANSACTION_MULTIINSTALL
[M] Install(multiversion) item (
Definition: Transaction.h:67
zypp::sat::Transaction::ZYPP_DECLARE_FLAGS
ZYPP_DECLARE_FLAGS(StepStages, StepStage)
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition: Solvable.h:53
zypp::sat::Transaction::STEP_DONE
[OK] success
Definition: Transaction.h:74
zypp::sat::Transaction::LoadFromPoolType
Ctor arg type.
Definition: Transaction.h:81
zypp::sat::Transaction::TRANSACTION_INSTALL
[+] Install(update) item
Definition: Transaction.h:66
zypp::sat::SolvableType::satSolvable
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
zypp::sat::Transaction::valid
bool valid() const
Whether transaction actually contains data and also fits the current pools content.
Definition: Transaction.cc:325
zypp::sat::Transaction::operator<<
friend std::ostream & operator<<(std::ostream &str, const Transaction &obj)
Definition: Transaction.cc:364
zypp::sat::Transaction::Impl
Transaction implementation.
Definition: Transaction.cc:49
zypp::sat::detail::Transaction_const_iterator::_pimpl
RW_pointer< Transaction::Impl > _pimpl
Pointer to implementation.
Definition: Transaction.h:345
zypp::sat::detail::Transaction_const_iterator::dereference
reference dereference() const
Definition: Transaction.h:340
zypp::Edition
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
zypp::sat::Transaction::find
const_iterator find(const sat::Solvable &solv_r) const
Return iterator pointing to solv_r or end.
Definition: Transaction.cc:349
zypp::sat::Transaction::dumpOn
friend std::ostream & dumpOn(std::ostream &str, const Transaction &obj)
Definition: Transaction.cc:367
zypp::sat::detail::Transaction_const_iterator::Transaction_const_iterator
Transaction_const_iterator(const RW_pointer< Transaction::Impl > &pimpl_r, base_type id_r)
Definition: Transaction.h:332
PtrTypes.h
zypp::make_filter_end
filter_iterator< TFilter, typename TContainer::const_iterator > make_filter_end(TFilter f, const TContainer &c)
Convenience to create filter_iterator from container::end().
Definition: Iterator.h:117
zypp::sat::detail::Transaction_iterator::_pimpl
RW_pointer< Transaction::Impl > _pimpl
Pointer to implementation.
Definition: Transaction.h:316
zypp::sat::Transaction
Libsolv transaction wrapper.
Definition: Transaction.h:51
zypp::sat::Transaction::Step::Step
Step()
Definition: Transaction.cc:385
zypp::sat::Transaction::actionBegin
action_iterator actionBegin(StepStages filter_r=StepStages()) const
Pointer to the 1st action step in [filtered] transaction.
Definition: Transaction.h:380
zypp::Arch
Architecture.
Definition: Arch.h:36
zypp::ResObject::constPtr
TraitsType::constPtrType constPtr
Definition: ResObject.h:43
zypp::sat::Transaction::Transaction
Transaction()
Default ctor: empty transaction.
Definition: Transaction.cc:314
bool
zypp::sat::dumpOn
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
Definition: LocaleSupport.cc:39
zypp::sat::Transaction::StepType
StepType
Type of (rpm) action to perform in a Step.
Definition: Transaction.h:62
zypp::IdString
Access to the sat-pools string space.
Definition: IdString.h:41
zypp::sat::Transaction::Step::edition
Edition edition() const
Definition: Transaction.cc:400
zypp::RW_pointer< Impl >
zypp::sat::Transaction::Step::_solv
Solvable _solv
Definition: Transaction.h:272
zypp::sat::Transaction::iterator
detail::Transaction_iterator iterator
Definition: Transaction.h:115
zypp::sat::Transaction::FilterAction::_filter
StepStages _filter
Definition: Transaction.h:377
zypp::sat::Transaction::Step::ident
IdString ident() const
Definition: Transaction.cc:397
zypp::sat::Transaction::STEP_ERROR
[**] error
Definition: Transaction.h:75
zypp::sat::detail::Transaction_iterator
Transaction iterator.
Definition: Transaction.h:292
zypp::sat::Transaction::action
Iterable< action_iterator > action(StepStages filter_r=StepStages()) const
Iterate the [filtered] transaction steps.
Definition: Transaction.h:397
zypp::sat::detail::Transaction_const_iterator::Transaction_const_iterator
Transaction_const_iterator()
Definition: Transaction.cc:451
zypp::sat::Transaction::Step::Step
Step(const RW_pointer< Impl > &pimpl_r, detail::IdType id_r)
Definition: Transaction.h:224
zypp::sat::Transaction::actionEmpty
bool actionEmpty(StepStages filter_r=StepStages()) const
Whether the [filtered] transaction contains any steps .
Definition: Transaction.h:386
zypp::sat::Transaction::const_iterator
detail::Transaction_const_iterator const_iterator
Definition: Transaction.h:116
zypp::sat::Transaction::loadFromPool
static constexpr LoadFromPoolType loadFromPool
Definition: Transaction.h:82
zypp::sat::detail::IdType
int IdType
Generic Id type.
Definition: PoolMember.h:104
zypp::sat::operator<<
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
Definition: FileConflicts.cc:109
zypp::sat::Transaction::action_iterator
filter_iterator< FilterAction, const_iterator > action_iterator
Definition: Transaction.h:153
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::sat::Transaction::begin
const_iterator begin() const
Iterator to the first TransactionStep.
Definition: Transaction.cc:337
Queue.h
zypp::sat::Transaction::FilterAction::FilterAction
FilterAction(StepStages filter_r)
Definition: Transaction.h:368
zypp::sat::Queue
Libsolv Id queue wrapper.
Definition: Queue.h:34
zypp::sat::Transaction::FilterAction::operator()
bool operator()(const Transaction::Step &step_r) const
Definition: Transaction.h:370
zypp::sat::Transaction::size
size_t size() const
Number of steps in transaction steps.
Definition: Transaction.cc:334
zypp::sat::Transaction::actionSize
size_t actionSize(StepStages filter_r=StepStages()) const
Number of steps in [filtered] transaction steps.
Definition: Transaction.h:389
zypp::sat::Transaction::Step::operator<<
friend std::ostream & operator<<(std::ostream &str, const Step &obj)
Definition: Transaction.cc:406
Iterator.h
zypp::sat::detail::Transaction_const_iterator::iterator_core_access
friend class boost::iterator_core_access
Definition: Transaction.h:338
zypp::sat::Transaction::TRANSACTION_ERASE
[-] Delete item
Definition: Transaction.h:65
zypp::sat::detail::Transaction_iterator::iterator_core_access
friend class boost::iterator_core_access
Definition: Transaction.h:308
zypp::sat::SolvIterMixin
Base class providing common iterator types based on a Solvable iterator.
Definition: SolvIterMixin.h:116
zypp::sat::detail::Transaction_const_iterator
Transaction const_iterator.
Definition: Transaction.h:321
zypp::make_filter_begin
filter_iterator< TFilter, typename TContainer::const_iterator > make_filter_begin(TFilter f, const TContainer &c)
Convenience to create filter_iterator from container::begin().
Definition: Iterator.h:101
zypp::sat::Transaction::installedResult
int installedResult(Queue &result_r) const
Return all packages that would be installed after the transaction is run.
Definition: Transaction.cc:355
SolvIterMixin.h
zypp::sat::Transaction::order
bool order()
Order transaction steps for commit.
Definition: Transaction.cc:328
zypp::sat::Transaction::STEP_TODO
[__] unprocessed
Definition: Transaction.h:73
zypp::sat::Transaction::actionEnd
action_iterator actionEnd() const
Pointer behind the last action step in transaction.
Definition: Transaction.h:383
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
zypp::sat::Transaction::FilterAction
Definition: Transaction.h:365
zypp::sat::detail::Transaction_iterator::Transaction_iterator
Transaction_iterator()
Definition: Transaction.cc:460
zypp::sat::Transaction::Step::stepType
StepType stepType() const
Type of action to perform in this step.
Definition: Transaction.cc:388
PoolItem.h
zypp::sat::Transaction::autoInstalled
StringQueue autoInstalled() const
Return the ident strings of all packages that would be auto-installed after the transaction is run.
Definition: Transaction.cc:358
zypp::sat::Transaction::StepStage
StepStage
Step action result.
Definition: Transaction.h:71
Solvable.h
Flags.h
str
String related utilities and Regular expression matching.
zypp::sat::Transaction::operator==
friend bool operator==(const Transaction &lhs, const Transaction &rhs)
Definition: Transaction.cc:376
zypp::sat::ZYPP_DECLARE_OPERATORS_FOR_FLAGS
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Transaction::StepStages)
zypp::sat::operator==
bool operator==(const Map &lhs, const Map &rhs)
Definition: Map.cc:125
zypp::sat::Transaction::Step::_pimpl
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: Transaction.h:274
zypp::sat::Transaction::~Transaction
~Transaction()
Dtor.
Definition: Transaction.cc:322
zypp::sat::Transaction::operator!=
bool operator!=(const Transaction &lhs, const Transaction &rhs)
Definition: Transaction.h:204
zypp::Iterable
Definition: Iterable.h:36
zypp::sat::detail::Transaction_iterator::Transaction_iterator
Transaction_iterator(const RW_pointer< Transaction::Impl > &pimpl_r, base_type id_r)
Definition: Transaction.h:302
DefaultIntegral.h
zypp::sat::Transaction::end
const_iterator end() const
Iterator behind the last TransactionStep.
Definition: Transaction.cc:343
zypp::sat::detail::Transaction_iterator::dereference
reference dereference() const
Definition: Transaction.h:310