- Fix SolvIterMixin to avioid multiple visits of the same Selectable.
authorMichael Andres <ma@suse.de>
Fri, 11 Apr 2008 10:51:59 +0000 (10:51 +0000)
committerMichael Andres <ma@suse.de>
Fri, 11 Apr 2008 10:51:59 +0000 (10:51 +0000)
- Add Resolvable::poolItem() providing access to the corresponding
  PoolItem. API to query isRelevant/isSatisfied/isBroken was moved
  to PoolItem.

zypp/PoolItem.cc
zypp/PoolItem.h
zypp/Resolvable.cc
zypp/Resolvable.h
zypp/sat/SolvIterMixin.cc
zypp/sat/SolvIterMixin.h
zypp/sat/Solvable.cc
zypp/sat/Solvable.h

index 4850edb..2d851f8 100644 (file)
@@ -54,20 +54,20 @@ namespace zypp
 
     public:
 
-      bool isSatisfied() const
+      bool isRelevant() const
       {
-        return _resolvable->isSatisfied();
+        return true;
       }
 
-      bool isRelevant() const
+      bool isSatisfied() const
       {
-        return _resolvable->isRelevant();
+        return true;
       }
 
-      bool validate() const
+      bool isBroken() const
       {
-        return _resolvable->validate();
-      }      
+        return true;
+      }
 
     private:
       mutable ResStatus     _status;
@@ -194,11 +194,14 @@ namespace zypp
   ResStatus & PoolItem::statusReset() const
   { return _pimpl->statusReset(); }
 
+  bool PoolItem::isRelevant() const
+  { return _pimpl->isSatisfied(); }
+
   bool PoolItem::isSatisfied() const
   { return _pimpl->isSatisfied(); }
 
-  ResObject::constPtr PoolItem::resolvable() const
-  { return _pimpl->resolvable(); }
+  bool PoolItem::isBroken() const
+  { return _pimpl->isSatisfied(); }
 
   void PoolItem::saveState() const
   { _pimpl->saveState(); }
@@ -209,6 +212,9 @@ namespace zypp
   bool PoolItem::sameState() const
   { return _pimpl->sameState(); }
 
+  ResObject::constPtr PoolItem::resolvable() const
+  { return _pimpl->resolvable(); }
+
   /******************************************************************
    **
    **  FUNCTION NAME : operator<<
index acfc1e7..c01bade 100644 (file)
@@ -69,30 +69,32 @@ namespace zypp
       ~PoolItem();
 
     public:
+      /** \name Status related methods. */
+      //@{
       /** Returns the current status. */
       ResStatus & status() const;
 
       /** Reset status. */
       ResStatus & statusReset() const;
 
-      /** Whether the items requirements are met. */
-      bool isSatisfied() const;
-
-      /** Whether the items requirements are broken. */
-      bool isBroken() const
-      { return ! isSatisfied(); }
 
-      /** Returns true if the solvable is relevant which means e.G. for patches
+      /** \name Status validation.
+       *
+      */
+      //@{
+      /** Returns true if the solvable is relevant which means e.g. for patches
        *  that at least one package of the patch is installed.
        */
       bool isRelevant() const;
 
-      /** Check if the solvable is satisfied,broken or not relevant
-       *  (not important, so it can be ignored)
-       * \return BROKEN, SATISFIED, NOTRELEVANT          
-      */
-      ValidValue validate() const;
+      /** Whether a relevant items requirements are met. */
+      bool isSatisfied() const;
 
+      /** Whether a relevant items requirements are broken. */
+      bool isBroken() const;
+      //@}
+
+      //@}
     public:
       /** Return the \ref ResPool the item belongs to. */
       ResPool pool() const;
index 628801e..aa8ccad 100644 (file)
@@ -11,7 +11,8 @@
 */
 #include "zypp/Resolvable.h"
 #include "zypp/ResObject.h"
-             
+#include "zypp/PoolItem.h"
+
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
@@ -37,6 +38,14 @@ namespace zypp
 
   ///////////////////////////////////////////////////////////////////
   //
