- backup, providing ui::Selectables in ResPoolProxy.
authorMichael Andres <ma@suse.de>
Tue, 7 Feb 2006 09:24:39 +0000 (09:24 +0000)
committerMichael Andres <ma@suse.de>
Tue, 7 Feb 2006 09:24:39 +0000 (09:24 +0000)
zypp/ResPoolManager.h
zypp/ResStatus.h
zypp/pool/PoolImpl.cc
zypp/pool/PoolTraits.h
zypp/ui/Makefile.am
zypp/ui/ResPoolProxy.cc
zypp/ui/Selectable.cc
zypp/ui/Selectable.h
zypp/ui/SelectableImpl.cc [new file with mode: 0644]
zypp/ui/SelectableImpl.h [new file with mode: 0644]

index a292a1d..4846deb 100644 (file)
@@ -48,12 +48,12 @@ namespace zypp
   public:
     /**  */
     void insert( ResObject::constPtr ptr_r, bool installed = false )
-    { inserter()( ptr_r, installed ); }
+    { inserter(installed)( ptr_r ); }
 
     /**  */
     template <class _InputIterator>
       void insert( _InputIterator first_r, _InputIterator last_r, bool installed = false )
-      { while (first_r != last_r) { inserter()( *first_r, installed ); ++first_r; } }
+      { std::for_each( first_r, last_r, inserter(installed) ); }
 
     /**  */
     void erase( ResObject::constPtr ptr_r )
@@ -77,8 +77,8 @@ namespace zypp
     /** Pointer to implementation */
     RW_pointer<pool::PoolTraits::Impl> _pimpl;
     /**  */
-    Inserter inserter()
-    { return Inserter( *_pimpl ); }
+    Inserter inserter( bool installed )
+    { return Inserter( *_pimpl, installed ); }
     /**  */
     Deleter deleter()
     { return Deleter( *_pimpl ); }
index 9a6522b..01fc89a 100644 (file)
@@ -130,7 +130,7 @@ namespace zypp
     /** Dtor. */
     ~ResStatus();
 
-  private:
+  public:
 
     bool isInstalled() const
     { return fieldValueIs<StateField>( INSTALLED ); }
@@ -222,7 +222,7 @@ namespace zypp
            return false;
        }
     }
-      
+
     bool maySetNoTransact (TransactByValue causer)
     {
        bit::BitField<FieldType> savBitfield = _bitfield;
@@ -233,16 +233,16 @@ namespace zypp
 
     bool setTransact (bool val_r, TransactByValue causer)
     {
-       if (!isGreaterThan<TransactByField>( causer )) {        
+       if (!isGreaterThan<TransactByField>( causer )) {
            fieldValueAssign<TransactField>( val_r ? TRANSACT : KEEP_STATE );
            if (val_r) fieldValueAssign<TransactByField>( causer );                     // remember the causer on set
            else fieldValueAssign<TransactByField>( SOLVER );                           // clear it on reset
            return true;
-       } else if (fieldValueIs<TransactField>(val_r ? TRANSACT : KEEP_STATE)) { 
+       } else if (fieldValueIs<TransactField>(val_r ? TRANSACT : KEEP_STATE)) {
            return true; // is already set
        } else {
            return false;
-       }           
+       }
     }
 
     bool maySetTransact (bool val_r, TransactByValue causer)
@@ -265,7 +265,7 @@ namespace zypp
        bool ret = setToBeInstalled (causer);
        _bitfield = savBitfield;
        return ret;
-    }      
+    }
 
     bool setToBeUninstalled (TransactByValue causer)
     {
@@ -279,7 +279,7 @@ namespace zypp
        bool ret = setToBeUninstalled (causer);
        _bitfield = savBitfield;
        return ret;
-    }            
+    }
 
     //------------------------------------------------------------------------
     // *** These are only for the Resolver ***
