[Aptitude-svn-commit] r4214 - in branches/aptitude-0.3/aptitude: . src/generic/problemresolver

Daniel Burrows dburrows at costa.debian.org
Sat Sep 24 04:10:39 UTC 2005


Author: dburrows
Date: Sat Sep 24 04:10:35 2005
New Revision: 4214

Added:
   branches/aptitude-0.3/aptitude/src/generic/problemresolver/resolver_undo.h
Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h
Log:
Preliminary resolver undo support in the backend.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Sat Sep 24 04:10:35 2005
@@ -1,5 +1,12 @@
 2005-09-23  Daniel Burrows  <dburrows at debian.org>
 
+	* src/generic/problemresolver/problemresolver.h, src/generic/problemresolver/resolver_undo.h:
+
+	  Add support in the resolver for recording the inverse of
+	  operations performed on it.  (could be done at a higher level,
+	  but for obvious reasons, the resolver is uniquely positioned to
+	  know exactly how to reverse its actions)
+
 	* src/vscreen/vs_menu.cc, src/vscreen/vs_menu.h:
 
 	  Allow the user to scroll the menu up and down on small

Modified: branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h	Sat Sep 24 04:10:35 2005
@@ -52,6 +52,7 @@
 #include "dump_universe.h"
 #include "exceptions.h"
 #include "solution.h"
+#include "resolver_undo.h"
 
 #include "../dense_setset.h"
 #include "../threads.h"
@@ -2062,33 +2063,63 @@
 
   /** Reject future solutions containing this version.
    */
-  void reject_version(const version &ver)
+  void reject_version(const version &ver, undo_group *undo = NULL)
   {
-    user_rejected.insert(ver);
-    unmandate_version(ver);
+    std::pair<std::set<version>, bool>
+      insert_result = user_rejected.insert(ver);
+
+    if(insert_result.second)
+      {
+	if(undo != NULL)
+	  undo->add_item(new undo_resolver_manipulation<PackageUniverse, version>(this, ver, &generic_resolver<PackageUniverse>::unreject_version));
+
+	unmandate_version(ver, undo);
+      }
   }
 
   /** Cancel any rejection of ver, allowing the resolver to once
    *  again generate solutions containing it.
    */
-  void unreject_version(const version &ver)
+  void unreject_version(const version &ver, undo_group *undo = NULL)
   {
-    user_rejected.erase(ver);
+    typename std::set<version>::size_type
+      erased_count = user_rejected.erase(ver);
+
+    if(erased_count > 0)
+      {
+	if(undo != NULL)
+	  undo->add_item(new undo_resolver_manipulation<PackageUniverse, version>(this, ver, &generic_resolver<PackageUniverse>::reject_version));
 
-    deferred_dirty = true;
+	deferred_dirty = true;
+      }
   }
 
-  void mandate_version(const version &ver)
+  void mandate_version(const version &ver, undo_group *undo = NULL)
   {
-    user_mandated.insert(ver);
-    unreject_version(ver);
+    std::pair<std::set<version>, bool>
+      insert_result = user_mandated.insert(ver);
+
+    if(insert_result.second)
+      {
+	if(undo != NULL)
+	  undo->add_item(new undo_resolver_manipulation<PackageUniverse, version>(this, ver, &generic_resolver<PackageUniverse>::unmandate_version));
+
+	unreject_version(ver, undo);
+      }
   }
 
-  void unmandate_version(const version &ver)
+  void unmandate_version(const version &ver, undo_group *undo = NULL)
   {
-    user_mandated.erase(ver);
+    typename std::set<version>::size_type
+      erased_count = user_mandated.erase(ver);
 
-    deferred_dirty = true;
+    if(erased_count > 0)
+      {
+	if(undo != NULL)
+	  undo->add_item(new undo_resolver_manipulation<PackageUniverse, version>(this, ver, &generic_resolver<PackageUniverse>::mandate_version));
+
+	deferred_dirty = true;
+      }
   }
 
   /** Query whether the given version is rejected. */
@@ -2110,20 +2141,35 @@
   }
 
   /** Harden the given dependency. */
