00001
00002
00003
00004
00005
00006
00007
00008
00012 #include <iostream>
00013 #include "zypp/base/Logger.h"
00014
00015 #include "zypp/pool/PoolImpl.h"
00016 #include "zypp/pool/PoolStats.h"
00017 #include "zypp/CapSet.h"
00018 #include "zypp/Package.h"
00019 #include "zypp/VendorAttr.h"
00020
00021 using std::endl;
00022
00024 namespace zypp
00025 {
00026
00027 std::ostream & operator<<( std::ostream & str, const CapAndItem & obj )
00028 {
00029 return str << "{" << obj.cap << ", " << obj.item << "}";
00030 }
00031
00033 namespace pool
00034 {
00035
00037
00038
00039
00040
00041 NameHash::NameHash()
00042 {}
00043
00045
00046
00047
00048
00049 NameHash::~NameHash()
00050 {}
00051
00052 void
00053 NameHash::insert( const PoolItem & item_r )
00054 {
00055 _store[item_r->name()].insert( item_r );
00056 }
00057
00058 void
00059 NameHash::erase( const PoolItem & item_r )
00060 {
00061 PoolTraits::ItemContainerT & items = _store[item_r->name()];
00062 for ( PoolTraits::iterator nit = items.begin(); nit != items.end(); )
00063 {
00064 if ( *nit == item_r )
00065 items.erase( nit++ );
00066 else
00067 ++nit;
00068 }
00069 }
00070
00071 NameHash::ItemContainerT & NameHash::getItemContainer( const std::string & tag_r )
00072 { ContainerT::iterator it = _store.find( tag_r );
00073 if (it == _store.end()) {
00074
00075 return _empty;
00076 }
00077
00078 return it->second;
00079 }
00080
00081 const NameHash::ItemContainerT & NameHash::getConstItemContainer( const std::string & tag_r ) const
00082 { ContainerT::const_iterator it = _store.find( tag_r );
00083 if (it == _store.end()) {
00084
00085 return _empty;
00086 }
00087
00088 return it->second;
00089 }
00090
00092
00093
00094
00095
00096 CapHash::CapHash()
00097 {}
00098
00100
00101
00102
00103
00104 CapHash::~CapHash()
00105 {}
00106
00107 static void
00108 storeInsert( CapHash::ContainerT & store_r, const PoolItem & item_r, Dep cap_r )
00109 {
00110 CapSet caps = item_r->dep( cap_r );
00111 for (CapSet::iterator ic = caps.begin(); ic != caps.end(); ++ic) {
00112 store_r[cap_r][ic->index()].push_back( CapAndItem( *ic, item_r ) );
00113 }
00114 }
00115
00116 void CapHash::insert( const PoolItem & item_r )
00117 {
00118 storeInsert( _store, item_r, Dep::PROVIDES );
00119 storeInsert( _store, item_r, Dep::REQUIRES );
00120 storeInsert( _store, item_r, Dep::CONFLICTS );
00121 storeInsert( _store, item_r, Dep::OBSOLETES );
00122 storeInsert( _store, item_r, Dep::RECOMMENDS );
00123 storeInsert( _store, item_r, Dep::SUGGESTS );
00124 storeInsert( _store, item_r, Dep::FRESHENS );
00125 storeInsert( _store, item_r, Dep::ENHANCES );
00126 storeInsert( _store, item_r, Dep::SUPPLEMENTS );
00127 }
00128
00129 static void
00130 storeDelete( PoolTraits::DepCapItemContainerT & store_r, const PoolItem & item_r, Dep cap_r )
00131 {
00132 CapSet caps = item_r->dep( cap_r );
00133
00134 for ( CapSet::iterator ic = caps.begin(); ic != caps.end(); ++ic )
00135 {
00136 PoolTraits::CapItemContainerT & capitems = store_r[cap_r][ic->index()];
00137 for ( PoolTraits::CapItemContainerT::iterator pos = capitems.begin(); pos != capitems.end(); )
00138 {
00139 if ( pos->item == item_r )
00140 capitems.erase( pos++ );
00141 else
00142 ++pos;
00143 }
00144 }
00145 }
00146
00147 void CapHash::erase( const PoolItem & item_r )
00148 {
00149
00150 storeDelete( _store, item_r, Dep::PROVIDES );
00151 storeDelete( _store, item_r, Dep::REQUIRES );
00152 storeDelete( _store, item_r, Dep::CONFLICTS );
00153 storeDelete( _store, item_r, Dep::OBSOLETES );
00154 storeDelete( _store, item_r, Dep::RECOMMENDS );
00155 storeDelete( _store, item_r, Dep::SUGGESTS );
00156 storeDelete( _store, item_r, Dep::FRESHENS );
00157 storeDelete( _store, item_r, Dep::ENHANCES );
00158 storeDelete( _store, item_r, Dep::SUPPLEMENTS );
00159 }
00160
00161 const CapHash::CapItemStoreT & CapHash::capItemStore ( Dep cap_r ) const
00162 { static CapItemStoreT capitemstore;
00163 ContainerT::const_iterator it = store().find( cap_r );
00164 if (it == store().end()) {
00165
00166 return capitemstore;
00167 }
00168
00169 return it->second;
00170 }
00171
00172
00173 const CapHash::CapItemContainerT & CapHash::capItemContainer( const CapItemStoreT & cis, const std::string & tag_r ) const
00174 { static CapItemContainerT captemcontainer;
00175 CapItemStoreT::const_iterator it = cis.find( tag_r );
00176 if (it == cis.end()) {
00177
00178 return captemcontainer;
00179 }
00180
00181
00182 return it->second;
00183 }
00184
00186
00187
00188
00190
00192
00193
00194
00195
00196 PoolImpl::PoolImpl()
00197 {}
00198
00200
00201
00202
00203
00204 PoolImpl::~PoolImpl()
00205 {}
00206
00207
00208
00209
00210
00211
00212 std::ostream & operator<<( std::ostream & str, const PoolImpl & obj )
00213 {
00214 return dumpPoolStats( str << "ResPool ",
00215 obj.begin(), obj.end() );
00216 }
00217
00218
00219
00220
00221
00222
00226 void PoolImplInserter::operator()( ResObject::constPtr ptr_r )
00227 {
00228
00229
00230
00231 if ( ! ptr_r )
00232 return;
00233
00234 if ( isKind<SrcPackage>( ptr_r ) )
00235 return;
00236
00237 if ( ! _installed )
00238 {
00239
00240
00241
00242 if ( ptr_r->kind() != ResTraits<Atom>::kind ) {
00243 if ( ! ptr_r->arch().compatibleWith( _poolImpl.targetArch() ) )
00244 return;
00245 }
00246 }
00247
00248
00249
00250
00251 PoolImpl::Item item( ptr_r, ResStatus (_installed) );
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 if ( _poolImpl._store.insert( item ).second )
00262 {
00263 _poolImpl._namehash.insert( item );
00264 _poolImpl._caphash.insert( item );
00265
00266 _poolImpl.invalidateProxy();
00267 }
00268 }
00269
00270
00271
00272
00273
00274
00275 void PoolImplDeleter::operator()( ResObject::constPtr ptr_r )
00276 {
00277 PoolImpl::Item item( ptr_r );
00278 _poolImpl._store.erase( item );
00279 _poolImpl._namehash.erase( item );
00280 _poolImpl._caphash.erase( item );
00281
00282
00283 _poolImpl.invalidateProxy();
00284 }
00285
00286
00288 }
00291 }