Author: mlandres
Date: Fri Nov 23 18:37:29 2007
New Revision: 7905
URL: http://svn.opensuse.org/viewcvs/zypp?rev=7905&view=rev
Log:
backup
Added:
trunk/libzypp/zypp/sat/detail/
trunk/libzypp/zypp/sat/detail/PoolImpl.cc
trunk/libzypp/zypp/sat/detail/PoolImpl.h
trunk/libzypp/zypp/sat/detail/PoolMember.h
Modified:
trunk/libzypp/devel/devel.ma/NewPool.cc
trunk/libzypp/zypp/CMakeLists.txt
trunk/libzypp/zypp/sat/Pool.cc
trunk/libzypp/zypp/sat/Pool.h
trunk/libzypp/zypp/sat/Repo.cc
trunk/libzypp/zypp/sat/Repo.h
trunk/libzypp/zypp/sat/Solvable.cc
trunk/libzypp/zypp/sat/Solvable.h
Modified: trunk/libzypp/devel/devel.ma/NewPool.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.ma/NewPool.cc?rev=7905&r1=7904&r2=7905&view=diff
==============================================================================
--- trunk/libzypp/devel/devel.ma/NewPool.cc (original)
+++ trunk/libzypp/devel/devel.ma/NewPool.cc Fri Nov 23 18:37:29 2007
@@ -43,6 +43,8 @@
#include "zypp/sat/Pool.h"
#include "zypp/sat/Repo.h"
+#include "zypp/sat/Solvable.h"
+#include "zypp/sat/detail/PoolImpl.h"
using namespace std;
using namespace zypp;
@@ -397,12 +399,17 @@
}
///////////////////////////////////////////////////////////////////
-struct AI
-{};
-struct AA
+void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
{
- RW_pointer<AI> _impl;
-};
+ SEC << *l << " - " << *r << endl;
+ INT << "== " << (l==r) << endl;
+ INT << "!= " << (l!=r) << endl;
+}
+
+bool isTrue() { return true; }
+bool isFalse() { return false; }
+
+
/******************************************************************
**
** FUNCTION NAME : main
@@ -413,21 +420,40 @@
//zypp::base::LogControl::instance().logfile( "log.restrict" );
INT << "===[START]==========================================" << endl;
- zypp::sat::Pool satpool;
+
+ sat::Pool satpool( sat::Pool::instance() );
+
+ //sat::Repo r( satpool.addRepoSolv( "sl10.1-beta7-packages.solv" ) );
+ sat::Repo s( satpool.addRepoSolv( "sl10.1-beta7-selections.solv" ) );
MIL << satpool << endl;
- std::for_each( satpool.solvablesBegin(), satpool.solvablesEnd(), Print() );
+ std::for_each( s.solvablesBegin(), s.solvablesEnd(), Print() );
+ // r.eraseFromPool();
+ // MIL << satpool << endl;
+ //MIL << s << endl;
+ //std::for_each( s.solvablesBegin(), s.solvablesEnd(), Print() );
+
+
+#if 0
satpool.addRepoSolv( "sl10.1-beta7-packages.solv" );
satpool.addRepoSolv( "sl10.1-beta7-selections.solv" );
MIL << satpool << endl;
+ sat::Repo outdated( satpool.reposFind( "sl10.1-beta7-packages.solv" ) );
+ satpool.reposErase( "sl10.1-beta7-packages.solv" );
+
+ WAR << outdated << endl;
+ for_( sit, outdated.solvablesBegin(), outdated.solvablesEnd() )
+ MIL << *sit << endl;
+
+ if ( 0 )
for_( it, satpool.reposBegin(), satpool.reposEnd() )
{
WAR << *it << endl;
for_( sit, it->solvablesBegin(), it->solvablesEnd() )
MIL << *sit << endl;
}
-
+#endif
///////////////////////////////////////////////////////////////////
INT << "===[END]============================================" << endl << endl;
zypp::base::LogControl::instance().logNothing();
Modified: trunk/libzypp/zypp/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/CMakeLists.txt?rev=7905&r1=7904&r2=7905&view=diff
==============================================================================
--- trunk/libzypp/zypp/CMakeLists.txt (original)
+++ trunk/libzypp/zypp/CMakeLists.txt Fri Nov 23 18:37:29 2007
@@ -676,6 +676,7 @@
)
SET( zypp_sat_SRCS
+ sat/detail/PoolImpl.cc
sat/Pool.cc
sat/Repo.cc
sat/Solvable.cc
@@ -683,6 +684,8 @@
)
SET( zypp_sat_HEADERS
+ sat/detail/PoolMember.h
+ sat/detail/PoolImpl.h
sat/Pool.h
sat/Repo.h
sat/Solvable.h
Modified: trunk/libzypp/zypp/sat/Pool.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/Pool.cc?rev=7905&r1=7904&r2=7905&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/Pool.cc (original)
+++ trunk/libzypp/zypp/sat/Pool.cc Fri Nov 23 18:37:29 2007
@@ -22,8 +22,13 @@
#include "zypp/base/Gettext.h"
#include "zypp/base/Exception.h"
+#include "zypp/Pathname.h"
+#include "zypp/AutoDispose.h"
+
+#include "zypp/sat/detail/PoolImpl.h"
#include "zypp/sat/Pool.h"
#include "zypp/sat/Repo.h"
+#include "zypp/sat/Solvable.h"
///////////////////////////////////////////////////////////////////
namespace zypp
@@ -32,61 +37,60 @@
namespace sat
{ /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : Pool::Pool
- // METHOD TYPE : Ctor
- //
- Pool::Pool()
- : _raii( ::pool_create(), ::pool_free )
- , _pool( *_raii.value() )
- {
- if ( _raii == NULL )
- {
- _raii.resetDispose(); // no call to ::pool_free
- ZYPP_THROW( Exception( _("Can not create sat-pool.") ) );
- }
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : Pool::~Pool
- // METHOD TYPE : Dtor
- //
- Pool::~Pool()
- {}
+ ::_Pool * Pool::get() const
+ { return myPool().getPool(); }
bool Pool::reposEmpty() const
- { return _pool.nrepos; }
+ { return myPool()->nrepos; }
unsigned Pool::reposSize() const
- { return _pool.nrepos; }
+ { return myPool()->nrepos; }
- RepoIterator Pool::reposBegin() const
- { return make_transform_iterator( _pool.repos, detail::mkRepo() ); }
+ Pool::RepoIterator Pool::reposBegin() const
+ { return RepoIterator( myPool()->repos ); }
- RepoIterator Pool::reposEnd() const
- { return make_transform_iterator( _pool.repos+_pool.nrepos, detail::mkRepo() ); }
+ Pool::RepoIterator Pool::reposEnd() const
+ { return RepoIterator( myPool()->repos+myPool()->nrepos ); }
bool Pool::solvablesEmpty() const
- { return _pool.nsolvables;}
+ {
+ // return myPool()->nsolvables;
+ // nsolvables is the array size including
+ // invalid Solvables.
+ for_( it, reposBegin(), reposEnd() )
+ {
+ if ( ! it->solvablesEmpty() )
+ return false;
+ }
+ return true;
+ }
unsigned Pool::solvablesSize() const
- { return _pool.nsolvables;}
+ {
+ // return myPool()->nsolvables;
+ // nsolvables is the array size including
+ // invalid Solvables.
+ unsigned ret = 0;
+ for_( it, reposBegin(), reposEnd() )
+ {
+ ret += it->solvablesSize();
+ }
+ return ret;
+ }
- SolvableIterator Pool::solvablesBegin() const
- { return SolvableIterator( _pool.solvables ); }
+ Pool::SolvableIterator Pool::solvablesBegin() const
+ { return SolvableIterator( myPool().getFirstId() ); }
- SolvableIterator Pool::solvablesEnd() const
- { return SolvableIterator( _pool.solvables+_pool.nsolvables ); }
+ Pool::SolvableIterator Pool::solvablesEnd() const
+ { return SolvableIterator(); }
Repo Pool::reposInsert( const std::string & name_r )
{
Repo ret( reposFind( name_r ) );
if ( ret )
return ret;
- return ::repo_create( &_pool, name_r.c_str() );
+ return Repo( ::repo_create( get(), name_r.c_str() ) );
}
Repo Pool::reposFind( const std::string & name_r ) const
@@ -99,10 +103,15 @@
return Repo();
}
+ void Pool::reposErase( const std::string & name_r )
+ {
+ reposFind( name_r ).eraseFromPool();
+ }
+
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()) );
+ AutoDispose<Repo> tmprepo( (Repo::EraseFromPool()) );
*tmprepo = reposInsert( name_r );
tmprepo->addSolv( file_r );
@@ -111,6 +120,11 @@
return tmprepo;
}
+ Repo Pool::addRepoSolv( const Pathname & file_r )
+ {
+ return addRepoSolv( file_r, file_r.basename() );
+ }
+
/******************************************************************
**
** FUNCTION NAME : operator<<
Modified: trunk/libzypp/zypp/sat/Pool.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/Pool.h?rev=7905&r1=7904&r2=7905&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/Pool.h (original)
+++ trunk/libzypp/zypp/sat/Pool.h Fri Nov 23 18:37:29 2007
@@ -14,22 +14,14 @@
#include <iosfwd>
-#include "zypp/base/PtrTypes.h"
-#include "zypp/base/NonCopyable.h"
-#include "zypp/base/Iterator.h"
-
-#include "zypp/AutoDispose.h"
-
-#include "zypp/sat/Repo.h"
+#include "zypp/sat/detail/PoolMember.h"
///////////////////////////////////////////////////////////////////
-extern "C"
-{
-struct _Pool;
-}
-///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
+
+ class Pathname;
+
///////////////////////////////////////////////////////////////////
namespace sat
{ /////////////////////////////////////////////////////////////////
@@ -38,19 +30,36 @@
//
// CLASS NAME : Pool
//
- /** */
- class Pool
+ /** Global sat-pool.
+ *
+ * Explicitly shared singleton \ref Pool::instance.
+ */
+ class Pool : protected detail::PoolMember
{
public:
- /** Default ctor */
- Pool();
- /** Dtor */
- ~Pool();
+ typedef detail::SolvableIterator SolvableIterator;
+ typedef detail::RepoIterator RepoIterator;
public:
+ /** Singleton ctor. */
+ static Pool instance()
+ { return Pool(); }
+
+ /** Ctor from \ref PoolMember. */
+ Pool( const detail::PoolMember & )
+ {}
+
+ public:
+ /** Whether \ref Pool contains repos. */
bool reposEmpty() const;
+
+ /** Number of repos in \ref Pool. */
unsigned reposSize() const;
+
+ /** Iterator to the first \ref Repo. */
RepoIterator reposBegin() const;
+
+ /** Iterator behind the last \ref Repo. */
RepoIterator reposEnd() const;
/** Return a \ref Repo named \c name_r.
@@ -64,80 +73,53 @@
*/
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(); }
+ /** Remove a \ref Repo named \c name_r.
+ * \see \ref Repo::eraseFromPool
+ */
+ void reposErase( const std::string & name_r );
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.
+ * \see \ref Repo::EraseFromPool
*/
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() ); }
+ Repo addRepoSolv( const Pathname & file_r );
public:
+ /** Whether \ref Pool contains solvables. */
bool solvablesEmpty() const;
+
+ /** Number of solvables in \ref Pool. */
unsigned solvablesSize() const;
+
+ /** Iterator to the first \ref Solvable. */
SolvableIterator solvablesBegin() const;
+
+ /** Iterator behind the last \ref Solvable. */
SolvableIterator solvablesEnd() const;
+ public:
+ /** Expert backdoor. */
+ ::_Pool * get() const;
private:
- /** Explicitly shared sat-pool. */
- AutoDispose< ::_Pool *> _raii;
- /** Convenient access. */
- ::_Pool & _pool;
+ /** Default ctor */
+ Pool() {}
};
///////////////////////////////////////////////////////////////////
/** \relates Pool Stream output */
std::ostream & operator<<( std::ostream & str, const Pool & obj );
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : Pool::EraseRepo
- //
- /** 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;
- * {
- * AutoDisposesat::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
- * 1 sat::pool(){0repos|2slov}
- * 2 sat::pool(){1repos|2612slov}
- * 3 sat::pool(){0repos|2slov}
- * \endcode
- * Leaving the block without calling <tt>tmprepo.resetDispose();</tt>
- * before, will automatically remove the \ref Repo from it's \ref Pool.
- */
- struct Pool::EraseRepo
- {
- void operator()( Repo repo_r ) const
- { repo_r.eraseFromPool(); }
- };
- ///////////////////////////////////////////////////////////////////
+ /** \relates Pool */
+ inline bool operator==( const Pool & lhs, const Pool & rhs )
+ { return lhs.get() == rhs.get(); }
+
+ /** \relates Pool */
+ inline bool operator!=( const Pool & lhs, const Pool & rhs )
+ { return lhs.get() != rhs.get(); }
/////////////////////////////////////////////////////////////////
} // namespace sat
Modified: trunk/libzypp/zypp/sat/Repo.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/Repo.cc?rev=7905&r1=7904&r2=7905&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/Repo.cc (original)
+++ trunk/libzypp/zypp/sat/Repo.cc Fri Nov 23 18:37:29 2007
@@ -9,12 +9,6 @@
/** \file zypp/sat/Repo.cc
*
*/
-extern "C"
-{
-#include
-#include
-#include
-}
#include <iostream>
#include "zypp/base/Logger.h"
@@ -22,8 +16,11 @@
#include "zypp/base/Exception.h"
#include "zypp/AutoDispose.h"
+#include "zypp/Pathname.h"
+#include "zypp/sat/detail/PoolImpl.h"
#include "zypp/sat/Repo.h"
+#include "zypp/sat/Solvable.h"
using std::endl;
@@ -34,50 +31,69 @@
namespace sat
{ /////////////////////////////////////////////////////////////////
- const Repo Repo::norepo( NULL );
+ const Repo Repo::norepo;
+
+ /////////////////////////////////////////////////////////////////
+
+ ::_Repo * Repo::get() const
+ { return myPool().getRepo( _id ); }
+
+#define NO_REPO_RETURN( VAL ) \
+ ::_Repo * _repo( get() ); \
+ if ( ! _repo ) return VAL
+
+#define NO_REPO_THROW( VAL ) \
+ ::_Repo * _repo( get() ); \
+ if ( ! _repo ) ZYPP_THROW( VAL )
std::string Repo::name() const
{
- if ( ! _repo || ! _repo->name ) return std::string();
+ NO_REPO_RETURN( std::string() );
+ if ( ! _repo->name ) return std::string();
return _repo->name;
}
bool Repo::solvablesEmpty() const
{
- if ( ! _repo ) return true;
+ NO_REPO_RETURN( true );
return _repo->nsolvables;
}
unsigned Repo::solvablesSize() const
{
- if ( ! _repo ) return 0;
+ NO_REPO_RETURN( 0 );
return _repo->nsolvables;
}
- SolvableIterator Repo::solvablesBegin() const
+ Repo::SolvableIterator Repo::solvablesBegin() const
{
- if ( ! _repo ) return SolvableIterator();
- return SolvableIterator( _repo->pool->solvables+_repo->start );
- }
-
- SolvableIterator Repo::solvablesEnd() const
- {
- if ( ! _repo ) return SolvableIterator();
- return SolvableIterator( _repo->pool->solvables+_repo->start+_repo->nsolvables );
+ NO_REPO_RETURN( make_filter_iterator( detail::ByRepo( *this ),
+ detail::SolvableIterator(),
+ detail::SolvableIterator() ) );
+ return make_filter_iterator( detail::ByRepo( *this ),
+ detail::SolvableIterator(_repo->start),
+ detail::SolvableIterator(_repo->end) );
+ }
+
+ Repo::SolvableIterator Repo::solvablesEnd() const
+ {
+ NO_REPO_RETURN( make_filter_iterator( detail::ByRepo( *this ),
+ detail::SolvableIterator(),
+ detail::SolvableIterator() ) );
+ return make_filter_iterator(detail::ByRepo( *this ),
+ detail::SolvableIterator(_repo->end),
+ detail::SolvableIterator(_repo->end) );
}
void Repo::eraseFromPool()
{
- if ( ! _repo ) return;
- ::repo_free( _repo, /*reuseids*/false );
+ NO_REPO_RETURN();
+ ::repo_free( _repo, /*reuseids*/true );
}
void Repo::addSolv( const Pathname & file_r )
{
- if ( ! _repo )
- {
- ZYPP_THROW( Exception( "Can't add solvables to noepo." ) );
- }
+ NO_REPO_THROW( Exception( "Can't add solvables to noepo." ) );
AutoDispose file( ::fopen( file_r.c_str(), "r" ), ::fclose );
if ( file == NULL )
@@ -89,6 +105,18 @@
::repo_add_solv( _repo, file );
}
+ detail::SolvableIdType Repo::addSolvable()
+ {
+ NO_REPO_THROW( Exception( "Can't add solvables to noepo." ) );
+ return ::repo_add_solvable( _repo );
+ }
+
+ detail::SolvableIdType Repo::addSolvables( unsigned count_r )
+ {
+ NO_REPO_THROW( Exception( "Can't add solvables to noepo." ) );
+ return ::repo_add_solvable_block( _repo, count_r );
+ }
+
/******************************************************************
**
** FUNCTION NAME : operator<<
Modified: trunk/libzypp/zypp/sat/Repo.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/Repo.h?rev=7905&r1=7904&r2=7905&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/Repo.h (original)
+++ trunk/libzypp/zypp/sat/Repo.h Fri Nov 23 18:37:29 2007
@@ -16,18 +16,15 @@
#include "zypp/base/SafeBool.h"
-#include "zypp/Pathname.h"
-
+#include "zypp/sat/detail/PoolMember.h"
#include "zypp/sat/Solvable.h"
///////////////////////////////////////////////////////////////////
-extern "C"
-{
-struct _Repo;
-}
-///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
+
+ class Pathname;
+
///////////////////////////////////////////////////////////////////
namespace sat
{ /////////////////////////////////////////////////////////////////
@@ -37,13 +34,20 @@
// CLASS NAME : Repo
//
/** */
- class Repo : private base::SafeBool<Repo>
+ class Repo : protected detail::PoolMember,
+ private base::SafeBool<Repo>
{
public:
- /** Ctor defaults to \ref norepo.*/
- Repo( ::_Repo * repo_r = NULL )
- : _repo( repo_r )
- {}
+ typedef filter_iterator SolvableIterator;
+
+ public:
+ /** Default ctor creates \ref norepo.*/
+ Repo()
+ : _id( detail::noRepoId ) {}
+
+ /** \ref PoolImpl ctor. */
+ explicit Repo( detail::RepoIdType id_r )
+ : _id( id_r ) {}
public:
/** Represents no \ref Repo. */
@@ -56,32 +60,47 @@
/** The repos name (alias?). */
std::string name() const;
+ /** Whether \ref Repo contains solvables. */
bool solvablesEmpty() const;
+ /** Number of solvables in \ref Repo. */
unsigned solvablesSize() const;
+ /** Iterator to the first \ref Solvable. */
SolvableIterator solvablesBegin() const;
+ /** Iterator behind the last \ref Solvable. */
SolvableIterator solvablesEnd() const;
public:
/** Remove this \ref Repo from it's \ref Pool. */
void eraseFromPool();
+ /** Functor calling \ref eraseFromPool. */
+ struct EraseFromPool;
+
public:
/** Load \ref Solvables from a solv-file.
* \throws Exception if loading the solv-file fails.
*/
void addSolv( const Pathname & file_r );
+ /** Add a new empt \ref Solvable to this \ref Repo. */
+ detail::SolvableIdType addSolvable();
+
+ /** Add \c count_r new empty \ref Solvable to this \ref Repo. */
+ detail::SolvableIdType addSolvables( unsigned count_r );
+
public:
/** Expert backdoor. */
- ::_Repo * get() const { return _repo; }
+ ::_Repo * get() const;
+ /** Expert backdoor. */
+ detail::RepoIdType id() const { return _id; }
private:
friend base::SafeBool<Repo>::operator bool_type() const;
- bool boolTest() const { return _repo; }
+ bool boolTest() const { return get(); }
private:
- ::_Repo * _repo;
+ detail::RepoIdType _id;
};
///////////////////////////////////////////////////////////////////
@@ -96,23 +115,97 @@
inline bool operator!=( const Repo & lhs, const Repo & rhs )
{ return lhs.get() != rhs.get(); }
- //////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : Repo::EraseFromPool
+ //
+ /** 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;
+ * {
+ * AutoDisposesat::Repo tmprepo( (sat::Repo::EraseFromPool()) );
+ * *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
+ * 1 sat::pool(){0repos|2slov}
+ * 2 sat::pool(){1repos|2612slov}
+ * 3 sat::pool(){0repos|2slov}
+ * \endcode
+ * Leaving the block without calling <tt>tmprepo.resetDispose();</tt>
+ * before, will automatically remove the \ref Repo from it's \ref Pool.
+ */
+ struct Repo::EraseFromPool
+ {
+ void operator()( Repo repo_r ) const
+ { repo_r.eraseFromPool(); }
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
namespace detail
{ /////////////////////////////////////////////////////////////////
- /** Helper functor constructing \ref Repo. */
- struct mkRepo
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : RepoIterator
+ //
+ /** */
+ class RepoIterator : public boost::iterator_adaptor<
+ RepoIterator // Derived
+ , ::_Repo ** // Base
+ , Repo // Value
+ , boost::forward_traversal_tag // CategoryOrTraversal
+ , Repo // Reference
+ >
{
- typedef Repo result_type;
- result_type operator()( ::_Repo *const & ptr_r ) const
- { return ptr_r; }
+ public:
+ RepoIterator()
+ : RepoIterator::iterator_adaptor_( 0 )
+ {}
+
+ explicit RepoIterator( ::_Repo ** p )
+ : RepoIterator::iterator_adaptor_( p )
+ {}
+
+ private:
+ friend class boost::iterator_core_access;
+
+ Repo dereference() const
+ { return Repo( *base() ); }
};
- } /////////////////////////////////////////////////////////////////
- // namespace detail
- //////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : ByRepo
+ //
+ /** Functor filtering \ref Solvable by \ref Repo.*/
+ struct ByRepo
+ {
+ public:
+ ByRepo( const Repo & repo_r ) : _repo( repo_r ) {}
+ ByRepo( RepoIdType id_r ) : _repo( id_r ) {}
+
+ bool operator()( const Solvable & slv_r ) const
+ { return slv_r.repo() == _repo; }
- typedef transform_iterator RepoIterator;
+ private:
+ Repo _repo;
+ };
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+ } // namespace detail
+ ///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
} // namespace sat
///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
Modified: trunk/libzypp/zypp/sat/Solvable.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/Solvable.cc?rev=7905&r1=7904&r2=7905&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/Solvable.cc (original)
+++ trunk/libzypp/zypp/sat/Solvable.cc Fri Nov 23 18:37:29 2007
@@ -9,18 +9,13 @@
/** \file zypp/sat/Solvable.cc
*
*/
-extern "C"
-{
-#include
-#include
-#include
-}
#include <iostream>
#include "zypp/base/Logger.h"
#include "zypp/base/Gettext.h"
#include "zypp/base/Exception.h"
+#include "zypp/sat/detail/PoolImpl.h"
#include "zypp/sat/Solvable.h"
#include "zypp/sat/Repo.h"
@@ -42,43 +37,58 @@
*/
std::ostream & operator<<( std::ostream & str, const PoolId & obj )
{
+ return str << ::id2str( detail::PoolMember::myPool().getPool(), obj.get() );
return str << "sat::Id(" << obj.get() << ")";
}
- const Solvable Solvable::nosolvable( NULL );
+ /////////////////////////////////////////////////////////////////
+
+ const Solvable Solvable::nosolvable;
+
+ /////////////////////////////////////////////////////////////////
+
+ ::_Solvable * Solvable::get() const
+ { return myPool().getSolvable( _id ); }
+
+ Solvable Solvable::nextInPool() const
+ { return Solvable( myPool().getNextId( _id ) ); }
+
+#define NO_SOLVABLE_RETURN( VAL ) \
+ ::_Solvable * _solvable( get() ); \
+ if ( ! _solvable ) return VAL
NameId Solvable::name() const
{
- if ( ! _solvable ) return NameId::noid;
+ NO_SOLVABLE_RETURN( NameId::noid );
return _solvable->name; }
EvrId Solvable::evr() const
{
- if ( ! _solvable ) return EvrId::noid;
+ NO_SOLVABLE_RETURN( EvrId::noid );
return _solvable->arch;
}
ArchId Solvable::arch() const
{
- if ( ! _solvable ) return ArchId::noid;
+ NO_SOLVABLE_RETURN( ArchId::noid );
return _solvable->evr;
}
VendorId Solvable::vendor() const
{
- if ( ! _solvable ) return VendorId::noid;
+ NO_SOLVABLE_RETURN( VendorId::noid );
return _solvable->vendor;
}
Repo Solvable::repo() const
{
- if ( ! _solvable ) return 0;
- return _solvable->repo;
+ NO_SOLVABLE_RETURN( Repo::norepo );
+ return Repo( _solvable->repo );
}
const char * Solvable::string( const PoolId & id_r ) const
{
- if ( ! _solvable ) return "";
+ NO_SOLVABLE_RETURN( "" );
SEC << id_r<< endl;
SEC << " n " << ::id2str( _solvable->repo->pool, id_r.get() ) << endl;
SEC << " e " << ::dep2str( _solvable->repo->pool, id_r.get() )<< endl;
@@ -98,19 +108,10 @@
if ( ! obj )
return str << "sat::solvable()";
- return str << "sat::solvable(" << obj.name() << '-' << obj.evr() << '.' << obj.arch() << "){"
+ return str << "sat::solvable(" << obj.id() << "|" << obj.name() << '-' << obj.evr() << '.' << obj.arch() << "){"
<< obj.repo().name() << "}";
}
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : SolvableIterator
- //
- ///////////////////////////////////////////////////////////////////
-
- void SolvableIterator::increment()
- { ++base_reference(); }
-
/////////////////////////////////////////////////////////////////
} // namespace sat
///////////////////////////////////////////////////////////////////
Modified: trunk/libzypp/zypp/sat/Solvable.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/Solvable.h?rev=7905&r1=7904&r2=7905&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/Solvable.h (original)
+++ trunk/libzypp/zypp/sat/Solvable.h Fri Nov 23 18:37:29 2007
@@ -15,13 +15,9 @@
#include <iosfwd>
#include "zypp/base/SafeBool.h"
-#include "zypp/base/Iterator.h"
-///////////////////////////////////////////////////////////////////
-extern "C"
-{
-struct _Solvable;
-}
+#include "zypp/sat/detail/PoolMember.h"
+
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
@@ -29,8 +25,6 @@
namespace sat
{ /////////////////////////////////////////////////////////////////
- class Repo;
-
class PoolId : private base::SafeBool<PoolId>
{
public:
@@ -68,13 +62,17 @@
// CLASS NAME : Solvable
//
/** */
- class Solvable : private base::SafeBool<Solvable>
+ class Solvable : protected detail::PoolMember,
+ private base::SafeBool<Solvable>
{
public:
- /** Ctor defaults to \ref nosolvable.*/
- Solvable( ::_Solvable * solvable_r = NULL )
- : _solvable( solvable_r )
- {}
+ /** Default ctor creates \ref nosolvable.*/
+ Solvable()
+ : _id( detail::noSolvableId ) {}
+
+ /** \ref PoolImpl ctor. */
+ explicit Solvable( detail::SolvableIdType id_r )
+ : _id( id_r ) {}
public:
/** Represents no \ref Solvable. */
@@ -100,13 +98,20 @@
const char * vendorStr() const { return string( vendor() ); }
public:
+ /** Return next Solvable in \ref Pool (or \ref nosolvable). */
+ Solvable nextInPool() const;
+ /** Return next Solvable in \ref Repo (or \ref nosolvable). */
+ Solvable nextInRepo() const;
+ public:
/** Expert backdoor. */
- ::_Solvable * get() const { return _solvable; }
+ ::_Solvable * get() const;
+ /** Expert backdoor. */
+ detail::SolvableIdType id() const { return _id; }
private:
friend base::SafeBool<Solvable>::operator bool_type() const;
- bool boolTest() const { return _solvable; }
+ bool boolTest() const { return get(); }
private:
- ::_Solvable * _solvable;
+ detail::SolvableIdType _id;
};
///////////////////////////////////////////////////////////////////
@@ -122,35 +127,51 @@
{ return lhs.get() != rhs.get(); }
///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : SolvableIterator
- //
- /** */
- class SolvableIterator : public boost::iterator_adaptor<
- SolvableIterator // Derived
- , ::_Solvable * // Base
- , Solvable // Value
- , boost::forward_traversal_tag // CategoryOrTraversal
- , Solvable // Reference
- >
- {
- public:
- SolvableIterator()
- : SolvableIterator::iterator_adaptor_( 0 )
- {}
-
- explicit SolvableIterator( ::_Solvable * p )
- : SolvableIterator::iterator_adaptor_( p )
- {}
-
- private:
- friend class boost::iterator_core_access;
-
- void increment();
-
- Solvable dereference() const
- { return base(); }
- };
+ namespace detail
+ { /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : SolvableIterator
+ //
+ /** */
+ class SolvableIterator : public boost::iterator_adaptor<
+ SolvableIterator // Derived
+ , ::_Solvable* // Base
+ , Solvable // Value
+ , boost::single_pass_traversal_tag // CategoryOrTraversal
+ , Solvable // Reference
+ >
+ {
+ public:
+ SolvableIterator()
+ : SolvableIterator::iterator_adaptor_( 0 )
+ {}
+
+ explicit SolvableIterator( const Solvable & val_r )
+ : SolvableIterator::iterator_adaptor_( 0 )
+ { assignVal( val_r ); }
+
+ explicit SolvableIterator( SolvableIdType id_r )
+ : SolvableIterator::iterator_adaptor_( 0 )
+ { assignVal( Solvable( id_r ) ); }
+
+ private:
+ friend class boost::iterator_core_access;
+
+ void increment()
+ { assignVal( _val.nextInPool() ); }
+
+ Solvable dereference() const
+ { return _val; }
+
+ void assignVal( const Solvable & val_r )
+ { _val = val_r; base_reference() = _val.get(); }
+
+ Solvable _val;
+ };
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+ } // namespace detail
///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
Added: trunk/libzypp/zypp/sat/detail/PoolImpl.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/detail/PoolImpl.cc?rev=7905&view=auto
==============================================================================
--- trunk/libzypp/zypp/sat/detail/PoolImpl.cc (added)
+++ trunk/libzypp/zypp/sat/detail/PoolImpl.cc Fri Nov 23 18:37:29 2007
@@ -0,0 +1,81 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/sat/detail/PoolImpl.cc
+ *
+*/
+extern "C"
+{
+#include
+#include
+#include
+}
+
+#include <iostream>
+#include "zypp/base/Logger.h"
+#include "zypp/base/Gettext.h"
+#include "zypp/base/Exception.h"
+
+#include "zypp/sat/detail/PoolImpl.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace sat
+ { /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace detail
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : PoolMember::myPool
+ // METHOD TYPE : PoolImpl
+ //
+ PoolImpl & PoolMember::myPool()
+ {
+ static PoolImpl _global;
+ return _global;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : PoolImpl::PoolImpl
+ // METHOD TYPE : Ctor
+ //
+ PoolImpl::PoolImpl()
+ : _pool( ::pool_create() )
+ {
+ if ( ! _pool )
+ {
+ ZYPP_THROW( Exception( _("Can not create sat-pool.") ) );
+ }
+ }
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : PoolImpl::~PoolImpl
+ // METHOD TYPE : Dtor
+ //
+ PoolImpl::~PoolImpl()
+ {
+ ::pool_free( _pool );
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace detail
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+ } // namespace sat
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
Added: trunk/libzypp/zypp/sat/detail/PoolImpl.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/detail/PoolImpl.h?rev=7905&view=auto
==============================================================================
--- trunk/libzypp/zypp/sat/detail/PoolImpl.h (added)
+++ trunk/libzypp/zypp/sat/detail/PoolImpl.h Fri Nov 23 18:37:29 2007
@@ -0,0 +1,120 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/sat/detail/PoolImpl.h
+ *
+*/
+#ifndef ZYPP_SAT_DETAIL_POOLIMPL_H
+#define ZYPP_SAT_DETAIL_POOLIMPL_H
+extern "C"
+{
+#include
+#include
+#include
+#include
+}
+#include <iosfwd>
+
+#include "zypp/base/NonCopyable.h"
+
+#include "zypp/sat/detail/PoolMember.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace sat
+ { /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace detail
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : PoolImpl
+ //
+ /** */
+ class PoolImpl : private base::NonCopyable
+ {
+ public:
+ /** Default ctor */
+ PoolImpl();
+
+ /** Dtor */
+ ~PoolImpl();
+
+ /** Pointer style access forwarded to sat-pool. */
+ ::_Pool * operator->()
+ { return _pool; }
+
+ public:
+ /** a \c valid \ref Solvable has a non NULL repo pointer. */
+ bool validSolvable( const ::_Solvable & slv_r ) const
+ { return slv_r.repo; }
+ /** \overload Check also for id_r being in range of _pool->solvables. */
+ bool validSolvable( SolvableIdType id_r ) const
+ { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
+ /** \overload Check also for slv_r being in range of _pool->solvables. */
+ bool validSolvable( const ::_Solvable * slv_r ) const
+ { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
+
+ public:
+ ::_Pool * getPool() const
+ { return _pool; }
+
+ /** \todo a quick check whether the repo was meanwhile deleted. */
+ ::_Repo * getRepo( RepoIdType id_r ) const
+ { return id_r; }
+
+ /** Return pointer to the sat-solvable or NULL if it is not valid.
+ * \see \ref validSolvable.
+ */
+ ::_Solvable * getSolvable( SolvableIdType id_r ) const
+ {
+ if ( validSolvable( id_r ) )
+ return &_pool->solvables[id_r];
+ return 0;
+ }
+
+ public:
+ /** Get id of the first valid \ref Solvable.
+ * This is the next valid after the system solvable.
+ */
+ SolvableIdType getFirstId() const
+ { return getNextId( 1 ); }
+
+ /** Get id of the next valid \ref Solvable.
+ * This goes round robbin. At the end it returns \ref noSolvableId.
+ * Passing \ref noSolvableId it returns the 1st valid \ref Solvable.
+ * \see \ref validSolvable.
+ */
+ SolvableIdType getNextId( SolvableIdType id_r ) const
+ {
+ for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
+ {
+ if ( validSolvable( _pool->solvables[id_r] ) )
+ return id_r;
+ }
+ return noSolvableId;
+ }
+
+ private:
+ ::_Pool * _pool;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace detail
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+ } // namespace sat
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SAT_DETAIL_POOLIMPL_H
Added: trunk/libzypp/zypp/sat/detail/PoolMember.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/detail/PoolMember.h?rev=7905&view=auto
==============================================================================
--- trunk/libzypp/zypp/sat/detail/PoolMember.h (added)
+++ trunk/libzypp/zypp/sat/detail/PoolMember.h Fri Nov 23 18:37:29 2007
@@ -0,0 +1,98 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/sat/detail/PoolMember.h
+ *
+*/
+#ifndef ZYPP_SAT_DETAIL_POOLMEMBER_H
+#define ZYPP_SAT_DETAIL_POOLMEMBER_H
+
+#include "zypp/base/Iterator.h"
+
+extern "C"
+{
+struct _Solvable;
+struct _Repo;
+struct _Pool;
+}
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace sat
+ { /////////////////////////////////////////////////////////////////
+
+ class Solvable;
+ class Repo;
+ class Pool;
+
+ ///////////////////////////////////////////////////////////////////
+ namespace detail
+ { /////////////////////////////////////////////////////////////////
+
+ class PoolImpl;
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : PoolMember
+ //
+ /** Backlink to the associated \ref PoolImpl.
+ * Simple as we currently use one global PoolImpl. If we change our
+ * minds this is where we'd store and do the \c Id to \ref PoolImpl
+ * mapping.
+ */
+ struct PoolMember
+ {
+ static PoolImpl & myPool();
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace detail
+ ///////////////////////////////////////////////////////////////////
+
+
+ ///////////////////////////////////////////////////////////////////
+ namespace detail
+ { /////////////////////////////////////////////////////////////////
+
+ /** Id type to connect \ref Solvable and sat-solvable. */
+ typedef unsigned SolvableIdType;
+ /** Id to denote \ref Solvable::nosolvable. */
+ static const SolvableIdType noSolvableId( 0 );
+
+ /** Id type to connect \ref Repo and sat-repo. */
+ typedef ::_Repo * RepoIdType;
+ /** Id to denote \ref Repo::nosolvable. */
+ static const RepoIdType noRepoId( 0 );
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace detail
+ ///////////////////////////////////////////////////////////////////
+
+
+ ///////////////////////////////////////////////////////////////////
+ namespace detail
+ { /////////////////////////////////////////////////////////////////
+
+ class SolvableIterator;
+ class RepoIterator;
+ class ByRepo;
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace detail
+ ///////////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace sat
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SAT_DETAIL_POOLMEMBER_H
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org