1#ifndef FINITE_MACHINE_STATE_H
2#define FINITE_MACHINE_STATE_H
5#include <initializer_list>
6#include "./machine_state.h"
22 std::map<T, MachineState<T> *> mStates;
36 for (
auto state : states)
38 mStates.emplace(state->GetState(), state);
39 state->Register(
this);
42 auto _initialState = mStates.at(entrypoint);
44 _initialState->Activate(entrypoint);
45 mCurrentState = entrypoint;
59 return mStates.at(mCurrentState);
62 void Transit(T previousState, T nextState)
override
65 if (previousState == mCurrentState)
67 auto _nextMachineState = mStates.at(nextState);
68 mCurrentState = nextState;
69 _nextMachineState->Activate(previousState);
Abstract Finite State Machine (FMS) that transits between states.
Definition: abstract_state_machine.h:14
Finite State Machine (FMS) controller.
Definition: finite_state_machine.h:20
void Transit(T previousState, T nextState) override
Tranit from the current state to a new state.
Definition: finite_state_machine.h:62
MachineState< T > * GetMachineState() const
Get the current machine state object.
Definition: finite_state_machine.h:57
void Initialize(std::initializer_list< MachineState< T > * > states, T entrypoint)
Initalize the FSM.
Definition: finite_state_machine.h:34
T GetState() const noexcept
Get the FSM current state.
Definition: finite_state_machine.h:50
Machine state abstract class.
Definition: machine_state.h:46