- Enable ui::Selectable lookup by Solvable/PoolItem in ResPoolProxy.
authorMichael Andres <ma@suse.de>
Wed, 9 Apr 2008 19:37:13 +0000 (19:37 +0000)
committerMichael Andres <ma@suse.de>
Wed, 9 Apr 2008 19:37:13 +0000 (19:37 +0000)
- Add SolvIterMixin: Base class providing PoolItem_iterator and
  Selectable_iterator iterator types based on a Solvable iterator.
- Enhanced WhatProvides and SolvableSet to PoolItem_iterator to offer
  PoolItem_iterator and Selectable_iterator.
- Add Solvable::SplitIdent: Helper class that splits an identifier
  into kind and name.
- Provide methods Pattern::contents returning a collection of packages
  associated with the pattern/patch.

19 files changed:
devel/devel.ma/NewPool.cc
package/libzypp.changes
zypp/CMakeLists.txt
zypp/Package.cc
zypp/Patch.cc
zypp/Patch.h
zypp/PoolItem.h
zypp/ResPoolProxy.cc
zypp/ResPoolProxy.h
zypp/sat/LookupAttr.cc
zypp/sat/LookupAttr.h
zypp/sat/SolvIterMixin.cc [new file with mode: 0644]
zypp/sat/SolvIterMixin.h [new file with mode: 0644]
zypp/sat/Solvable.cc
zypp/sat/Solvable.h
zypp/sat/SolvableSet.h
zypp/sat/WhatProvides.h
zypp/ui/Selectable.cc
zypp/ui/Selectable.h

index 140172f..50404e5 100644 (file)
@@ -36,6 +36,8 @@
 #include "zypp/sat/Pool.h"
 #include "zypp/sat/LocaleSupport.h"
 #include "zypp/sat/LookupAttr.h"
+#include "zypp/sat/SolvableSet.h"
+#include "zypp/sat/SolvIterMixin.h"
 #include "zypp/sat/detail/PoolImpl.h"
 
 #include <zypp/base/GzStream.h>
@@ -506,34 +508,31 @@ namespace zypp
 {
   namespace sat
   {
-
-
-
   }
 }
 
+void dit( const Pattern::Contents & c_r )
+{
+  {
+  sat::WhatProvides c( Capability("amarok") );
+  INT << c << endl;
+  dumpRange( MIL, c.solvableBegin(), c.solvableEnd() ) << endl;
+  dumpRange( WAR, c.poolItemBegin(), c.poolItemEnd() ) << endl;
+  dumpRange( ERR, c.selectableBegin(), c.selectableEnd() ) << endl;
+  }
+  {
+  const Pattern::Contents & c( c_r );
+  dumpRange( MIL, c.solvableBegin(), c.solvableEnd() ) << endl;
+  dumpRange( WAR, c.poolItemBegin(), c.poolItemEnd() ) << endl;
+  dumpRange( ERR, c.selectableBegin(), c.selectableEnd() ) << endl;
+  }
+}
 
 void ditest( sat::Solvable slv_r )
 {
   MIL << slv_r << endl;
-
-  //sat::LookupAttr q( sat::SolvAttr::keywords, slv_r.repository() );
-  sat::LookupAttr q( sat::SolvAttr::allAttr );
-
-  WAR << q << endl;
-  for_( it, q.begin(), q.end() )
-  {
-    WAR << "" << it << endl;
-    const ::_Dataiterator * dip( it.get() );
-
-    switch ( it.solvAttrType() )
-    {
-
-    }
-
-    //it.nextSkipRepo();
-    it.nextSkipSolvable();
- }
+  Package::Ptr   pkg( make<Package>( slv_r ) );
+  dumpRange( DBG, pkg->keywords().begin(), pkg->keywords().end() ) << endl;
   return;
 }
 
