Pool.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00013 #include <iostream>
00014 
00015 #include "zypp/base/Easy.h"
00016 #include "zypp/base/Logger.h"
00017 #include "zypp/base/Gettext.h"
00018 #include "zypp/base/Exception.h"
00019 
00020 #include "zypp/AutoDispose.h"
00021 
00022 #include "zypp/sat/detail/PoolImpl.h"
00023 #include "zypp/sat/Pool.h"
00024 #include "zypp/sat/LookupAttr.h"
00025 
00027 namespace zypp
00028 { 
00029 
00030   namespace sat
00031   { 
00032 
00033     const std::string & Pool::systemRepoAlias()
00034     { return detail::PoolImpl::systemRepoAlias(); }
00035 
00036     ::_Pool * Pool::get() const
00037     { return myPool().getPool(); }
00038 
00039     Pool::size_type Pool::capacity() const
00040     { return myPool()->nsolvables; }
00041 
00042     const SerialNumber & Pool::serial() const
00043     { return myPool().serial(); }
00044 
00045     void Pool::prepare() const
00046     { return myPool().prepare(); }
00047 
00048     bool Pool::reposEmpty() const
00049     { return ! myPool()->nrepos; }
00050 
00051     Pool::size_type Pool::reposSize() const
00052     { return myPool()->nrepos; }
00053 
00054     Pool::RepositoryIterator Pool::reposBegin() const
00055     { return RepositoryIterator( myPool()->repos ); }
00056 
00057     Pool::RepositoryIterator Pool::reposEnd() const
00058     { return RepositoryIterator( myPool()->repos+myPool()->nrepos ); }
00059 
00060     bool Pool::solvablesEmpty() const
00061     {
00062       // return myPool()->nsolvables;
00063       // nsolvables is the array size including
00064       // invalid Solvables.
00065       for_( it, reposBegin(), reposEnd() )
00066       {
00067         if ( ! it->solvablesEmpty() )
00068           return false;
00069       }
00070       return true;
00071     }
00072 
00073     Pool::size_type Pool::solvablesSize() const
00074     {
00075       // Do not return myPool()->nsolvables;
00076       // nsolvables is the array size including
00077       // invalid Solvables.
00078       size_type ret = 0;
00079       for_( it, reposBegin(), reposEnd() )
00080       {
00081         ret += it->solvablesSize();
00082       }
00083       return ret;
00084     }
00085 
00086     Pool::SolvableIterator Pool::solvablesBegin() const
00087     { return SolvableIterator( myPool().getFirstId() ); }
00088 
00089     Pool::SolvableIterator Pool::solvablesEnd() const
00090     { return SolvableIterator(); }
00091 
00092     Repository Pool::reposInsert( const std::string & alias_r )
00093     {
00094       Repository ret( reposFind( alias_r ) );
00095       if ( ret )
00096         return ret;
00097 
00098       ret = Repository( myPool()._createRepo( alias_r ) );
00099       if ( ret.isSystemRepo() )
00100       {
00101         // autoprovide (dummy) RepoInfo
00102         RepoInfo info;
00103         info.setAlias( alias_r );
00104         info.setName( alias_r );
00105         info.setAutorefresh( true );
00106         info.setEnabled( true );
00107         ret.setInfo( info );
00108       }
00109       return ret;
00110     }
00111 
00112     Repository Pool::reposFind( const std::string & alias_r ) const
00113     {
00114       for_( it, reposBegin(), reposEnd() )
00115       {
00116         if ( alias_r == it->alias() )
00117           return *it;
00118       }
00119       return Repository();
00120     }
00121 
00122     Repository Pool::findSystemRepo() const
00123     {
00124       return Repository( myPool().systemRepo() );
00125     }
00126 
00127     Repository Pool::systemRepo()
00128     {
00129       if ( myPool().systemRepo() )
00130         return Repository( myPool().systemRepo() );
00131       return reposInsert( systemRepoAlias() );
00132     }
00133 
00134     Repository Pool::addRepoSolv( const Pathname & file_r, const std::string & alias_r )
00135     {
00136       // Using a temporay repo! (The additional parenthesis are required.)
00137       AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
00138       *tmprepo = reposInsert( alias_r );
00139       tmprepo->addSolv( file_r );
00140 
00141       // no exceptions so we keep it:
00142       tmprepo.resetDispose();
00143       return tmprepo;
00144     }
00145 
00146     Repository Pool::addRepoSolv( const Pathname & file_r )
00147     { return addRepoSolv( file_r, file_r.basename() ); }
00148 
00149     Repository Pool::addRepoSolv( const Pathname & file_r, const RepoInfo & info_r )
00150     {
00151       Repository ret( addRepoSolv( file_r, info_r.alias() ) );
00152       ret.setInfo( info_r );
00153       return ret;
00154     }
00155 
00157 
00158     Repository Pool::addRepoHelix( const Pathname & file_r, const std::string & alias_r )
00159     {
00160       // Using a temporay repo! (The additional parenthesis are required.)
00161       AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
00162       *tmprepo = reposInsert( alias_r );
00163       tmprepo->addHelix( file_r );
00164 
00165       // no exceptions so we keep it:
00166       tmprepo.resetDispose();
00167       return tmprepo;
00168     }
00169 
00170     Repository Pool::addRepoHelix( const Pathname & file_r )
00171     { return addRepoHelix( file_r, file_r.basename() ); }
00172 
00173     Repository Pool::addRepoHelix( const Pathname & file_r, const RepoInfo & info_r )
00174     {
00175       Repository ret( addRepoHelix( file_r, info_r.alias() ) );
00176       ret.setInfo( info_r );
00177       return ret;
00178     }
00179 
00181 
00182     void Pool::setTextLocale( const Locale & locale_r )
00183     { myPool().setTextLocale( locale_r ); }
00184 
00185     void Pool::setRequestedLocales( const LocaleSet & locales_r )
00186     { myPool().setRequestedLocales( locales_r ); }
00187 
00188     bool Pool::addRequestedLocale( const Locale & locale_r )
00189     { return myPool().addRequestedLocale( locale_r ); }
00190 
00191     bool Pool::eraseRequestedLocale( const Locale & locale_r )
00192     { return myPool().eraseRequestedLocale( locale_r ); }
00193 
00194     const LocaleSet & Pool::getRequestedLocales() const
00195     { return myPool().getRequestedLocales(); }
00196 
00197     bool Pool::isRequestedLocale( const Locale & locale_r ) const
00198     { return myPool().isRequestedLocale( locale_r ); }
00199 
00200     const LocaleSet & Pool::getAvailableLocales() const
00201     {  return myPool().getAvailableLocales(); }
00202 
00203     bool Pool::isAvailableLocale( const Locale & locale_r ) const
00204     { return myPool().isAvailableLocale( locale_r ); }
00205 
00206     bool Pool::multiversionEmpty() const                        { return myPool().multiversionList().empty(); }
00207     size_t Pool::multiversionSize() const                       { return myPool().multiversionList().size(); }
00208     Pool::MultiversionIterator Pool::multiversionBegin() const  { return myPool().multiversionList().begin(); }
00209     Pool::MultiversionIterator Pool::multiversionEnd() const    { return myPool().multiversionList().end(); }
00210     bool Pool::isMultiversion( IdString ident_r ) const         { return myPool().isMultiversion( ident_r ); }
00211 
00212    /******************************************************************
00213     **
00214     **  FUNCTION NAME : operator<<
00215     **  FUNCTION TYPE : std::ostream &
00216     */
00217     std::ostream & operator<<( std::ostream & str, const Pool & obj )
00218     {
00219       return str << "sat::pool(" << obj.serial() << ")["
00220           << obj.capacity() << "]{"
00221           << obj.reposSize() << "repos|"
00222           << obj.solvablesSize() << "slov}";
00223     }
00224 
00226   } // namespace sat
00229 } // namespace zypp

doxygen