PoolImpl.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_SAT_DETAIL_POOLIMPL_H
00013 #define ZYPP_SAT_DETAIL_POOLIMPL_H
00014 extern "C"
00015 {
00016 #include <satsolver/pool.h>
00017 #include <satsolver/repo.h>
00018 #include <satsolver/solvable.h>
00019 #include <satsolver/poolarch.h>
00020 #include <satsolver/repo_solv.h>
00021 }
00022 #include <iosfwd>
00023 
00024 #include "zypp/base/Tr1hash.h"
00025 #include "zypp/base/NonCopyable.h"
00026 #include "zypp/base/SerialNumber.h"
00027 #include "zypp/sat/detail/PoolMember.h"
00028 #include "zypp/RepoInfo.h"
00029 #include "zypp/Locale.h"
00030 #include "zypp/Capability.h"
00031 #include "zypp/IdString.h"
00032 
00034 namespace zypp
00035 { 
00036 
00037   namespace sat
00038   { 
00039 
00040     namespace detail
00041     { 
00042 
00044       //
00045       //        CLASS NAME : PoolImpl
00046       //
00048       class PoolImpl : private base::NonCopyable
00049       {
00050         public:
00052           PoolImpl();
00053 
00055           ~PoolImpl();
00056 
00058           ::_Pool * operator->()
00059           { return _pool; }
00060 
00061         public:
00063           const SerialNumber & serial() const
00064           { return _serial; }
00065 
00069           void prepare() const;
00070 
00071         private:
00075           void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
00076 
00079           void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
00080 
00082           static detail::IdType nsCallback( ::_Pool *, void * data, detail::IdType lhs, detail::IdType rhs );
00083 
00084         public:
00086           static const std::string & systemRepoAlias();
00087 
00088           bool isSystemRepo( ::_Repo * repo_r ) const
00089           { return repo_r && _pool->installed == repo_r; }
00090 
00091           ::_Repo * systemRepo() const
00092           { return _pool->installed; }
00093 
00094         public:
00101           ::_Repo * _createRepo( const std::string & name_r );
00102 
00104           void _deleteRepo( ::_Repo * repo_r );
00105 
00110           int _addSolv( ::_Repo * repo_r, FILE * file_r );
00111 
00116           int _addHelix( ::_Repo * repo_r, FILE * file_r );
00117 
00119           detail::SolvableIdType _addSolvables( ::_Repo * repo_r, unsigned count_r );
00121 
00123           void _postRepoAdd( ::_Repo * repo_r );
00124 
00125         public:
00127           bool validSolvable( const ::_Solvable & slv_r ) const
00128           { return slv_r.repo; }
00130           bool validSolvable( SolvableIdType id_r ) const
00131           { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
00133           bool validSolvable( const ::_Solvable * slv_r ) const
00134           { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
00135 
00136         public:
00137           ::_Pool * getPool() const
00138           { return _pool; }
00139 
00141           ::_Repo * getRepo( RepoIdType id_r ) const
00142           { return id_r; }
00143 
00147           ::_Solvable * getSolvable( SolvableIdType id_r ) const
00148           {
00149             if ( validSolvable( id_r ) )
00150               return &_pool->solvables[id_r];
00151             return 0;
00152           }
00153 
00154         public:
00158           SolvableIdType getFirstId()  const
00159           { return getNextId( 1 ); }
00160 
00166           SolvableIdType getNextId( SolvableIdType id_r ) const
00167           {
00168             for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
00169             {
00170               if ( validSolvable( _pool->solvables[id_r] ) )
00171                 return id_r;
00172             }
00173             return noSolvableId;
00174           }
00175 
00176         public:
00178           const RepoInfo & repoInfo( RepoIdType id_r )
00179           { return _repoinfos[id_r]; }
00181           void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r );
00183           void eraseRepoInfo( RepoIdType id_r )
00184           { _repoinfos.erase( id_r ); }
00185 
00186         public:
00190           const sat::detail::IdType whatProvidesData( unsigned offset_r )
00191           { return _pool->whatprovidesdata[offset_r]; }
00192 
00196           unsigned whatProvides( Capability cap_r )
00197           { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
00198 
00199         public:
00202           void setTextLocale( const Locale & locale_r );
00203           void setRequestedLocales( const LocaleSet & locales_r );
00204           bool addRequestedLocale( const Locale & locale_r );
00205           bool eraseRequestedLocale( const Locale & locale_r );
00206 
00207           const LocaleSet & getRequestedLocales() const
00208           { return _requestedLocales; }
00209 
00210           bool isRequestedLocale( const Locale & locale_r ) const
00211           {
00212             LocaleSet::const_iterator it( _requestedLocales.find( locale_r ) );
00213             return it != _requestedLocales.end();
00214           }
00215 
00216           const LocaleSet & getAvailableLocales() const;
00217 
00218           bool isAvailableLocale( const Locale & locale_r ) const
00219           {
00220             const LocaleSet & avl( getAvailableLocales() );
00221             LocaleSet::const_iterator it( avl.find( locale_r ) );
00222             return it != avl.end();
00223           }
00225 
00226         public:
00229           typedef std::tr1::unordered_set<IdString> MultiversionList;
00230 
00231           const MultiversionList & multiversionList() const
00232           {
00233             if ( ! _multiversionListPtr )
00234               multiversionListInit();
00235             return *_multiversionListPtr;
00236           }
00237 
00238           bool isMultiversion( IdString ident_r ) const
00239           {
00240             const MultiversionList & l( multiversionList() );
00241             return l.find( ident_r ) != l.end();
00242           }
00243 
00245 
00246         private:
00248           ::_Pool * _pool;
00250           SerialNumber _serial;
00252           SerialNumberWatcher _watcher;
00254           std::map<RepoIdType,RepoInfo> _repoinfos;
00255 
00257           LocaleSet _requestedLocales;
00258           mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
00259           mutable std::tr1::unordered_set<IdString> _locale2Solver;
00260 
00262           void multiversionListInit() const;
00263           mutable scoped_ptr<MultiversionList> _multiversionListPtr;
00264       };
00266 
00268     } // namespace detail
00271   } // namespace sat
00274 } // namespace zypp
00276 #define POOL_SETDIRTY
00277 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H

doxygen