+  //   METHOD NAME : Resolvable::poolItem
+  //   METHOD TYPE : PoolItem
+  //
+  PoolItem Resolvable::poolItem() const
+  { return PoolItem( *this ); }
+
+  ///////////////////////////////////////////////////////////////////
+  //
   //   METHOD NAME : Resolvable::dumpOn
   //   METHOD TYPE : std::ostream &
   //
index 1be9cb1..f45348f 100644 (file)
@@ -30,6 +30,7 @@ namespace zypp
 { /////////////////////////////////////////////////////////////////
 
   struct NVRAD;
+  class PoolItem;
 
   ///////////////////////////////////////////////////////////////////
   //
@@ -82,26 +83,12 @@ namespace zypp
     //@}
 
   public:
-    /** Returns true if the solvable is satisfied */
-    using sat::Solvable::isSatisfied;
-      
-    /** Returns true if the solvable is satisfied */
-    using sat::Solvable::isBroken;
-      
-    /** Returns true if the solvable is relevant which means e.G. for patches
-     *  that at least one package of the patch is installed.
-     */
-    using sat::Solvable::isRelevant;
-
-    /** Check if the solvable is satisfied,broken or not relevant
-     *  (not important, so it can be ignored)
-     * \return BROKEN, SATISFIED, NOTRELEVANT   
-    */
-    using sat::Solvable::validate;
-
-  public:
+    /** Access the corresponding \ref sat:::Solvable. */
     const sat::Solvable & satSolvable() const { return *this; }
 
+    /** Access the corresponding \ref PoolItem. */
+    PoolItem poolItem() const;
+
   protected:
     /** Ctor */
     Resolvable( const sat::Solvable & solvable_r );
index cece2e5..7d2340a 100644 (file)
@@ -13,6 +13,7 @@
 //#include "zypp/base/Logger.h"
 
 #include "zypp/sat/SolvIterMixin.h"
+#include "zypp/sat/Solvable.h"
 #include "zypp/ResPoolProxy.h"
 
 using std::endl;
@@ -21,13 +22,29 @@ using std::endl;
 namespace zypp
 { /////////////////////////////////////////////////////////////////
   ///////////////////////////////////////////////////////////////////
-  namespace ui
+  namespace sat
   { /////////////////////////////////////////////////////////////////
 
-      Selectable_Ptr asSelectable::operator()( const sat::Solvable & sov_r ) const
+    namespace solvitermixin_detail
+    {
+      bool UnifyByIdent::operator()( const Solvable & solv_r ) const
       {
-        return ResPool::instance().proxy().lookup( sov_r );
+        return( solv_r && _uset->insert( solv_r.ident().id() ).second );
       }
+    }
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace sat
+  ///////////////////////////////////////////////////////////////////
+
+  ///////////////////////////////////////////////////////////////////
+  namespace ui
+  { /////////////////////////////////////////////////////////////////
+
+    Selectable_Ptr asSelectable::operator()( const sat::Solvable & sov_r ) const
+    {
+      return ResPool::instance().proxy().lookup( sov_r );
+    }
 
     /////////////////////////////////////////////////////////////////
   } // namespace ui
index bd060b9..9bad52f 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "zypp/base/PtrTypes.h"
 #include "zypp/base/Iterator.h"
+#include "zypp/base/Tr1hash.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -34,6 +35,26 @@ namespace zypp
 
     class Solvable;
 
+    namespace solvitermixin_detail
+    {
+      /** Unify by \c ident \c (kind:name).
+       * Return true on the 1st appearance of a new \c ident. This is
+       * used in \ref SolvIterMixin when mapping a  Solvable iterator
+       * to a Selectable iterator.
+      */
+      struct UnifyByIdent
+      {
+        bool operator()( const Solvable & solv_r ) const;
+
+        typedef std::tr1::unordered_set<unsigned> Uset;
+        UnifyByIdent()
+          : _uset( new Uset )
+        {}
+        shared_ptr<Uset> _uset;
+      };
+    } // namespace solvitermixin_detail
+
+
     ///////////////////////////////////////////////////////////////////
     //
     // CLASS NAME : SolvIterMixin<Derived,DerivedSolvable_iterator>
@@ -103,16 +124,27 @@ namespace zypp
         { return make_transform_iterator( solvableEnd(), asPoolItem() ); }
         //@}
 
+      private:
+        typedef filter_iterator<solvitermixin_detail::UnifyByIdent,Solvable_iterator> UnifiedSolvable_iterator;
+      public:
         /** \name Iterate ui::Selectable::Ptr */
         //@{
-        typedef transform_iterator<ui::asSelectable,Solvable_iterator> Selectable_iterator;
+        typedef transform_iterator<ui::asSelectable,UnifiedSolvable_iterator> Selectable_iterator;
         Selectable_iterator selectableBegin() const
-        { return make_transform_iterator( solvableBegin(), ui::asSelectable() ); }
+        { return make_transform_iterator( unifiedSolvableBegin(), ui::asSelectable() ); }
         Selectable_iterator selectableEnd() const
-        { return make_transform_iterator( solvableEnd(), ui::asSelectable() ); }
+        { return make_transform_iterator( unifiedSolvableEnd(), ui::asSelectable() ); }
         //@}
 
       private:
+        /** \name Iterate unified Solbvables to be transformed into Selectable. */
+        //@{
+        UnifiedSolvable_iterator unifiedSolvableBegin() const
+        { return make_filter_iterator( solvitermixin_detail::UnifyByIdent(), solvableBegin(), solvableEnd() ); }
+        UnifiedSolvable_iterator unifiedSolvableEnd() const
+        { return make_filter_iterator( solvitermixin_detail::UnifyByIdent(), solvableEnd(), solvableEnd() );; }
+        //@}
+      private:
         const Derived & self() const
         { return *static_cast<const Derived*>( this ); }
       protected:
index 77f7739..025e979 100644 (file)
@@ -383,35 +383,6 @@ namespace zypp
     }
 
     ///////////////////////////////////////////////////////////////////
-
-    ValidValue Solvable::validate() const
-    {
-       NO_SOLVABLE_RETURN( NOTRELEVANT );
-       int ret = solvable_trivial_installable_repo (_solvable, Pool::instance().systemRepo().get());
-       if (ret == 0)
-           return BROKEN;
-       else if (ret > 0)
-           return SATISFIED;
-       else
-           return NOTRELEVANT;
-    }
-
-    bool Solvable::isSatisfied() const
-    {
-       return validate() == SATISFIED;
-    }
-
-    bool Solvable::isRelevant() const
-    {
-       NO_SOLVABLE_RETURN( false );
-       if (isKind (ResKind::package))
-           return true; // packages are always relevant
-       
-       return validate() == BROKEN;    
-    }
-      
-
-    ///////////////////////////////////////////////////////////////////
     namespace
     { /////////////////////////////////////////////////////////////////
       /** Expand \ref Capability and call \c fnc_r for each namescpace:language
index b91ebbc..649e2c0 100644 (file)
@@ -34,8 +34,6 @@ namespace zypp
   class CheckSum;
   class OnMediaLocation;
 
-  enum ValidValue { BROKEN, SATISFIED, NOTRELEVANT };    
-
   ///////////////////////////////////////////////////////////////////
   namespace sat
   { /////////////////////////////////////////////////////////////////
@@ -180,23 +178,6 @@ namespace zypp
         //@}
 
       public:
-        /** Returns true if the solvable is satisfied */
-        bool isSatisfied() const;
-        /** Returns true if the solvable is satisfied */
-        bool isBroken() const { return !isSatisfied(); }
-        /** Returns true if the solvable is relevant which means e.G. for patches
-        *  that at least one package of the patch is installed.
-        */
-        bool isRelevant() const;
-
-       /** Check if the solvable is satisfied,broken or not relevant
-        *  (not important, so it can be ignored)
-        * \return BROKEN, SATISFIED, NOTRELEVANT   
-       */
-       
-       ValidValue validate() const;
-
-      public:
         /** \name Locale support. */
         //@{
         /** Whether this \c Solvable claims to support locales. */