]> git.localhorst.tv Git - blank.git/blob - src/app/StateControl.hpp
basic message state
[blank.git] / src / app / StateControl.hpp
1 #ifndef BLANK_APP_STATECONTROL_HPP_
2 #define BLANK_APP_STATECONTROL_HPP_
3
4 #include <queue>
5
6
7 namespace blank {
8
9 class HeadlessApplication;
10 class State;
11
12 class StateControl {
13
14 public:
15         // add state to the front
16         void Push(State *s) {
17                 cue.emplace(PUSH, s);
18         }
19
20         // swap state at the front
21         void Switch(State *s) {
22                 cue.emplace(SWITCH, s);
23         }
24
25         // remove state at the front
26         void Pop() {
27                 cue.emplace(POP);
28         }
29
30         // remove all states
31         // application will exit if nothing is pushed after this
32         void PopAll() {
33                 cue.emplace(POP_ALL);
34         }
35
36         // pop states until this one is on top
37         void PopAfter(State *s) {
38                 cue.emplace(POP_AFTER, s);
39         }
40
41         // pop states until this one is removed
42         void PopUntil(State *s) {
43                 cue.emplace(POP_UNTIL, s);
44         }
45
46
47         void Commit(HeadlessApplication &);
48
49 private:
50         enum Command {
51                 PUSH,
52                 SWITCH,
53                 POP,
54                 POP_ALL,
55                 POP_AFTER,
56                 POP_UNTIL,
57         };
58         struct Memo {
59                 State *state;
60                 Command cmd;
61                 explicit Memo(Command c, State *s = nullptr): state(s), cmd(c) { }
62         };
63         std::queue<Memo> cue;
64
65 };
66
67 }
68
69 #endif