libzypp  13.10.6
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/Tr1hash.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::tr1::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 _Solv>
143  bool contains( const _Solv & 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 
165  typedef transform_iterator<asPoolItem,Solvable_iterator> PoolItem_iterator;
167  { return make_transform_iterator( solvableBegin(), asPoolItem() ); }
169  { return make_transform_iterator( solvableEnd(), asPoolItem() ); }
171 
172  private:
173  typedef filter_iterator<solvitermixin_detail::UnifyByIdent,Solvable_iterator> UnifiedSolvable_iterator;
174  public:
177  typedef transform_iterator<ui::asSelectable,UnifiedSolvable_iterator> Selectable_iterator;
179  { return make_transform_iterator( unifiedSolvableBegin(), ui::asSelectable() ); }
181  { return make_transform_iterator( unifiedSolvableEnd(), ui::asSelectable() ); }
183 
184  private:
188  { return make_filter_iterator( solvitermixin_detail::UnifyByIdent(), solvableBegin(), solvableEnd() ); }
190  { return make_filter_iterator( solvitermixin_detail::UnifyByIdent(), solvableEnd(), solvableEnd() );; }
192  private:
193  const Derived & self() const
194  { return *static_cast<const Derived*>( this ); }
195  protected:
199  void operator=(const SolvIterMixin &) {}
200  };
202 
204  } // namespace sat
207 } // namespace zypp
209 #endif // ZYPP_SAT_SOLVITERMIXIN_H
A Solvable object within the sat Pool.
Definition: Solvable.h:55
bool contains(const _Solv &solv_r) const
Whether collection contains a specific Solvable.
bool operator()(const Solvable &solv_r) const
UnifiedSolvable_iterator unifiedSolvableBegin() const
UnifiedSolvable_iterator unifiedSolvableEnd() const
filter_iterator< solvitermixin_detail::UnifyByIdent, Solvable_iterator > UnifiedSolvable_iterator
SolvIterMixin(const SolvIterMixin &)
Selectable_iterator selectableEnd() const
transform_iterator< ui::asSelectable, UnifiedSolvable_iterator > Selectable_iterator
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
transform_iterator< asPoolItem, Solvable_iterator > PoolItem_iterator
Base class providing common iterator types based on a Solvable iterator.
DerivedSolvable_iterator Solvable_iterator
Solvable_iterator solvableBegin() const
PoolItem_iterator poolItemEnd() const
PoolItem_iterator poolItemBegin() const
Selectable_iterator selectableBegin() const
Solvable_iterator solvableEnd() const
void operator=(const SolvIterMixin &)
size_type size() const
Size of the collection.
std::tr1::unordered_set< unsigned > Uset
Definition: SolvIterMixin.h:53
bool empty() const
Whether the collection is epmty.
To Solvable transform functor.
Definition: Solvable.h:398
Solvable to PoolItem transform functor.
Definition: PoolItem.h:225
Solvable to Selectable transform functor.
Definition: Selectable.h:520