-  void harden(const dep &d)
+  void harden(const dep &d, undo_group *undo = NULL)
   {
     assert(d.is_soft());
 
-    user_hardened.insert(d);
-    unforce_break(d);
+    std::pair<std::set<dep>, bool>
+      insert_result = user_hardened.insert(d);
+
+    if(insert_result.second)
+      {
+	if(undo != NULL)
+	  undo->add_item(new undo_resolver_manipulation<PackageUniverse, dep>(this, d, &generic_resolver<PackageUniverse>::unharden));
+
+	unforce_break(d, undo);
+      }
   }
 
   /** Un-harden (soften?) the given dependency. */
-  void unharden(const dep &d)
+  void unharden(const dep &d, const undo_group *undo = NULL)
   {
-    user_hardened.erase(d);
+    typename std::set<dep>::size_type
+      erased_count = user_hardened.erase(d);
 
-    deferred_dirty = true;
+    if(erased_count > 0)
+      {
+	if(undo != NULL)
+	  undo->add_item(new undo_resolver_manipulation<PackageUniverse, dep>(this, d, &generic_resolver<PackageUniverse>::harden));
+
+	deferred_dirty = true;
+      }
   }
 
   /** Query whether the given dependency is forced to be broken. */
@@ -2144,27 +2190,27 @@
    *
    *  \param d a soft dependency.
    */
-  void force_break(const dep &d)
+  void force_break(const dep &d, undo_group *undo = NULL)
   {
     assert(d.is_soft());
 
     for(typename dep::solver_iterator si = d.solvers_begin();
 	!si.end(); ++si)
-      reject_version(*si);
+      reject_version(*si, undo);
 
-    unharden(d);
+    unharden(d, undo);
   }
 
   /** The given soft dependency must be forced-broken; allow it to be
    *  resolved in any way.
    */
-  void unforce_break(const dep &d)
+  void unforce_break(const dep &d, undo_group *undo = NULL)
   {
     assert(d.is_soft());
 
     for(typename dep::solver_iterator si = d.solvers_begin();
 	!si.end(); ++si)
-      unreject_version(*si);
+      unreject_version(*si, undo);
   }
 
   /** Cancel any find_next_solution call that is executing in the

Added: branches/aptitude-0.3/aptitude/src/generic/problemresolver/resolver_undo.h
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/generic/problemresolver/resolver_undo.h	Sat Sep 24 04:10:35 2005
@@ -0,0 +1,56 @@
+// resolver_undo.h                            -*-c++-*-
+//
+//   Copyright (C) 2005 Daniel Burrows
+//
+//   This program is free software; you can redistribute it and/or
+//   modify it under the terms of the GNU General Public License as
+//   published by the Free Software Foundation; either version 2 of
+//   the License, or (at your option) any later version.
+//
+//   This program is distributed in the hope that it will be useful,
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//   General Public License for more details.
+//
+//   You should have received a copy of the GNU General Public License
+//   along with this program; see the file COPYING.  If not, write to
+//   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+//   Boston, MA 02111-1307, USA.
+//
+// Undo items related to the resolver.  (Q: these could be unified
+// into a single item based on slots or somesuch?)
+
+#ifndef RESOLVER_UNDO_H
+#define RESOLVER_UNDO_H
+
+#include "../undo.h"
+
+template<typename PackageUniverse>
+class generic_resolver;
+
+/** An undoable that executes the given action on the given object. */
+template<typename PackageUniverse, typename T>
+class undo_resolver_manipulation : public undoable
+{
+public:
+  typedef void (generic_resolver<PackageUniverse>::*undo_method)(const T &, undo_group *);
+
+  generic_resolver<PackageUniverse> *resolver;
+  T t;
+  undo_method reverse_action;
+
+public:
+  undo_resolver_manipulation(generic_resolver<PackageUniverse> *_resolver,
+			     const T &_t,
+			     undo_method _reverse_action)
+    : resolver(_resolver), t(_t), reverse_action(_reverse_action)
+  {
+  }
+
+  void undo()
+  {
+    (resolver->*reverse_action)(t, NULL);
+  }
+};
+
+#endif // RESOLVER_UNDO_H



More information about the Aptitude-svn-commit mailing list