ProvideProcess pulled out to header for use elsewhere
authorJan Kupec <jkupec@suse.cz>
Mon, 23 Oct 2006 13:17:16 +0000 (13:17 +0000)
committerJan Kupec <jkupec@suse.cz>
Mon, 23 Oct 2006 13:17:16 +0000 (13:17 +0000)
tools/zmart/zmart-misc.cc
tools/zmart/zmart-misc.h

index d8f4c6f..ff57c87 100644 (file)
@@ -78,63 +78,49 @@ ResObject::Kind string_to_kind (const string &skind)
 }
 
 // copied from yast2-pkg-bindings:PkgModuleFunctions::DoProvideNameKind
-struct ProvideProcess
+bool ProvideProcess::operator()( const PoolItem& provider )
 {
-  PoolItem_Ref item;
-  ResStatus::TransactByValue whoWantsIt;
-  string version;
-  Arch _architecture;
-
-  ProvideProcess( Arch arch, const string &vers)
-    : whoWantsIt(zypp::ResStatus::USER)
-    , version(vers)
-    , _architecture( arch )
-    { }
-
-  bool operator()( const PoolItem& provider )
-  {
-    cerr_vv << "Considering " << provider << endl;
-    // 1. compatible arch
-    // 2. best arch
-    // 3. best edition
-       
-    // check the version if it's specified
-    if (!version.empty() && version != provider->edition().asString()) {
-      cerr_vv << format ("Skipping version %s (requested: %s)")
-       % provider->edition().asString() % version << endl;
-      return true;
-    }
-
-    if (!provider.status().isInstalled()) {
-      // deselect the item if it's already selected,
-      // only one item should be selected
-      if (provider.status().isToBeInstalled()) {
-       cerr_vv << "  Deselecting" << endl;
-       provider.status().resetTransact(whoWantsIt);
-      }
+  cerr_vv << "Considering " << provider << endl;
+  // 1. compatible arch
+  // 2. best arch
+  // 3. best edition
+
+  // check the version if it's specified
+  if (!version.empty() && version != provider->edition().asString()) {
+    cerr_vv << format ("Skipping version %s (requested: %s)")
+      % provider->edition().asString() % version << endl;
+    return true;
+  }
 
-      // regarding items which are installable only
-      if (!provider->arch().compatibleWith( _architecture )) {
-       cerr_vv << format ("provider %s has incompatible arch '%s'")
-         % provider->name() % provider->arch().asString() << endl;
-      }
-      else if (!item) {
-       cerr_vv << "  First match" << endl;
-       item = provider;
-      }
-      else if (item->arch().compare( provider->arch() ) < 0) {
-       cerr_vv << "  Better arch" << endl;
-       item = provider;
-      }
-      else if (item->edition().compare( provider->edition() ) < 0) {
-       cerr_vv << "  Better edition" << endl;
-       item = provider;
-      }
+  if (!provider.status().isInstalled()) {
+    // deselect the item if it's already selected,
+    // only one item should be selected
+    if (provider.status().isToBeInstalled()) {
+      cerr_vv << "  Deselecting" << endl;
+      provider.status().resetTransact(whoWantsIt);
     }
 
-    return true;
+    // regarding items which are installable only
+    if (!provider->arch().compatibleWith( _architecture )) {
+      cerr_vv << format ("provider %s has incompatible arch '%s'")
+        % provider->name() % provider->arch().asString() << endl;
+    }
+    else if (!item) {
+      cerr_vv << "  First match" << endl;
+      item = provider;
+    }
+    else if (item->arch().compare( provider->arch() ) < 0) {
+      cerr_vv << "  Better arch" << endl;
+      item = provider;
+    }
+    else if (item->edition().compare( provider->edition() ) < 0) {
+      cerr_vv << "  Better edition" << endl;
+      item = provider;
+    }
   }
-};
+
+  return true;
+}
 
 
 // this does only resolvables with this _name_.
index 775feeb..5d571eb 100644 (file)
@@ -39,6 +39,24 @@ void mark_updates( const zypp::ResObject::Kind &kind );
 void usage(int argc, char **argv);
 void solve_and_commit ();
 
+// copied from yast2-pkg-bindings:PkgModuleFunctions::DoProvideNameKind
+struct ProvideProcess
+{
+  zypp::PoolItem_Ref item;
+  zypp::ResStatus::TransactByValue whoWantsIt;
+  std::string version;
+  zypp::Arch _architecture;
+
+  ProvideProcess(zypp::Arch arch, const std::string &vers)
+    : whoWantsIt(zypp::ResStatus::USER)
+    , version(vers)
+    , _architecture( arch )
+    { }
+
+  bool operator()( const zypp::PoolItem& provider );
+};
+
+
 /**
  * Functor for filling search output table. 
  */
@@ -50,7 +68,7 @@ struct FillTable
     *_table << header; 
   }
 
-  void operator()(const zypp::PoolItem & pool_item) {
+  void operator()(const zypp::PoolItem & pool_item) const {
     TableRow row;
     row << (pool_item.status().isInstalled() ? "i" : "")
         << pool_item.resolvable()->source().alias()