drop ResPool byName iterator and use byIdent
authorMichael Andres <ma@suse.de>
Tue, 12 Feb 2008 11:29:42 +0000 (11:29 +0000)
committerMichael Andres <ma@suse.de>
Tue, 12 Feb 2008 11:29:42 +0000 (11:29 +0000)
zypp/NameKindProxy.cc
zypp/NameKindProxy.h
zypp/ResPool.cc
zypp/ResPool.h
zypp/base/Easy.h
zypp/pool/PoolTraits.h
zypp/solver/detail/Helper.cc

index 6e8102e..b3ddf65 100644 (file)
@@ -10,8 +10,8 @@
  *
 */
 #include <iostream>
-//#include "zypp/base/Logger.h"
 
+#include "zypp/base/Easy.h"
 #include "zypp/NameKindProxy.h"
 
 using std::endl;
@@ -52,21 +52,30 @@ namespace zypp
   //   METHOD NAME : NameKindProxy::NameKindProxy
   //   METHOD TYPE : Ctor
   //
-  NameKindProxy::NameKindProxy( ResPool pool_r, const std::string & name_r, Resolvable::Kind kind_r )
+  NameKindProxy::NameKindProxy( ResPool pool_r, const C_Str & name_r, Resolvable::Kind kind_r )
     : _kind( kind_r )
     , _name( name_r )
     {
-      for ( ResPool::byName_iterator it = pool_r.byNameBegin( _name );
-            it != pool_r.byNameEnd( _name ); ++it )
-        {
-          if ( (*it)->kind() == _kind )
-            {
-              if ( it->status().isInstalled() )
-                _installed.insert( *it ) ;
-              else
-                _available.insert( *it );
-            }
-        }
+      for_( it, pool_r.byIdentBegin( kind_r, _name ), pool_r.byIdentEnd( kind_r, _name ) )
+      {
+        if ( it->status().isInstalled() )
+          _installed.insert( *it ) ;
+        else
+          _available.insert( *it );
+      }
+    }
+
+   NameKindProxy::NameKindProxy( ResPool pool_r, IdString name_r, Resolvable::Kind kind_r )
+    : _kind( kind_r )
+    , _name( name_r )
+    {
+      for_( it, pool_r.byIdentBegin( kind_r, _name ), pool_r.byIdentEnd( kind_r, _name ) )
+      {
+        if ( it->status().isInstalled() )
+          _installed.insert( *it ) ;
+        else
+          _available.insert( *it );
+      }
     }
 
   /******************************************************************
index 76ab935..cd77a62 100644 (file)
@@ -100,14 +100,14 @@ namespace zypp
     typedef AvailableSet::size_type      Available_size_type;
 
   public:
-    NameKindProxy( ResPool pool_r,
-                   const std::string & name_r, Resolvable::Kind kind_r );
+    NameKindProxy( ResPool pool_r, IdString name_r, ResKind kind_r );
+    NameKindProxy( ResPool pool_r, const C_Str & name_r, ResKind kind_r );
 
   public:
-    ResObject::Kind kind() const
+    ResKind kind() const
     { return _kind; }
 
-    const std::string & name() const
+    IdString name() const
     { return _name; }
 
   public:
@@ -141,10 +141,10 @@ namespace zypp
     // status query and manip stuff...
 
   private:
-    ResObject::Kind _kind;
-    std::string     _name;
-    InstalledSet    _installed;
-    AvailableSet    _available;
+    ResKind      _kind;
+    IdString     _name;
+    InstalledSet _installed;
+    AvailableSet _available;
   };
   ///////////////////////////////////////////////////////////////////
 
@@ -153,7 +153,10 @@ namespace zypp
 
   /** \relates NameKindProxy Convenience construction. */
   template<class _Res>
-    inline NameKindProxy nameKindProxy( ResPool pool_r, const std::string & name_r )
+    inline NameKindProxy nameKindProxy( ResPool pool_r, IdString name_r )
+    { return NameKindProxy( pool_r, name_r, ResTraits<_Res>::kind ); }
+  template<class _Res>
+    inline NameKindProxy nameKindProxy( ResPool pool_r, const C_Str & name_r )
     { return NameKindProxy( pool_r, name_r, ResTraits<_Res>::kind ); }
 
   /////////////////////////////////////////////////////////////////
