libzypp 17.37.10

ResPoolProxy.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <utility>
14#include <zypp/base/LogTools.h>
15
16#include <zypp/base/Iterator.h>
17#include <zypp/base/Algorithm.h>
18#include <zypp/base/Functional.h>
19
20#include <zypp/ResPoolProxy.h>
21#include <zypp/pool/PoolImpl.h>
22#include <zypp/ui/SelectableImpl.h>
23
24 using std::endl;
25
27 namespace zypp
28{
29
31 struct PoolItemSaver
32 {
33 void saveState( const ResPool& pool_r )
34 {
35 std::for_each( pool_r.begin(), pool_r.end(),
36 std::mem_fn(&PoolItem::saveState) );
37 }
38
39 void saveState( const ResPool& pool_r, const ResKind & kind_r )
40 {
41 std::for_each( pool_r.byKindBegin(kind_r), pool_r.byKindEnd(kind_r),
42 std::mem_fn(&PoolItem::saveState) );
43 }
44
45 void restoreState( const ResPool& pool_r )
46 {
47 std::for_each( pool_r.begin(), pool_r.end(),
48 std::mem_fn(&PoolItem::restoreState) );
49 }
50
51 void restoreState( const ResPool& pool_r, const ResKind & kind_r )
52 {
53 std::for_each( pool_r.byKindBegin(kind_r), pool_r.byKindEnd(kind_r),
54 std::mem_fn(&PoolItem::restoreState) );
55 }
56
57 bool diffState( const ResPool& pool_r ) const
58 {
59 // return whether some PoolItem::sameState reported \c false.
60 return( invokeOnEach( pool_r.begin(), pool_r.end(),
61 std::mem_fn(&PoolItem::sameState) ) < 0 );
62 }
63
64 bool diffState( const ResPool& pool_r, const ResKind & kind_r ) const
65 {
66 // return whether some PoolItem::sameState reported \c false.
67 return( invokeOnEach( pool_r.byKindBegin(kind_r), pool_r.byKindEnd(kind_r),
68 std::mem_fn(&PoolItem::sameState) ) < 0 );
69 }
70 };
71
72 namespace
73 {
74 ui::Selectable::Ptr makeSelectablePtr( pool::PoolImpl::Id2ItemT::const_iterator begin_r,
75 pool::PoolImpl::Id2ItemT::const_iterator end_r )
76 {
77 pool::PoolTraits::byIdent_iterator begin( begin_r, pool::PoolTraits::Id2ItemValueSelector() );
78 pool::PoolTraits::byIdent_iterator end( end_r, pool::PoolTraits::Id2ItemValueSelector() );
79 sat::Solvable solv( begin->satSolvable() );
80
81 return new ui::Selectable( ui::Selectable::Impl_Ptr( new ui::Selectable::Impl( solv.kind(), solv.name(), begin, end ) ) );
82 }
83 } // namespace
84
86 //
87 // CLASS NAME : ResPoolProxy::Impl
88 //
92 struct ResPoolProxy::Impl
93 {
94 friend std::ostream & operator<<( std::ostream & str, const Impl & obj );
95 friend std::ostream & dumpOn( std::ostream & str, const Impl & obj );
96
97 using SelectableIndex = std::unordered_map<sat::detail::IdType, ui::Selectable::Ptr>;
98 using const_iterator = ResPoolProxy::const_iterator;
99
100 public:
101 Impl()
102 :_pool( ResPool::instance() )
103 {}
104
105 Impl( ResPool &&pool_r, const pool::PoolImpl & poolImpl_r )
106 : _pool( std::move(pool_r) )
107 {
108 const pool::PoolImpl::Id2ItemT & id2item( poolImpl_r.id2item() );
109 if ( ! id2item.empty() )
110 {
111 // set startpoint
112 pool::PoolImpl::Id2ItemT::const_iterator cbegin = id2item.begin();
113
114 for_( it, id2item.begin(), id2item.end() )
115 {
116 if ( it->first != cbegin->first )
117 {
118 // starting a new Selectable, create the previous one
119 ui::Selectable::Ptr p( makeSelectablePtr( cbegin, it ) );
120 _selPool.insert( SelectablePool::value_type( p->kind(), p ) );
121 _selIndex[cbegin->first] = p;
122 // remember new startpoint
123 cbegin = it;
124 }
125 }
126 // create the final one
127 ui::Selectable::Ptr p( makeSelectablePtr( cbegin, id2item.end() ) );
128 _selPool.insert( SelectablePool::value_type( p->kind(), p ) );
129 _selIndex[cbegin->first] = p;
130 }
131 }
132
133 public:
134 ui::Selectable::Ptr lookup( const pool::ByIdent & ident_r ) const
135 {
136 SelectableIndex::const_iterator it( _selIndex.find( ident_r.get() ) );
137 if ( it != _selIndex.end() )
138 return it->second;
139 return ui::Selectable::Ptr();
140 }
141
142 public:
143 bool empty() const
144 { return _selPool.empty(); }
145
146 size_type size() const
147 { return _selPool.size(); }
148
149 const_iterator begin() const
150 { return make_map_value_begin( _selPool ); }
151
152 const_iterator end() const
153 { return make_map_value_end( _selPool ); }
154
155 public:
156 bool empty( const ResKind & kind_r ) const
157 { return( _selPool.count( kind_r ) == 0 ); }
158
159 size_type size( const ResKind & kind_r ) const
160 { return _selPool.count( kind_r ); }
161
162 const_iterator byKindBegin( const ResKind & kind_r ) const
163 { return make_map_value_lower_bound( _selPool, kind_r ); }
164
165 const_iterator byKindEnd( const ResKind & kind_r ) const
166 { return make_map_value_upper_bound( _selPool, kind_r ); }
167
168 public:
169 size_type knownRepositoriesSize() const
170 { return _pool.knownRepositoriesSize(); }
171
172 repository_iterator knownRepositoriesBegin() const
173 { return _pool.knownRepositoriesBegin(); }
174
175 repository_iterator knownRepositoriesEnd() const
176 { return _pool.knownRepositoriesEnd(); }
177
178 public:
179
180 void saveState() const
181 { PoolItemSaver().saveState( _pool ); }
182
183 void saveState( const ResKind & kind_r ) const
184 { PoolItemSaver().saveState( _pool, kind_r ); }
185
186 void restoreState() const
187 { PoolItemSaver().restoreState( _pool ); }
188
189 void restoreState( const ResKind & kind_r ) const
190 { PoolItemSaver().restoreState( _pool, kind_r ); }
191
192 bool diffState() const
193 { return PoolItemSaver().diffState( _pool ); }
194
195 bool diffState( const ResKind & kind_r ) const
196 { return PoolItemSaver().diffState( _pool, kind_r ); }
197
198 private:
199 ResPool _pool;
200 mutable SelectablePool _selPool;
201 mutable SelectableIndex _selIndex;
202
203 public:
205 static shared_ptr<Impl> nullimpl()
206 {
207 static shared_ptr<Impl> _nullimpl( new Impl );
208 return _nullimpl;
209 }
210 };
211
212
214 inline std::ostream & operator<<( std::ostream & str, const ResPoolProxy::Impl & obj )
215 {
216 return str << "ResPoolProxy (" << obj._pool.serial() << ") [" << obj._pool.size()
217 << "solv/" << obj.size()<< "sel]";
218 }
219
220 namespace detail
221 {
222 struct DumpFilter
223 {
224 bool operator()( const ui::Selectable::Ptr & selp ) const
225 { return selp->toModify(); }
226 };
227 }
228
230 inline std::ostream & dumpOn( std::ostream & str, const ResPoolProxy::Impl & obj )
231 {
232 detail::DumpFilter f;
233 return dumpRange( str << obj << " toModify: ",
234 make_filter_begin( f, obj ),
235 make_filter_end( f, obj ) );
236 }
237
239 //
240 // CLASS NAME : ResPoolProxy
241 //
243
245 //
246 // METHOD NAME : ResPoolProxy::ResPoolProxy
247 // METHOD TYPE : Ctor
248 //
249 ResPoolProxy::ResPoolProxy()
250 : _pimpl( Impl::nullimpl() )
251 {}
252
254 //
255 // METHOD NAME : ResPoolProxy::ResPoolProxy
256 // METHOD TYPE : Ctor
257 //
258 ResPoolProxy::ResPoolProxy( ResPool pool_r, const pool::PoolImpl & poolImpl_r )
259 : _pimpl( new Impl( std::move(pool_r), poolImpl_r ) )
260 {}
261
263 //
264 // METHOD NAME : ResPoolProxy::~ResPoolProxy
265 // METHOD TYPE : Dtor
266 //
267 ResPoolProxy::~ResPoolProxy()
268 {}
269
271 //
272 // forward to implementation
273 //
275
276 ui::Selectable::Ptr ResPoolProxy::lookup( const pool::ByIdent & ident_r ) const
277 { return _pimpl->lookup( ident_r ); }
278
279 bool ResPoolProxy::empty() const
280 { return _pimpl->empty(); }
281
282 ResPoolProxy::size_type ResPoolProxy::size() const
283 { return _pimpl->size(); }
284
285 ResPoolProxy::const_iterator ResPoolProxy::begin() const
286 { return _pimpl->begin(); }
287
288 ResPoolProxy::const_iterator ResPoolProxy::end() const
289 { return _pimpl->end(); }
290
291 bool ResPoolProxy::empty( const ResKind & kind_r ) const
292 { return _pimpl->empty( kind_r ); }
293
294 ResPoolProxy::size_type ResPoolProxy::size( const ResKind & kind_r ) const
295 { return _pimpl->size( kind_r ); }
296
297 ResPoolProxy::const_iterator ResPoolProxy::byKindBegin( const ResKind & kind_r ) const
298 { return _pimpl->byKindBegin( kind_r ); }
299
300 ResPoolProxy::const_iterator ResPoolProxy::byKindEnd( const ResKind & kind_r ) const
301 { return _pimpl->byKindEnd( kind_r ); }
302
303 ResPoolProxy::size_type ResPoolProxy::knownRepositoriesSize() const
304 { return _pimpl->knownRepositoriesSize(); }
305
306 ResPoolProxy::repository_iterator ResPoolProxy::knownRepositoriesBegin() const
307 { return _pimpl->knownRepositoriesBegin(); }
308
309 ResPoolProxy::repository_iterator ResPoolProxy::knownRepositoriesEnd() const
310 { return _pimpl->knownRepositoriesEnd(); }
311
312 void ResPoolProxy::saveState() const
313 { _pimpl->saveState(); }
314
315 void ResPoolProxy::saveState( const ResKind & kind_r ) const
316 { _pimpl->saveState( kind_r ); }
317
318 void ResPoolProxy::restoreState() const
319 { _pimpl->restoreState(); }
320
321 void ResPoolProxy::restoreState( const ResKind & kind_r ) const
322 { _pimpl->restoreState( kind_r ); }
323
324 bool ResPoolProxy::diffState() const
325 { return _pimpl->diffState(); }
326
327 bool ResPoolProxy::diffState( const ResKind & kind_r ) const
328 { return _pimpl->diffState( kind_r ); }
329
330 std::ostream & operator<<( std::ostream & str, const ResPoolProxy & obj )
331 { return str << *obj._pimpl; }
332
333 std::ostream & dumpOn( std::ostream & str, const ResPoolProxy & obj )
334 { return dumpOn( str, *obj._pimpl ); }
335
337} // namespace zypp
Algorithm.h
Functional.h
ResPoolProxy.h
SelectableImpl.h
shared_ptr
zypp::PoolItem::restoreState
void restoreState() const
Definition PoolItem.cc:225
zypp::PoolItem::saveState
void saveState() const
Definition PoolItem.cc:224
zypp::PoolItem::sameState
bool sameState() const
Definition PoolItem.cc:226
zypp::ResKind
Resolvable kinds.
Definition ResKind.h:33
zypp::ResPoolProxy::repository_iterator
ResPool::repository_iterator repository_iterator
Definition ResPoolProxy.h:48
zypp::ResPoolProxy::saveState
void saveState() const
Definition ResPoolProxy.cc:312
zypp::ResPoolProxy::size
size_type size() const
Definition ResPoolProxy.cc:282
zypp::ResPoolProxy::byKindEnd
const_iterator byKindEnd() const
Definition ResPoolProxy.h:120
zypp::ResPoolProxy::knownRepositoriesSize
size_type knownRepositoriesSize() const
Definition ResPoolProxy.cc:303
zypp::ResPoolProxy::~ResPoolProxy
~ResPoolProxy()
Dtor.
Definition ResPoolProxy.cc:267
zypp::ResPoolProxy::begin
const_iterator begin() const
Definition ResPoolProxy.cc:285
zypp::ResPoolProxy::SelectablePool
std::multimap< ResKind, ui::Selectable::Ptr > SelectablePool
Definition ResPoolProxy.h:39
zypp::ResPoolProxy::end
const_iterator end() const
Definition ResPoolProxy.cc:288
zypp::ResPoolProxy::ResPoolProxy
ResPoolProxy()
Default ctor: no pool Nonempty proxies are provided by ResPool.
Definition ResPoolProxy.cc:249
zypp::ResPoolProxy::_pimpl
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition ResPoolProxy.h:252
zypp::ResPoolProxy::empty
bool empty() const
Definition ResPoolProxy.cc:279
zypp::ResPoolProxy::diffState
bool diffState() const
Definition ResPoolProxy.cc:324
zypp::ResPoolProxy::const_iterator
MapKVIteratorTraits< SelectablePool >::Value_const_iterator const_iterator
Definition ResPoolProxy.h:45
zypp::ResPoolProxy::restoreState
void restoreState() const
Definition ResPoolProxy.cc:318
zypp::ResPoolProxy::size_type
SelectablePool::size_type size_type
Definition ResPoolProxy.h:46
zypp::ResPoolProxy::knownRepositoriesBegin
repository_iterator knownRepositoriesBegin() const
Definition ResPoolProxy.cc:306
zypp::ResPoolProxy::lookup
ui::Selectable::Ptr lookup(const pool::ByIdent &ident_r) const
Definition ResPoolProxy.cc:276
zypp::ResPoolProxy::knownRepositoriesEnd
repository_iterator knownRepositoriesEnd() const
Definition ResPoolProxy.cc:309
zypp::ResPoolProxy::byKindBegin
const_iterator byKindBegin() const
Definition ResPoolProxy.h:113
zypp::ResPool
Global ResObject pool.
Definition ResPool.h:62
zypp::ResPool::end
const_iterator end() const
Definition ResPool.h:101
zypp::ResPool::byKindEnd
byKind_iterator byKindEnd(const ResKind &kind_r) const
Definition ResPool.h:269
zypp::ResPool::serial
const SerialNumber & serial() const
The pools serial number.
Definition ResPool.cc:65
zypp::ResPool::byKindBegin
byKind_iterator byKindBegin(const ResKind &kind_r) const
Definition ResPool.h:262
zypp::ResPool::begin
const_iterator begin() const
Definition ResPool.h:98
zypp::ResPool::size
size_type size() const
Definition ResPool.cc:71
zypp::pool::ByIdent
Main filter selecting PoolItems by name and kind.
Definition ByIdent.h:29
zypp::pool::ByIdent::get
sat::detail::IdType get() const
Definition ByIdent.h:90
zypp::pool::PoolImpl
Definition PoolImpl.h:169
zypp::pool::PoolImpl::id2item
const Id2ItemT & id2item() const
Definition PoolImpl.h:431
zypp::pool::PoolImpl::Id2ItemT
PoolTraits::Id2ItemT Id2ItemT
Definition PoolImpl.h:177
zypp::ui::Selectable::Impl_Ptr
shared_ptr< Impl > Impl_Ptr
Definition Selectable.h:562
zypp::ui::Selectable::Ptr
intrusive_ptr< Selectable > Ptr
Definition Selectable.h:58
std
Definition Arch.h:364
str
String related utilities and Regular expression matching.
zypp::solver::detail
Definition PoolImpl.h:110
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::dumpRange
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
Definition LogTools.h:120
zypp::make_map_value_lower_bound
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_lower_bound(const TMap &map_r, const typename TMap::key_type &key_r)
Convenience to create the value iterator from container::lower_bound()
Definition Iterator.h:256
zypp::make_map_value_begin
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_begin(const TMap &map_r)
Convenience to create the value iterator from container::begin()
Definition Iterator.h:236
zypp::dumpOn
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition Capability.cc:580
zypp::make_filter_begin
filter_iterator< TFilter, typename TContainer::const_iterator > make_filter_begin(TFilter f, const TContainer &c)
Convenience to create filter_iterator from container::begin().
Definition Iterator.h:101
zypp::make_map_value_end
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_end(const TMap &map_r)
Convenience to create the value iterator from container::end()
Definition Iterator.h:241
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition SerialNumber.cc:52
zypp::make_map_value_upper_bound
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_upper_bound(const TMap &map_r, const typename TMap::key_type &key_r)
Convenience to create the value iterator from container::upper_bound()
Definition Iterator.h:261
zypp::make_filter_end
filter_iterator< TFilter, typename TContainer::const_iterator > make_filter_end(TFilter f, const TContainer &c)
Convenience to create filter_iterator from container::end().
Definition Iterator.h:117
zypp::invokeOnEach
int invokeOnEach(TIterator begin_r, TIterator end_r, TFilter filter_r, TFunction fnc_r)
Iterate through [begin_r,end_r) and invoke fnc_r on each item that passes filter_r.
Definition Algorithm.h:30
PoolImpl.h
zypp::PoolItemSaver
Tem.
Definition ResPoolProxy.cc:32
zypp::PoolItemSaver::saveState
void saveState(const ResPool &pool_r, const ResKind &kind_r)
Definition ResPoolProxy.cc:39
zypp::PoolItemSaver::diffState
bool diffState(const ResPool &pool_r, const ResKind &kind_r) const
Definition ResPoolProxy.cc:64
zypp::PoolItemSaver::saveState
void saveState(const ResPool &pool_r)
Definition ResPoolProxy.cc:33
zypp::PoolItemSaver::restoreState
void restoreState(const ResPool &pool_r, const ResKind &kind_r)
Definition ResPoolProxy.cc:51
zypp::PoolItemSaver::restoreState
void restoreState(const ResPool &pool_r)
Definition ResPoolProxy.cc:45
zypp::PoolItemSaver::diffState
bool diffState(const ResPool &pool_r) const
Definition ResPoolProxy.cc:57
zypp::ResPoolProxy::Impl
ResPoolProxy implementation.
Definition ResPoolProxy.cc:93
zypp::ResPoolProxy::Impl::_selPool
SelectablePool _selPool
Definition ResPoolProxy.cc:200
zypp::ResPoolProxy::Impl::size
size_type size() const
Definition ResPoolProxy.cc:146
zypp::ResPoolProxy::Impl::restoreState
void restoreState(const ResKind &kind_r) const
Definition ResPoolProxy.cc:189
zypp::ResPoolProxy::Impl::Impl
Impl()
Definition ResPoolProxy.cc:101
zypp::ResPoolProxy::Impl::diffState
bool diffState(const ResKind &kind_r) const
Definition ResPoolProxy.cc:195
zypp::ResPoolProxy::Impl::operator<<
std::ostream & operator<<(std::ostream &str, const ResPoolProxy::Impl &obj)
Stream output.
Definition ResPoolProxy.cc:214
zypp::ResPoolProxy::Impl::saveState
void saveState() const
Definition ResPoolProxy.cc:180
zypp::ResPoolProxy::Impl::knownRepositoriesEnd
repository_iterator knownRepositoriesEnd() const
Definition ResPoolProxy.cc:175
zypp::ResPoolProxy::Impl::knownRepositoriesBegin
repository_iterator knownRepositoriesBegin() const
Definition ResPoolProxy.cc:172
zypp::ResPoolProxy::Impl::Impl
Impl(ResPool &&pool_r, const pool::PoolImpl &poolImpl_r)
Definition ResPoolProxy.cc:105
zypp::ResPoolProxy::Impl::begin
const_iterator begin() const
Definition ResPoolProxy.cc:149
zypp::ResPoolProxy::Impl::nullimpl
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Definition ResPoolProxy.cc:205
zypp::ResPoolProxy::Impl::empty
bool empty() const
Definition ResPoolProxy.cc:143
zypp::ResPoolProxy::Impl::diffState
bool diffState() const
Definition ResPoolProxy.cc:192
zypp::ResPoolProxy::Impl::dumpOn
std::ostream & dumpOn(std::ostream &str, const ResPoolProxy::Impl &obj)
Verbose stream output.
Definition ResPoolProxy.cc:230
zypp::ResPoolProxy::Impl::restoreState
void restoreState() const
Definition ResPoolProxy.cc:186
zypp::ResPoolProxy::Impl::_selIndex
SelectableIndex _selIndex
Definition ResPoolProxy.cc:201
zypp::ResPoolProxy::Impl::empty
bool empty(const ResKind &kind_r) const
Definition ResPoolProxy.cc:156
zypp::ResPoolProxy::Impl::operator<<
friend std::ostream & operator<<(std::ostream &str, const Impl &obj)
zypp::ResPoolProxy::Impl::saveState
void saveState(const ResKind &kind_r) const
Definition ResPoolProxy.cc:183
zypp::ResPoolProxy::Impl::size
size_type size(const ResKind &kind_r) const
Definition ResPoolProxy.cc:159
zypp::ResPoolProxy::Impl::SelectableIndex
std::unordered_map< sat::detail::IdType, ui::Selectable::Ptr > SelectableIndex
Definition ResPoolProxy.cc:97
zypp::ResPoolProxy::Impl::lookup
ui::Selectable::Ptr lookup(const pool::ByIdent &ident_r) const
Definition ResPoolProxy.cc:134
zypp::ResPoolProxy::Impl::knownRepositoriesSize
size_type knownRepositoriesSize() const
Definition ResPoolProxy.cc:169
zypp::ResPoolProxy::Impl::end
const_iterator end() const
Definition ResPoolProxy.cc:152
zypp::ResPoolProxy::Impl::_pool
ResPool _pool
Definition ResPoolProxy.cc:199
zypp::ResPoolProxy::Impl::const_iterator
ResPoolProxy::const_iterator const_iterator
Definition ResPoolProxy.cc:98
zypp::ResPoolProxy::Impl::byKindEnd
const_iterator byKindEnd(const ResKind &kind_r) const
Definition ResPoolProxy.cc:165
zypp::ResPoolProxy::Impl::byKindBegin
const_iterator byKindBegin(const ResKind &kind_r) const
Definition ResPoolProxy.cc:162
zypp::ResPoolProxy::Impl::dumpOn
friend std::ostream & dumpOn(std::ostream &str, const Impl &obj)
zypp::detail::DumpFilter
Definition ResPoolProxy.cc:223
zypp::detail::DumpFilter::operator()
bool operator()(const ui::Selectable::Ptr &selp) const
Definition ResPoolProxy.cc:224
zypp::pool::PoolTraits::Id2ItemValueSelector
P_Select2nd< Id2ItemT::value_type > Id2ItemValueSelector
Definition PoolTraits.h:78
zypp::pool::PoolTraits::byIdent_iterator
transform_iterator< Id2ItemValueSelector, Id2ItemT::const_iterator > byIdent_iterator
Definition PoolTraits.h:79
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
Iterator.h
LogTools.h