-
define the state
S
, inputI
and outputO
of the stateclass S { // ... }; class I { // ... }; class O { // ... };
-
inherit the state machine class based on
sm::SM<S, I, O>
and override the transition functiontf
and output functionof
and functiongoon
class StateMachine : public sm::SM<S, I, O> { virtual S tf(const I &i, const S &s) override { // ... } virtual O of(const I &i, const S &s) override { // ... } virtual bool goon(const S &s) override { // ... } };
-
create state machine instances in main function and run
int main() { auto sm = StateMachine([] { return I::MSG; }, [](const O &) { std::cout << "ok" << std::endl; }); sm.run(S::INIT); return 0; }