1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ResPoolProxy.cc
13 #include "zypp/base/LogTools.h"
15 #include "zypp/base/Measure.h"
16 using zypp::debug::Measure;
18 #include "zypp/base/Iterator.h"
19 #include "zypp/base/Algorithm.h"
20 #include "zypp/base/Functional.h"
22 #include "zypp/ResPoolProxy.h"
23 #include "zypp/pool/PoolImpl.h"
24 #include "zypp/ui/SelectableImpl.h"
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
32 /** Tem. friend of PoolItem */
35 void saveState( ResPool pool_r )
37 std::for_each( pool_r.begin(), pool_r.end(),
38 std::mem_fun_ref(&PoolItem::saveState) );
41 void saveState( ResPool pool_r, const ResKind & kind_r )
43 std::for_each( pool_r.byKindBegin(kind_r), pool_r.byKindEnd(kind_r),
44 std::mem_fun_ref(&PoolItem::saveState) );
47 void restoreState( ResPool pool_r )
49 std::for_each( pool_r.begin(), pool_r.end(),
50 std::mem_fun_ref(&PoolItem::restoreState) );
53 void restoreState( ResPool pool_r, const ResKind & kind_r )
55 std::for_each( pool_r.byKindBegin(kind_r), pool_r.byKindEnd(kind_r),
56 std::mem_fun_ref(&PoolItem::restoreState) );
59 bool diffState( ResPool pool_r ) const
61 // return whether some PoolItem::sameState reported \c false.
62 return( invokeOnEach( pool_r.begin(), pool_r.end(),
63 std::mem_fun_ref(&PoolItem::sameState) ) < 0 );
66 bool diffState( ResPool pool_r, const ResKind & kind_r ) const
68 // return whether some PoolItem::sameState reported \c false.
69 return( invokeOnEach( pool_r.byKindBegin(kind_r), pool_r.byKindEnd(kind_r),
70 std::mem_fun_ref(&PoolItem::sameState) ) < 0 );
76 ui::Selectable::Ptr makeSelectablePtr( pool::PoolImpl::Id2ItemT::const_iterator begin_r,
77 pool::PoolImpl::Id2ItemT::const_iterator end_r )
79 pool::PoolTraits::byIdent_iterator begin( begin_r, pool::PoolTraits::Id2ItemValueSelector() );
80 pool::PoolTraits::byIdent_iterator end( end_r, pool::PoolTraits::Id2ItemValueSelector() );
81 sat::Solvable solv( begin->satSolvable() );
83 return new ui::Selectable( ui::Selectable::Impl_Ptr( new ui::Selectable::Impl( solv.kind(), solv.name(), begin, end ) ) );
87 ///////////////////////////////////////////////////////////////////
89 // CLASS NAME : ResPoolProxy::Impl
91 /** ResPoolProxy implementation.
92 * \todo Seedup as it is still using old index
94 struct ResPoolProxy::Impl
96 typedef std::tr1::unordered_map<sat::detail::IdType,ui::Selectable::Ptr>
101 :_pool( ResPool::instance() )
104 Impl( ResPool pool_r, const pool::PoolImpl & poolImpl_r )
107 Measure( "id2item" );
108 const pool::PoolImpl::Id2ItemT & id2item( poolImpl_r.id2item() );
109 if ( ! id2item.empty() )
111 sat::detail::IdType cidx = sat::detail::noId;
112 pool::PoolImpl::Id2ItemT::const_iterator cbegin = id2item.begin();
114 for_( it, id2item.begin(), id2item.end() )
116 sat::detail::IdType idx( it->first );
119 // starting a new Selectable
122 // create the previous one
123 ui::Selectable::Ptr p( makeSelectablePtr( cbegin, it ) );
124 _selPool[p->kind()].push_back( p );
131 // create the final one
132 ui::Selectable::Ptr p( makeSelectablePtr( cbegin, id2item.end() ) );
133 _selPool[p->kind()].push_back( p );
139 ui::Selectable::Ptr lookup( const pool::ByIdent & ident_r ) const
141 SelectableIndex::const_iterator it( _selIndex.find( ident_r.get() ) );
142 if ( it != _selIndex.end() )
144 return ui::Selectable::Ptr();
148 bool empty( const ResKind & kind_r ) const
149 { return _selPool[kind_r].empty(); }
151 size_type size( const ResKind & kind_r ) const
152 { return _selPool[kind_r].size(); }
154 const_iterator byKindBegin( const ResKind & kind_r ) const
155 { return _selPool[kind_r].begin(); }
157 const_iterator byKindEnd( const ResKind & kind_r ) const
158 { return _selPool[kind_r].end(); }
161 size_type knownRepositoriesSize() const
162 { return _pool.knownRepositoriesSize(); }
164 repository_iterator knownRepositoriesBegin() const
165 { return _pool.knownRepositoriesBegin(); }
167 repository_iterator knownRepositoriesEnd() const
168 { return _pool.knownRepositoriesEnd(); }
172 void saveState() const
173 { PoolItemSaver().saveState( _pool ); }
175 void saveState( const ResKind & kind_r ) const
176 { PoolItemSaver().saveState( _pool, kind_r ); }
178 void restoreState() const
179 { PoolItemSaver().restoreState( _pool ); }
181 void restoreState( const ResKind & kind_r ) const
182 { PoolItemSaver().restoreState( _pool, kind_r ); }
184 bool diffState() const
185 { return PoolItemSaver().diffState( _pool ); }
187 bool diffState( const ResKind & kind_r ) const
188 { return PoolItemSaver().diffState( _pool, kind_r ); }
192 mutable SelectablePool _selPool;
193 mutable SelectableIndex _selIndex;
196 /** Offer default Impl. */
197 static shared_ptr<Impl> nullimpl()
199 static shared_ptr<Impl> _nullimpl( new Impl );
203 ///////////////////////////////////////////////////////////////////
205 /** \relates ResPoolProxy::Impl Stream output */
206 inline std::ostream & operator<<( std::ostream & str, const ResPoolProxy::Impl & obj )
208 return str << "ResPoolProxy::Impl";
211 ///////////////////////////////////////////////////////////////////
213 // CLASS NAME : ResPoolProxy
215 ///////////////////////////////////////////////////////////////////
217 ///////////////////////////////////////////////////////////////////
219 // METHOD NAME : ResPoolProxy::ResPoolProxy
220 // METHOD TYPE : Ctor
222 ResPoolProxy::ResPoolProxy()
223 : _pimpl( Impl::nullimpl() )
226 ///////////////////////////////////////////////////////////////////
228 // METHOD NAME : ResPoolProxy::ResPoolProxy
229 // METHOD TYPE : Ctor
231 ResPoolProxy::ResPoolProxy( ResPool pool_r, const pool::PoolImpl & poolImpl_r )
232 : _pimpl( new Impl( pool_r, poolImpl_r ) )
235 ///////////////////////////////////////////////////////////////////
237 // METHOD NAME : ResPoolProxy::~ResPoolProxy
238 // METHOD TYPE : Dtor
240 ResPoolProxy::~ResPoolProxy()
243 ///////////////////////////////////////////////////////////////////
245 // forward to implementation
247 ///////////////////////////////////////////////////////////////////
249 ui::Selectable::Ptr ResPoolProxy::lookup( const pool::ByIdent & ident_r ) const
250 { return _pimpl->lookup( ident_r ); }
252 bool ResPoolProxy::empty( const ResKind & kind_r ) const
253 { return _pimpl->empty( kind_r ); }
255 ResPoolProxy::size_type ResPoolProxy::size( const ResKind & kind_r ) const
256 { return _pimpl->size( kind_r ); }
258 ResPoolProxy::const_iterator ResPoolProxy::byKindBegin( const ResKind & kind_r ) const
259 { return _pimpl->byKindBegin( kind_r ); }
261 ResPoolProxy::const_iterator ResPoolProxy::byKindEnd( const ResKind & kind_r ) const
262 { return _pimpl->byKindEnd( kind_r ); }
264 ResPoolProxy::size_type ResPoolProxy::knownRepositoriesSize() const
265 { return _pimpl->knownRepositoriesSize(); }
267 ResPoolProxy::repository_iterator ResPoolProxy::knownRepositoriesBegin() const
268 { return _pimpl->knownRepositoriesBegin(); }
270 ResPoolProxy::repository_iterator ResPoolProxy::knownRepositoriesEnd() const
271 { return _pimpl->knownRepositoriesEnd(); }
273 void ResPoolProxy::saveState() const
274 { _pimpl->saveState(); }
276 void ResPoolProxy::saveState( const ResKind & kind_r ) const
277 { _pimpl->saveState( kind_r ); }
279 void ResPoolProxy::restoreState() const
280 { _pimpl->restoreState(); }
282 void ResPoolProxy::restoreState( const ResKind & kind_r ) const
283 { _pimpl->restoreState( kind_r ); }
285 bool ResPoolProxy::diffState() const
286 { return _pimpl->diffState(); }
288 bool ResPoolProxy::diffState( const ResKind & kind_r ) const
289 { return _pimpl->diffState( kind_r ); }
291 /******************************************************************
293 ** FUNCTION NAME : operator<<
294 ** FUNCTION TYPE : std::ostream &
296 std::ostream & operator<<( std::ostream & str, const ResPoolProxy & obj )
298 return str << *obj._pimpl;
301 /////////////////////////////////////////////////////////////////
303 ///////////////////////////////////////////////////////////////////