libzypp 17.38.15
ResPoolProxy.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <utility>
15
17#include <zypp/base/Algorithm.h>
19
20#include <zypp/ResPoolProxy.h>
21#include <zypp/pool/PoolImpl.h>
23
24using std::endl;
25
27namespace zypp
28{
29
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 {
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 //
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>;
99
100 public:
102 :_pool( ResPool::instance() )
103 {}
104
105 Impl( ResPool &&pool_r, const pool::PoolImpl & poolImpl_r )
106 : _pool( std::move(pool_r) )
107 , _id2item( &poolImpl_r.id2item() )
108 , _serial( poolImpl_r.serial().serial() )
109 {}
110
111 public:
112 ui::Selectable::Ptr lookup( const pool::ByIdent & ident_r ) const
113 {
114 SelectableIndex::const_iterator it( _selIndex.find( ident_r.get() ) );
115 if ( it != _selIndex.end() )
116 return it->second;
117 if ( _id2item && _pool.serial().serial() == _serial )
118 {
119 // create just this Selectable; a single lookup does not
120 // have to pay for materializing the whole pool
121 auto range = _id2item->equal_range( ident_r.get() );
122 if ( range.first != range.second )
123 {
124 ui::Selectable::Ptr p( makeSelectablePtr( range.first, range.second ) );
125 _selPool.insert( SelectablePool::value_type( p->kind(), p ) );
126 _selIndex[ident_r.get()] = p;
127 return p;
128 }
129 }
130 return ui::Selectable::Ptr();
131 }
132
133 private:
134 void materialize() const
135 {
136 if ( ! _id2item )
137 return;
138 const pool::PoolImpl::Id2ItemT & id2item( *_id2item );
139 _id2item = nullptr;
140 if ( _pool.serial().serial() != _serial )
141 return;
142 if ( ! id2item.empty() )
143 {
144 // set startpoint
145 pool::PoolImpl::Id2ItemT::const_iterator cbegin = id2item.begin();
146
147 for_( it, id2item.begin(), id2item.end() )
148 {
149 if ( it->first != cbegin->first )
150 {
151 // starting a new Selectable, create the previous one
152 if ( ! _selIndex.count( cbegin->first ) )
153 {
154 ui::Selectable::Ptr p( makeSelectablePtr( cbegin, it ) );
155 _selPool.insert( SelectablePool::value_type( p->kind(), p ) );
156 _selIndex[cbegin->first] = p;
157 }
158 // remember new startpoint
159 cbegin = it;
160 }
161 }
162 // create the final one
163 if ( ! _selIndex.count( cbegin->first ) )
164 {
165 ui::Selectable::Ptr p( makeSelectablePtr( cbegin, id2item.end() ) );
166 _selPool.insert( SelectablePool::value_type( p->kind(), p ) );
167 _selIndex[cbegin->first] = p;
168 }
169 }
170 }
171
172 public:
173 bool empty() const
174 { materialize(); return _selPool.empty(); }
175
177 { materialize(); return _selPool.size(); }
178
181
184
185 public:
186 bool empty( const ResKind & kind_r ) const
187 { materialize(); return( _selPool.count( kind_r ) == 0 ); }
188
189 size_type size( const ResKind & kind_r ) const
190 { materialize(); return _selPool.count( kind_r ); }
191
192 const_iterator byKindBegin( const ResKind & kind_r ) const
193 { materialize(); return make_map_value_lower_bound( _selPool, kind_r ); }
194
195 const_iterator byKindEnd( const ResKind & kind_r ) const
196 { materialize(); return make_map_value_upper_bound( _selPool, kind_r ); }
197
198 public:
200 { return _pool.knownRepositoriesSize(); }
201
203 { return _pool.knownRepositoriesBegin(); }
204
206 { return _pool.knownRepositoriesEnd(); }
207
208 public:
209
210 void saveState() const
212
213 void saveState( const ResKind & kind_r ) const
214 { PoolItemSaver().saveState( _pool, kind_r ); }
215
216 void restoreState() const
218
219 void restoreState( const ResKind & kind_r ) const
220 { PoolItemSaver().restoreState( _pool, kind_r ); }
221
222 bool diffState() const
223 { return PoolItemSaver().diffState( _pool ); }
224
225 bool diffState( const ResKind & kind_r ) const
226 { return PoolItemSaver().diffState( _pool, kind_r ); }
227
228 private:
230 mutable const pool::PoolImpl::Id2ItemT * _id2item = nullptr; //< unmaterialized idents, guarded by _serial
231 unsigned _serial = 0;
234
235 public:
238 {
239 static shared_ptr<Impl> _nullimpl( new Impl );
240 return _nullimpl;
241 }
242 };
243
244
246 inline std::ostream & operator<<( std::ostream & str, const ResPoolProxy::Impl & obj )
247 {
248 return str << "ResPoolProxy (" << obj._pool.serial() << ") [" << obj._pool.size()
249 << "solv/" << obj.size()<< "sel]";
250 }
251
252 namespace detail
253 {
255 {
256 bool operator()( const ui::Selectable::Ptr & selp ) const
257 { return selp->toModify(); }
258 };
259 }
260
262 inline std::ostream & dumpOn( std::ostream & str, const ResPoolProxy::Impl & obj )
263 {
265 return dumpRange( str << obj << " toModify: ",
266 make_filter_begin( f, obj ),
267 make_filter_end( f, obj ) );
268 }
269
271 //
272 // CLASS NAME : ResPoolProxy
273 //
275
277 //
278 // METHOD NAME : ResPoolProxy::ResPoolProxy
279 // METHOD TYPE : Ctor
280 //
282 : _pimpl( Impl::nullimpl() )
283 {}
284
286 //
287 // METHOD NAME : ResPoolProxy::ResPoolProxy
288 // METHOD TYPE : Ctor
289 //
291 : _pimpl( new Impl( std::move(pool_r), poolImpl_r ) )
292 {}
293
295 //
296 // METHOD NAME : ResPoolProxy::~ResPoolProxy
297 // METHOD TYPE : Dtor
298 //
301
303 //
304 // forward to implementation
305 //
307
309 { return _pimpl->lookup( ident_r ); }
310
312 { return _pimpl->empty(); }
313
315 { return _pimpl->size(); }
316
319
322
323 bool ResPoolProxy::empty( const ResKind & kind_r ) const
324 { return _pimpl->empty( kind_r ); }
325
327 { return _pimpl->size( kind_r ); }
328
330 { return _pimpl->byKindBegin( kind_r ); }
331
333 { return _pimpl->byKindEnd( kind_r ); }
334
336 { return _pimpl->knownRepositoriesSize(); }
337
339 { return _pimpl->knownRepositoriesBegin(); }
340
342 { return _pimpl->knownRepositoriesEnd(); }
343
345 { _pimpl->saveState(); }
346
347 void ResPoolProxy::saveState( const ResKind & kind_r ) const
348 { _pimpl->saveState( kind_r ); }
349
351 { _pimpl->restoreState(); }
352
353 void ResPoolProxy::restoreState( const ResKind & kind_r ) const
354 { _pimpl->restoreState( kind_r ); }
355
357 { return _pimpl->diffState(); }
358
359 bool ResPoolProxy::diffState( const ResKind & kind_r ) const
360 { return _pimpl->diffState( kind_r ); }
361
362 std::ostream & operator<<( std::ostream & str, const ResPoolProxy & obj )
363 { return str << *obj._pimpl; }
364
365 std::ostream & dumpOn( std::ostream & str, const ResPoolProxy & obj )
366 { return dumpOn( str, *obj._pimpl ); }
367
369} // namespace zypp
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
void restoreState() const
Definition PoolItem.cc:225
void saveState() const
Definition PoolItem.cc:224
bool sameState() const
Definition PoolItem.cc:226
Resolvable kinds.
Definition ResKind.h:33
ResPool::repository_iterator repository_iterator
void saveState() const
size_type size() const
const_iterator byKindEnd() const
size_type knownRepositoriesSize() const
const_iterator begin() const
std::multimap< ResKind, ui::Selectable::Ptr > SelectablePool
const_iterator end() const
ResPoolProxy()
Default ctor: no pool Nonempty proxies are provided by ResPool.
RW_pointer< Impl > _pimpl
Pointer to implementation.
bool diffState() const
MapKVIteratorTraits< SelectablePool >::Value_const_iterator const_iterator
void restoreState() const
SelectablePool::size_type size_type
repository_iterator knownRepositoriesBegin() const
ui::Selectable::Ptr lookup(const pool::ByIdent &ident_r) const
repository_iterator knownRepositoriesEnd() const
const_iterator byKindBegin() const
Global ResObject pool.
Definition ResPool.h:62
const_iterator end() const
Definition ResPool.h:101
byKind_iterator byKindEnd(const ResKind &kind_r) const
Definition ResPool.h:269
const SerialNumber & serial() const
The pools serial number.
Definition ResPool.cc:65
byKind_iterator byKindBegin(const ResKind &kind_r) const
Definition ResPool.h:262
const_iterator begin() const
Definition ResPool.h:98
size_type size() const
Definition ResPool.cc:71
Main filter selecting PoolItems by name and kind.
Definition ByIdent.h:29
sat::detail::IdType get() const
Definition ByIdent.h:90
PoolTraits::Id2ItemT Id2ItemT
Definition PoolImpl.h:177
shared_ptr< Impl > Impl_Ptr
Definition Selectable.h:562
intrusive_ptr< Selectable > Ptr
Definition Selectable.h:58
nullptr CURL handle void * p
Definition curl_dl.cc:99
Definition ansi.h:855
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
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:419
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
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
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
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
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
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
relates: Capability Detailed stream output
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
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
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
void saveState(const ResPool &pool_r, const ResKind &kind_r)
bool diffState(const ResPool &pool_r, const ResKind &kind_r) const
void saveState(const ResPool &pool_r)
void restoreState(const ResPool &pool_r, const ResKind &kind_r)
void restoreState(const ResPool &pool_r)
bool diffState(const ResPool &pool_r) const
ResPoolProxy implementation.
size_type size() const
void restoreState(const ResKind &kind_r) const
bool diffState(const ResKind &kind_r) const
repository_iterator knownRepositoriesEnd() const
repository_iterator knownRepositoriesBegin() const
Impl(ResPool &&pool_r, const pool::PoolImpl &poolImpl_r)
const_iterator begin() const
static shared_ptr< Impl > nullimpl()
Offer default Impl.
const pool::PoolImpl::Id2ItemT * _id2item
SelectableIndex _selIndex
bool empty(const ResKind &kind_r) const
friend std::ostream & operator<<(std::ostream &str, const Impl &obj)
relates: ResPoolProxy::Impl Stream output
void saveState(const ResKind &kind_r) const
size_type size(const ResKind &kind_r) const
std::unordered_map< sat::detail::IdType, ui::Selectable::Ptr > SelectableIndex
ui::Selectable::Ptr lookup(const pool::ByIdent &ident_r) const
size_type knownRepositoriesSize() const
const_iterator end() const
ResPoolProxy::const_iterator const_iterator
const_iterator byKindEnd(const ResKind &kind_r) const
const_iterator byKindBegin(const ResKind &kind_r) const
friend std::ostream & dumpOn(std::ostream &str, const Impl &obj)
relates: ResPoolProxy::Impl Verbose stream output
bool operator()(const ui::Selectable::Ptr &selp) const
P_Select2nd< Id2ItemT::value_type > Id2ItemValueSelector
Definition PoolTraits.h:78
transform_iterator< Id2ItemValueSelector, Id2ItemT::const_iterator > byIdent_iterator
Definition PoolTraits.h:79