From 4078b9ec645f4fc71dc3693c7ee70354183393d5 Mon Sep 17 00:00:00 2001 From: Hans Fugal Date: Thu, 22 Jun 2006 22:37:08 +0000 Subject: [PATCH] r80@gandalf: fugalh | 2006-06-22 16:37:01 -0600 reworked templatization of UndoCommand git-svn-id: svn://localhost/ardour2/branches/undo@636 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/pbd3/pbd/serializable.h | 32 +++++++++++++++ libs/pbd3/pbd/undo.h | 37 +---------------- libs/pbd3/pbd/undo_command.h | 80 ++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 36 deletions(-) create mode 100644 libs/pbd3/pbd/serializable.h create mode 100644 libs/pbd3/pbd/undo_command.h diff --git a/libs/pbd3/pbd/serializable.h b/libs/pbd3/pbd/serializable.h new file mode 100644 index 0000000000..8032f0038a --- /dev/null +++ b/libs/pbd3/pbd/serializable.h @@ -0,0 +1,32 @@ +/* + Copyright (C) 2006 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id: /local/undo/libs/pbd3/pbd/undo.h 59 2006-06-15T18:16:20.960977Z fugalh $ +*/ + +#ifndef __lib_pbd_serializable_h__ +#define __lib_pbd_serializable_h__ + +#include + +class Serializable +{ +public: + XMLNode &serialize(); +}; + +#endif // __lib_pbd_serializable_h__ diff --git a/libs/pbd3/pbd/undo.h b/libs/pbd3/pbd/undo.h index 488e896706..d2ad6088cd 100644 --- a/libs/pbd3/pbd/undo.h +++ b/libs/pbd3/pbd/undo.h @@ -27,48 +27,13 @@ #include #include #include -#include +#include using std::string; using std::list; typedef sigc::slot UndoAction; -// TODO stick this in its own file, and make the arguments multiply-inherit it -class Serializable -{ -public: - XMLNode &serialize(); -}; - -class UndoCommand -{ -public: - UndoCommand(id_t object_id, std::string method_name); - void operator() () { return _slot(); } - XMLNode &serialize(); -protected: - sigc::slot _slot; -}; - -template -class SlotCommand; - -template <> -class SlotCommand <> : public UndoCommand {}; - -template -class SlotCommand : public UndoCommand -{ - T1 _arg1; -public: - SlotCommand(id_t object_id, std::string key, T1 arg1) - : UndoCommand(object_id, key), _arg1(arg1) - { - _slot = sigc::bind(_slot, arg1); - } -}; - class UndoTransaction { public: diff --git a/libs/pbd3/pbd/undo_command.h b/libs/pbd3/pbd/undo_command.h new file mode 100644 index 0000000000..2f45e2799a --- /dev/null +++ b/libs/pbd3/pbd/undo_command.h @@ -0,0 +1,80 @@ +/* + Copyright (C) 2006 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id: /local/undo/libs/pbd3/pbd/undo.h 59 2006-06-15T18:16:20.960977Z fugalh $ +*/ + +#ifndef __lib_pbd_undo_command_h__ +#define __lib_pbd_undo_command_h__ + +#include + +using sigc::nil; +using sigc::slot; +using std::list; +using std::string; + +template +class UndoCommand +{ + public: + /* It only makes sense to use the constructor corresponding to the + * template given. e.g. + * + * 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) + { + _args.push_back(arg1); + } + 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); + } + 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); + } + 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); + } + + void operator() () { return _slot(); } + XMLNode &serialize(); + protected: + 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; +}; + +#endif // __lib_pbd_undo_command_h__