PoolImpl.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_POOL_POOLIMPL_H
00013 #define ZYPP_POOL_POOLIMPL_H
00014 
00015 #include <iosfwd>
00016 #include <map>
00017 
00018 #include "zypp/base/Easy.h"
00019 #include "zypp/base/SerialNumber.h"
00020 #include "zypp/pool/PoolTraits.h"
00021 #include "zypp/ResPoolProxy.h"
00022 #include "zypp/ZYppFactory.h"
00023 
00025 namespace zypp
00026 { 
00027 
00028   namespace pool
00029   { 
00030 
00032     //
00033     //  CLASS NAME : NameHash
00034     //
00036     class NameHash
00037     {
00038     public:
00040       NameHash();
00042       ~NameHash();
00043 
00044       public:
00045 
00046       typedef PoolTraits::ItemContainerT         ItemContainerT;
00047       typedef PoolTraits::NameItemContainerT     ContainerT;
00048       typedef PoolTraits::size_type              size_type;
00049       typedef PoolTraits::iterator               iterator;
00050       typedef PoolTraits::const_iterator         const_iterator;
00051 
00052       private:
00053         ItemContainerT & getItemContainer( const std::string & tag_r );
00054         const ItemContainerT & getConstItemContainer( const std::string & tag_r ) const;
00055 
00056       public:
00058       ContainerT & store()
00059       { return _store; }
00061       const ContainerT & store() const
00062       { return _store; }
00063 
00065       bool empty() const
00066       { return _store.empty(); }
00068       size_type size() const
00069       { return _store.size(); }
00070 
00072       iterator begin( const std::string & tag_r )
00073       { return getItemContainer( tag_r ).begin(); }
00075       const_iterator begin( const std::string & tag_r ) const
00076       { return getConstItemContainer( tag_r ).begin(); }
00077 
00079       iterator end( const std::string & tag_r )
00080       { return getItemContainer( tag_r ).end(); }
00082       const_iterator end( const std::string & tag_r ) const
00083       { return getConstItemContainer( tag_r ).end(); }
00084 
00086       void clear()
00087       { _store.clear(); }
00088 
00090       void insert( const PoolItem & item_r );
00092       void erase( const PoolItem & item_r );
00093 
00094       private:
00095         ContainerT _store;
00096         ItemContainerT _empty;  // for begin(), end() if tag_r can't be found
00097     };
00098 
00100     //
00101     //  CLASS NAME : CapHash
00102     //
00104     class CapHash
00105     {
00106     public:
00108       CapHash();
00110       ~CapHash();
00111 
00112       public:
00113 
00114       typedef PoolTraits::DepCapItemContainerT  ContainerT;
00115       typedef PoolTraits::capitemsize_type      size_type;
00116       typedef PoolTraits::capitemiterator       iterator;
00117       typedef PoolTraits::const_capitemiterator const_iterator;
00118 
00119       private:
00120 
00121       typedef PoolTraits::CapItemStoreT         CapItemStoreT;
00122       typedef PoolTraits::CapItemContainerT     CapItemContainerT;
00123 
00124       // Dep -> CapItemStoreT
00125       const CapItemStoreT & capItemStore ( Dep cap_r ) const;
00126 
00127       // CapItemStoreT, index -> CapItemContainerT
00128       const CapItemContainerT & capItemContainer( const CapItemStoreT & cis, const std::string & tag_r ) const;
00129 
00130       public:
00131 
00133       ContainerT & store()
00134       { return _store; }
00136       const ContainerT & store() const
00137       { return _store; }
00138 
00140       bool empty() const
00141       { return _store.empty(); }
00143       size_type size() const
00144       { return _store.size(); }
00145 
00147       iterator begin( const std::string & tag_r, Dep cap_r )
00148       { return _store[cap_r][tag_r].begin(); }
00150       const_iterator begin( const std::string & tag_r, Dep cap_r ) const
00151       { const CapItemStoreT & capitemstore = capItemStore( cap_r );
00152         const CapItemContainerT & capcontainer = capItemContainer ( capitemstore, tag_r );
00153         return capcontainer.begin(); }
00154 
00156       iterator end( const std::string & tag_r, Dep cap_r )
00157       { return _store[cap_r][tag_r].begin(); }
00159       const_iterator end( const std::string & tag_r, Dep cap_r ) const
00160       { const CapItemStoreT & capitemstore = capItemStore( cap_r );
00161         const CapItemContainerT & capcontainer = capItemContainer ( capitemstore, tag_r );
00162         return capcontainer.end(); }
00163 
00165       void clear()
00166       { _store.clear(); }
00167 
00169       void insert( const PoolItem & item_r );
00171       void erase( const PoolItem & item_r );
00172 
00173       private:
00174         PoolTraits::DepCapItemContainerT _store;
00175     };
00176 
00178     //
00179     //  CLASS NAME : PoolImpl
00180     //
00182     class PoolImpl
00183     {
00184       friend std::ostream & operator<<( std::ostream & str, const PoolImpl & obj );
00185 
00186     public:
00188     typedef PoolTraits::Item                    Item;
00189     typedef PoolTraits::ItemContainerT          ContainerT;
00190     typedef PoolTraits::iterator                iterator;
00191     typedef PoolTraits::const_iterator          const_iterator;
00192     typedef PoolTraits::size_type               size_type;
00193     typedef PoolTraits::Inserter                Inserter;
00194     typedef PoolTraits::Deleter                 Deleter;
00195     typedef PoolTraits::AdditionalCapSet        AdditionalCapSet;
00196     typedef PoolTraits::RepoContainerT          KnownRepositories;
00197 
00198     public:
00200       PoolImpl();
00202       ~PoolImpl();
00203 
00205       Arch targetArch() const
00206       { return getZYpp()->architecture(); }
00207 
00208     public:
00210       ContainerT & store()
00211       { return _store; }
00213       const ContainerT & store() const
00214       { return _store; }
00215 
00217       bool empty() const
00218       { return _store.empty(); }
00220       size_type size() const
00221       { return _store.size(); }
00222 
00224       iterator begin()
00225       { return _store.begin(); }
00227       const_iterator begin() const
00228       { return _store.begin(); }
00229 
00231       iterator end()
00232       { return _store.end(); }
00234       const_iterator end() const
00235       { return _store.end(); }
00236 
00247         void setAdditionalRequire( const AdditionalCapSet & capset ) const
00248             { _additionalRequire = capset; }
00249         AdditionalCapSet & additionalRequire() const
00250             { return _additionalRequire; }
00251 
00260         void setAdditionalConflict( const AdditionalCapSet & capset ) const
00261             { _additionaConflict = capset; }
00262         AdditionalCapSet & additionaConflict() const
00263             { return _additionaConflict; }
00264 
00274         void setAdditionalProvide( const AdditionalCapSet & capset ) const
00275             { _additionaProvide = capset; }
00276         AdditionalCapSet & additionaProvide() const
00277             { return _additionaProvide; }
00278 
00280       void clear()
00281       {
00282         _store.clear();
00283         _caphash.clear();
00284         _namehash.clear();
00285         _additionalRequire.clear();
00286         _additionaConflict.clear();
00287         _additionaProvide.clear();
00288         // don't miss to invalidate ResPoolProxy
00289         invalidateProxy();
00290         return;
00291       }
00292 
00294       void eraseInstalled() const;
00295 
00296     public:
00300       const KnownRepositories & knownRepositories() const
00301       {
00302         if ( ! _knownRepositoriesPtr )
00303         {
00304           _knownRepositoriesPtr.reset( new KnownRepositories );
00305           for_( it, _store.begin(), _store.end() )
00306           {
00307             if ( (*it)->repository() != Repository::noRepository )
00308             {
00309               _knownRepositoriesPtr->insert( (*it)->repository() );
00310             }
00311           }
00312         }
00313 
00314         return *_knownRepositoriesPtr;
00315       }
00316 
00317     public:
00320       void SaveState( const ResObject::Kind & kind_r );
00321 
00322       void RestoreState( const ResObject::Kind & kind_r );
00324 
00325     public:
00328       const SerialNumber & serial() const;
00329 
00330     private:
00332       SerialNumber        _serial;
00334       SerialNumberWatcher _watchFilesystemSysconfigStorage;
00335 
00336     public:
00337       ContainerT   _store;
00338       NameHash     _namehash;
00339       CapHash      _caphash;
00340       mutable AdditionalCapSet _additionalRequire;
00341       mutable AdditionalCapSet _additionaConflict;
00342       mutable AdditionalCapSet _additionaProvide;
00343 
00344     public:
00345       ResPoolProxy proxy( ResPool self ) const
00346       {
00347         if ( !_poolProxy )
00348           _poolProxy.reset( new ResPoolProxy( self ) );
00349         return *_poolProxy;
00350       }
00351 
00355       void invalidateProxy()
00356       {
00357         _serial.setDirty();
00358         _poolProxy.reset();
00359         _knownRepositoriesPtr.reset();
00360       }
00361 
00362       mutable shared_ptr<ResPoolProxy> _poolProxy;
00363 
00364     private:
00368       mutable scoped_ptr<KnownRepositories> _knownRepositoriesPtr;
00369     };
00371 
00373     std::ostream & operator<<( std::ostream & str, const PoolImpl & obj );
00374 
00376   } // namespace pool
00379 } // namespace zypp
00381 #endif // ZYPP_POOL_POOLIMPL_H

Generated on Tue Sep 25 19:23:05 2007 for libzypp by  doxygen 1.5.3