Hierarchical Finite State Machine Framework
Header-only heriarchical FSM framework in C++14, completely static (no dynamic allocations), built with variadic templates.
DEPRECATED, FURTHER DEVELOPMENT CONTINUES IN HFSM2
// 1. Include HFSM header:
#include <hfsm/machine_single.hpp>
// 2. Define interface class between the FSM and its owner
// (also ok to use the owner object itself):
struct Context { /* ... */ };
// 3. (Optional) Typedef hfsm::Machine for convenience:
using M = hfsm::Machine<OwnerClass>;
// 4. Define states:
struct MyState1 : M::Bare {
// 5. Override some of the following state functions:
void enter(Context& _);
void update(Context& _);
void transition(Control& c, Context& _);
void leave(Context& _);
};
struct MyState2 : M::Bare { /* .. */ };
struct MySubState1 : M::Bare { /* .. */ };
struct MySubState2 : M::Bare { /* .. */ };
struct MyState3 : M::Bare { /* .. */ };
struct MyOrthogonalState1 : M::Bare { /* .. */ };
struct MyOrthogonalState2 : M::Bare { /* .. */ };
// 6. Declare state machine structure:
using MyFSM = M::PeerRoot<
MyState1,
M::Composite<MyState2,
MySubState1,
MySubState2,
>,
M::Orthogonal<MyState3,
MyOrthogonalState1,
MyOrthogonalState2,
>
>;
int main() {
// 7. Create context and state machine instances:
Context context;
MyFSM fsm(context);
// 8. Kick off periodic updates:
bool running = true;
while (running)
fsm.update();
return 0;
}
FSM.changeTo<TargetState>()
State::update()
#define HFSM_ENABLE_STRUCTURE_REPORT
See Wiki for Tutorial and docs.