2 Copyright (C) 2006 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __lib_pbd_memento_command_h__
22 #define __lib_pbd_memento_command_h__
26 #include "pbd/command.h"
27 #include "pbd/stacktrace.h"
28 #include "pbd/xml++.h"
29 #include "pbd/shiva.h"
31 #include <sigc++/slot.h>
34 /** This command class is initialized with before and after mementos
35 * (from Stateful::get_state()), so undo becomes restoring the before
36 * memento, and redo is restoring the after memento.
38 template <class obj_T>
39 class MementoCommand : public Command
42 MementoCommand(obj_T& a_object, XMLNode* a_before, XMLNode* a_after)
43 : obj(a_object), before(a_before), after(a_after)
45 /* catch destruction of the object */
46 new PBD::PairedShiva< obj_T,MementoCommand<obj_T> > (obj, *this);
50 GoingAway(); /* EMIT SIGNAL */
57 obj.set_state(*after);
63 obj.set_state(*before);
67 virtual XMLNode &get_state() {
69 if (before && after) {
70 name = "MementoCommand";
72 name = "MementoUndoCommand";
74 name = "MementoRedoCommand";
77 XMLNode* node = new XMLNode(name);
79 node->add_property("obj_id", obj.id().to_s());
80 node->add_property("type_name", typeid(obj).name());
83 node->add_child_copy(*before);
87 node->add_child_copy(*after);
99 #endif // __lib_pbd_memento_h__