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() )
112 pool::PoolImpl::Id2ItemT::const_iterator cbegin = id2item.begin();
114 for_( it, id2item.begin(), id2item.end() )
116 if ( it->first != cbegin->first )
118 // starting a new Selectable, create the previous one
119 ui::Selectable::Ptr p( makeSelectablePtr( cbegin, it ) );
120 _selPool[p->kind()].push_back( p );
121 _selIndex[cbegin->first] = p;
122 // remember new startpoint
126 // create the final one
127 ui::Selectable::Ptr p( makeSelectablePtr( cbegin, id2item.end() ) );
128 _selPool[p->kind()].push_back( p );
129 _selIndex[cbegin->first] = p;
134 ui::Selectable::Ptr lookup( const pool::ByIdent & ident_r ) const
136 SelectableIndex::const_iterator it( _selIndex.find( ident_r.get() ) );
137 if ( it != _selIndex.end() )
139 return ui::Selectable::Ptr();
143 bool empty( const ResKind & kind_r ) const
144 { return _selPool[kind_r].empty(); }
146 size_type size( const ResKind & kind_r ) const
147 { return _selPool[kind_r].size(); }
149 const_iterator byKindBegin( const ResKind & kind_r ) const
150 { return _selPool[kind_r].begin(); }
152 const_iterator byKindEnd( const ResKind & kind_r ) const
153 { return _selPool[kind_r].end(); }
156 size_type knownRepositoriesSize() const
157 { return _pool.knownRepositoriesSize(); }
159 repository_iterator knownRepositoriesBegin() const
160 { return _pool.knownRepositoriesBegin(); }
162 repository_iterator knownRepositoriesEnd() const
163 { return _pool.knownRepositoriesEnd(); }
167 void saveState() const
168 { PoolItemSaver().saveState( _pool ); }
170 void saveState( const ResKind & kind_r ) const
171 { PoolItemSaver().saveState( _pool, kind_r ); }
173 void restoreState() const
174 { PoolItemSaver().restoreState( _pool ); }
176 void restoreState( const ResKind & kind_r ) const
177 { PoolItemSaver().restoreState( _pool, kind_r ); }
179 bool diffState() const
180 { return PoolItemSaver().diffState( _pool ); }
182 bool diffState( const ResKind & kind_r ) const
183 { return PoolItemSaver().diffState( _pool, kind_r ); }
187 mutable SelectablePool _selPool;
188 mutable SelectableIndex _selIndex;
191 /** Offer default Impl. */
192 static shared_ptr<Impl> nullimpl()
194 static shared_ptr<Impl> _nullimpl( new Impl );
198 ///////////////////////////////////////////////////////////////////
200 /** \relates ResPoolProxy::Impl Stream output */
201 inline std::ostream & operator<<( std::ostream & str, const ResPoolProxy::Impl & obj )
203 return str << "ResPoolProxy::Impl";
206 ///////////////////////////////////////////////////////////////////
208 // CLASS NAME : ResPoolProxy
210 ///////////////////////////////////////////////////////////////////
212 ///////////////////////////////////////////////////////////////////
214 // METHOD NAME : ResPoolProxy::ResPoolProxy
215 // METHOD TYPE : Ctor
217 ResPoolProxy::ResPoolProxy()
218 : _pimpl( Impl::nullimpl() )
221 ///////////////////////////////////////////////////////////////////
223 // METHOD NAME : ResPoolProxy::ResPoolProxy
224 // METHOD TYPE : Ctor
226 ResPoolProxy::ResPoolProxy( ResPool pool_r, const pool::PoolImpl & poolImpl_r )
227 : _pimpl( new Impl( pool_r, poolImpl_r ) )
230 ///////////////////////////////////////////////////////////////////
232 // METHOD NAME : ResPoolProxy::~ResPoolProxy
233 // METHOD TYPE : Dtor
235 ResPoolProxy::~ResPoolProxy()
238 ///////////////////////////////////////////////////////////////////
240 // forward to implementation
242 ///////////////////////////////////////////////////////////////////
244 ui::Selectable::Ptr ResPoolProxy::lookup( const pool::ByIdent & ident_r ) const
245 { return _pimpl->lookup( ident_r ); }
247 bool ResPoolProxy::empty( const ResKind & kind_r ) const
248 { return _pimpl->empty( kind_r ); }
250 ResPoolProxy::size_type ResPoolProxy::size( const ResKind & kind_r ) const
251 { return _pimpl->size( kind_r ); }
253 ResPoolProxy::const_iterator ResPoolProxy::byKindBegin( const ResKind & kind_r ) const
254 { return _pimpl->byKindBegin( kind_r ); }
256 ResPoolProxy::const_iterator ResPoolProxy::byKindEnd( const ResKind & kind_r ) const
257 { return _pimpl->byKindEnd( kind_r ); }
259 ResPoolProxy::size_type ResPoolProxy::knownRepositoriesSize() const
260 { return _pimpl->knownRepositoriesSize(); }
262 ResPoolProxy::repository_iterator ResPoolProxy::knownRepositoriesBegin() const
263 { return _pimpl->knownRepositoriesBegin(); }
265 ResPoolProxy::repository_iterator ResPoolProxy::knownRepositoriesEnd() const
266 { return _pimpl->knownRepositoriesEnd(); }
268 void ResPoolProxy::saveState() const
269 { _pimpl->saveState(); }
271 void ResPoolProxy::saveState( const ResKind & kind_r ) const
272 { _pimpl->saveState( kind_r ); }
274 void ResPoolProxy::restoreState() const
275 { _pimpl->restoreState(); }
277 void ResPoolProxy::restoreState( const ResKind & kind_r ) const
278 { _pimpl->restoreState( kind_r ); }
280 bool ResPoolProxy::diffState() const
281 { return _pimpl->diffState(); }
283 bool ResPoolProxy::diffState( const ResKind & kind_r ) const
284 { return _pimpl->diffState( kind_r ); }
286 /******************************************************************
288 ** FUNCTION NAME : operator<<
289 ** FUNCTION TYPE : std::ostream &
291 std::ostream & operator<<( std::ostream & str, const ResPoolProxy & obj )
293 return str << *obj._pimpl;
296 /////////////////////////////////////////////////////////////////
298 ///////////////////////////////////////////////////////////////////