libzypp: zypp/sat/SolvIterMixin.h Source File

libzypp 17.25.10

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;
48 UnifyByIdent()
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>
116 class SolvIterMixin
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;
151 Solvable_iterator solvableBegin() const
152 { return self().begin(); }
153 Solvable_iterator solvableEnd() const
154 { return self().end(); }
155 Iterable<Solvable_iterator> solvable() const
156 { return makeIterable( solvableBegin(), solvableEnd() ); }
158
161 typedef transform_iterator<asPoolItem,Solvable_iterator> PoolItem_iterator;
162 PoolItem_iterator poolItemBegin() const
163 { return make_transform_iterator( solvableBegin(), asPoolItem() ); }
164 PoolItem_iterator poolItemEnd() const
165 { return make_transform_iterator( solvableEnd(), asPoolItem() ); }
166 Iterable<PoolItem_iterator> poolItem() const
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;
176 Selectable_iterator selectableBegin() const
177 { return make_transform_iterator( unifiedSolvableBegin(), ui::asSelectable() ); }
178 Selectable_iterator selectableEnd() const
179 { return make_transform_iterator( unifiedSolvableEnd(), ui::asSelectable() ); }
180 Iterable<Selectable_iterator> selectable() const
181 { return makeIterable( selectableBegin(), selectableEnd() ); }
183
184 private:
187 UnifiedSolvable_iterator unifiedSolvableBegin() const
188 { return make_filter_iterator( solvitermixin_detail::UnifyByIdent(), solvableBegin(), solvableEnd() ); }
189 UnifiedSolvable_iterator unifiedSolvableEnd() const
190 { return make_filter_iterator( solvitermixin_detail::UnifyByIdent(), solvableEnd(), solvableEnd() ); }
191 Iterable<UnifiedSolvable_iterator> unifiedSolvable() const
192 { return makeIterable( unifiedSolvableBegin(), unifiedSolvableEnd() ); }
194 private:
195 const Derived & self() const
196 { return *static_cast<const Derived*>( this ); }
197 protected:
198 SolvIterMixin() {}
199 ~SolvIterMixin() {}
200 SolvIterMixin(const SolvIterMixin &) {}
201 void operator=(const SolvIterMixin &) {}
202 };
204
206 } // namespace sat
209 } // namespace zypp
211 #endif // ZYPP_SAT_SOLVITERMIXIN_H
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
Hash.h
Iterator.h
PoolItem.h
PtrTypes.h
Selectable.h
Solvable.h
zypp::Iterable
Definition: Iterable.h:37
zypp::sat::SolvIterMixin
Base class providing common iterator types based on a Solvable iterator.
Definition: SolvIterMixin.h:117
zypp::sat::SolvIterMixin::PoolItem_iterator
transform_iterator< asPoolItem, Solvable_iterator > PoolItem_iterator
Definition: SolvIterMixin.h:161
zypp::sat::SolvIterMixin::solvableBegin
Solvable_iterator solvableBegin() const
Definition: SolvIterMixin.h:151
zypp::sat::SolvIterMixin::SolvIterMixin
SolvIterMixin(const SolvIterMixin &)
Definition: SolvIterMixin.h:200
zypp::sat::SolvIterMixin::selectableBegin
Selectable_iterator selectableBegin() const
Definition: SolvIterMixin.h:176
zypp::sat::SolvIterMixin::operator=
void operator=(const SolvIterMixin &)
Definition: SolvIterMixin.h:201
zypp::sat::SolvIterMixin::solvable
Iterable< Solvable_iterator > solvable() const
Definition: SolvIterMixin.h:155
zypp::sat::SolvIterMixin::UnifiedSolvable_iterator
filter_iterator< solvitermixin_detail::UnifyByIdent, Solvable_iterator > UnifiedSolvable_iterator
Definition: SolvIterMixin.h:171
zypp::sat::SolvIterMixin::Solvable_iterator
DerivedSolvable_iterator Solvable_iterator
Definition: SolvIterMixin.h:150
zypp::sat::SolvIterMixin::contains
bool contains(const TSolv &solv_r) const
Whether collection contains a specific Solvable.
Definition: SolvIterMixin.h:137
zypp::sat::SolvIterMixin::~SolvIterMixin
~SolvIterMixin()
Definition: SolvIterMixin.h:199
zypp::sat::SolvIterMixin::selectable
Iterable< Selectable_iterator > selectable() const
Definition: SolvIterMixin.h:180
zypp::sat::SolvIterMixin::Selectable_iterator
transform_iterator< ui::asSelectable, UnifiedSolvable_iterator > Selectable_iterator
Definition: SolvIterMixin.h:175
zypp::sat::SolvIterMixin::size_type
size_t size_type
Definition: SolvIterMixin.h:119
zypp::sat::SolvIterMixin::poolItemEnd
PoolItem_iterator poolItemEnd() const
Definition: SolvIterMixin.h:164
zypp::sat::SolvIterMixin::selectableEnd
Selectable_iterator selectableEnd() const
Definition: SolvIterMixin.h:178
zypp::sat::SolvIterMixin::unifiedSolvable
Iterable< UnifiedSolvable_iterator > unifiedSolvable() const
Definition: SolvIterMixin.h:191
zypp::sat::SolvIterMixin::SolvIterMixin
SolvIterMixin()
Definition: SolvIterMixin.h:198
zypp::sat::SolvIterMixin::solvableEnd
Solvable_iterator solvableEnd() const
Definition: SolvIterMixin.h:153
zypp::sat::SolvIterMixin::poolItemBegin
PoolItem_iterator poolItemBegin() const
Definition: SolvIterMixin.h:162
zypp::sat::SolvIterMixin::empty
bool empty() const
Whether the collection is epmty.
Definition: SolvIterMixin.h:128
zypp::sat::SolvIterMixin::poolItem
Iterable< PoolItem_iterator > poolItem() const
Definition: SolvIterMixin.h:166
zypp::sat::SolvIterMixin::unifiedSolvableBegin
UnifiedSolvable_iterator unifiedSolvableBegin() const
Definition: SolvIterMixin.h:187
zypp::sat::SolvIterMixin::unifiedSolvableEnd
UnifiedSolvable_iterator unifiedSolvableEnd() const
Definition: SolvIterMixin.h:189
zypp::sat::SolvIterMixin::size
size_type size() const
Size of the collection.
Definition: SolvIterMixin.h:132
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition: Solvable.h:54
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::asPoolItem
Solvable to PoolItem transform functor.
Definition: PoolItem.h:199
zypp::sat::asSolvable
To Solvable transform functor.
Definition: Solvable.h:529
zypp::sat::solvitermixin_detail::UnifyByIdent
Unify by ident (kind:name).
Definition: SolvIterMixin.h:44
zypp::sat::solvitermixin_detail::UnifyByIdent::_uset
shared_ptr< Uset > _uset
Definition: SolvIterMixin.h:51
zypp::sat::solvitermixin_detail::UnifyByIdent::Uset
std::unordered_set< unsigned > Uset
Definition: SolvIterMixin.h:47
zypp::sat::solvitermixin_detail::UnifyByIdent::UnifyByIdent
UnifyByIdent()
Definition: SolvIterMixin.h:48
zypp::sat::solvitermixin_detail::UnifyByIdent::operator()
bool operator()(const Solvable &solv_r) const
Definition: SolvIterMixin.cc:31
zypp::ui::asSelectable
Solvable to Selectable transform functor.
Definition: Selectable.h:566