libzypp  17.25.1
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 #include <zypp/PoolItem.h>
23 #include <zypp/ui/Selectable.h>
24 
26 namespace zypp
27 {
28 
30  namespace sat
31  {
32 
33  class Solvable;
34  //class asSolvable; // transform functor
35 
36  namespace solvitermixin_detail
37  {
43  struct UnifyByIdent
44  {
45  bool operator()( const Solvable & solv_r ) const;
46 
47  typedef std::unordered_set<unsigned> Uset;
49  : _uset( new Uset )
50  {}
51  shared_ptr<Uset> _uset;
52  };
53 
54 
55  } // namespace solvitermixin_detail
56 
57 
59  //
60  // CLASS NAME : SolvIterMixin<Derived,DerivedSolvable_iterator>
61  //
115  template <class Derived,class DerivedSolvable_iterator>
117  {
118  public:
119  typedef size_t size_type;
120 
121  public:
128  bool empty() const
129  { return( self().begin() == self().end() ); }
130 
132  size_type size() const
133  { size_type s = 0; for_( it, self().begin(), self().end() ) ++s; return s;}
134 
136  template<class TSolv>
137  bool contains( const TSolv & solv_r ) const
138  {
139  Solvable solv( asSolvable()( solv_r ) );
140  for_( it, self().begin(), self().end() )
141  if ( *it == solv )
142  return true;
143  return false;
144  }
146 
147  public:
150  typedef DerivedSolvable_iterator Solvable_iterator;
152  { return self().begin(); }
154  { return self().end(); }
156  { return makeIterable( solvableBegin(), solvableEnd() ); }
158 
161  typedef transform_iterator<asPoolItem,Solvable_iterator> PoolItem_iterator;
163  { return make_transform_iterator( solvableBegin(), asPoolItem() ); }
165  { return make_transform_iterator( solvableEnd(), asPoolItem() ); }
167  { return makeIterable( poolItemBegin(), poolItemEnd() ); }
169 
170  private:
171  typedef filter_iterator<solvitermixin_detail::UnifyByIdent,Solvable_iterator> UnifiedSolvable_iterator;
172  public:
175  typedef transform_iterator<ui::asSelectable,UnifiedSolvable_iterator> Selectable_iterator;
177  { return make_transform_iterator( unifiedSolvableBegin(), ui::asSelectable() ); }
179  { return make_transform_iterator( unifiedSolvableEnd(), ui::asSelectable() ); }
181  { return makeIterable( selectableBegin(), selectableEnd() ); }
183 
184  private:
188  { return make_filter_iterator( solvitermixin_detail::UnifyByIdent(), solvableBegin(), solvableEnd() ); }
190  { return make_filter_iterator( solvitermixin_detail::UnifyByIdent(), solvableEnd(), solvableEnd() ); }
192  { return makeIterable( unifiedSolvableBegin(), unifiedSolvableEnd() ); }
194  private:
195  const Derived & self() const
196  { return *static_cast<const Derived*>( this ); }
197  protected:
201  void operator=(const SolvIterMixin &) {}
202  };
204 
206  } // namespace sat
209 } // namespace zypp
211 #endif // ZYPP_SAT_SOLVITERMIXIN_H
zypp::sat::SolvIterMixin::PoolItem_iterator
transform_iterator< asPoolItem, Solvable_iterator > PoolItem_iterator
Definition: SolvIterMixin.h:161
zypp::sat::SolvIterMixin::unifiedSolvableEnd
UnifiedSolvable_iterator unifiedSolvableEnd() const
Definition: SolvIterMixin.h:189
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition: Solvable.h:53
zypp::sat::solvitermixin_detail::UnifyByIdent
Unify by ident (kind:name).
Definition: SolvIterMixin.h:43
zypp::sat::solvitermixin_detail::UnifyByIdent::operator()
bool operator()(const Solvable &solv_r) const
Definition: SolvIterMixin.cc:31
zypp::sat::SolvIterMixin::size
size_type size() const
Size of the collection.
Definition: SolvIterMixin.h:132
zypp::sat::SolvIterMixin::poolItem
Iterable< PoolItem_iterator > poolItem() const
Definition: SolvIterMixin.h:166
zypp::sat::SolvIterMixin::solvable
Iterable< Solvable_iterator > solvable() const
Definition: SolvIterMixin.h:155
zypp::sat::SolvIterMixin::size_type
size_t size_type
Definition: SolvIterMixin.h:119
zypp::sat::SolvIterMixin::~SolvIterMixin
~SolvIterMixin()
Definition: SolvIterMixin.h:199
zypp::sat::solvitermixin_detail::UnifyByIdent::_uset
shared_ptr< Uset > _uset
Definition: SolvIterMixin.h:51
PtrTypes.h
zypp::sat::SolvIterMixin::SolvIterMixin
SolvIterMixin()
Definition: SolvIterMixin.h:198
zypp::sat::SolvIterMixin::selectableEnd
Selectable_iterator selectableEnd() const
Definition: SolvIterMixin.h:178
zypp::asPoolItem
Solvable to PoolItem transform functor.
Definition: PoolItem.h:198
zypp::sat::asSolvable
To Solvable transform functor.
Definition: Solvable.h:528
zypp::sat::SolvIterMixin::Selectable_iterator
transform_iterator< ui::asSelectable, UnifiedSolvable_iterator > Selectable_iterator
Definition: SolvIterMixin.h:175
zypp::sat::SolvIterMixin::UnifiedSolvable_iterator
filter_iterator< solvitermixin_detail::UnifyByIdent, Solvable_iterator > UnifiedSolvable_iterator
Definition: SolvIterMixin.h:171
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::sat::SolvIterMixin::contains
bool contains(const TSolv &solv_r) const
Whether collection contains a specific Solvable.
Definition: SolvIterMixin.h:137
Selectable.h
Iterator.h
zypp::sat::SolvIterMixin::selectableBegin
Selectable_iterator selectableBegin() const
Definition: SolvIterMixin.h:176
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
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
zypp::sat::solvitermixin_detail::UnifyByIdent::UnifyByIdent
UnifyByIdent()
Definition: SolvIterMixin.h:48
zypp::ui::asSelectable
Solvable to Selectable transform functor.
Definition: Selectable.h:565
zypp::sat::SolvIterMixin::selectable
Iterable< Selectable_iterator > selectable() const
Definition: SolvIterMixin.h:180
PoolItem.h
zypp::sat::SolvIterMixin::Solvable_iterator
DerivedSolvable_iterator Solvable_iterator
Definition: SolvIterMixin.h:150
zypp::sat::SolvIterMixin::unifiedSolvableBegin
UnifiedSolvable_iterator unifiedSolvableBegin() const
Definition: SolvIterMixin.h:187
zypp::sat::SolvIterMixin::SolvIterMixin
SolvIterMixin(const SolvIterMixin &)
Definition: SolvIterMixin.h:200
Solvable.h
zypp::sat::solvitermixin_detail::UnifyByIdent::Uset
std::unordered_set< unsigned > Uset
Definition: SolvIterMixin.h:47
Hash.h
zypp::sat::SolvIterMixin::poolItemBegin
PoolItem_iterator poolItemBegin() const
Definition: SolvIterMixin.h:162
zypp::sat::SolvIterMixin::unifiedSolvable
Iterable< UnifiedSolvable_iterator > unifiedSolvable() const
Definition: SolvIterMixin.h:191
zypp::sat::SolvIterMixin::empty
bool empty() const
Whether the collection is epmty.
Definition: SolvIterMixin.h:128
zypp::sat::SolvIterMixin::solvableBegin
Solvable_iterator solvableBegin() const
Definition: SolvIterMixin.h:151
zypp::sat::SolvIterMixin::solvableEnd
Solvable_iterator solvableEnd() const
Definition: SolvIterMixin.h:153
zypp::sat::SolvIterMixin::operator=
void operator=(const SolvIterMixin &)
Definition: SolvIterMixin.h:201
zypp::sat::SolvIterMixin::poolItemEnd
PoolItem_iterator poolItemEnd() const
Definition: SolvIterMixin.h:164
zypp::Iterable
Definition: Iterable.h:36