index d161b30..cd15b93 100644 (file)
@@ -108,8 +108,8 @@ namespace zypp
   */
   std::ostream & operator<<( std::ostream & str, const ResPool & obj )
   {
-    dumpPoolStats( str << "ResPool " << sat::Pool::instance() << endl << "  ",
-                            obj.begin(), obj.end() );
+    return dumpPoolStats( str << "ResPool " << sat::Pool::instance() << endl << "  ",
+                          obj.begin(), obj.end() );
   }
 
   /////////////////////////////////////////////////////////////////
index af1f997..7ef97c8 100644 (file)
@@ -128,6 +128,13 @@ namespace zypp
       byIdent_iterator byIdentBegin( const C_Str & name_r ) const
       { return make_filter_begin( ByIdent(ResTraits<_Res>::kind,name_r), *this ); }
 
+      /** Derive name and kind from \ref PoolItem. */
+      byIdent_iterator byIdentBegin( const PoolItem & pi_r ) const
+      { return make_filter_begin( ByIdent(pi_r.satSolvable()), *this ); }
+      /** Derive name and kind from \ref sat::Solvable. */
+      byIdent_iterator byIdentBegin( sat::Solvable slv_r ) const
+      { return make_filter_begin( ByIdent(slv_r), *this ); }
+
 
       byIdent_iterator byIdentEnd( ResKind kind_r, IdString name_r ) const
       { return make_filter_end( ByIdent(kind_r,name_r), *this ); }
@@ -142,7 +149,14 @@ namespace zypp
       template<class _Res>
       byIdent_iterator byIdentEnd( const C_Str & name_r ) const
       { return make_filter_end( ByIdent(ResTraits<_Res>::kind,name_r), *this ); }
-      //@}
+
+      /** Derive name and kind from \ref PoolItem. */
+      byIdent_iterator byIdentEnd( const PoolItem & pi_r ) const
+      { return make_filter_begin( ByIdent(pi_r.satSolvable()), *this ); }
+      /** Derive name and kind from \ref sat::Solvable. */
+      byIdent_iterator byIdentEnd( sat::Solvable slv_r ) const
+      { return make_filter_begin( ByIdent(slv_r), *this ); }
+     //@}
 
     public:
       /** \name Iterate through all ResObjects of a certain kind. */
@@ -166,15 +180,17 @@ namespace zypp
       //@}
 
     public:
-      /** \name Iterate through all ResObjects with a certain name (all kinds). */
+      /** \name Iterate through all ResObjects with a certain name (all kinds).
+       * \deprecated Instead of iterating byName and filter byKind use ByIdent iterator.
+      */
       //@{
       typedef zypp::resfilter::ByName ByName;
       typedef filter_iterator<ByName,const_iterator> byName_iterator;
 
-      byName_iterator byNameBegin( const std::string & name_r ) const
+      byName_iterator ZYPP_DEPRECATED byNameBegin( const std::string & name_r ) const
       { return make_filter_begin( ByName(name_r), *this ); }
 
-      byName_iterator byNameEnd( const std::string & name_r ) const
+      byName_iterator ZYPP_DEPRECATED byNameEnd( const std::string & name_r ) const
       { return make_filter_end( ByName(name_r), *this ); }
       //@}
 
index 7359989..7f37a20 100644 (file)
@@ -21,7 +21,7 @@
  *  }
  * \endcode
 */
