merge (w/fix) with master
[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 class LIBPBD_API Command : public PBD::StatefulDestructible, public PBD::ScopedConnectionList
32 {
33 public:
34         virtual ~Command() { /* NOTE: derived classes must call drop_references() */ }
35
36         virtual void operator() () = 0;
37         
38         void set_name (const std::string& str) { _name = str; }
39         const std::string& name() const { return _name; }
40
41         virtual void undo() = 0;
42         virtual void redo() { (*this)(); }
43         
44         virtual XMLNode &get_state();
45         virtual int set_state(const XMLNode&, int /*version*/) { /* noop */ return 0; }
46
47         virtual bool empty () const {
48                 return false;
49         }
50
51 protected:
52         Command() {}
53         Command(const std::string& name) : _name(name) {}
54
55         std::string _name;
56 };
57
58 #endif // __lib_pbd_command_h_