dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / scd / fsm / scd_cont_fsm.h
diff --git a/dol/src/dol/visitor/hdsd/scd/fsm/scd_cont_fsm.h b/dol/src/dol/visitor/hdsd/scd/fsm/scd_cont_fsm.h
new file mode 100644 (file)
index 0000000..f5d2eb4
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef SCD_CONT_FSM_H
+#define SCD_CONT_FSM_H
+
+#include <string>
+
+/* forward declaration */
+class scd_cont_state;
+
+
+/**
+ * FSM base class. Holds the current and the history state and allows
+ * state transitions. Transitions are logged in debug loglevel.
+ */
+class scd_cont_fsm
+{
+
+public:
+    /**
+     * Constructor.
+     * \param name the name of the state machine
+     */
+    scd_cont_fsm(const std::string& name): _name(name) {}
+
+    virtual ~scd_cont_fsm() {}
+
+    /**
+     * Sets a new state. This is a state transition.
+     */
+    void set_state(scd_cont_state& state);
+
+    /**
+     * Saves the current state as the history state. This is not a state
+     * transition.
+     */
+    void save_state();
+
+    /**
+     * Saves a specified state as the history state. This is not a state
+     * transition.
+     */
+    void save_state(scd_cont_state& state);
+
+    /**
+     * Restores the saved history state. This is a state transition.
+     */
+    void load_state();
+
+protected:
+    scd_cont_state* _state;
+    scd_cont_state* _hist_state;
+    std::string _name;
+};
+
+#endif