libzypp  17.5.0
SolvIterMixin.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_SAT_SOLVITERMIXIN_H
13 #define ZYPP_SAT_SOLVITERMIXIN_H
14 
15 #include <iosfwd>
16 
17 #include "zypp/base/PtrTypes.h"
18 #include "zypp/base/Iterator.h"
19 #include "zypp/base/Hash.h"
20 
21 #include "zypp/sat/Solvable.h"
22 
24 namespace zypp
25 {
26 
27  class PoolItem;
28  class asPoolItem; // transform functor
29 
30  namespace ui
31  {
32  class asSelectable; // transform functor
33  }
34 
36  namespace sat
37  {
38 
39  class Solvable;
40  class asSolvable; // transform functor
41 
42  namespace solvitermixin_detail
43  {
49  struct UnifyByIdent
50  {
51  bool operator()( const Solvable & solv_r ) const;
52 
53  typedef std::unordered_set<unsigned> Uset;
55  : _uset( new Uset )
56  {}
57  shared_ptr<Uset> _uset;
58  };
59 
60 
61  } // namespace solvitermixin_detail
62 
63 
65  //
66  // CLASS NAME : SolvIterMixin<Derived,DerivedSolvable_iterator>
67  //
121  template <class Derived,class DerivedSolvable_iterator>
123  {
124  public:
125  typedef size_t size_type;
126 
127  public:
134  bool empty() const
135  { return( self().begin() == self().end() ); }
136 
138  size_type size() const
139  { size_type s = 0; for_( it, self().begin(), self().end() ) ++s; return s;}
140 
142  template<class TSolv>
143  bool contains( const TSolv & solv_r ) const
144  {
145  Solvable solv( asSolvable()( solv_r ) );
146  for_( it, self().begin(), self().end() )
147  if ( *it == solv )
148  return true;
149  return false;
150  }
152 
153  public:
156  typedef DerivedSolvable_iterator Solvable_iterator;
158  { return self().begin(); }
160  { return self().end(); }
162  { return makeIterable( solvableBegin(), solvableEnd() ); }
164 
167  typedef transform_iterator<asPoolItem,Solvable_iterator> PoolItem_iterator;
169  { return make_transform_iterator( solvableBegin(), asPoolItem() ); }
171  { return make_transform_iterator( solvableEnd(), asPoolItem() ); }
173  { return makeIterable( poolItemBegin(), poolItemEnd() ); }
175 
176  private:
177  typedef filter_iterator<solvitermixin_detail::UnifyByIdent,Solvable_iterator> UnifiedSolvable_iterator;
178  public:
181  typedef transform_iterator<ui::asSelectable,UnifiedSolvable_iterator> Selectable_iterator;
183  { return make_transform_iterator( unifiedSolvableBegin(), ui::asSelectable() ); }
185  { return make_transform_iterator( unifiedSolvableEnd(), ui::asSelectable() ); }
187  { return makeIterable( selectableBegin(), selectableEnd() ); }
189 
190  private:
194  { return make_filter_iterator( solvitermixin_detail::UnifyByIdent(), solvableBegin(), solvableEnd() ); }
196  { return make_filter_iterator( solvitermixin_detail::UnifyByIdent(), solvableEnd(), solvableEnd() ); }
198  { return makeIterable( unifiedSolvableBegin(), unifiedSolvableEnd() ); }
200  private:
201  const Derived & self() const
202  { return *static_cast<const Derived*>( this ); }
203  protected:
207  void operator=(const SolvIterMixin &) {}
208  };
210 
212  } // namespace sat
215 } // namespace zypp
217 #endif // ZYPP_SAT_SOLVITERMIXIN_H
Selectable_iterator selectableBegin() const
A Solvable object within the sat Pool.
Definition: Solvable.h:53
std::unordered_set< unsigned > Uset
Definition: SolvIterMixin.h:53
filter_iterator< solvitermixin_detail::UnifyByIdent, Solvable_iterator > UnifiedSolvable_iterator
Solvable_iterator solvableBegin() const
SolvIterMixin(const SolvIterMixin &)
transform_iterator< ui::asSelectable, UnifiedSolvable_iterator > Selectable_iterator
PoolItem_iterator poolItemBegin() const
Iterable< UnifiedSolvable_iterator > unifiedSolvable() const
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
PoolItem_iterator poolItemEnd() const
transform_iterator< asPoolItem, Solvable_iterator > PoolItem_iterator
bool operator()(const Solvable &solv_r) const
Base class providing common iterator types based on a Solvable iterator.
Iterable< Selectable_iterator > selectable() const
DerivedSolvable_iterator Solvable_iterator
UnifiedSolvable_iterator unifiedSolvableBegin() const
size_type size() const
Size of the collection.
Iterable< Solvable_iterator > solvable() const
Solvable_iterator solvableEnd() const
bool empty() const
Whether the collection is epmty.
void operator=(const SolvIterMixin &)
UnifiedSolvable_iterator unifiedSolvableEnd() const
Selectable_iterator selectableEnd() const
Iterable< PoolItem_iterator > poolItem() const
To Solvable transform functor.
Definition: Solvable.h:514
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
Solvable to PoolItem transform functor.
Definition: PoolItem.h:198
Solvable to Selectable transform functor.
Definition: Selectable.h:542
bool contains(const TSolv &solv_r) const
Whether collection contains a specific Solvable.