}
}
- dumpRange( USR, satpool.reposBegin(), satpool.reposEnd() );
- USR << "pool: " << pool << endl;
- ui::Selectable::Ptr t( getSel<Package>( "test" ) );
- MIL << dump(t) << endl;
-
- ///////////////////////////////////////////////////////////////////
- INT << "===[END]============================================" << endl << endl;
- zypp::base::LogControl::instance().logNothing();
- return 0;
-
- if ( 0 )
+ if ( 1 )
{
RepoManager repoManager( makeRepoManager( sysRoot ) );
RepoInfoList repos = repoManager.knownRepositories();
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
+ ui::Selectable::Ptr item( ui::Selectable::get( "amarok" ) );
+ MIL << dump(item) << endl;
+
+ ///////////////////////////////////////////////////////////////////
+ INT << "===[END]============================================" << endl << endl;
+ zypp::base::LogControl::instance().logNothing();
+ return 0;
+
if ( 0 )
{
PoolItem pi ( getPi<Package>("amarok") );
-------------------------------------------------------------------
+Fri Aug 8 17:01:00 CEST 2008 - ma@suse.de
+
+- Add static ui::Selectable::get methods as convenient ctor
+ substitute.
+- revision 10806
+
+-------------------------------------------------------------------
Fri Aug 8 15:41:17 CEST 2008 - ma@suse.de
- Adapt zypp-query-pool to new product handling.
pool/PoolImpl.h
pool/PoolStats.h
pool/PoolTraits.h
+ pool/ByIdent.h
)
INSTALL( FILES
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/pool/ByIdent.h
+ *
+*/
+#ifndef ZYPP_POOL_BYIDENT_H
+#define ZYPP_POOL_BYIDENT_H
+
+#include "zypp/PoolItem.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace pool
+ { /////////////////////////////////////////////////////////////////
+
+ /** Main filter selecting PoolItems by \c name and \c kind.
+ */
+ class ByIdent
+ {
+ public:
+ ByIdent()
+ : _id( 0 )
+ {}
+
+ explicit ByIdent( sat::Solvable slv_r )
+ : _id( makeIdent( slv_r ) )
+ {}
+
+ explicit ByIdent( IdString ident_r )
+ : _id( ident_r.id() )
+ {}
+
+ ByIdent( ResKind kind_r, IdString name_r )
+ : _id( makeIdent( kind_r, name_r ) )
+ {}
+
+ ByIdent( ResKind kind_r, const C_Str & name_r )
+ : _id( makeIdent( kind_r, name_r ) )
+ {}
+
+ public:
+ bool operator()( sat::Solvable slv_r ) const
+ {
+ return _id >= 0 ? ( slv_r.ident().id() == _id && ! slv_r.isKind( ResKind::srcpackage ) )
+ : ( slv_r.ident().id() == -_id && slv_r.isKind( ResKind::srcpackage ) );
+ }
+
+ bool operator()( const PoolItem & pi_r ) const
+ { return operator()( pi_r.satSolvable() ); }
+
+ bool operator()( ResObject::constPtr p_r ) const
+ { return p_r ? operator()( p_r->satSolvable() ) : !_id; }
+
+ private:
+ sat::detail::IdType makeIdent( sat::Solvable slv_r )
+ {
+ return slv_r.isKind( ResKind::srcpackage ) ? -slv_r.ident().id()
+ : slv_r.ident().id();
+ }
+
+ sat::detail::IdType makeIdent( ResKind kind_r, IdString name_r )
+ {
+ if ( kind_r == ResKind::package )
+ return name_r.id();
+ else if ( kind_r == ResKind::srcpackage )
+ return -name_r.id();
+ return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
+ }
+
+ sat::detail::IdType makeIdent( ResKind kind_r, const C_Str & name_r )
+ {
+ if ( kind_r == ResKind::package )
+ return IdString( name_r ).id();
+ else if ( kind_r == ResKind::srcpackage )
+ return -(IdString( name_r ).id());
+ return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
+ }
+
+ public:
+ sat::detail::IdType get() const { return _id; }
+
+ private:
+ /** negative \c _id for \c srcpackage, as they use the same \c ident
+ * as \c package.
+ */
+ sat::detail::IdType _id;
+ };
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace pool
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_POOL_BYIDENT_H
#include "zypp/base/Tr1hash.h"
#include "zypp/PoolItem.h"
+#include "zypp/pool/ByIdent.h"
#include "zypp/sat/Pool.h"
///////////////////////////////////////////////////////////////////
{ return pi; }
};
- /** Main filter selecting PoolItems by \c name and \c kind.
- *
- */
- class ByIdent
- {
- public:
- ByIdent()
- : _id( 0 )
- {}
-
- explicit ByIdent( sat::Solvable slv_r )
- : _id( makeIdent( slv_r ) )
- {}
-
- explicit ByIdent( IdString ident_r )
- : _id( ident_r.id() )
- {}
-
- ByIdent( ResKind kind_r, IdString name_r )
- : _id( makeIdent( kind_r, name_r ) )
- {}
-
- ByIdent( ResKind kind_r, const C_Str & name_r )
- : _id( makeIdent( kind_r, name_r ) )
- {}
-
- public:
- bool operator()( sat::Solvable slv_r ) const
- {
- return _id >= 0 ? ( slv_r.ident().id() == _id && ! slv_r.isKind( ResKind::srcpackage ) )
- : ( slv_r.ident().id() == -_id && slv_r.isKind( ResKind::srcpackage ) );
- }
-
- bool operator()( const PoolItem & pi_r ) const
- { return operator()( pi_r.satSolvable() ); }
-
- bool operator()( ResObject::constPtr p_r ) const
- { return p_r ? operator()( p_r->satSolvable() ) : !_id; }
-
- private:
- sat::detail::IdType makeIdent( sat::Solvable slv_r )
- {
- return slv_r.isKind( ResKind::srcpackage ) ? -slv_r.ident().id()
- : slv_r.ident().id();
- }
-
- sat::detail::IdType makeIdent( ResKind kind_r, IdString name_r )
- {
- if ( kind_r == ResKind::package )
- return name_r.id();
- else if ( kind_r == ResKind::srcpackage )
- return -name_r.id();
- return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
- }
-
- sat::detail::IdType makeIdent( ResKind kind_r, const C_Str & name_r )
- {
- if ( kind_r == ResKind::package )
- return IdString( name_r ).id();
- else if ( kind_r == ResKind::srcpackage )
- return -(IdString( name_r ).id());
- return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
- }
-
- public:
- sat::detail::IdType get() const { return _id; }
-
- private:
- /** negative \c _id for \c srcpackage, as they use the same \c ident
- * as \c package.
- */
- sat::detail::IdType _id;
- };
-
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : PoolTraits
#include "zypp/ui/Selectable.h"
#include "zypp/ui/SelectableImpl.h"
+#include "zypp/ResPool.h"
///////////////////////////////////////////////////////////////////
namespace zypp
IMPL_PTR_TYPE(Selectable);
+ Selectable::Ptr Selectable::get( const pool::ByIdent & ident_r )
+ { return ResPool::instance().proxy().lookup( ident_r ); }
+
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : Selectable::Selectable
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
+
///////////////////////////////////////////////////////////////////
namespace ui
{ /////////////////////////////////////////////////////////////////
typedef SelectableTraits::installed_size_type installed_size_type;
public:
+ /** \name Static ctor substitues picking the item from the pool.
+ * \code
+ * Selectable::Ptr item;
+ * item = Selectable::get( "amarok ); // package amamrok
+ * item = Selectable::get( ResKind::patch, "amarok ); // patch amamrok
+ * item = Selectable::get( IdString( "patch:amarok" ); // patch amamrok
+ * \endcode
+ */
+ //@{
+ /** Get the \ref Selctable */
+ static Ptr get( const pool::ByIdent & ident_r );
+
+ /** Get the \ref Selctable by it's \c sat-identifyer. */
+ static Ptr get( IdString ident_r )
+ { return get( pool::ByIdent( ident_r ) ); }
+
+ /** Get the \ref Selctable by \c kind and \c name. */
+ static Ptr get( ResKind kind_r, const std::string & name_r )
+ { return get( pool::ByIdent( kind_r, name_r ) ); }
+
+ /** Get the \c Package \ref Selctable by \c name. */
+ static Ptr get( const std::string & name_r )
+ { return get( pool::ByIdent( ResKind::package, name_r ) ); }
+
+ /** Get the \ref Selctable containing a specific \ref sat::Solvable. */
+ static Ptr get( const sat::Solvable & solv_r )
+ { return get( pool::ByIdent( solv_r ) ); }
+
+ /** Get the \ref Selctable containing a specific \ref ResObject. */
+ static Ptr get( const ResObject::constPtr & resolvable_r )
+ { return resolvable_r ? get( resolvable_r->satSolvable() ) : Ptr(); }
+
+ /** Get the \ref Selctable containing a specific \ref PoolItem. */
+ static Ptr get( const PoolItem & pi_r )
+ { return get( pi_r.satSolvable() ); }
+ //@}
+
+ public:
/** The identifier.
* This is the solvables \ref name, \b except for packages and
* source packes, prefixed by it's \ref kind.
#include "zypp/base/Iterator.h"
#include "zypp/PoolItem.h"
-#include "zypp/ResObject.h"
+#include "zypp/pool/ByIdent.h"
+//#include "zypp/ResObject.h"
///////////////////////////////////////////////////////////////////
namespace zypp