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::FRESHENS );
00123 storeInsert( _store, item_r, Dep::SUPPLEMENTS );
00124 }
00125
00126 static void
00127 storeDelete( PoolTraits::DepCapItemContainerT & store_r, const PoolItem & item_r, Dep cap_r )
00128 {
00129 CapSet caps = item_r->dep( cap_r );
00130
00131 for ( CapSet::iterator ic = caps.begin(); ic != caps.end(); ++ic )
00132 {
00133 PoolTraits::CapItemContainerT & capitems = store_r[cap_r][ic->index()];
00134 for ( PoolTraits::CapItemContainerT::iterator pos = capitems.begin(); pos != capitems.end(); )
00135 {
00136 if ( pos->item == item_r )
00137 capitems.erase( pos++ );
00138 else
00139 ++pos;
00140 }
00141 }
00142 }
00143
00144 void CapHash::erase( const PoolItem & item_r )
00145 {
00146
00147 storeDelete( _store, item_r, Dep::PROVIDES );
00148 storeDelete( _store, item_r, Dep::REQUIRES );
00149 storeDelete( _store, item_r, Dep::CONFLICTS );
00150 storeDelete( _store, item_r, Dep::OBSOLETES );
00151 storeDelete( _store, item_r, Dep::FRESHENS );
00152 storeDelete( _store, item_r, Dep::SUPPLEMENTS );
00153 }
00154
00155 const CapHash::CapItemStoreT & CapHash::capItemStore ( Dep cap_r ) const
00156 { static CapItemStoreT capitemstore;
00157 ContainerT::const_iterator it = store().find( cap_r );
00158 if (it == store().end()) {
00159
00160 return capitemstore;
00161 }
00162
00163 return it->second;
00164 }
00165
00166
00167 const CapHash::CapItemContainerT & CapHash::capItemContainer( const CapItemStoreT & cis, const std::string & tag_r ) const
00168 { static CapItemContainerT captemcontainer;
00169 CapItemStoreT::const_iterator it = cis.find( tag_r );
00170 if (it == cis.end()) {
00171
00172 return captemcontainer;
00173 }
00174
00175
00176 return it->second;
00177 }
00178
00180
00181
00182
00184
00186
00187
00188
00189
00190 PoolImpl::PoolImpl()
00191 {}
00192
00194
00195
00196
00197
00198 PoolImpl::~PoolImpl()
00199 {}
00200
00201
00202
00203
00204
00205
00206 std::ostream & operator<<( std::ostream & str, const PoolImpl & obj )
00207 {
00208 return dumpPoolStats( str << "ResPool ",
00209 obj.begin(), obj.end() );
00210 }
00211
00212
00213
00214
00215
00216
00220 void PoolImplInserter::operator()( ResObject::constPtr ptr_r )
00221 {
00222
00223
00224
00225 if ( ! ptr_r )
00226 return;
00227
00228 if ( isKind<SrcPackage>( ptr_r ) )
00229 return;
00230
00231 if ( ! _installed )
00232 {
00233
00234
00235
00236 if ( ptr_r->kind() != ResTraits<Atom>::kind ) {
00237 if ( ! ptr_r->arch().compatibleWith( _poolImpl.targetArch() ) )
00238 return;
00239 }
00240 }
00241
00242
00243
00244
00245 PoolImpl::Item item( ptr_r, ResStatus (_installed) );
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 _poolImpl._store.insert( item );
00256 _poolImpl._namehash.insert( item );
00257 _poolImpl._caphash.insert( item );
00258
00259 _poolImpl.invalidateProxy();
00260 }
00261
00262
00263
00264
00265
00266
00267 void PoolImplDeleter::operator()( ResObject::constPtr ptr_r )
00268 {
00269 PoolImpl::Item item( ptr_r );
00270 _poolImpl._store.erase( item );
00271 _poolImpl._namehash.erase( item );
00272 _poolImpl._caphash.erase( item );
00273
00274
00275 _poolImpl.invalidateProxy();
00276 }
00277
00278
00280 }
00283 }