-#define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG; IT != END; ++IT )
+#define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG, _ZZ = END; IT != _ZZ; ++IT )
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
index e5aa31a..d3cbc9c 100644 (file)
@@ -44,6 +44,10 @@ namespace zypp
     class ByIdent //: public ResObjectFilterFunctor
     {
       public:
+        ByIdent( sat::Solvable slv_r )
+        : _id( makeIdent( slv_r ) )
+        {}
+
         ByIdent( ResKind kind_r, IdString name_r )
         : _id( makeIdent( kind_r, name_r ) )
         {}
@@ -66,6 +70,12 @@ namespace zypp
         { 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 )
index dee2449..f43f951 100644 (file)
@@ -77,10 +77,9 @@ Helper::findInstalledByNameAndKind (const ResPool & pool, const string & name, c
 {
     LookFor info;
 
-    invokeOnEach( pool.byNameBegin( name ),
-                 pool.byNameEnd( name ),
-                 functor::chain (resfilter::ByInstalled (),                    // ByInstalled
-                                 resfilter::ByKind( kind ) ),                  // equal kind
+    invokeOnEach( pool.byIdentBegin( kind, name ),
+                 pool.byIdentEnd( kind, name ),
+                 resfilter::ByInstalled (),                                    // ByInstalled
                  functor::functorRef<bool,PoolItem> (info) );
 
     _XDEBUG("Helper::findInstalledByNameAndKind (" << name << ", " << kind << ") => " << info.item);
@@ -95,10 +94,9 @@ Helper::findUninstalledByNameAndKind (const ResPool & pool, const string & name,
 {
     LookFor info;
 
-    invokeOnEach( pool.byNameBegin( name ),
-                 pool.byNameEnd( name ),
-                 functor::chain (resfilter::ByUninstalled (),                  // ByUninstalled
-                                 resfilter::ByKind( kind ) ),                  // equal kind
+    invokeOnEach( pool.byIdentBegin( kind, name ),
+                 pool.byIdentEnd( kind, name ),
+                 resfilter::ByUninstalled(),                                   // ByUninstalled
                  functor::functorRef<bool,PoolItem> (info) );
 
     _XDEBUG("Helper::findUninstalledByNameAndKind (" << name << ", " << kind << ") => " << info.item);
@@ -142,13 +140,13 @@ class LookForUpdate : public resfilter::PoolItemFilterFunctor
             return true;
           }
         }
-        
+
        if ((!uninstalled                                                       // none yet
            || (uninstalled->edition().compare( provider->edition() ) < 0)      // or a better edition
            || (uninstalled->arch().compare( provider->arch() ) < 0) ) // or a better architecture
            && !provider.status().isLocked() )                                  // is not locked
        {
-           uninstalled = provider;                                             // store 
+           uninstalled = provider;                                             // store
        }
        return true;
     }
@@ -164,10 +162,9 @@ Helper::findUpdateItem (const ResPool & pool, PoolItem item)
     LookForUpdate info;
     info.installed = item;
 
-    invokeOnEach( pool.byNameBegin( item->name() ),
-                 pool.byNameEnd( item->name() ),
-                 functor::chain (functor::chain (resfilter::ByUninstalled (),                  // ByUninstalled
-                                                 resfilter::ByKind( item->kind() ) ),          // equal kind
+    invokeOnEach( pool.byIdentBegin( item ),
+                 pool.byIdentEnd( item ),
+                 functor::chain (resfilter::ByUninstalled (),                                          // ByUninstalled
                                  resfilter::byEdition<CompareByGT<Edition> >( item->edition() )),      // only look at better editions
                  functor::functorRef<bool,PoolItem> (info) );
 
@@ -200,10 +197,9 @@ Helper::findReinstallItem (const ResPool & pool, PoolItem item)
 {
     LookForReinstall info;
 
-    invokeOnEach( pool.byNameBegin( item->name() ),
-                 pool.byNameEnd( item->name() ),
-                 functor::chain (functor::chain (resfilter::ByUninstalled (),                  // ByUninstalled
-                                                 resfilter::ByKind( item->kind() ) ),          // equal kind
+    invokeOnEach( pool.byIdentBegin( item ),
+                 pool.byIdentEnd( item ),
+                 functor::chain (resfilter::ByUninstalled (),                                          // ByUninstalled
                                  resfilter::byEdition<CompareByEQ<Edition> >( item->edition() )),
                  functor::functorRef<bool,PoolItem> (info) );
 
@@ -249,10 +245,9 @@ Helper::isBestUninstalledItem (const ResPool & pool, PoolItem item)
 {
     CheckIfBest info( item );
 
-    invokeOnEach( pool.byNameBegin( item->name() ),
-                 pool.byNameEnd( item->name() ),
-                 functor::chain( resfilter::ByUninstalled(),                   // ByUninstalled
-                                 resfilter::ByKind( item->kind() ) ),          // equal kind
+    invokeOnEach( pool.byIdentBegin( item ),
+                 pool.byIdentEnd( item ),
+                 resfilter::ByUninstalled(),                   // ByUninstalled
                  functor::functorRef<bool,PoolItem>( info ) );
 
     _XDEBUG("Helper::isBestUninstalledItem(" << item << ") => " << info.is_best);