2 Copyright (C) 2006 Hans Fugal & Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 $Id: /local/undo/libs/pbd3/pbd/undo.h 132 2006-06-29T18:45:16.609763Z fugalh $
21 #ifndef __lib_pbd_memento_command_h__
22 #define __lib_pbd_memento_command_h__
24 #include <pbd/command.h>
25 #include <sigc++/slot.h>
27 #define MEMENTO_COMMAND(obj_T, mem_T, obj, meth) \
28 (MementoCommand<(obj_T),(mem_T)>((obj),sigc::mem_fun((obj),&(meth)),#meth))
30 #define MEMENTO_COMMAND_1(obj_T, mem_T, obj, meth, arg1) \
31 (MementoCommand<(obj_T),(mem_T)>((obj),\
32 sigc::bind(sigc::mem_fun((obj),\
36 #define MEMENTO_COMMAND_2(obj_T, mem_T, obj, meth, arg1, arg2) \
37 (MementoCommand<(obj_T),(mem_T)>((obj),\
38 sigc::bind(sigc::mem_fun((obj),\
42 #define MEMENTO_COMMAND_3(obj_T, mem_T, obj, meth, arg1, arg2, arg3) \
43 (MementoCommand<(obj_T),(mem_T)>((obj),\
44 sigc::bind(sigc::mem_fun((obj),\
46 arg1, arg2, arg3),#meth))
49 template <class obj_T, class mem_T>
50 class MementoCommand : public Command
53 MementoCommand(obj_T obj,
54 sigc::slot<void> action,
56 std::list<Serializable *> args
58 : obj(obj), action(action), key(key), args(args), memento(obj.get_memento()) {}
59 MementoCommand(obj_T obj,
60 sigc::slot<void> action,
62 Serializable *arg1 = 0,
63 Serializable *arg2 = 0,
64 Serializable *arg3 = 0
66 : obj(obj), action(action), key(key), memento(obj.get_memento())
80 void operator() () { action(); }
81 void undo() { obj.set_memento(memento); }
82 virtual XMLNode &serialize()
91 sigc::slot<void> action;
93 std::list<Serializable*> args;
96 #endif // __lib_pbd_memento_h__