]> git.localhorst.tv Git - blank.git/blobdiff - src/app/StateControl.hpp
state management and control
[blank.git] / src / app / StateControl.hpp
diff --git a/src/app/StateControl.hpp b/src/app/StateControl.hpp
new file mode 100644 (file)
index 0000000..818bce5
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef BLANK_APP_STATECONTROL_HPP_
+#define BLANK_APP_STATECONTROL_HPP_
+
+#include <queue>
+
+
+namespace blank {
+
+class Application;
+class State;
+
+class StateControl {
+
+public:
+       void Push(State *s) {
+               cue.emplace(PUSH, s);
+       }
+
+       void Switch(State *s) {
+               cue.emplace(SWITCH, s);
+       }
+
+       void Pop() {
+               cue.emplace(POP);
+       }
+
+       void PopAll() {
+               cue.emplace(POP_ALL);
+       }
+
+
+       void Commit(Application &);
+
+private:
+       enum Command {
+               PUSH,
+               SWITCH,
+               POP,
+               POP_ALL,
+       };
+       struct Memo {
+               State *state;
+               Command cmd;
+               explicit Memo(Command c, State *s = nullptr): state(s), cmd(c) { }
+       };
+       std::queue<Memo> cue;
+
+};
+
+}
+
+#endif