libzypp  13.10.6
Transaction.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
11 extern "C"
12 {
13  struct _Transaction;
14 }
15 #ifndef ZYPP_SAT_TRANSACTION_H
16 #define ZYPP_SAT_TRANSACTION_H
17 
18 #include <iosfwd>
19 
20 #include "zypp/base/PtrTypes.h"
21 #include "zypp/base/Flags.h"
22 #include "zypp/base/Iterator.h"
24 
25 #include "zypp/sat/SolvIterMixin.h"
26 #include "zypp/sat/Solvable.h"
27 
28 #include "zypp/PoolItem.h"
29 
31 namespace zypp
32 {
33  namespace sat
35  {
36 
37  namespace detail
38  {
40  class Transaction_iterator;
42  class Transaction_const_iterator;
43  }
44 
54  class Transaction : public SolvIterMixin<Transaction, detail::Transaction_const_iterator>
55  {
56  friend std::ostream & operator<<( std::ostream & str, const Transaction & obj );
57  friend std::ostream & dumpOn( std::ostream & str, const Transaction & obj );
58  friend bool operator==( const Transaction & lhs, const Transaction & rhs );
59 
60  public:
62  class Step;
63 
65  enum StepType
66  {
71  };
72 
74  enum StepStage
75  {
76  STEP_TODO = (1 << 0),
77  STEP_DONE = (1 << 1),
78  STEP_ERROR = (1 << 2),
79  };
80 
81  ZYPP_DECLARE_FLAGS(StepStages,StepStage);
82 
83  public:
84  struct LoadFromPoolType {};
86 
87  public:
89  Transaction();
90 
93 
95  ~Transaction();
96 
97  public:
99  bool valid() const;
100 
102  explicit operator bool() const
103  { return valid(); }
104 
110  bool order();
111 
113  bool empty() const;
114 
116  size_t size() const;
117 
120 
122  const_iterator begin() const;
124  iterator begin();
125 
127  const_iterator end() const;
129  iterator end();
130 
132  const_iterator find( const sat::Solvable & solv_r ) const;
133  iterator find( const sat::Solvable & solv_r );
135  const_iterator find( const ResObject::constPtr & resolvable_r ) const;
136  iterator find( const ResObject::constPtr & resolvable_r );
138  const_iterator find( const PoolItem & pi_r ) const;
139  iterator find( const PoolItem & pi_r );
140 
141  public:
156  struct FilterAction;
157  typedef filter_iterator<FilterAction,const_iterator> action_iterator;
158 
160  bool actionEmpty( StepStages filter_r = StepStages() ) const;
161 
163  size_t actionSize( StepStages filter_r = StepStages() ) const;
164 
166  action_iterator actionBegin( StepStages filter_r = StepStages() ) const;
167 
169  action_iterator actionEnd() const;
170 
172 
173  public:
175  class Impl;
176  private:
179  };
180 
181  ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Transaction::StepStages);
182 
184  std::ostream & operator<<( std::ostream & str, const Transaction & obj );
185 
187  std::ostream & dumpOn( std::ostream & str, const Transaction & obj );
188 
190  bool operator==( const Transaction & lhs, const Transaction & rhs );
191 
193  inline bool operator!=( const Transaction & lhs, const Transaction & rhs )
194  { return !( lhs == rhs ); }
195 
196 
208  {
209  friend std::ostream & operator<<( std::ostream & str, const Step & obj );
210 
211  public:
212  Step();
213  Step( const RW_pointer<Impl> & pimpl_r, detail::IdType id_r )
214  : _solv( id_r )
215  , _pimpl( pimpl_r )
216  {}
217 
218  public:
220  StepType stepType() const;
221 
223  StepStage stepStage() const;
224 
226  void stepStage( StepStage val_r );
227 
233  { return _solv; }
234 
246  IdString ident() const;
247 
249  Edition edition() const;
250 
252  Arch arch() const;
254 
256  operator const Solvable &() const { return _solv; }
258  operator Solvable &() { return _solv; }
259 
260  private:
264  };
265 
267  std::ostream & operator<<( std::ostream & str, const Transaction::Step & obj );
268 
270  std::ostream & operator<<( std::ostream & str, Transaction::StepType obj );
271 
273  std::ostream & operator<<( std::ostream & str, Transaction::StepStage obj );
274 
276  namespace detail
277  {
278 
281  class Transaction_iterator : public boost::iterator_adaptor<
282  Transaction_iterator // Derived
283  , const detail::IdType * // Base
284  , Transaction::Step // Value
285  , boost::forward_traversal_tag // CategoryOrTraversal
286  , Transaction::Step // Reference
287  >
288  {
289  public:
291  Transaction_iterator( const RW_pointer<Transaction::Impl> & pimpl_r, base_type id_r )
292  : Transaction_iterator::iterator_adaptor_( id_r )
293  , _pimpl( pimpl_r )
294  {}
295 
296  private:
297  friend class boost::iterator_core_access;
298 
299  reference dereference() const
300  { return Transaction::Step( _pimpl, *base() ); }
301 
302  private:
306  };
307 
310  class Transaction_const_iterator : public boost::iterator_adaptor<
311  Transaction_const_iterator // Derived
312  , const detail::IdType * // Base
313  , const Transaction::Step // Value
314  , boost::forward_traversal_tag // CategoryOrTraversal
315  , const Transaction::Step // Reference
316  >
317  {
318  public:
322  : Transaction_const_iterator::iterator_adaptor_( id_r )
323  , _pimpl( pimpl_r )
324  {}
325 
326  private:
327  friend class boost::iterator_core_access;
328 
329  reference dereference() const
330  { return Transaction::Step( _pimpl, *base() ); }
331 
332  private:
335  };
336 
338  } // namespace detail
340 
342  { return( resolvable_r ? find( resolvable_r->satSolvable() ) : end() ); }
343 
345  { return( resolvable_r ? find( resolvable_r->satSolvable() ) : end() ); }
346 
348  { return find( pi_r.satSolvable() ); }
349 
351  { return find( pi_r.satSolvable() ); }
352 
353 
355  {
357  FilterAction( StepStages filter_r ) : _filter( filter_r ) {}
358 
359  bool operator()( const Transaction::Step & step_r ) const
360  {
361  if ( step_r.stepType() == Transaction::TRANSACTION_IGNORE )
362  return false; // no action
363  return !_filter || _filter.testFlag( step_r.stepStage() );
364  }
365 
366  StepStages _filter;
367  };
368 
369  inline Transaction::action_iterator Transaction::actionBegin( StepStages filter_r ) const
370  { return make_filter_begin( FilterAction( filter_r ), *this ); }
371 
373  { return make_filter_end( FilterAction(), *this ); }
374 
375  inline bool Transaction::actionEmpty( StepStages filter_r ) const
376  { return( actionBegin( filter_r ) == actionEnd() ); }
377 
378  inline size_t Transaction::actionSize( StepStages filter_r ) const
379  {
380  size_t cnt = 0;
381  for_( it, actionBegin( filter_r ), actionEnd() )
382  ++cnt;
383  return cnt;
384  }
385 
387  } // namespace sat
390 } // namespace zypp
392 #endif // ZYPP_SAT_TRANSACTION_H
int IdType
Generic Id type.
Definition: PoolMember.h:82
A Solvable object within the sat Pool.
Definition: Solvable.h:55
friend bool operator==(const Transaction &lhs, const Transaction &rhs)
Definition: Transaction.cc:354
[M] Install(multiversion) item (
Definition: Transaction.h:70
ZYPP_DECLARE_FLAGS(StepStages, StepStage)
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: Transaction.h:263
Architecture.
Definition: Arch.h:36
friend std::ostream & dumpOn(std::ostream &str, const Transaction &obj)
Definition: Transaction.cc:345
size_t actionSize(StepStages filter_r=StepStages()) const
Number of steps in [filtered] transaction steps.
Definition: Transaction.h:378
RW_pointer< Transaction::Impl > _pimpl
Pointer to implementation.
Definition: Transaction.h:334
const_iterator find(const sat::Solvable &solv_r) const
Return iterator pointing to solv_r or end.
Definition: Transaction.cc:336
StepStage
Step action result.
Definition: Transaction.h:74
Transaction()
Default ctor: empty transaction.
Definition: Transaction.cc:301
Access to the sat-pools string space.
Definition: IdString.h:39
Libsolv transaction wrapper.
Definition: Transaction.h:54
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
filter_iterator< _Filter, typename _Container::const_iterator > make_filter_begin(_Filter f, const _Container &c)
Convenience to create filter_iterator from container::begin().
Definition: Iterator.h:99
TraitsType::constPtrType constPtr
Definition: ResObject.h:50
Transaction_const_iterator(const RW_pointer< Transaction::Impl > &pimpl_r, base_type id_r)
Definition: Transaction.h:321
Step(const RW_pointer< Impl > &pimpl_r, detail::IdType id_r)
Definition: Transaction.h:213
const_iterator begin() const
Iterator to the first TransactionStep.
Definition: Transaction.cc:324
StepStage stepStage() const
Step action result.
Definition: Transaction.cc:369
[ ] Nothing (includes implicit deletes due to obsoletes and non-package actions)
Definition: Transaction.h:67
Base class providing common iterator types based on a Solvable iterator.
StepType stepType() const
Type of action to perform in this step.
Definition: Transaction.cc:366
filter_iterator< FilterAction, const_iterator > action_iterator
Definition: Transaction.h:156
Transaction_iterator(const RW_pointer< Transaction::Impl > &pimpl_r, base_type id_r)
Definition: Transaction.h:291
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: Transaction.h:175
friend std::ostream & operator<<(std::ostream &str, const Transaction &obj)
Definition: Transaction.cc:342
bool actionEmpty(StepStages filter_r=StepStages()) const
Whether the [filtered] transaction contains any steps .
Definition: Transaction.h:375
A single step within a Transaction.
Definition: Transaction.h:207
detail::Transaction_const_iterator const_iterator
Definition: Transaction.h:119
Transaction implementation.
Definition: Transaction.cc:47
bool order()
Order transaction steps for commit.
Definition: Transaction.cc:315
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Transaction::StepStages)
bool valid() const
Whether transaction actually contains data and also fits the current pools content.
Definition: Transaction.cc:312
action_iterator actionEnd() const
Pointer behind the last action step in transaction.
Definition: Transaction.h:372
Solvable satSolvable() const
Return the corresponding Solvable.
Definition: Transaction.h:232
StepType
Type of (rpm) action to perform in a Step.
Definition: Transaction.h:65
size_t size() const
Number of steps in transaction steps.
Definition: Transaction.cc:321
action_iterator actionBegin(StepStages filter_r=StepStages()) const
Pointer to the 1st action step in [filtered] transaction.
Definition: Transaction.h:369
static constexpr LoadFromPoolType loadFromPool
Definition: Transaction.h:85
bool empty() const
Whether the transaction contains any steps.
Definition: Transaction.cc:318
const_iterator end() const
Iterator behind the last TransactionStep.
Definition: Transaction.cc:330
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:265
sat::Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: PoolItem.h:114
filter_iterator< _Filter, typename _Container::const_iterator > make_filter_end(_Filter f, const _Container &c)
Convenience to create filter_iterator from container::end().
Definition: Iterator.h:115
FilterAction(StepStages filter_r)
Definition: Transaction.h:357
Reference to a PoolItem connecting ResObject and ResStatus.
Definition: PoolItem.h:50
bool operator()(const Transaction::Step &step_r) const
Definition: Transaction.h:359
RW_pointer< Transaction::Impl > _pimpl
Pointer to implementation.
Definition: Transaction.h:305
detail::Transaction_iterator iterator
Definition: Transaction.h:118
bool operator!=(const Transaction &lhs, const Transaction &rhs)
Definition: Transaction.h:193