isomorphous fix for UndoTransaction death as was previously applied for MementoComman...
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 17 Oct 2006 21:15:41 +0000 (21:15 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 17 Oct 2006 21:15:41 +0000 (21:15 +0000)
git-svn-id: svn://localhost/ardour2/trunk@989 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/pbd/pbd/undo.h
libs/pbd/undo.cc

index eecd8ae49d59d46495a2577c4681614e33cde1f0..943c115af2a1f9a6e913fe1833192ae9b76ae4d1 100644 (file)
@@ -40,8 +40,11 @@ class UndoTransaction : public Command
        ~UndoTransaction ();
 
        void clear ();
+       bool empty() const;
+       bool clearing () const { return _clearing; }
 
        void add_command (Command* const);
+       void remove_command (Command* const);
 
         void operator() ();
        void undo();
@@ -66,8 +69,7 @@ class UndoTransaction : public Command
        std::list<Command*>    actions;
        struct timeval        _timestamp;
        std::string           _name;
-       bool                   clearing;
-       void remove_command (Command* const);
+       bool                  _clearing;
 };
 
 class UndoHistory
@@ -94,7 +96,7 @@ class UndoHistory
         void save_state();
 
   private:
-       bool clearing;
+       bool _clearing;
        std::list<UndoTransaction*> UndoList;
        std::list<UndoTransaction*> RedoList;
 
index 717c355baecdaed551c06bf0b106a70d371edce0..af408a24a4a9eaf9ac5f2b507d2682e795aa4d03 100644 (file)
 using namespace std;
 using namespace sigc;
 
+/* grrr, strict C++ says that static member functions are not C functions, but we also want
+   to be able to pack this into a sigc::ptr_fun and not sigc::mem_fun, so we have to make
+   it a genuine function rather than a member.
+*/
+
+static void command_death (UndoTransaction* ut, Command* c)
+{
+       if (ut->clearing()) {
+               return;
+       }
+
+       ut->remove_command (c);
+
+       if (ut->empty()) {
+               delete ut;
+       }
+}
+
+
 UndoTransaction::UndoTransaction ()
 {
-       clearing = false;
+       _clearing = false;
 }
 
 UndoTransaction::UndoTransaction (const UndoTransaction& rhs)
 {
        _name = rhs._name;
-       clearing = false;
+       _clearing = false;
        clear ();
        actions.insert(actions.end(),rhs.actions.begin(),rhs.actions.end());
 }
@@ -62,31 +81,31 @@ UndoTransaction::operator= (const UndoTransaction& rhs)
 void
 UndoTransaction::add_command (Command *const action)
 {
-       action->GoingAway.connect (bind (mem_fun (*this, &UndoTransaction::remove_command), action));
+       action->GoingAway.connect (bind (sigc::ptr_fun (command_death), this, const_cast<Command*>(action)));
        actions.push_back (action);
 }
 
 void
 UndoTransaction::remove_command (Command* const action)
 {
-       if (clearing) {
-               return;
-       }
        actions.remove (action);
-       if (actions.empty()) {
-               delete this;
-       }
+}
+
+bool
+UndoTransaction::empty () const
+{
+       return actions.empty();
 }
 
 void
 UndoTransaction::clear ()
 {
-       clearing = true;
+       _clearing = true;
        for (list<Command*>::iterator i = actions.begin(); i != actions.end(); ++i) {
                delete *i;
        }
        actions.clear ();
-       clearing = false;
+       _clearing = false;
 }
 
 void
@@ -131,7 +150,7 @@ XMLNode &UndoTransaction::get_state()
 
 UndoHistory::UndoHistory ()
 {
-       clearing = false;
+       _clearing = false;
 }
 
 void
@@ -146,7 +165,7 @@ UndoHistory::add (UndoTransaction* const ut)
 void
 UndoHistory::remove (UndoTransaction* const ut)
 {
-       if (clearing) {
+       if (_clearing) {
                return;
        }
 
@@ -185,17 +204,17 @@ UndoHistory::redo (unsigned int n)
 void
 UndoHistory::clear_redo ()
 {
-       clearing = true;
+       _clearing = true;
        RedoList.clear ();
-       clearing = false;
+       _clearing = false;
 }
 
 void
 UndoHistory::clear_undo ()
 {
-       clearing = true;
+       _clearing = true;
        UndoList.clear ();
-       clearing = false;
+       _clearing = false;
 }
 
 void