@@ -639,18 +638,13 @@ try {
   ///////////////////////////////////////////////////////////////////
 
 
-  //Repository repo( satpool.reposFind("openSUSE-10.3-DVD 10.3") );
-  if(0)//for_( it, repo.solvablesBegin(), repo.solvablesEnd() )
-  {
-    //testDump( MIL, PoolItem(*it) );
-  }
-
   for_( it, pool.byKindBegin<Pattern>(), pool.byKindEnd<Pattern>() )
   {
     if ( (*it)->name() != "apparmor" )
       continue;
-    USR << asKind<Pattern>(*it)->contents() << endl;
-
+    Pattern::Contents c( asKind<Pattern>(*it)->contents() );
+    dumpRange( USR, c.begin(), c.end() ) << endl;
+    dit( c );
     break;
   }
 
index 9dffb40..782a5df 100644 (file)
@@ -1,4 +1,18 @@
 -------------------------------------------------------------------
+Wed Apr  9 21:24:54 CEST 2008 - ma@suse.de
+
+- Enable ui::Selectable lookup by Solvable/PoolItem in ResPoolProxy.
+- Add SolvIterMixin: Base class providing PoolItem_iterator and 
+  Selectable_iterator iterator types based on a Solvable iterator.
+- Enhanced WhatProvides and SolvableSet to PoolItem_iterator to offer
+  PoolItem_iterator and Selectable_iterator.
+- Add Solvable::SplitIdent: Helper class that splits an identifier 
+  into kind and name.
+- Provide methods Pattern::contents returning a collection of packages 
+  associated with the pattern/patch.
+- revision 9496
+
+-------------------------------------------------------------------
 Tue Apr  8 15:50:48 CEST 2008 - jreidinger@suse.cz
 
 - add comparing to PoolQuery
index d4136a3..37678ca 100644 (file)
@@ -515,6 +515,7 @@ SET( zypp_sat_SRCS
   sat/Pool.cc
   sat/Solvable.cc
   sat/SolvableSet.cc
+  sat/SolvIterMixin.cc
   sat/WhatProvides.cc
   sat/LocaleSupport.cc
   sat/LookupAttr.cc
@@ -526,6 +527,7 @@ SET( zypp_sat_HEADERS
   sat/Pool.h
   sat/Solvable.h
   sat/SolvableSet.h
+  sat/SolvIterMixin.h
   sat/WhatProvides.h
   sat/LocaleSupport.h
   sat/LookupAttr.h
index fc888cc..f4689e6 100644 (file)
@@ -79,10 +79,12 @@ namespace zypp
   ByteCount Package::sourcesize() const
   { return lookupNumAttribute( sat::SolvAttr::sourcesize ); }
 
-  /** */
-#warning DUMMY authors
   std::list<std::string> Package::authors() const
-  { return std::list<std::string>(); }
+  {
+    std::list<std::string> ret;
+    str::split( lookupStrAttribute( sat::SolvAttr::authors ), std::back_inserter(ret), "\n" );
+    return ret;
+  }
 
   /** */
 #warning DUMMY filenames
index c997df9..0870352 100644 (file)
@@ -78,52 +78,44 @@ namespace zypp
     return Contents();
   }
 
-  /////////////////////////////////////////////////////////////////
 
-    Patch::ReferenceIterator::ReferenceIterator()
-    {}
+  ///////////////////////////////////////////////////////////////////
+  //
+  //   CLASS NAME : Patch::ReferenceIterator
+  //
+  ///////////////////////////////////////////////////////////////////
 
-    Patch::ReferenceIterator::ReferenceIterator( const sat::Solvable & val_r )
-    {
-      base_reference() = sat::LookupAttr( sat::SolvAttr::updateReferenceId,
-                                            val_r ).begin();
-      _hrefit = sat::LookupAttr( sat::SolvAttr::updateReferenceHref,
-                                   val_r ).begin();
-      _titleit = sat::LookupAttr( sat::SolvAttr::updateReferenceTitle,
-                                    val_r ).begin();
-      _typeit = sat::LookupAttr( sat::SolvAttr::updateReferenceType,
-                                   val_r ).begin();
-    }
+  Patch::ReferenceIterator::ReferenceIterator( const sat::Solvable & val_r )
+  {
+    base_reference() = sat::LookupAttr( sat::SolvAttr::updateReferenceId,
+                   val_r ).begin();
+    _hrefit = sat::LookupAttr( sat::SolvAttr::updateReferenceHref,
+                               val_r ).begin();
+    _titleit = sat::LookupAttr( sat::SolvAttr::updateReferenceTitle,
+                                val_r ).begin();
+    _typeit = sat::LookupAttr( sat::SolvAttr::updateReferenceType,
+                               val_r ).begin();
+  }
 
-      
-    std::string Patch::ReferenceIterator::id() const
-    { return base_reference().asString(); }
-    std::string Patch::ReferenceIterator::href() const
-    { return _hrefit.asString(); }
-    std::string Patch::ReferenceIterator::title() const
-    { return _titleit.asString(); }
-    std::string Patch::ReferenceIterator::type() const
-    { return _typeit.asString(); }
-
-  
-        
-    int  Patch::ReferenceIterator::dereference() const
-    { return 0; }
-
-    void  Patch::ReferenceIterator::increment()
-    { 
-        ++base_reference();
-        ++_hrefit;
-        ++_titleit;
-        ++_typeit;
-    } 
-
-   inline Patch::ReferenceIterator Patch::referencesBegin() const
-   { return ReferenceIterator(satSolvable()); }
-   inline Patch::ReferenceIterator Patch::referencesEnd() const
-   { return ReferenceIterator(); }
 
+  std::string Patch::ReferenceIterator::id() const
+  { return base_reference().asString(); }
+  std::string Patch::ReferenceIterator::href() const
+  { return _hrefit.asString(); }
+  std::string Patch::ReferenceIterator::title() const
+  { return _titleit.asString(); }
+  std::string Patch::ReferenceIterator::type() const
+  { return _typeit.asString(); }
 
+
+  void  Patch::ReferenceIterator::increment()
+  {
+    ++base_reference();
+    ++_hrefit;
+    ++_titleit;
+    ++_typeit;
+  }
+
+  /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
index b43c384..5c808ed 100644 (file)
@@ -22,10 +22,10 @@ namespace zypp
 
   DEFINE_PTR_TYPE(Patch);
 
-  
-  /** 
+
+  /**
    * Class representing a patch.
-   * 
+   *
    * A patch represents a specific problem that
    * can be fixed by pulling in the patch dependencies.
    *
@@ -44,7 +44,7 @@ namespace zypp
       typedef sat::SolvableSet Contents;
 
     public:
-      /** 
+      /**
        * issue date time
        */
       Date timestamp() const
@@ -61,7 +61,7 @@ namespace zypp
       bool reboot_needed() const;
 
       /**
-       * Does the patch affect the package manager itself? 
+       * Does the patch affect the package manager itself?
        */
       bool affects_pkg_manager() const;
 
@@ -77,68 +77,9 @@ namespace zypp
       Contents contents() const;
 
     public:
-     
-      /**
-       * Query class for Patch issue references
-       * like bugzilla and security issues the
-       * patch is supposed to fix.
-       *
-       * The iterator does not provide a dereference
-       * operator so you can do * on it, but you can
-       * access the attributes of each patch issue reference
-       * directly from the iterator.
-       *
-       * \code
-       * for ( Patch::ReferenceIterator it = patch->referencesBegin();
-       *       it != patch->referencesEnd();
-       *       ++it )
-       * {
-       *   cout << it.href() << endl;
-       * }
-       * \endcode
-       *
-       */
-      class ReferenceIterator : public boost::iterator_adaptor<
-        Patch::ReferenceIterator            // Derived
-        , sat::LookupAttr::iterator         // Base
-        , int                              // Value
-        , boost::forward_traversal_tag     // CategoryOrTraversal
-        , int
-        >
-      {
-      public:
-          ReferenceIterator();
-          explicit ReferenceIterator( const sat::Solvable & val_r );
-          
-          /**
-           * The id of the reference. For bugzilla entries
-           * this is the bug number as a string.
-           */
-          std::string id() const;
-          /**
-           * Url or ponter where to find more information
-           */
-          std::string href() const;
-          /**
-           * Title describing the issue
-           */
-          std::string title() const;
-          /**
-           * Type of the reference. For example
-           * "bugzilla"
-           */
-          std::string type() const;
-      private:
-        friend class boost::iterator_core_access;
-
-        int dereference() const;
-        void increment();
-      private:
-        sat::LookupAttr::iterator _hrefit;
-        sat::LookupAttr::iterator _titleit;
-        sat::LookupAttr::iterator _typeit;
-      };
 
+      /** Query class for Patch issue references */
+      class ReferenceIterator
       /**
        * Get an iterator to the beginning of the patch
        * references. \see Patch::ReferenceIterator
@@ -173,6 +114,74 @@ namespace zypp
       virtual ~Patch();
   };
 
+
+  /**
+   * Query class for Patch issue references
+   * like bugzilla and security issues the
+   * patch is supposed to fix.
+   *
+   * The iterator does not provide a dereference
+   * operator so you can do * on it, but you can
+   * access the attributes of each patch issue reference
+   * directly from the iterator.
+   *
+   * \code
+   * for ( Patch::ReferenceIterator it = patch->referencesBegin();
+   *       it != patch->referencesEnd();
+   *       ++it )
+   * {
+   *   cout << it.href() << endl;
+   * }
+   * \endcode
+   *
+   */
+  class Patch::ReferenceIterator : public boost::iterator_adaptor<
+      Patch::ReferenceIterator           // Derived
+      , sat::LookupAttr::iterator        // Base
+      , int                              // Value
+      , boost::forward_traversal_tag     // CategoryOrTraversal
+      , int
+  >
+  {
+    public:
+      ReferenceIterator() {}
+      explicit ReferenceIterator( const sat::Solvable & val_r );
+
+      /**
+       * The id of the reference. For bugzilla entries
+       * this is the bug number as a string.
+       */
+      std::string id() const;
+      /**
+       * Url or pointer where to find more information
+       */
+      std::string href() const;
+      /**
+       * Title describing the issue
+       */
+      std::string title() const;
+      /**
+       * Type of the reference. For example
+       * "bugzilla"
+       */
+      std::string type() const;
+    private:
+      friend class boost::iterator_core_access;
+
+      int dereference() const { return 0; }
+      void increment();
+    private:
+      sat::LookupAttr::iterator _hrefit;
+      sat::LookupAttr::iterator _titleit;
+      sat::LookupAttr::iterator _typeit;
+  };
+
+  inline Patch::ReferenceIterator Patch::referencesBegin() const
+  { return ReferenceIterator(satSolvable()); }
+
+  inline Patch::ReferenceIterator Patch::referencesEnd() const
+  { return ReferenceIterator(); }
+
   /////////////////////////////////////////////////////////////////
 
 } // namespace zypp
index f4cd99a..ef21e2e 100644 (file)
@@ -160,6 +160,18 @@ namespace zypp
   inline bool operator!=( const ResObject::constPtr & lhs, const PoolItem & rhs )
   { return ! (lhs==rhs); }
 
+  /** Solvable to PoolItem transform functor.
+   * \relates PoolItem
+   * \relates sat::SolvIterMixin
+   */
+  struct asPoolItem
+  {
+    typedef PoolItem result_type;
+
+    PoolItem operator()( const sat::Solvable & solv_r ) const
+    { return PoolItem( solv_r ); }
+  };
+
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
index 41b9c30..dfa1434 100644 (file)
@@ -136,7 +136,9 @@ namespace zypp
   //
   //   CLASS NAME : ResPoolProxy::Impl
   //
-  /** ResPoolProxy implementation. */
+  /** ResPoolProxy implementation.
+   * \todo Seedup as it is still using old index
+  */
   struct ResPoolProxy::Impl
   {
   public:
@@ -154,7 +156,18 @@ namespace zypp
     }
 
   public:
+    ui::Selectable::Ptr lookup( ResKind kind_r, const std::string & name_r ) const
+    {
+      SelectableIndex idx( _selPool[kind_r] );
+      for_( it, idx.begin(), idx.end() )
+      {
+        if ( (*it)->name() == name_r )
+          return *it;
+      }
+      return ui::Selectable::Ptr();
+    }
 
+  public:
     bool empty( const ResObject::Kind & kind_r ) const
     { return _selPool[kind_r].empty(); }
 
@@ -255,6 +268,9 @@ namespace zypp
   //
   ///////////////////////////////////////////////////////////////////
 
+  ui::Selectable::Ptr ResPoolProxy::lookup( ResKind kind_r, const std::string & name_r ) const
+  { return _pimpl->lookup( kind_r, name_r ); }
+
   bool ResPoolProxy::empty( const ResObject::Kind & kind_r ) const
   { return _pimpl->empty( kind_r ); }
 
index 4f8b425..613790f 100644 (file)
@@ -46,7 +46,7 @@ namespace zypp
     typedef SelectableIndex::const_iterator const_iterator;
     typedef SelectableIndex::size_type      size_type;
 
-    typedef ResPool::repository_iterator          repository_iterator;
+    typedef ResPool::repository_iterator    repository_iterator;
 
   public:
 
@@ -63,6 +63,24 @@ namespace zypp
     ~ResPoolProxy();
 
   public:
+    /** \name Lookup individual Selectables. */
+    //@{
+    ui::Selectable::Ptr lookup( IdString ident_r ) const
+    { sat::Solvable::SplitIdent id( ident_r ); return lookup( id.kind(), id.name() ); }
+
+    ui::Selectable::Ptr lookup( ResKind kind_r, const std::string & name_r ) const;
+
+    ui::Selectable::Ptr lookup( const sat::Solvable & solv_r ) const
+    { return lookup( solv_r.kind(), solv_r.name() ); }
+
+    ui::Selectable::Ptr lookup( const ResObject::constPtr & resolvable_r ) const
+    { return resolvable_r ? lookup( resolvable_r->satSolvable() ) : ui::Selectable::Ptr(); }
+
+    ui::Selectable::Ptr lookup( const PoolItem & pi_r ) const
+    { return lookup( pi_r.satSolvable() ); }
+    //@}
+
+  public:
 
     /** True if there are items of a certain kind. */
     bool empty( const ResObject::Kind & kind_r ) const;
index b283609..1654516 100644 (file)
@@ -63,6 +63,14 @@ namespace zypp
     bool LookupAttr::empty() const
     { return begin() == end(); }
 
+    LookupAttr::size_type LookupAttr::size() const
+    {
+      size_type c = 0;
+      for_( it, begin(), end() )
+        ++c;
+      return c;
+    }
+
     std::ostream & operator<<( std::ostream & str, const LookupAttr & obj )
     {
       if ( obj.attr() == SolvAttr::noAttr )
index 89f1ae7..f9e63bd 100644 (file)
@@ -70,6 +70,9 @@ namespace zypp
      */
     class LookupAttr
     {
+     public:
+       typedef unsigned size_type;
+
       public:
         /** Default ctor finds nothing. */
         LookupAttr()
@@ -104,6 +107,11 @@ namespace zypp
         /** Whether the query is empty. */
         bool empty() const;
 
+        /** Ammount of results.
+         * \note This is not a cheap call. It runs the query.
+        */
+        size_type size() const;
+
         /** TransformIterator returning an \ref iterator vaue of type \c _ResultT. */
         template<class _ResultT, class _AttrT> class transformIterator;
         //@}
diff --git a/zypp/sat/SolvIterMixin.cc b/zypp/sat/SolvIterMixin.cc
new file mode 100644 (file)
index 0000000..cece2e5
--- /dev/null
@@ -0,0 +1,37 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/sat/SolvIterMixin.cc
+ *
+*/
+//#include <iostream>
+//#include "zypp/base/Logger.h"
+
+#include "zypp/sat/SolvIterMixin.h"
+#include "zypp/ResPoolProxy.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace ui
+  { /////////////////////////////////////////////////////////////////
+
+      Selectable_Ptr asSelectable::operator()( const sat::Solvable & sov_r ) const
+      {
+        return ResPool::instance().proxy().lookup( sov_r );
+      }
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace ui
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
diff --git a/zypp/sat/SolvIterMixin.h b/zypp/sat/SolvIterMixin.h
new file mode 100644 (file)
index 0000000..bd060b9
--- /dev/null
@@ -0,0 +1,132 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/sat/SolvIterMixin.h
+ *
+*/
+#ifndef ZYPP_SAT_SOLVITERMIXIN_H
+#define ZYPP_SAT_SOLVITERMIXIN_H
+
+#include <iosfwd>
+
+#include "zypp/base/PtrTypes.h"
+#include "zypp/base/Iterator.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+  class asPoolItem; // transform functor
+
+  namespace ui
+  {
+    class asSelectable; // transform functor
+  }
+
+  ///////////////////////////////////////////////////////////////////
+  namespace sat
+  { /////////////////////////////////////////////////////////////////
+
+    class Solvable;
+
+    ///////////////////////////////////////////////////////////////////
+    //
+    // CLASS NAME : SolvIterMixin<Derived,DerivedSolvable_iterator>
+    //
+    /** Base class providing common iterator types based on a \ref Solvable iterator.
+     *
+     * A class deriving from \ref SolvIterMixin must provide two methods
+     * \c begin and \c end returning iterator over \ref sat::Solvable.
+     *
+     * \ref SolvIterMixin will then provide iterators over the corresponding
+     * \ref PoolItem and \ref ui::Selectable_Ptr.
+     *
+     * \code
+     *     namespace detail
+     *     {
+     *       class WhatProvidesIterator;
+     *     }
+     *
+     *     class WhatProvides : public SolvIterMixin<WhatProvides,detail::WhatProvidesIterator>
+     *     {
+     *       public:
+     *         typedef detail::WhatProvidesIterator const_iterator;
+     *
+     *         // Iterator pointing to the first Solvable.
+     *         const_iterator begin() const;
+     *
+     *         // Iterator pointing behind the last Solvable.
+     *         const_iterator end() const;
+     *
+     *     };
+     *
+     *     namespace detail
+     *     {
+     *       class WhatProvidesIterator : public boost::iterator_adaptor<
+     *           WhatProvidesIterator          // Derived
+     *          , const detail::IdType *       // Base
+     *          , const Solvable               // Value
+     *          , boost::forward_traversal_tag // CategoryOrTraversal
+     *          , const Solvable               // Reference
+     *       >
+     *       {
+     *          ...
+     *       };
+     *     }
+     * \endcode
+     * \ingroup g_CRTP
+     */
+    template <class Derived,class DerivedSolvable_iterator>
+    class SolvIterMixin
+    {
+      public:
+        /** \name Iterate as Solvable */
+        //@{
+        typedef  DerivedSolvable_iterator Solvable_iterator;
+        Solvable_iterator solvableBegin() const
+        { return self().begin(); }
+        Solvable_iterator solvableEnd() const
+        { return self().end(); }
+        //@}
+
+        /** \name Iterate as PoolItem */
+        //@{
+        typedef transform_iterator<asPoolItem,Solvable_iterator> PoolItem_iterator;
+        PoolItem_iterator poolItemBegin() const
+        { return make_transform_iterator( solvableBegin(), asPoolItem() ); }
+        PoolItem_iterator poolItemEnd() const
+        { return make_transform_iterator( solvableEnd(), asPoolItem() ); }
+        //@}
+
+        /** \name Iterate ui::Selectable::Ptr */
+        //@{
+        typedef transform_iterator<ui::asSelectable,Solvable_iterator> Selectable_iterator;
+        Selectable_iterator selectableBegin() const
+        { return make_transform_iterator( solvableBegin(), ui::asSelectable() ); }
+        Selectable_iterator selectableEnd() const
+        { return make_transform_iterator( solvableEnd(), ui::asSelectable() ); }
+        //@}
+
+      private:
+        const Derived & self() const
+        { return *static_cast<const Derived*>( this ); }
+      protected:
+        SolvIterMixin() {}
+        ~SolvIterMixin() {}
+        SolvIterMixin(const SolvIterMixin &) {}
+        void operator=(const SolvIterMixin &) {}
+     };
+    ///////////////////////////////////////////////////////////////////
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace sat
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SAT_SOLVITERMIXIN_H
index 35ea1e4..01e12b7 100644 (file)
@@ -32,6 +32,49 @@ namespace zypp
   namespace sat
   { /////////////////////////////////////////////////////////////////
 
+    Solvable::SplitIdent::SplitIdent( IdString ident_r )
+    {
+      if ( ! ident_r )
+        return;
+
+      const char * ident = ident_r.c_str();
+      const char * sep = ::strchr( ident, ':' );
+
+      // no ':' in package names (hopefully)
+      if ( ! sep )
+      {
+        _kind = ResKind::package;
+        _name = ident_r.asString();
+        return;
+      }
+
+      // save name
+      _name = sep+1;
+      // quick check for well known kinds
+      if ( sep-ident >= 4 )
+      {
+        switch ( ident[3] )
+        {
+#define OUTS(K,S) if ( !::strncmp( ident, ResKind::K.c_str(), S ) ) _kind = ResKind::K
+          //             ----v
+          case 'c': OUTS( patch, 5 );       return; break;
+          case 'd': OUTS( product, 7 );     return; break;
+          case 'i': OUTS( script, 6 );      return; break;
+          case 'k': OUTS( package, 7 );     return; break;
+          case 'm': OUTS( atom, 4 );        return; break;
+          case 'p': OUTS( srcpackage, 10 ); return; break;
+          case 's': OUTS( message, 7 );     return; break;
+          case 't': OUTS( pattern, 7 );     return; break;
+#undef OUTS
+        }
+      }
+
+      // an unknown kind
+      _kind = ResKind( std::string( ident, sep-ident ) );
+    }
+
+    /////////////////////////////////////////////////////////////////
+
     const Solvable Solvable::noSolvable;
 
     /////////////////////////////////////////////////////////////////
@@ -343,7 +386,7 @@ namespace zypp
 
     bool Solvable::isSatisfied() const
     {
-       NO_SOLVABLE_RETURN( false );    
+       NO_SOLVABLE_RETURN( false );
        if (solvable_trivial_installable (_solvable, Pool::instance().systemRepo().get()) == 1)
            return true;
        else
index 345879b..d7ce9c4 100644 (file)
@@ -209,6 +209,21 @@ namespace zypp
         /** Return next Solvable in \ref Repo (or \ref noSolvable). */
         Solvable nextInRepo() const;
 
+        /** Helper that splits an identifier into kind and name.
+         * \see \ref ident
+        */
+        class SplitIdent
+        {
+          public:
+            SplitIdent() {}
+            SplitIdent( IdString ident_r );
+            ResKind      kind() const { return _kind; }
+            std::string  name() const { return _name; }
+          private:
+            ResKind      _kind;
+            std::string  _name;
+        };
+
       public:
         /** Expert backdoor. */
         ::_Solvable * get() const;
index 5482691..c38c383 100644 (file)
@@ -17,6 +17,7 @@
 #include "zypp/base/PtrTypes.h"
 #include "zypp/base/Tr1hash.h"
 #include "zypp/sat/Solvable.h"
+#include "zypp/sat/SolvIterMixin.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -31,7 +32,7 @@ namespace zypp
     //
     /** Solvable set wrapper to allow adding additioanal convenience iterators.
      */
-    class SolvableSet
+    class SolvableSet : public SolvIterMixin<SolvableSet,std::tr1::unordered_set<Solvable>::const_iterator>
     {
       friend std::ostream & operator<<( std::ostream & str, const SolvableSet & obj );
 
index 9913205..d5b61e6 100644 (file)
@@ -18,6 +18,7 @@
 #include "zypp/base/PtrTypes.h"
 #include "zypp/sat/detail/PoolMember.h"
 #include "zypp/sat/Solvable.h"
+#include "zypp/sat/SolvIterMixin.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -26,6 +27,11 @@ namespace zypp
   namespace sat
   { /////////////////////////////////////////////////////////////////
 
+    namespace detail
+    {
+      class WhatProvidesIterator;
+    }
+
     ///////////////////////////////////////////////////////////////////
     //
     // CLASS NAME : WhatProvides
@@ -78,7 +84,8 @@ namespace zypp
      * }
      * \endcode
      */
-    class WhatProvides : protected detail::PoolMember
+    class WhatProvides : public SolvIterMixin<WhatProvides,detail::WhatProvidesIterator>,
+                         protected detail::PoolMember
     {
       public:
         typedef Solvable  value_type;
@@ -111,7 +118,7 @@ namespace zypp
         size_type size() const;
 
       public:
-        class const_iterator;
+        typedef detail::WhatProvidesIterator const_iterator;
 
         /** Iterator pointing to the first \ref Solvable. */
         const_iterator begin() const;
@@ -128,14 +135,16 @@ namespace zypp
     /** \relates WhatProvides Stream output */
     std::ostream & operator<<( std::ostream & str, const WhatProvides & obj );
 
+    namespace detail
+    {
     ///////////////////////////////////////////////////////////////////
     //
     // CLASS NAME : WhatProvides::const_iterator
     //
     /** \ref WhatProvides iterator.
      */
-    class WhatProvides::const_iterator : public boost::iterator_adaptor<
-          const_iterator               // Derived
+    class WhatProvidesIterator : public boost::iterator_adaptor<
+          WhatProvidesIterator         // Derived
         , const detail::IdType *       // Base
         , const Solvable               // Value
         , boost::forward_traversal_tag // CategoryOrTraversal
@@ -143,12 +152,12 @@ namespace zypp
         >
     {
       public:
-        const_iterator()
-        : const_iterator::iterator_adaptor_( 0 )
+        WhatProvidesIterator()
+        : iterator_adaptor_( 0 )
         {}
 
-        explicit const_iterator( const sat::detail::IdType * _idx )
-        : const_iterator::iterator_adaptor_( _idx )
+        explicit WhatProvidesIterator( const sat::detail::IdType * _idx )
+        : iterator_adaptor_( _idx )
         {}
 
       private:
@@ -169,6 +178,7 @@ namespace zypp
         { ++base_reference(); }
     };
     ///////////////////////////////////////////////////////////////////
+    }
 
     inline WhatProvides::const_iterator WhatProvides::begin() const
     { return const_iterator( _begin ); }
index 9b46ef4..2aa0b94 100644 (file)
@@ -22,6 +22,8 @@ namespace zypp
   namespace ui
   { /////////////////////////////////////////////////////////////////
 
+    IMPL_PTR_TYPE(Selectable);
+
     ///////////////////////////////////////////////////////////////////
     //
     // METHOD NAME : Selectable::Selectable
@@ -80,12 +82,12 @@ namespace zypp
 
     Selectable::available_iterator Selectable::availableBegin() const
     { return _pimpl->availableBegin(); }
-    
+
     Selectable::available_iterator Selectable::availableEnd() const
     { return _pimpl->availableEnd(); }
 
     ////////////////////////////////////////////////////////////////////////
-   
+
     bool Selectable::installedEmpty() const
     { return _pimpl->installedEmpty(); }
 
@@ -103,7 +105,7 @@ namespace zypp
 
     bool Selectable::isUnmaintained() const
     { return _pimpl->isUnmaintained(); }
-      
+
 
 
     ResStatus::TransactByValue Selectable::modifiedBy() const
index 36231ed..0041c78 100644 (file)
@@ -29,6 +29,8 @@ namespace zypp
   namespace ui
   { /////////////////////////////////////////////////////////////////
 
+    DEFINE_PTR_TYPE(Selectable);
+
     ///////////////////////////////////////////////////////////////////
     //
     // CLASS NAME : Selectable
@@ -109,8 +111,8 @@ namespace zypp
        */
       available_size_type availableSize() const;
 
-      /** 
-       * Number of available objects. 
+      /**
+       * Number of available objects.
        * \deprecated Use availableSize
        */
       ZYPP_DEPRECATED available_size_type availableObjs() const
@@ -154,8 +156,8 @@ namespace zypp
       bool hasObject() const
       { return (! installedEmpty()) || candidateObj(); }
 
-      /** 
-       * True if installed object is present. 
+      /**
+       * True if installed object is present.
        * \deprecated Use ! installedEmpty()
        */
       ZYPP_DEPRECATED bool hasInstalledObj() const
@@ -214,7 +216,7 @@ namespace zypp
       //@}
 
     public:
-      /** 
+      /**
        * \name Special inteface for Y2UI.
        * \note This interface acts on \ref ResStatus::USER level.
        * The \ref Status enum, and allowed state transitions are
@@ -225,7 +227,7 @@ namespace zypp
       /** Return the current Status */
       Status status() const;
 
-      /** 
+      /**
        * Try to set a new Status.
        * Returns \c false if the transitions is not allowed.
        */
@@ -265,6 +267,20 @@ namespace zypp
     /** \relates Selectable Stream output */
     std::ostream & operator<<( std::ostream & str, const Selectable & obj );
 
+    /** Solvable to Selectable transform functor.
+     * \relates Selectable
+     * \relates sat::SolvIterMixin
+     */
+    struct asSelectable
+    {
+      typedef Selectable_Ptr result_type;
+
+      Selectable_Ptr operator()( const sat::Solvable & solv_r ) const;
+
+      Selectable_Ptr operator()( const PoolItem & pi_r ) const
+      { return operator()( pi_r.satSolvable() ); }
+    };
+
     /////////////////////////////////////////////////////////////////
   } // namespace ui
   ///////////////////////////////////////////////////////////////////