libzypp: zypp/sat/SolvIterMixin.h Source File

libzypp 17.38.5

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-core/base/PtrTypes.h>
18#include <zypp-core/base/Iterator.h>
19#include <zypp-core/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 {
44 struct ZYPP_API UnifyByIdent2
45 {
46 bool operator()( const Solvable & solv_r ) const;
47
48 using Umap = std::unordered_map<sat::detail::IdType,sat::detail::SolvableIdType>;
49 UnifyByIdent2()
50 : _umap( new Umap )
51 {}
52 shared_ptr<Umap> _umap;
53 };
54
55#if LEGACY(1735)
56 // Keep legacy version to stay binary compatible.
57 // Recompiled code will use UnifyByIdent2.
58 struct ZYPP_API UnifyByIdent
59 {
60 bool operator()( const Solvable & solv_r ) const;
61
62 using Uset = std::unordered_set<unsigned int>;
63 UnifyByIdent()
64 : _uset( new Uset )
65 {}
66 shared_ptr<Uset> _uset;
67 };
68#endif
69 } // namespace solvitermixin_detail
70
71
73 //
74 // CLASS NAME : SolvIterMixin<Derived,DerivedSolvable_iterator>
75 //
129 template <class Derived,class DerivedSolvable_iterator>
130 class SolvIterMixin
131 {
132 public:
133 using size_type = size_t;
134
135 public:
141
142 bool empty() const
143 { return( self().begin() == self().end() ); }
144
146 size_type size() const
147 { size_type s = 0; for_( it, self().begin(), self().end() ) ++s; return s;}
148
150 template<class TSolv>
151 bool contains( const TSolv & solv_r ) const
152 {
153 Solvable solv( asSolvable()( solv_r ) );
154 for_( it, self().begin(), self().end() )
155 if ( *it == solv )
156 return true;
157 return false;
158 }
159
160
161 public:
164 using Solvable_iterator = DerivedSolvable_iterator;
165 Solvable_iterator solvableBegin() const
166 { return self().begin(); }
167 Solvable_iterator solvableEnd() const
168 { return self().end(); }
169 Iterable<Solvable_iterator> solvable() const
170 { return makeIterable( solvableBegin(), solvableEnd() ); }
171
172
175 using PoolItem_iterator = transform_iterator<asPoolItem, Solvable_iterator>;
176 PoolItem_iterator poolItemBegin() const
177 { return make_transform_iterator( solvableBegin(), asPoolItem() ); }
178 PoolItem_iterator poolItemEnd() const
179 { return make_transform_iterator( solvableEnd(), asPoolItem() ); }
180 Iterable<PoolItem_iterator> poolItem() const
181 { return makeIterable( poolItemBegin(), poolItemEnd() ); }
182
183
184 private:
185 using UnifiedSolvable_iterator = filter_iterator<solvitermixin_detail::UnifyByIdent2, Solvable_iterator>;
186 public:
189 using Selectable_iterator = transform_iterator<ui::asSelectable, UnifiedSolvable_iterator>;
190 Selectable_iterator selectableBegin() const
191 { return make_transform_iterator( unifiedSolvableBegin(), ui::asSelectable() ); }
192 Selectable_iterator selectableEnd() const
193 { return make_transform_iterator( unifiedSolvableEnd(), ui::asSelectable() ); }
194 Iterable<Selectable_iterator> selectable() const
195 { return makeIterable( selectableBegin(), selectableEnd() ); }
196
197
198 private:
201 UnifiedSolvable_iterator unifiedSolvableBegin() const
202 { return make_filter_iterator( solvitermixin_detail::UnifyByIdent2(), solvableBegin(), solvableEnd() ); }
203 UnifiedSolvable_iterator unifiedSolvableEnd() const
204 { return make_filter_iterator( solvitermixin_detail::UnifyByIdent2(), solvableEnd(), solvableEnd() ); }
205 Iterable<UnifiedSolvable_iterator> unifiedSolvable() const
206 { return makeIterable( unifiedSolvableBegin(), unifiedSolvableEnd() ); }
207
208 private:
209 const Derived & self() const
210 { return *static_cast<const Derived*>( this ); }
211 protected:
212 SolvIterMixin() {}
213 ~SolvIterMixin() {}
214 SolvIterMixin(const SolvIterMixin &) = default;
215 SolvIterMixin & operator=(const SolvIterMixin &) = default;
216 SolvIterMixin(SolvIterMixin &&) noexcept = default;
217 SolvIterMixin &operator=(SolvIterMixin &&) noexcept = default;
218 };
219
220
222 } // namespace sat
225} // namespace zypp
227#endif // ZYPP_SAT_SOLVITERMIXIN_H
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
Hash.h
Iterator.h
PoolItem.h
PtrTypes.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::Arch::operator()
bool operator()(const zypp::Arch &lhs, const zypp::Arch &rhs) const
Default order for std::container based Arch::compare.
Definition Arch.h:370
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:165
zypp::sat::SolvIterMixin::selectableBegin
Selectable_iterator selectableBegin() const
Definition SolvIterMixin.h:190
zypp::sat::SolvIterMixin::solvable
Iterable< Solvable_iterator > solvable() const
Definition SolvIterMixin.h:169
zypp::sat::SolvIterMixin::PoolItem_iterator
transform_iterator< asPoolItem, Solvable_iterator > PoolItem_iterator
Definition SolvIterMixin.h:175
zypp::sat::SolvIterMixin::contains
bool contains(const TSolv &solv_r) const
Whether collection contains a specific Solvable.
Definition SolvIterMixin.h:151
zypp::sat::SolvIterMixin::~SolvIterMixin
~SolvIterMixin()
Definition SolvIterMixin.h:213
zypp::sat::SolvIterMixin::Solvable_iterator
DerivedSolvable_iterator Solvable_iterator
Definition SolvIterMixin.h:164
zypp::sat::SolvIterMixin::size_type
size_t size_type
Definition SolvIterMixin.h:133
zypp::sat::SolvIterMixin::unifiedSolvable
Iterable< UnifiedSolvable_iterator > unifiedSolvable() const
Definition SolvIterMixin.h:205
zypp::sat::SolvIterMixin::poolItemEnd
PoolItem_iterator poolItemEnd() const
Definition SolvIterMixin.h:178
zypp::sat::SolvIterMixin::selectableEnd
Selectable_iterator selectableEnd() const
Definition SolvIterMixin.h:192
zypp::sat::SolvIterMixin::poolItem
Iterable< PoolItem_iterator > poolItem() const
Definition SolvIterMixin.h:180
zypp::sat::SolvIterMixin::SolvIterMixin
SolvIterMixin()
Definition SolvIterMixin.h:212
zypp::sat::SolvIterMixin::solvableEnd
Solvable_iterator solvableEnd() const
Definition SolvIterMixin.h:167
zypp::sat::SolvIterMixin::SolvIterMixin
SolvIterMixin(SolvIterMixin &&) noexcept=default
zypp::sat::SolvIterMixin::poolItemBegin
PoolItem_iterator poolItemBegin() const
Definition SolvIterMixin.h:176
zypp::sat::SolvIterMixin::self
const Derived & self() const
Definition SolvIterMixin.h:209
zypp::sat::SolvIterMixin::UnifiedSolvable_iterator
filter_iterator< solvitermixin_detail::UnifyByIdent2, Solvable_iterator > UnifiedSolvable_iterator
Definition SolvIterMixin.h:185
zypp::sat::SolvIterMixin::empty
bool empty() const
Whether the collection is epmty.
Definition SolvIterMixin.h:142
zypp::sat::SolvIterMixin::Selectable_iterator
transform_iterator< ui::asSelectable, UnifiedSolvable_iterator > Selectable_iterator
Definition SolvIterMixin.h:189
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:201
zypp::sat::SolvIterMixin::selectable
Iterable< Selectable_iterator > selectable() const
Definition SolvIterMixin.h:194
zypp::sat::SolvIterMixin::unifiedSolvableEnd
UnifiedSolvable_iterator unifiedSolvableEnd() const
Definition SolvIterMixin.h:203
zypp::sat::SolvIterMixin::size
size_type size() const
Size of the collection.
Definition SolvIterMixin.h:146
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition Solvable.h:54
zypp::sat::solvitermixin_detail
Definition SolvIterMixin.cc:30
zypp::sat
Libsolv interface
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
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:598
zypp::sat::solvitermixin_detail::UnifyByIdent2
Unify by ident (kind:name).
Definition SolvIterMixin.h:45
zypp::sat::solvitermixin_detail::UnifyByIdent2::_umap
shared_ptr< Umap > _umap
Definition SolvIterMixin.h:52
zypp::sat::solvitermixin_detail::UnifyByIdent2::Umap
std::unordered_map< sat::detail::IdType, sat::detail::SolvableIdType > Umap
Definition SolvIterMixin.h:48
zypp::sat::solvitermixin_detail::UnifyByIdent2::operator()
bool operator()(const Solvable &solv_r) const
Definition SolvIterMixin.cc:31
zypp::sat::solvitermixin_detail::UnifyByIdent2::UnifyByIdent2
UnifyByIdent2()
Definition SolvIterMixin.h:49
zypp::ui::asSelectable
Solvable to Selectable transform functor.
Definition Selectable.h:587