libzypp  17.3.0
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  {
64  TRANSACTION_IGNORE = 0x00,
65  TRANSACTION_ERASE = 0x10,
66  TRANSACTION_INSTALL = 0x20,
67  TRANSACTION_MULTIINSTALL = 0x30
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 {};
82  static constexpr LoadFromPoolType loadFromPool = 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 
170  public:
174  int installedResult( Queue & result_r ) const;
175 
177  StringQueue autoInstalled() const;
178 
180  void autoInstalled( const StringQueue & queue_r );
181 
182  public:
184  class Impl;
185  private:
188  };
189 
190  ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Transaction::StepStages);
191 
193  std::ostream & operator<<( std::ostream & str, const Transaction & obj );
194 
196  std::ostream & dumpOn( std::ostream & str, const Transaction & obj );
197 
199  bool operator==( const Transaction & lhs, const Transaction & rhs );
200 
202  inline bool operator!=( const Transaction & lhs, const Transaction & rhs )
203  { return !( lhs == rhs ); }
204 
205 
217  {
218  friend std::ostream & operator<<( std::ostream & str, const Step & obj );
219 
220  public:
221  Step();
222  Step( const RW_pointer<Impl> & pimpl_r, detail::IdType id_r )
223  : _solv( id_r )
224  , _pimpl( pimpl_r )
225  {}
226 
227  public:
229  StepType stepType() const;
230 
232  StepStage stepStage() const;
233 
235  void stepStage( StepStage val_r );
236 
242  { return _solv; }
243 
255  IdString ident() const;
256 
258  Edition edition() const;
259 
261  Arch arch() const;
263 
265  operator const Solvable &() const { return _solv; }
267  operator Solvable &() { return _solv; }
268 
269  private:
273  };
274 
276  std::ostream & operator<<( std::ostream & str, const Transaction::Step & obj );
277 
279  std::ostream & operator<<( std::ostream & str, Transaction::StepType obj );
280 
282  std::ostream & operator<<( std::ostream & str, Transaction::StepStage obj );
283 
285  namespace detail
286  {
287 
290  class Transaction_iterator : public boost::iterator_adaptor<
291  Transaction_iterator // Derived
292  , const detail::IdType * // Base
293  , Transaction::Step // Value
294  , boost::forward_traversal_tag // CategoryOrTraversal
295  , Transaction::Step // Reference
296  >
297  {
298  public:
300  Transaction_iterator( const RW_pointer<Transaction::Impl> & pimpl_r, base_type id_r )
301  : Transaction_iterator::iterator_adaptor_( id_r )
302  , _pimpl( pimpl_r )
303  {}
304 
305  private:
306  friend class boost::iterator_core_access;
307 
308  reference dereference() const
309  { return Transaction::Step( _pimpl, *base() ); }
310 
311  private:
315  };
316 
319  class Transaction_const_iterator : public boost::iterator_adaptor<
320  Transaction_const_iterator // Derived
321  , const detail::IdType * // Base
322  , const Transaction::Step // Value
323  , boost::forward_traversal_tag // CategoryOrTraversal
324  , const Transaction::Step // Reference
325  >
326  {
327  public:
331  : Transaction_const_iterator::iterator_adaptor_( id_r )
332  , _pimpl( pimpl_r )
333  {}
334 
335  private:
336  friend class boost::iterator_core_access;
337 
338  reference dereference() const
339  { return Transaction::Step( _pimpl, *base() ); }
340 
341  private:
344  };
345 
347  } // namespace detail
349 
351  { return( resolvable_r ? find( resolvable_r->satSolvable() ) : end() ); }
352 
354  { return( resolvable_r ? find( resolvable_r->satSolvable() ) : end() ); }
355 
357  { return find( pi_r.satSolvable() ); }
358 
360  { return find( pi_r.satSolvable() ); }
361 
362 
364  {
366  FilterAction( StepStages filter_r ) : _filter( filter_r ) {}
367 
368  bool operator()( const Transaction::Step & step_r ) const
369  {
370  if ( step_r.stepType() == Transaction::TRANSACTION_IGNORE )
371  return false; // no action
372  return !_filter || _filter.testFlag( step_r.stepStage() );
373  }
374 
375  StepStages _filter;
376  };
377 
378  inline Transaction::action_iterator Transaction::actionBegin( StepStages filter_r ) const
379  { return make_filter_begin( FilterAction( filter_r ), *this ); }
380 
382  { return make_filter_end( FilterAction(), *this ); }
383 
384  inline bool Transaction::actionEmpty( StepStages filter_r ) const
385  { return( actionBegin( filter_r ) == actionEnd() ); }
386 
387  inline size_t Transaction::actionSize( StepStages filter_r ) const
388  {
389  size_t cnt = 0;
390  for_( it, actionBegin( filter_r ), actionEnd() )
391  ++cnt;
392  return cnt;
393  }
394 
396  } // namespace sat
399 } // namespace zypp
401 #endif // ZYPP_SAT_TRANSACTION_H
ZYPP_DECLARE_FLAGS(VendorSupportOptions, VendorSupportOption)
int IdType
Generic Id type.
Definition: PoolMember.h:104
A Solvable object within the sat Pool.
Definition: Solvable.h:53
Solvable satSolvable() const
Return the corresponding Solvable.
Definition: Transaction.h:241
const_iterator find(const sat::Solvable &solv_r) const
Return iterator pointing to solv_r or end.
Definition: Transaction.cc:347
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: Transaction.h:272
Architecture.
Definition: Arch.h:36
bool operator==(const Map &lhs, const Map &rhs)
Definition: Map.cc:123
StepStage stepStage() const
Step action result.
Definition: Transaction.cc:389
RW_pointer< Transaction::Impl > _pimpl
Pointer to implementation.
Definition: Transaction.h:343
String related utilities and Regular expression matching.
StepStage
Step action result.
Definition: Transaction.h:71
Access to the sat-pools string space.
Definition: IdString.h:41
Libsolv transaction wrapper.
Definition: Transaction.h:51
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
TraitsType::constPtrType constPtr
Definition: ResObject.h:44
Transaction_const_iterator(const RW_pointer< Transaction::Impl > &pimpl_r, base_type id_r)
Definition: Transaction.h:330
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
Step(const RW_pointer< Impl > &pimpl_r, detail::IdType id_r)
Definition: Transaction.h:222
[ ] Nothing (includes implicit deletes due to obsoletes and non-package actions)
Definition: Transaction.h:64
bool operator()(const Transaction::Step &step_r) const
Definition: Transaction.h:368
Base class providing common iterator types based on a Solvable iterator.
filter_iterator< FilterAction, const_iterator > action_iterator
Definition: Transaction.h:153
Transaction_iterator(const RW_pointer< Transaction::Impl > &pimpl_r, base_type id_r)
Definition: Transaction.h:300
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: Transaction.h:184
A single step within a Transaction.
Definition: Transaction.h:216
size_t actionSize(StepStages filter_r=StepStages()) const
Number of steps in [filtered] transaction steps.
Definition: Transaction.h:387
detail::Transaction_const_iterator const_iterator
Definition: Transaction.h:116
Transaction implementation.
Definition: Transaction.cc:47
std::ostream & operator<<(std::ostream &str, const DIWrap &obj)
Definition: LookupAttr.cc:337
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Transaction::StepStages)
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
Libsolv Id queue wrapper.
Definition: Queue.h:34
StepType
Type of (rpm) action to perform in a Step.
Definition: Transaction.h:62
bool actionEmpty(StepStages filter_r=StepStages()) const
Whether the [filtered] transaction contains any steps .
Definition: Transaction.h:384
StepType stepType() const
Type of action to perform in this step.
Definition: Transaction.cc:386
action_iterator actionEnd() const
Pointer behind the last action step in transaction.
Definition: Transaction.h:381
FilterAction(StepStages filter_r)
Definition: Transaction.h:366
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
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
RW_pointer< Transaction::Impl > _pimpl
Pointer to implementation.
Definition: Transaction.h:314
action_iterator actionBegin(StepStages filter_r=StepStages()) const
Pointer to the 1st action step in [filtered] transaction.
Definition: Transaction.h:378
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
detail::Transaction_iterator iterator
Definition: Transaction.h:115
bool operator!=(const Transaction &lhs, const Transaction &rhs)
Definition: Transaction.h:202