From ab1b29bcb265404a3a31cd888c768b910c79fd77 Mon Sep 17 00:00:00 2001 From: Hans Fugal Date: Thu, 6 Jul 2006 18:25:58 +0000 Subject: [PATCH] r162@gandalf: fugalh | 2006-06-30 19:30:58 -0600 some macros for MementoCommand() git-svn-id: svn://localhost/ardour2/branches/undo@666 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/pbd3/pbd/memento_command.h | 44 ++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/libs/pbd3/pbd/memento_command.h b/libs/pbd3/pbd/memento_command.h index 6ecacf6d67..4b541a2327 100644 --- a/libs/pbd3/pbd/memento_command.h +++ b/libs/pbd3/pbd/memento_command.h @@ -24,7 +24,28 @@ #include #include -// TODO: make a macro to make constructing this even easier +#define MEMENTO_COMMAND(obj_T, mem_T, obj, meth) \ + (MementoCommand<(obj_T),(mem_T)>((obj),sigc::mem_fun((obj),&(meth)),#meth)) + +#define MEMENTO_COMMAND_1(obj_T, mem_T, obj, meth, arg1) \ + (MementoCommand<(obj_T),(mem_T)>((obj),\ + sigc::bind(sigc::mem_fun((obj),\ + &(meth)),\ + arg1),#meth)) + +#define MEMENTO_COMMAND_2(obj_T, mem_T, obj, meth, arg1, arg2) \ + (MementoCommand<(obj_T),(mem_T)>((obj),\ + sigc::bind(sigc::mem_fun((obj),\ + &(meth)),\ + arg1, arg2),#meth)) + +#define MEMENTO_COMMAND_3(obj_T, mem_T, obj, meth, arg1, arg2, arg3) \ + (MementoCommand<(obj_T),(mem_T)>((obj),\ + sigc::bind(sigc::mem_fun((obj),\ + &(meth)),\ + arg1, arg2, arg3),#meth)) + + template class MementoCommand : public Command { @@ -35,6 +56,27 @@ class MementoCommand : public Command std::list args ) : obj(obj), action(action), key(key), args(args), memento(obj.get_memento()) {} + MementoCommand(obj_T obj, + sigc::slot action, + std::string key + Serializable *arg1 = 0, + Serializable *arg2 = 0, + Serializable *arg3 = 0 + ) + : obj(obj), action(action), key(key), memento(obj.get_memento()) + { + if (arg1 == 0) + return; + args.push_back(arg1); + + if (arg2 == 0) + return; + args.push_back(arg2); + + if (arg3 == 0) + return; + args.push_back(arg3); + } void operator() () { action(); } void undo() { obj.set_memento(memento); } virtual XMLNode &serialize() -- 2.30.2