some strategic documentation
[ardour.git] / libs / pbd / pbd / command.h
1
2 /*
3     Copyright (C) 2006 Paul Davis
4     Author: Hans Fugal
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 */
21
22 #ifndef __lib_pbd_command_h__
23 #define __lib_pbd_command_h__
24
25 #include <string>
26
27 #include "pbd/libpbd_visibility.h"
28 #include "pbd/signals.h"
29 #include "pbd/statefuldestructible.h"
30
31 /** Base class for Undo/Redo commands and changesets */
32 class LIBPBD_API Command : public PBD::StatefulDestructible, public PBD::ScopedConnectionList
33 {
34 public:
35         virtual ~Command() { /* NOTE: derived classes must call drop_references() */ }
36
37         virtual void operator() () = 0;
38
39         void set_name (const std::string& str) { _name = str; }
40         const std::string& name() const { return _name; }
41
42         virtual void undo() = 0;
43         virtual void redo() { (*this)(); }
44
45         virtual XMLNode &get_state();
46         virtual int set_state(const XMLNode&, int /*version*/) { /* noop */ return 0; }
47
48         virtual bool empty () const {
49                 return false;
50         }
51
52 protected:
53         Command() {}
54         Command(const std::string& name) : _name(name) {}
55
56         std::string _name;
57 };
58
59 #endif // __lib_pbd_command_h_