- Add static ui::Selectable::get methods as convenient ctor substitute.
authorMichael Andres <ma@suse.de>
Fri, 8 Aug 2008 15:04:06 +0000 (15:04 +0000)
committerMichael Andres <ma@suse.de>
Fri, 8 Aug 2008 15:04:06 +0000 (15:04 +0000)
devel/devel.ma/NewPool.cc
package/libzypp.changes
zypp/CMakeLists.txt
zypp/pool/ByIdent.h [new file with mode: 0644]
zypp/pool/PoolTraits.h
zypp/ui/Selectable.cc
zypp/ui/Selectable.h
zypp/ui/SelectableTraits.h

index d8e769b..335a046 100644 (file)
@@ -451,17 +451,7 @@ try {
     }
   }
 
-  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();
@@ -533,6 +523,14 @@ try {
   ///////////////////////////////////////////////////////////////////
   ///////////////////////////////////////////////////////////////////
 
+  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") );
index 43a1574..f14bafd 100644 (file)
@@ -1,4 +1,11 @@
 -------------------------------------------------------------------
+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.
index 026c1b9..e8c69a9 100644 (file)
@@ -422,6 +422,7 @@ SET( zypp_pool_HEADERS
   pool/PoolImpl.h
   pool/PoolStats.h
   pool/PoolTraits.h
+  pool/ByIdent.h
 )
 
 INSTALL(  FILES
diff --git a/zypp/pool/ByIdent.h b/zypp/pool/ByIdent.h
new file mode 100644 (file)
index 0000000..3f8b192
--- /dev/null
@@ -0,0 +1,103 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ 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
index 0310bab..0b180d4 100644 (file)
@@ -21,6 +21,7 @@
 #include "zypp/base/Tr1hash.h"
 
 #include "zypp/PoolItem.h"
+#include "zypp/pool/ByIdent.h"
 #include "zypp/sat/Pool.h"
 
 ///////////////////////////////////////////////////////////////////
@@ -42,80 +43,6 @@ namespace zypp
       { 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
index df960a8..0e94548 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "zypp/ui/Selectable.h"
 #include "zypp/ui/SelectableImpl.h"
+#include "zypp/ResPool.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -24,6 +25,9 @@ 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
index 89b5cdf..a37d6fe 100644 (file)
@@ -25,6 +25,7 @@
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
+
   ///////////////////////////////////////////////////////////////////
   namespace ui
   { /////////////////////////////////////////////////////////////////
@@ -62,6 +63,44 @@ namespace zypp
       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.
index f713880..a6375b9 100644 (file)
@@ -16,7 +16,8 @@
 
 #include "zypp/base/Iterator.h"
 #include "zypp/PoolItem.h"
-#include "zypp/ResObject.h"
+#include "zypp/pool/ByIdent.h"
+//#include "zypp/ResObject.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp