a metric ton of changes
[ardour.git] / libs / ardour / ardour / state_manager.h
1 #ifndef __ardour_state_manager_h__
2 #define __ardour_state_manager_h__
3
4 #include <list>
5 #include <string>
6 #include <vector>
7
8 #include <sigc++/signal.h>
9
10 #include <ardour/ardour.h>
11
12 namespace ARDOUR {
13
14 typedef uint32_t state_id_t;
15
16
17 class StateManager : public sigc::trackable
18 {
19   public:
20         struct State {
21             std::string operation;
22             State (std::string why) : operation (why) {}
23             virtual ~State() {}
24         };
25
26         typedef std::list<State*> StateMap;
27
28         StateManager ();
29         virtual ~StateManager ();
30         
31         virtual void drop_all_states ();
32         virtual void use_state (state_id_t);
33         virtual void save_state (std::string why);
34
35         sigc::signal<void,Change> StateChanged;
36
37         state_id_t _current_state_id;
38
39         static void set_allow_save (bool);
40         static bool allow_save ();
41
42   protected:
43         static bool _allow_save;
44         typedef std::pair<StateManager*,std::string> DeferredSave;
45         static std::vector<DeferredSave> deferred;
46
47         StateMap   states;
48
49         virtual Change   restore_state (State&) = 0;
50         virtual State* state_factory (std::string why) const = 0;
51         virtual void   send_state_changed (Change);
52 };
53
54 } // namespace ARDOUR
55
56 #endif /* __ardour_state_manager_h__ */