ResPoolProxy.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00012 #include <iostream>
00013 #include "zypp/base/LogTools.h"
00014
00015 #include "zypp/base/Measure.h"
00016 using zypp::debug::Measure;
00017
00018 #include "zypp/base/Iterator.h"
00019 #include "zypp/base/Algorithm.h"
00020 #include "zypp/base/Functional.h"
00021
00022 #include "zypp/ResPoolProxy.h"
00023 #include "zypp/pool/PoolImpl.h"
00024 #include "zypp/ui/SelectableImpl.h"
00025
00026 using std::endl;
00027
00029 namespace zypp
00030 {
00031
00033 struct PoolItemSaver
00034 {
00035 void saveState( ResPool pool_r )
00036 {
00037 std::for_each( pool_r.begin(), pool_r.end(),
00038 std::mem_fun_ref(&PoolItem::saveState) );
00039 }
00040
00041 void saveState( ResPool pool_r, const ResKind & kind_r )
00042 {
00043 std::for_each( pool_r.byKindBegin(kind_r), pool_r.byKindEnd(kind_r),
00044 std::mem_fun_ref(&PoolItem::saveState) );
00045 }
00046
00047 void restoreState( ResPool pool_r )
00048 {
00049 std::for_each( pool_r.begin(), pool_r.end(),
00050 std::mem_fun_ref(&PoolItem::restoreState) );
00051 }
00052
00053 void restoreState( ResPool pool_r, const ResKind & kind_r )
00054 {
00055 std::for_each( pool_r.byKindBegin(kind_r), pool_r.byKindEnd(kind_r),
00056 std::mem_fun_ref(&PoolItem::restoreState) );
00057 }
00058
00059 bool diffState( ResPool pool_r ) const
00060 {
00061
00062 return( invokeOnEach( pool_r.begin(), pool_r.end(),
00063 std::mem_fun_ref(&PoolItem::sameState) ) < 0 );
00064 }
00065
00066 bool diffState( ResPool pool_r, const ResKind & kind_r ) const
00067 {
00068
00069 return( invokeOnEach( pool_r.byKindBegin(kind_r), pool_r.byKindEnd(kind_r),
00070 std::mem_fun_ref(&PoolItem::sameState) ) < 0 );
00071 }
00072 };
00073
00074 namespace
00075 {
00076 ui::Selectable::Ptr makeSelectablePtr( pool::PoolImpl::Id2ItemT::const_iterator begin_r,
00077 pool::PoolImpl::Id2ItemT::const_iterator end_r )
00078 {
00079 pool::PoolTraits::byIdent_iterator begin( begin_r, pool::PoolTraits::Id2ItemValueSelector() );
00080 pool::PoolTraits::byIdent_iterator end( end_r, pool::PoolTraits::Id2ItemValueSelector() );
00081 sat::Solvable solv( begin->satSolvable() );
00082
00083 return new ui::Selectable( ui::Selectable::Impl_Ptr( new ui::Selectable::Impl( solv.kind(), solv.name(), begin, end ) ) );
00084 }
00085 }
00086
00088
00089
00090
00094 struct ResPoolProxy::Impl
00095 {
00096 typedef std::tr1::unordered_map<sat::detail::IdType,ui::Selectable::Ptr>
00097 SelectableIndex;
00098
00099 public:
00100 Impl()
00101 :_pool( ResPool::instance() )
00102 {}
00103
00104 Impl( ResPool pool_r, const pool::PoolImpl & poolImpl_r )
00105 : _pool( pool_r )
00106 {
00107 Measure( "id2item" );
00108 const pool::PoolImpl::Id2ItemT & id2item( poolImpl_r.id2item() );
00109 if ( ! id2item.empty() )
00110 {
00111
00112 pool::PoolImpl::Id2ItemT::const_iterator cbegin = id2item.begin();
00113
00114 for_( it, id2item.begin(), id2item.end() )
00115 {
00116 if ( it->first != cbegin->first )
00117 {
00118
00119 ui::Selectable::Ptr p( makeSelectablePtr( cbegin, it ) );
00120 _selPool[p->kind()].push_back( p );
00121 _selIndex[cbegin->first] = p;
00122
00123 cbegin = it;
00124 }
00125 }
00126
00127 ui::Selectable::Ptr p( makeSelectablePtr( cbegin, id2item.end() ) );
00128 _selPool[p->kind()].push_back( p );
00129 _selIndex[cbegin->first] = p;
00130 }
00131 }
00132
00133 public:
00134 ui::Selectable::Ptr lookup( const pool::ByIdent & ident_r ) const
00135 {
00136 SelectableIndex::const_iterator it( _selIndex.find( ident_r.get() ) );
00137 if ( it != _selIndex.end() )
00138 return it->second;
00139 return ui::Selectable::Ptr();
00140 }
00141
00142 public:
00143 bool empty( const ResKind & kind_r ) const
00144 { return _selPool[kind_r].empty(); }
00145
00146 size_type size( const ResKind & kind_r ) const
00147 { return _selPool[kind_r].size(); }
00148
00149 const_iterator byKindBegin( const ResKind & kind_r ) const
00150 { return _selPool[kind_r].begin(); }
00151
00152 const_iterator byKindEnd( const ResKind & kind_r ) const
00153 { return _selPool[kind_r].end(); }
00154
00155 public:
00156 size_type knownRepositoriesSize() const
00157 { return _pool.knownRepositoriesSize(); }
00158
00159 repository_iterator knownRepositoriesBegin() const
00160 { return _pool.knownRepositoriesBegin(); }
00161
00162 repository_iterator knownRepositoriesEnd() const
00163 { return _pool.knownRepositoriesEnd(); }
00164
00165 public:
00166
00167 void saveState() const
00168 { PoolItemSaver().saveState( _pool ); }
00169
00170 void saveState( const ResKind & kind_r ) const
00171 { PoolItemSaver().saveState( _pool, kind_r ); }
00172
00173 void restoreState() const
00174 { PoolItemSaver().restoreState( _pool ); }
00175
00176 void restoreState( const ResKind & kind_r ) const
00177 { PoolItemSaver().restoreState( _pool, kind_r ); }
00178
00179 bool diffState() const
00180 { return PoolItemSaver().diffState( _pool ); }
00181
00182 bool diffState( const ResKind & kind_r ) const
00183 { return PoolItemSaver().diffState( _pool, kind_r ); }
00184
00185 private:
00186 ResPool _pool;
00187 mutable SelectablePool _selPool;
00188 mutable SelectableIndex _selIndex;
00189
00190 public:
00192 static shared_ptr<Impl> nullimpl()
00193 {
00194 static shared_ptr<Impl> _nullimpl( new Impl );
00195 return _nullimpl;
00196 }
00197 };
00199
00201 inline std::ostream & operator<<( std::ostream & str, const ResPoolProxy::Impl & obj )
00202 {
00203 return str << "ResPoolProxy::Impl";
00204 }
00205
00207
00208
00209
00211
00213
00214
00215
00216
00217 ResPoolProxy::ResPoolProxy()
00218 : _pimpl( Impl::nullimpl() )
00219 {}
00220
00222
00223
00224
00225
00226 ResPoolProxy::ResPoolProxy( ResPool pool_r, const pool::PoolImpl & poolImpl_r )
00227 : _pimpl( new Impl( pool_r, poolImpl_r ) )
00228 {}
00229
00231
00232
00233
00234
00235 ResPoolProxy::~ResPoolProxy()
00236 {}
00237
00239
00240
00241
00243
00244 ui::Selectable::Ptr ResPoolProxy::lookup( const pool::ByIdent & ident_r ) const
00245 { return _pimpl->lookup( ident_r ); }
00246
00247 bool ResPoolProxy::empty( const ResKind & kind_r ) const
00248 { return _pimpl->empty( kind_r ); }
00249
00250 ResPoolProxy::size_type ResPoolProxy::size( const ResKind & kind_r ) const
00251 { return _pimpl->size( kind_r ); }
00252
00253 ResPoolProxy::const_iterator ResPoolProxy::byKindBegin( const ResKind & kind_r ) const
00254 { return _pimpl->byKindBegin( kind_r ); }
00255
00256 ResPoolProxy::const_iterator ResPoolProxy::byKindEnd( const ResKind & kind_r ) const
00257 { return _pimpl->byKindEnd( kind_r ); }
00258
00259 ResPoolProxy::size_type ResPoolProxy::knownRepositoriesSize() const
00260 { return _pimpl->knownRepositoriesSize(); }
00261
00262 ResPoolProxy::repository_iterator ResPoolProxy::knownRepositoriesBegin() const
00263 { return _pimpl->knownRepositoriesBegin(); }
00264
00265 ResPoolProxy::repository_iterator ResPoolProxy::knownRepositoriesEnd() const
00266 { return _pimpl->knownRepositoriesEnd(); }
00267
00268 void ResPoolProxy::saveState() const
00269 { _pimpl->saveState(); }
00270
00271 void ResPoolProxy::saveState( const ResKind & kind_r ) const
00272 { _pimpl->saveState( kind_r ); }
00273
00274 void ResPoolProxy::restoreState() const
00275 { _pimpl->restoreState(); }
00276
00277 void ResPoolProxy::restoreState( const ResKind & kind_r ) const
00278 { _pimpl->restoreState( kind_r ); }
00279
00280 bool ResPoolProxy::diffState() const
00281 { return _pimpl->diffState(); }
00282
00283 bool ResPoolProxy::diffState( const ResKind & kind_r ) const
00284 { return _pimpl->diffState( kind_r ); }
00285
00286
00287
00288
00289
00290
00291 std::ostream & operator<<( std::ostream & str, const ResPoolProxy & obj )
00292 {
00293 return str << *obj._pimpl;
00294 }
00295
00297 }