libzypp 17.37.17
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>
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 {
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
147 { return _selPool.size(); }
148
151
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:
170 { return _pool.knownRepositoriesSize(); }
171
173 { return _pool.knownRepositoriesBegin(); }
174
176 { return _pool.knownRepositoriesEnd(); }
177
178 public:
179
180 void saveState() const
182
183 void saveState( const ResKind & kind_r ) const
184 { PoolItemSaver().saveState( _pool, kind_r ); }
185
186 void restoreState() const
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:
202
203 public:
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 {
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 {
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 //
250 : _pimpl( Impl::nullimpl() )
251 {}
252
254 //
255 // METHOD NAME : ResPoolProxy::ResPoolProxy
256 // METHOD TYPE : Ctor
257 //
259 : _pimpl( new Impl( std::move(pool_r), poolImpl_r ) )
260 {}
261
263 //
264 // METHOD NAME : ResPoolProxy::~ResPoolProxy
265 // METHOD TYPE : Dtor
266 //
269
271 //
272 // forward to implementation
273 //
275
277 { return _pimpl->lookup( ident_r ); }
278
280 { return _pimpl->empty(); }
281
283 { return _pimpl->size(); }
284
287
290
291 bool ResPoolProxy::empty( const ResKind & kind_r ) const
292 { return _pimpl->empty( kind_r ); }
293
295 { return _pimpl->size( kind_r ); }
296
298 { return _pimpl->byKindBegin( kind_r ); }
299
301 { return _pimpl->byKindEnd( kind_r ); }
302
304 { return _pimpl->knownRepositoriesSize(); }
305
307 { return _pimpl->knownRepositoriesBegin(); }
308
310 { return _pimpl->knownRepositoriesEnd(); }
311
313 { _pimpl->saveState(); }
314
315 void ResPoolProxy::saveState( const ResKind & kind_r ) const
316 { _pimpl->saveState( kind_r ); }
317
319 { _pimpl->restoreState(); }
320
321 void ResPoolProxy::restoreState( const ResKind & kind_r ) const
322 { _pimpl->restoreState( kind_r ); }
323
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
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
const Id2ItemT & id2item() const
Definition PoolImpl.h:431
PoolTraits::Id2ItemT Id2ItemT
Definition PoolImpl.h:177
shared_ptr< Impl > Impl_Ptr
Definition Selectable.h:562
intrusive_ptr< Selectable > Ptr
Definition Selectable.h:58
Definition Arch.h:364
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:120
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
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
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
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
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
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
std::ostream & operator<<(std::ostream &str, const ResPoolProxy::Impl &obj)
Stream output.
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.
std::ostream & dumpOn(std::ostream &str, const ResPoolProxy::Impl &obj)
Verbose stream output.
SelectableIndex _selIndex
bool empty(const ResKind &kind_r) const
friend std::ostream & operator<<(std::ostream &str, const Impl &obj)
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)
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
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27