#include <zypp/base/PtrTypes.h>
#include <zypp/base/Exception.h>
+#include <zypp/base/Gettext.h>
#include <zypp/base/LogTools.h>
#include <zypp/base/ProvideNumericId.h>
#include <zypp/AutoDispose.h>
}
///////////////////////////////////////////////////////////////////
+struct AI
+{};
+struct AA
+{
+ RW_pointer<AI> _impl;
+};
/******************************************************************
**
** FUNCTION NAME : main
zypp::sat::Pool satpool;
MIL << satpool << endl;
- DBG << satpool.addRepoSolv( "sl10.1-beta7-selections.solv" ) << endl;
- MIL << satpool << endl;
- DBG << satpool.addRepoSolv( "1234567890.solv" ) << endl;
- MIL << satpool << endl;
- DBG << satpool.addRepoSolv( "sl10.1-beta7-packages.solv" ) << endl;
+ std::for_each( satpool.solvablesBegin(), satpool.solvablesEnd(), Print() );
+
+ satpool.addRepoSolv( "sl10.1-beta7-packages.solv" );
+ satpool.addRepoSolv( "sl10.1-beta7-selections.solv" );
MIL << satpool << endl;
for_( it, satpool.reposBegin(), satpool.reposEnd() )
MIL << *sit << endl;
}
-
- satpool.t();
-
-
///////////////////////////////////////////////////////////////////
INT << "===[END]============================================" << endl << endl;
zypp::base::LogControl::instance().logNothing();
}
#include <iostream>
+#include "zypp/base/Easy.h"
#include "zypp/base/Logger.h"
#include "zypp/base/Gettext.h"
#include "zypp/base/Exception.h"
Pool::~Pool()
{}
+ bool Pool::reposEmpty() const
+ { return _pool.nrepos; }
+
unsigned Pool::reposSize() const
{ return _pool.nrepos; }
{ return make_transform_iterator( _pool.repos+_pool.nrepos, detail::mkRepo() ); }
+ bool Pool::solvablesEmpty() const
+ { return _pool.nsolvables;}
+
unsigned Pool::solvablesSize() const
{ return _pool.nsolvables;}
SolvableIterator Pool::solvablesEnd() const
{ return SolvableIterator( _pool.solvables+_pool.nsolvables ); }
-
- Repo Pool::addRepo( const std::string & name_r )
+ Repo Pool::reposInsert( const std::string & name_r )
{
-#warning Implement name check
+ Repo ret( reposFind( name_r ) );
+ if ( ret )
+ return ret;
return ::repo_create( &_pool, name_r.c_str() );
}
- Repo Pool::addRepoSolv( const Pathname & file_r, const std::string & name_r )
+ Repo Pool::reposFind( const std::string & name_r ) const
{
- Repo repo( addRepo( name_r.empty() ? file_r.basename() : name_r ) );
- try
+ for_( it, reposBegin(), reposEnd() )
{
- repo.addSolv( file_r );
+ if ( name_r == it->name() )
+ return *it;
}
- catch ( ... )
- {
-#warning use RAII to avoid cleanup catch
- ::repo_free( repo.get() );
- throw;
- }
- return repo;
+ return Repo();
+ }
+
+ Repo Pool::addRepoSolv( const Pathname & file_r, const std::string & name_r )
+ {
+ // Using a temporay repo! (The additional parenthesis are required.)
+ AutoDispose<Repo> tmprepo( (EraseRepo()) );
+ *tmprepo = reposInsert( name_r );
+ tmprepo->addSolv( file_r );
+
+ // no exceptions so we keep it:
+ tmprepo.resetDispose();
+ return tmprepo;
}
/******************************************************************
#include <iosfwd>
#include "zypp/base/PtrTypes.h"
+#include "zypp/base/NonCopyable.h"
#include "zypp/base/Iterator.h"
#include "zypp/AutoDispose.h"
~Pool();
public:
+ bool reposEmpty() const;
unsigned reposSize() const;
RepoIterator reposBegin() const;
RepoIterator reposEnd() const;
- unsigned solvablesSize() const;
- SolvableIterator solvablesBegin() const;
- SolvableIterator solvablesEnd() const;
-
- public:
- /** Add new empty \ref Repo named \c name_r.
- * \throws Exception if \ref Repo with named \c name_r exists.
+ /** Return a \ref Repo named \c name_r.
+ * It a such a \ref Repo does not already exist
+ * a new empty \ref Repo is created.
*/
- Repo addRepo( const std::string & name_r );
+ Repo reposInsert( const std::string & name_r );
- /** Add new \ref Repo from solv-file.
- * \c name_r defaults to the solvfiles basename.
- * \throws Exception from \ref Pool::addRepo or \ref Repo::addSolv
+ /** Find a \ref Repo named \c name_r.
+ * Returns \ref norepo if there is no such \ref Repo.
*/
- Repo addRepoSolv( const Pathname & file_r, const std::string & name_r = std::string() );
+ Repo reposFind( const std::string & name_r ) const;
+
+ /** Remove a \ref Repo named \c name_r. */
+ void reposErase( const std::string & name_r )
+ { reposErase( reposFind( name_r ) ); }
+ /** \overload */
+ void reposErase( Repo repo_r )
+ { repo_r.eraseFromPool(); }
- private:
+ public:
+ /** Functor removing \ref Repo from it's \ref Pool. */
+ struct EraseRepo;
+
+ /** Load \ref Solvables from a solv-file into a \ref Repo named \c name_r.
+ * In case of an exception the \ref Repo is removed from the \ref Pool.
+ * \throws Exception if loading the solv-file fails.
+ */
+ Repo addRepoSolv( const Pathname & file_r, const std::string & name_r );
+ /** \overload Using the files basename as \ref Repo name. */
+ Repo addRepoSolv( const Pathname & file_r )
+ { return addRepoSolv( file_r, file_r.basename() ); }
+
+ public:
+ bool solvablesEmpty() const;
+ unsigned solvablesSize() const;
+ SolvableIterator solvablesBegin() const;
+ SolvableIterator solvablesEnd() const;
+
+ private:
/** Explicitly shared sat-pool. */
AutoDispose< ::_Pool *> _raii;
/** Convenient access. */
/** \relates Pool Stream output */
std::ostream & operator<<( std::ostream & str, const Pool & obj );
-#if 0
+
+ ///////////////////////////////////////////////////////////////////
+
///////////////////////////////////////////////////////////////////
//
- // CLASS NAME : TempRepo
+ // CLASS NAME : Pool::EraseRepo
//
- /** Maintain a temporary \ref Repo.
- * Any included temporary \ref Repo is removed from the \ref Prool
- * upon destruction. This may ease convenient and exception safe
- * creation of repos.
+ /** Functor removing \ref Repo from it's \ref Pool.
+ * E.g. used as dispose function in. \ref AutoDispose
+ * to provide a convenient and exception safe temporary
+ * \ref Repo.
+ * \code
+ * sat::Pool satpool;
+ * MIL << "1 " << satpool << endl;
+ * {
+ * AutoDispose<sat::Repo> tmprepo( (sat::Pool::EraseRepo()) );
+ * *tmprepo = satpool.reposInsert( "A" );
+ * tmprepo->addSolv( "sl10.1-beta7-packages.solv" );
+ * DBG << "2 " << satpool << endl;
+ * // Calling 'tmprepo.resetDispose();' here
+ * // would keep the Repo.
+ * }
+ * MIL << "3 " << satpool << endl;
+ * \endcode
* \code
- * {
- * TempRepo tmp( pool.addRepo( "newrepo" ) );
- *
- * // Exceptions when loading Solvables into "newrepo"
- * // may bypass, and "newrepo" will be removed from
- * // the pool.
- *
- * if ( keep )
- * {
- * // If you decide to keep "newrepo", simply
- * // clear TempRepo to prevent removal.
- * tmp.reset();
- * }
- * }
+ * 1 sat::pool(){0repos|2slov}
+ * 2 sat::pool(){1repos|2612slov}
+ * 3 sat::pool(){0repos|2slov}
* \endcode
- */
- class TempRepo : private base::NonCopyable
+ * Leaving the block without calling <tt>tmprepo.resetDispose();</tt>
+ * before, will automatically remove the \ref Repo from it's \ref Pool.
+ */
+ struct Pool::EraseRepo
{
- public:
- TempRepo( const Repo & repo_r )
- : _repo( repo_r )
- {}
-
- ~TempRepo()
- {
- if ( _repo )
- _repo.
- }
-
- private:
- Repo _repo;
+ void operator()( Repo repo_r ) const
+ { repo_r.eraseFromPool(); }
};
///////////////////////////////////////////////////////////////////
-#endif
+
/////////////////////////////////////////////////////////////////
} // namespace sat
///////////////////////////////////////////////////////////////////
const Repo Repo::norepo( NULL );
- const char * Repo::name() const
+ std::string Repo::name() const
{
- if ( ! _repo ) return "";
+ if ( ! _repo || ! _repo->name ) return std::string();
return _repo->name;
}
+ bool Repo::solvablesEmpty() const
+ {
+ if ( ! _repo ) return true;
+ return _repo->nsolvables;
+ }
+
unsigned Repo::solvablesSize() const
{
if ( ! _repo ) return 0;
return SolvableIterator( _repo->pool->solvables+_repo->start+_repo->nsolvables );
}
+ void Repo::eraseFromPool()
+ {
+ if ( ! _repo ) return;
+ ::repo_free( _repo, /*reuseids*/false );
+ }
+
void Repo::addSolv( const Pathname & file_r )
{
-#warning add ecxception in repo_add_solv
+ if ( ! _repo )
+ {
+ ZYPP_THROW( Exception( "Can't add solvables to noepo." ) );
+ }
+
AutoDispose<FILE*> file( ::fopen( file_r.c_str(), "r" ), ::fclose );
if ( file == NULL )
{
file.resetDispose();
- throw;
- //return Repo();
+ ZYPP_THROW( Exception( "Can't read solv-file "+file_r.asString() ) );
}
::repo_add_solv( _repo, file );
return str << "sat::repo(" << obj.name() << ")"
<< "{"
<< obj.solvablesSize()
+ << ' ' << obj.get()->start << ' ' << obj.get()->end << ' '
<< (obj.get()->start < 0 ? "_START_":"")
<< (obj.get()->nsolvables < 0 ?"_NUMSOLV_":"")
<<"}";
public:
/** The repos name (alias?). */
- const char * name() const;
+ std::string name() const;
+
+ bool solvablesEmpty() const;
unsigned solvablesSize() const;
+
SolvableIterator solvablesBegin() const;
+
SolvableIterator solvablesEnd() const;
public:
- /** Load Solvables from a solv-file.
+ /** Remove this \ref Repo from it's \ref Pool. */
+ void eraseFromPool();
+
+ public:
+ /** Load \ref Solvables from a solv-file.
* \throws Exception if loading the solv-file fails.
*/
void addSolv( const Pathname & file_r );