From fd742b30fa1071c44d053cf4676149641f977a35 Mon Sep 17 00:00:00 2001 From: Hans Fugal Date: Thu, 22 Jun 2006 23:38:19 +0000 Subject: [PATCH] r111@gandalf: fugalh | 2006-06-22 17:38:14 -0600 progress on UndoCommand constructors git-svn-id: svn://localhost/ardour2/branches/undo@637 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/pbd3/pbd/undo_command.h | 55 ++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/libs/pbd3/pbd/undo_command.h b/libs/pbd3/pbd/undo_command.h index 2f45e2799a..26550650be 100644 --- a/libs/pbd3/pbd/undo_command.h +++ b/libs/pbd3/pbd/undo_command.h @@ -21,13 +21,23 @@ #ifndef __lib_pbd_undo_command_h__ #define __lib_pbd_undo_command_h__ +#include +#include +#include +#include #include using sigc::nil; using sigc::slot; +using sigc::bind; +using sigc::mem_fun; using std::list; using std::string; + +/* One of the joys of templates is that you have to do everything right here + * in the header file; you can't split this to make undo_command.cc */ + template class UndoCommand { @@ -38,40 +48,55 @@ class UndoCommand * UndoCommand cmd(id, key, foo_instance); */ UndoCommand(id_t object_id, string key) - : _obj_id(object_id), _key(key) {} - UndoCommand(id_t object_id, string key, T1 arg1) + : _obj_id(object_id), _key(key) + { + _slot = mem_fun( get_object(object_id), get_method(key) ); + } + UndoCommand(id_t object_id, string key, T1 &arg1) : _obj_id(object_id), _key(key) { - _args.push_back(arg1); + _slot = bind( mem_fun( get_object(object_id), get_method(key) ), + arg1); + _args.push_back(&arg1); } - UndoCommand(id_t object_id, string key, T1 arg1, T2 arg2) + UndoCommand(id_t object_id, string key, T1 &arg1, T2 &arg2) : _obj_id(object_id), _key(key) { - _args.push_back(arg1); - _args.push_back(arg2); + _slot = bind( mem_fun( get_object(object_id), get_method(key) ), + arg1, arg2); + _args.push_back(&arg1); + _args.push_back(&arg2); } - UndoCommand(id_t object_id, string key, T1 arg1, T2 arg2, T3 arg3) + UndoCommand(id_t object_id, string key, T1 &arg1, T2 &arg2, T3 &arg3) : _obj_id(object_id), _key(key) { - _args.push_back(arg1); - _args.push_back(arg2); - _args.push_back(arg3); + _slot = bind( mem_fun( get_object(object_id), get_method(key) ), + arg1, arg2, arg3); + _args.push_back(&arg1); + _args.push_back(&arg2); + _args.push_back(&arg3); } - UndoCommand(id_t object_id, string key, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + UndoCommand(id_t object_id, string key, T1 &arg1, T2 &arg2, T3 &arg3, T4 &arg4) : _obj_id(object_id), _key(key) { - _args.push_back(arg1); - _args.push_back(arg2); - _args.push_back(arg3); - _args.push_back(arg4); + _slot = bind( mem_fun( get_object(object_id), get_method(key) ), + arg1, arg2, arg4); + _args.push_back(&arg1); + _args.push_back(&arg2); + _args.push_back(&arg3); + _args.push_back(&arg4); } void operator() () { return _slot(); } + XMLNode &serialize(); protected: + template T_object &get_object(id_t); + template T_method &get_method(string); id_t _obj_id; string _key; slot _slot; + // Note that arguments must be instances of Serializable or this will // rightly cause a compiler error when compiling the constructor. list _args; -- 2.30.2