r80@gandalf: fugalh | 2006-06-22 16:37:01 -0600
authorHans Fugal <hans@fugal.net>
Thu, 22 Jun 2006 22:37:08 +0000 (22:37 +0000)
committerHans Fugal <hans@fugal.net>
Thu, 22 Jun 2006 22:37:08 +0000 (22:37 +0000)
 reworked templatization of UndoCommand

git-svn-id: svn://localhost/ardour2/branches/undo@636 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/pbd3/pbd/serializable.h [new file with mode: 0644]
libs/pbd3/pbd/undo.h
libs/pbd3/pbd/undo_command.h [new file with mode: 0644]

diff --git a/libs/pbd3/pbd/serializable.h b/libs/pbd3/pbd/serializable.h
new file mode 100644 (file)
index 0000000..8032f00
--- /dev/null
@@ -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 <pbd/xml++.h>
+
+class Serializable 
+{
+public:
+    XMLNode &serialize();
+};
+
+#endif // __lib_pbd_serializable_h__
index 488e896706f081b451d0485bf87a161d7c6a1b46..d2ad6088cdc72b7c07e033c13c344028febb6b8f 100644 (file)
 #include <sigc++/slot.h>
 #include <sigc++/bind.h>
 #include <sys/time.h>
-#include <pbd/xml++.h>
+#include <pbd/undo_command.h>
 
 using std::string;
 using std::list;
 
 typedef sigc::slot<void> 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<void> _slot;
-};
-
-template <class T1=void, class T2=void, class T3=void, class T4=void>
-class SlotCommand;
-
-template <>
-class SlotCommand <> : public UndoCommand {};
-
-template <class T1>
-class SlotCommand <T1> : 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 (file)
index 0000000..2f45e27
--- /dev/null
@@ -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 <pbd/serializable.h>
+
+using sigc::nil;
+using sigc::slot;
+using std::list;
+using std::string;
+
+template <class T1=nil, class T2=nil, class T3=nil, class T4=nil>
+class UndoCommand
+{
+    public:
+       /* It only makes sense to use the constructor corresponding to the
+        * template given. e.g.
+        * 
+        *   UndoCommand<Foo> 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<void> _slot;
+       // Note that arguments must be instances of Serializable or this will
+       // rightly cause a compiler error when compiling the constructor.
+       list<Serializable*> _args;
+};
+
+#endif // __lib_pbd_undo_command_h__