libzypp  10.5.0
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     void Pool::prepareForSolving() const
00049     { return myPool().prepareForSolving(); }
00050 
00051     bool Pool::reposEmpty() const
00052     { return ! myPool()->nrepos; }
00053 
00054     Pool::size_type Pool::reposSize() const
00055     { return myPool()->nrepos; }
00056 
00057     Pool::RepositoryIterator Pool::reposBegin() const
00058     { return RepositoryIterator( myPool()->repos ); }
00059 
00060     Pool::RepositoryIterator Pool::reposEnd() const
00061     { return RepositoryIterator( myPool()->repos+myPool()->nrepos ); }
00062 
00063     bool Pool::solvablesEmpty() const
00064     {
00065       // return myPool()->nsolvables;
00066       // nsolvables is the array size including
00067       // invalid Solvables.
00068       for_( it, reposBegin(), reposEnd() )
00069       {
00070         if ( ! it->solvablesEmpty() )
00071           return false;
00072       }
00073       return true;
00074     }
00075 
00076     Pool::size_type Pool::solvablesSize() const
00077     {
00078       // Do not return myPool()->nsolvables;
00079       // nsolvables is the array size including
00080       // invalid Solvables.
00081       size_type ret = 0;
00082       for_( it, reposBegin(), reposEnd() )
00083       {
00084         ret += it->solvablesSize();
00085       }
00086       return ret;
00087     }
00088 
00089     Pool::SolvableIterator Pool::solvablesBegin() const
00090     { return SolvableIterator( myPool().getFirstId() ); }
00091 
00092     Pool::SolvableIterator Pool::solvablesEnd() const
00093     { return SolvableIterator(); }
00094 
00095     Repository Pool::reposInsert( const std::string & alias_r )
00096     {
00097       Repository ret( reposFind( alias_r ) );
00098       if ( ret )
00099         return ret;
00100 
00101       ret = Repository( myPool()._createRepo( alias_r ) );
00102       if ( ret.isSystemRepo() )
00103       {
00104         // autoprovide (dummy) RepoInfo
00105         RepoInfo info;
00106         info.setAlias( alias_r );
00107         info.setName( alias_r );
00108         info.setAutorefresh( true );
00109         info.setEnabled( true );
00110         ret.setInfo( info );
00111       }
00112       return ret;
00113     }
00114 
00115     Repository Pool::reposFind( const std::string & alias_r ) const
00116     {
00117       for_( it, reposBegin(), reposEnd() )
00118       {
00119         if ( alias_r == it->alias() )
00120           return *it;
00121       }
00122       return Repository();
00123     }
00124 
00125     Repository Pool::findSystemRepo() const
00126     {
00127       return Repository( myPool().systemRepo() );
00128     }
00129 
00130     Repository Pool::systemRepo()
00131     {
00132       if ( myPool().systemRepo() )
00133         return Repository( myPool().systemRepo() );
00134       return reposInsert( systemRepoAlias() );
00135     }
00136 
00137     Repository Pool::addRepoSolv( const Pathname & file_r, const std::string & alias_r )
00138     {
00139       // Using a temporay repo! (The additional parenthesis are required.)
00140       AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
00141       *tmprepo = reposInsert( alias_r );
00142       tmprepo->addSolv( file_r );
00143 
00144       // no exceptions so we keep it:
00145       tmprepo.resetDispose();
00146       return tmprepo;
00147     }
00148 
00149     Repository Pool::addRepoSolv( const Pathname & file_r )
00150     { return addRepoSolv( file_r, file_r.basename() ); }
00151 
00152     Repository Pool::addRepoSolv( const Pathname & file_r, const RepoInfo & info_r )
00153     {
00154       Repository ret( addRepoSolv( file_r, info_r.alias() ) );
00155       ret.setInfo( info_r );
00156       return ret;
00157     }
00158 
00160 
00161     Repository Pool::addRepoHelix( const Pathname & file_r, const std::string & alias_r )
00162     {
00163       // Using a temporay repo! (The additional parenthesis are required.)
00164       AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
00165       *tmprepo = reposInsert( alias_r );
00166       tmprepo->addHelix( file_r );
00167 
00168       // no exceptions so we keep it:
00169       tmprepo.resetDispose();
00170       return tmprepo;
00171     }
00172 
00173     Repository Pool::addRepoHelix( const Pathname & file_r )
00174     { return addRepoHelix( file_r, file_r.basename() ); }
00175 
00176     Repository Pool::addRepoHelix( const Pathname & file_r, const RepoInfo & info_r )
00177     {
00178       Repository ret( addRepoHelix( file_r, info_r.alias() ) );
00179       ret.setInfo( info_r );
00180       return ret;
00181     }
00182 
00184 
00185     void Pool::setTextLocale( const Locale & locale_r )
00186     { myPool().setTextLocale( locale_r ); }
00187 
00188     void Pool::setRequestedLocales( const LocaleSet & locales_r )
00189     { myPool().setRequestedLocales( locales_r ); }
00190 
00191     bool Pool::addRequestedLocale( const Locale & locale_r )
00192     { return myPool().addRequestedLocale( locale_r ); }
00193 
00194     bool Pool::eraseRequestedLocale( const Locale & locale_r )
00195     { return myPool().eraseRequestedLocale( locale_r ); }
00196 
00197     const LocaleSet & Pool::getRequestedLocales() const
00198     { return myPool().getRequestedLocales(); }
00199 
00200     bool Pool::isRequestedLocale( const Locale & locale_r ) const
00201     { return myPool().isRequestedLocale( locale_r ); }
00202 
00203     const LocaleSet & Pool::getAvailableLocales() const
00204     {  return myPool().getAvailableLocales(); }
00205 
00206     bool Pool::isAvailableLocale( const Locale & locale_r ) const
00207     { return myPool().isAvailableLocale( locale_r ); }
00208 
00209     bool Pool::multiversionEmpty() const                        { return myPool().multiversionList().empty(); }
00210     size_t Pool::multiversionSize() const                       { return myPool().multiversionList().size(); }
00211     Pool::MultiversionIterator Pool::multiversionBegin() const  { return myPool().multiversionList().begin(); }
00212     Pool::MultiversionIterator Pool::multiversionEnd() const    { return myPool().multiversionList().end(); }
00213     bool Pool::isMultiversion( IdString ident_r ) const         { return myPool().isMultiversion( ident_r ); }
00214 
00215     bool Pool::onSystemByUserEmpty() const                      { return myPool().onSystemByUserList().empty(); }
00216     size_t Pool::onSystemByUserSize() const                     { return myPool().onSystemByUserList().size(); }
00217     Pool::OnSystemByUserIterator Pool::onSystemByUserBegin() const      { return myPool().onSystemByUserList().begin(); }
00218     Pool::OnSystemByUserIterator Pool::onSystemByUserEnd() const        { return myPool().onSystemByUserList().end(); }
00219     bool Pool::isOnSystemByUser( IdString ident_r ) const       { return myPool().isOnSystemByUser( ident_r ); }
00220 
00221    /******************************************************************
00222     **
00223     **  FUNCTION NAME : operator<<
00224     **  FUNCTION TYPE : std::ostream &
00225     */
00226     std::ostream & operator<<( std::ostream & str, const Pool & obj )
00227     {
00228       return str << "sat::pool(" << obj.serial() << ")["
00229           << obj.capacity() << "]{"
00230           << obj.reposSize() << "repos|"
00231           << obj.solvablesSize() << "slov}";
00232     }
00233 
00235   } // namespace sat
00238 } // namespace zypp