libzypp: zypp/sat/SolvIterMixin.h Source File

libzypp 17.36.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/Hash.h>
20
21#include <zypp/sat/Solvable.h>
22#include <zypp/PoolItem.h>
23#include <zypp/ui/Selectable.h>
24
26namespace zypp
27{
28
30 namespace sat
31 {
32
33 class Solvable;
34 //class asSolvable; // transform functor
35
36 namespace solvitermixin_detail
37 {
43 struct ZYPP_API UnifyByIdent
44 {
45 bool operator()( const Solvable & solv_r ) const;
46
47 using Uset = std::unordered_set<unsigned int>;
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 using size_type = size_t;
120
121 public:
127
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 }
145
146
147 public:
150 using Solvable_iterator = DerivedSolvable_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() ); }
157
158
161 using PoolItem_iterator = transform_iterator<asPoolItem, Solvable_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() ); }
168
169
170 private:
171 using UnifiedSolvable_iterator = filter_iterator<solvitermixin_detail::UnifyByIdent, Solvable_iterator>;
172 public:
175 using Selectable_iterator = transform_iterator<ui::asSelectable, UnifiedSolvable_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() ); }
182
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() ); }
193
194 private:
195 const Derived & self() const
196 { return *static_cast<const Derived*>( this ); }
197 protected:
198 SolvIterMixin() {}
199 ~SolvIterMixin() {}
200 SolvIterMixin(const SolvIterMixin &) = default;
201 SolvIterMixin & operator=(const SolvIterMixin &) = default;
202 SolvIterMixin(SolvIterMixin &&) noexcept = default;
203 SolvIterMixin &operator=(SolvIterMixin &&) noexcept = default;
204 };
205
206
208 } // namespace sat
211} // namespace zypp
213#endif // ZYPP_SAT_SOLVITERMIXIN_H
PoolItem.h
Selectable.h
Solvable.h
filter_iterator
An iterator over the subset of elements of some sequence which satisfy a given predicate.
shared_ptr
transform_iterator
An iterator over elements which are the result of applying some functional transformation to the elem...
zypp::Iterable
Definition Iterable.h:37
zypp::Iterable::makeIterable
Iterable< TIterator > makeIterable(TIterator &&begin_r, TIterator &&end_r)
convenient construction.
Definition Iterable.h:88
zypp::sat::SolvIterMixin::solvableBegin
Solvable_iterator solvableBegin() const
Definition SolvIterMixin.h:151
zypp::sat::SolvIterMixin::selectableBegin
Selectable_iterator selectableBegin() const
Definition SolvIterMixin.h:176
zypp::sat::SolvIterMixin::solvable
Iterable< Solvable_iterator > solvable() const
Definition SolvIterMixin.h:155
zypp::sat::SolvIterMixin::PoolItem_iterator
transform_iterator< asPoolItem, Solvable_iterator > PoolItem_iterator
Definition SolvIterMixin.h:161
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::Solvable_iterator
DerivedSolvable_iterator Solvable_iterator
Definition SolvIterMixin.h:150
zypp::sat::SolvIterMixin::size_type
size_t size_type
Definition SolvIterMixin.h:119
zypp::sat::SolvIterMixin::unifiedSolvable
Iterable< UnifiedSolvable_iterator > unifiedSolvable() const
Definition SolvIterMixin.h:191
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::poolItem
Iterable< PoolItem_iterator > poolItem() const
Definition SolvIterMixin.h:166
zypp::sat::SolvIterMixin::SolvIterMixin
SolvIterMixin()
Definition SolvIterMixin.h:198
zypp::sat::SolvIterMixin::solvableEnd
Solvable_iterator solvableEnd() const
Definition SolvIterMixin.h:153
zypp::sat::SolvIterMixin::SolvIterMixin
SolvIterMixin(SolvIterMixin &&) noexcept=default
zypp::sat::SolvIterMixin::poolItemBegin
PoolItem_iterator poolItemBegin() const
Definition SolvIterMixin.h:162
zypp::sat::SolvIterMixin::self
const Derived & self() const
Definition SolvIterMixin.h:195
zypp::sat::SolvIterMixin::empty
bool empty() const
Whether the collection is epmty.
Definition SolvIterMixin.h:128
zypp::sat::SolvIterMixin::Selectable_iterator
transform_iterator< ui::asSelectable, UnifiedSolvable_iterator > Selectable_iterator
Definition SolvIterMixin.h:175
zypp::sat::SolvIterMixin::SolvIterMixin
SolvIterMixin(const SolvIterMixin &)=default
zypp::sat::SolvIterMixin::operator=
SolvIterMixin & operator=(const SolvIterMixin &)=default
zypp::sat::SolvIterMixin::unifiedSolvableBegin
UnifiedSolvable_iterator unifiedSolvableBegin() const
Definition SolvIterMixin.h:187
zypp::sat::SolvIterMixin::selectable
Iterable< Selectable_iterator > selectable() const
Definition SolvIterMixin.h:180
zypp::sat::SolvIterMixin::UnifiedSolvable_iterator
filter_iterator< solvitermixin_detail::UnifyByIdent, Solvable_iterator > UnifiedSolvable_iterator
Definition SolvIterMixin.h:171
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::sat::solvitermixin_detail
Definition SolvIterMixin.cc:30
zypp::sat
Definition Resolver.h:28
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::ZYPP_API
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
zypp::asPoolItem
Solvable to PoolItem transform functor.
Definition PoolItem.h:204
zypp::sat::asSolvable
To Solvable transform functor.
Definition Solvable.h:579
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 int > 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:587
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
Hash.h
Iterator.h
PtrTypes.h