@@ -304,7 +304,7 @@ namespace zypp
       fieldValueAssign<TransactDetailField>(SOFT_INSTALL);
       return true;
     }
-      
+
     bool setToBeUninstalledSoft ( )
     {
       if (!setToBeUninstalled(SOLVER)) return false;
@@ -314,21 +314,21 @@ namespace zypp
 
     bool isSoftInstall () {
         return fieldValueIs<TransactDetailField> (SOFT_INSTALL);
-    }      
+    }
 
     bool isSoftUninstall () {
         return fieldValueIs<TransactDetailField> (SOFT_REMOVE);
-    }      
+    }
 
     bool setSoftInstall (bool flag) {
         fieldValueAssign<TransactDetailField>(flag?SOFT_INSTALL:0);
        return true;
-    }      
+    }
 
     bool setSoftUninstall (bool flag) {
         fieldValueAssign<TransactDetailField>(flag?SOFT_REMOVE:0);
        return true;
-    }      
+    }
 
     bool setUndetermined ()
     {
index 543c3c3..5ed3b05 100644 (file)
@@ -50,9 +50,9 @@ namespace zypp
       return str << "PoolImpl " << obj.size();
     }
 
-    void PoolImplInserter::operator()( ResObject::constPtr ptr_r, bool installed )
+    void PoolImplInserter::operator()( ResObject::constPtr ptr_r )
     {
-      PoolImpl::Item item ( ptr_r, ResStatus (installed) );
+      PoolImpl::Item item ( ptr_r, ResStatus (_installed) );
       _poolImpl.store().insert( item );
       _poolImpl.namestore().insert( PoolImpl::NameContainerT::value_type (item->name(), item ) );
       CapSet provides = item->dep( Dep::PROVIDES );
index 297e58a..55c611c 100644 (file)
@@ -29,12 +29,14 @@ namespace zypp
     /**  */
     struct PoolImplInserter
     {
-      void operator()( ResObject::constPtr ptr_r, bool installed = false );
+      void operator()( ResObject::constPtr ptr_r );
 
-      PoolImplInserter( PoolImpl & poolImpl_r )
+      PoolImplInserter( PoolImpl & poolImpl_r, bool installed_r )
       : _poolImpl( poolImpl_r )
+      , _installed( installed_r )
       {}
       PoolImpl & _poolImpl;
+      bool       _installed;
     };
 
     /**  */
index 4e1964c..25e0d75 100644 (file)
@@ -10,7 +10,9 @@ uiincludedir = $(pkgincludedir)/ui
 uiinclude_HEADERS = \
        Status.h        \
        Selectable.h    \
-       ResPoolProxy.h
+       ResPoolProxy.h  \
+       \
+       SelectableImpl.h
 
 noinst_LTLIBRARIES =   lib@PACKAGE@_ui.la
 
@@ -19,6 +21,8 @@ noinst_LTLIBRARIES =  lib@PACKAGE@_ui.la
 lib@PACKAGE@_ui_la_SOURCES = \
        Status.cc       \
        Selectable.cc   \
-       ResPoolProxy.cc
+       ResPoolProxy.cc \
+       \
+       SelectableImpl.cc
 
 ## ##################################################
index 6793b44..4a774fb 100644 (file)
 #include <iostream>
 #include "zypp/base/Logger.h"
 
+#include "zypp/base/Iterator.h"
+#include "zypp/base/Algorithm.h"
+#include "zypp/base/Functional.h"
+
 #include "zypp/ui/ResPoolProxy.h"
+#include "zypp/ui/SelectableImpl.h"
 
 using std::endl;
 
@@ -23,6 +28,78 @@ namespace zypp
   namespace ui
   { /////////////////////////////////////////////////////////////////
 
+    struct SelPoolHelper
+    {
+      typedef std::set<ResPool::Item>         ItemC;
+      struct SelC
+      {
+        void add( ResPool::Item it )
+        {
+          if ( it.status().isInstalled() )
+            installed.insert( it );
+          else
+            available.insert( it );
+        }
+        ItemC installed;
+        ItemC available;
+      };
+      typedef std::map<std::string,SelC>      NameC;
+      typedef std::map<ResObject::Kind,NameC> KindC;
+
+      KindC _kinds;
+
+      /** collect from a pool */
+      void operator()( ResPool::Item it )
+      {
+        _kinds[it->kind()][it->name()].add( it );
+      }
+
+
+      Selectable::Ptr buildSelectable( const ResObject::Kind & kind_r,
+                                       const std::string & name_r,
+                                       const PoolItem & installedItem_r,
+                                       const ItemC & available )
+      {
+        return Selectable::Ptr( new Selectable(
+               Selectable::Impl_Ptr( new Selectable::Impl( kind_r, name_r,
+                                                           installedItem_r,
+                                                           available.begin(),
+                                                           available.end() ) )
+                                              ) );
+      }
+
+      /** Build Selectable::Ptr and feed them to some container. */
+      template<class _OutputIterator>
+        void feed( _OutputIterator result_r )
+        {
+          for ( KindC::const_iterator kindIt = _kinds.begin(); kindIt != _kinds.end(); ++kindIt )
+            {
+              for ( NameC::const_iterator nameIt = kindIt->second.begin(); nameIt != kindIt->second.end(); ++nameIt )
+                {
+                  const ItemC & installed( nameIt->second.installed );
+                  const ItemC & available( nameIt->second.available );
+
+                  if ( installed.empty() )
+                    {
+                      if ( available.empty() )
+                        continue;
+                      *result_r = buildSelectable( kindIt->first, nameIt->first, PoolItem(), available );
+                      ++result_r;
+                    }
+                  else
+                    {
+                      // ui want's one Selectable per installed item
+                      for ( ItemC::const_iterator instIt = installed.begin(); instIt != installed.end(); ++instIt )
+                        {
+                          *result_r = buildSelectable( kindIt->first, nameIt->first, *instIt, available );
+                          ++result_r;
+                        }
+                    }
+                }
+            }
+        }
+    };
+
     ///////////////////////////////////////////////////////////////////
     //
     // CLASS NAME : ResPoolProxy::Impl
@@ -31,25 +108,26 @@ namespace zypp
     struct ResPoolProxy::Impl
     {
     public:
+
+      typedef std::set<Selectable::Ptr> SelPool;
+
+    public:
       Impl()
       {}
 
       Impl( ResPool_Ref pool_r )
       : _pool( pool_r )
       {
-#if 0
-        ui::PP collect;
-        for_each( query.begin(), query.end(),
-                  functorRef<void,ResPool::Item>( collect ) );
-        collect.dumpOn();
-#endif
 
+        SelPoolHelper collect;
+        std::for_each( _pool.begin(), _pool.end(),
+                       functor::functorRef<void,ResPool::Item>( collect ) );
+        collect.feed( std::inserter( _selectables, _selectables.end() ) );
       }
 
-
-
     private:
       ResPool_Ref _pool;
+      SelPool     _selectables;
 
     public:
       /** Offer default Impl. */
index 9967171..23d1dcf 100644 (file)
@@ -13,6 +13,7 @@
 //#include "zypp/base/Logger.h"
 
 #include "zypp/ui/Selectable.h"
+#include "zypp/ui/SelectableImpl.h"
 #include "zypp/ResPool.h"
 #include "zypp/PoolItem.h"
 
@@ -27,83 +28,6 @@ namespace zypp
 
     ///////////////////////////////////////////////////////////////////
     //
-    // CLASS NAME : Selectable::Impl
-    //
-    /** Selectable implementation. */
-    struct Selectable::Impl
-    {
-      typedef ResPool::Item                    PoolItem;
-      typedef std::set<PoolItem>               AvialableItemSet;
-      typedef AvialableItemSet::const_iterator available_iterator;
-      typedef AvialableItemSet::size_type      size_type;
-
-    public:
-      Impl( const Object::Kind & kind_r,
-            const std::string & name_r,
-            const PoolItem & installedItem_r,
-            available_iterator availableBegin_r,
-            available_iterator availableEnd_r )
-      : _kind( kind_r )
-      , _name( name_r )
-      , _installedItem( installedItem_r )
-      , _availableItems( availableBegin_r, availableEnd_r )
-      {}
-
-    public:
-      /**  */
-      Object::Kind kind() const
-      { return _kind; }
-      /**  */
-      const std::string & name() const
-      { return _name; }
-      /**  */
-      Status status() const
-      { return S_Taboo; }
-      /**  */
-      bool set_status( const Status state_r )
-      { return false; }
-
-      /** Installed object. */
-      Object_Ptr installedObj() const
-      { return _installedItem; }
-
-      /** Best among available objects. */
-      Object_Ptr candidateObj() const
-      { return 0; }
-
-      /** Best among all objects. */
-      Object_Ptr theObj() const
-      { return 0; }
-
-      /** . */
-      size_type availableObjs() const
-      { return 0; }
-
-    private:
-    public:
-      Object::Kind _kind;
-      std::string _name;
-      PoolItem _installedItem;
-      AvialableItemSet _availableItems;
-    };
-    ///////////////////////////////////////////////////////////////////
-
-    /** \relates Selectable::Impl Stream output */
-    inline std::ostream & operator<<( std::ostream & str, const Selectable::Impl & obj )
-    {
-      return str << '[' << obj.kind() << ']' << obj.name() << ": " << obj.status()
-                 << " (I " << obj._installedItem << ")"
-                 << " (A " << obj._availableItems.size() << ")";
-    }
-
-    ///////////////////////////////////////////////////////////////////
-    //
-    // CLASS NAME : Selectable
-    //
-    ///////////////////////////////////////////////////////////////////
-
-    ///////////////////////////////////////////////////////////////////
-    //
     // METHOD NAME : Selectable::Selectable
     // METHOD TYPE : Ctor
     //
@@ -125,7 +49,7 @@ namespace zypp
     //
     ///////////////////////////////////////////////////////////////////
 
-    Selectable::Object::Kind Selectable::kind() const
+    ResObject::Kind Selectable::kind() const
     { return _pimpl->kind(); }
 
     const std::string & Selectable::name() const
@@ -137,13 +61,13 @@ namespace zypp
     bool Selectable::set_status( const Status state_r )
     { return _pimpl->set_status( state_r ); }
 
-    Selectable::Object_Ptr Selectable::installedObj() const
+    ResObject::constPtr Selectable::installedObj() const
     { return _pimpl->installedObj(); }
 
-    Selectable::Object_Ptr Selectable::candidateObj() const
+    ResObject::constPtr Selectable::candidateObj() const
     { return _pimpl->candidateObj(); }
 
-    Selectable::Object_Ptr Selectable::theObj() const
+    ResObject::constPtr Selectable::theObj() const
      { return _pimpl->theObj(); }
 
     Selectable::size_type Selectable::availableObjs() const
index d17c0ec..12b63e3 100644 (file)
@@ -47,12 +47,9 @@ namespace zypp
       typedef intrusive_ptr<const Selectable>  constPtr;
       typedef unsigned                         size_type;
 
-      typedef ResObject                        Object;
-      typedef Object::constPtr                 Object_Ptr;
-
     public:
       /**  */
-      Object::Kind kind() const;
+      ResObject::Kind kind() const;
 
       /**  */
       const std::string & name() const;
@@ -64,13 +61,13 @@ namespace zypp
       bool set_status( const Status state_r );
 
       /** Installed object. */
-      Object_Ptr installedObj() const;
+      ResObject::constPtr installedObj() const;
 
       /** Best among available objects. */
-      Object_Ptr candidateObj() const;
+      ResObject::constPtr candidateObj() const;
 
       /** Best among all objects. */
-      Object_Ptr theObj() const;
+      ResObject::constPtr theObj() const;
 
       /** Number of available objects. */
       size_type availableObjs() const;
@@ -83,6 +80,7 @@ namespace zypp
       typedef shared_ptr<Impl> Impl_Ptr;
       /** Default ctor */
       Selectable( Impl_Ptr pimpl_r );
+    private:
       /** Dtor */
       ~Selectable();
     private:
diff --git a/zypp/ui/SelectableImpl.cc b/zypp/ui/SelectableImpl.cc
new file mode 100644 (file)
index 0000000..21429fb
--- /dev/null
@@ -0,0 +1,32 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/ui/SelectableImpl.cc
+ *
+*/
+#include <iostream>
+//#include "zypp/base/Logger.h"
+
+#include "zypp/ui/SelectableImpl.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace ui
+  { /////////////////////////////////////////////////////////////////
+
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace ui
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
diff --git a/zypp/ui/SelectableImpl.h b/zypp/ui/SelectableImpl.h
new file mode 100644 (file)
index 0000000..dcb2941
--- /dev/null
@@ -0,0 +1,108 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/ui/SelectableImpl.h
+ *
+*/
+#ifndef ZYPP_UI_SELECTABLEIMPL_H
+#define ZYPP_UI_SELECTABLEIMPL_H
+
+#include <iosfwd>
+
+#include "zypp/base/PtrTypes.h"
+
+#include "zypp/ResPool.h"
+#include "zypp/ResObject.h"
+#include "zypp/ui/Selectable.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace ui
+  { /////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////
+    //
+    // CLASS NAME : Selectable::Impl
+    //
+    /** Selectable implementation. */
+    struct Selectable::Impl
+    {
+      friend std::ostream & operator<<( std::ostream & str, const Selectable::Impl & obj );
+
+      typedef ResPool::Item                    PoolItem;
+      typedef std::set<PoolItem>               AvialableItemSet;
+      typedef AvialableItemSet::const_iterator available_iterator;
+      typedef AvialableItemSet::size_type      size_type;
+
+    public:
+      Impl( const ResObject::Kind & kind_r,
+            const std::string & name_r,
+            const PoolItem & installedItem_r,
+            available_iterator availableBegin_r,
+            available_iterator availableEnd_r )
+      : _kind( kind_r )
+      , _name( name_r )
+      , _installedItem( installedItem_r )
+      , _availableItems( availableBegin_r, availableEnd_r )
+      {}
+
+    public:
+      /**  */
+      ResObject::Kind kind() const
+      { return _kind; }
+      /**  */
+      const std::string & name() const
+      { return _name; }
+      /**  */
+      Status status() const
+      { return S_Taboo; }
+      /**  */
+      bool set_status( const Status state_r )
+      { return false; }
+
+      /** Installed object. */
+      ResObject::constPtr installedObj() const
+      { return _installedItem; }
+
+      /** Best among available objects. */
+      ResObject::constPtr candidateObj() const
+      { return 0; }
+
+      /** Best among all objects. */
+      ResObject::constPtr theObj() const
+      { return 0; }
+
+      /** . */
+      size_type availableObjs() const
+      { return 0; }
+
+    private:
+      ResObject::Kind _kind;
+      std::string _name;
+      PoolItem _installedItem;
+      AvialableItemSet _availableItems;
+    };
+    ///////////////////////////////////////////////////////////////////
+
+    /** \relates Selectable::Impl Stream output */
+    inline std::ostream & operator<<( std::ostream & str, const Selectable::Impl & obj )
+    {
+      return str << '[' << obj.kind() << ']' << obj.name() << ": " << obj.status()
+                 << " (I " << obj._installedItem << ")"
+                 << " (A " << obj._availableItems.size() << ")";
+    }
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace ui
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_UI_SELECTABLEIMPL_H