+void Application::PushState(State *s) {
+ states.emplace(s);
+}
+
+State *Application::PopState() {
+ State *s = states.top();
+ states.pop();
+ return s;
+}
+
+State *Application::SwitchState(State *s_new) {
+ State *s_old = states.top();
+ states.top() = s_new;
+ return s_old;
+}
+
+State &Application::GetState() {
+ return *states.top();
+}
+
+bool Application::HasState() const noexcept {
+ return !states.empty();
+}
+
+
+void StateControl::Commit(Application &app) {
+ while (!cue.empty()) {
+ Memo m(cue.front());
+ cue.pop();
+ switch (m.cmd) {
+ case PUSH:
+ app.PushState(m.state);
+ break;
+ case SWITCH:
+ app.SwitchState(m.state);
+ break;
+ case POP:
+ app.PopState();
+ break;
+ case POP_ALL:
+ while (app.HasState()) {
+ app.PopState();
+ }
+ break;
+ }
+ }