/* * File: AStateMachine.hpp * Author: jens * * Created on 21. Januar 2015, 05:20 */ #ifndef ASTATEMACHINE_HPP #define ASTATEMACHINE_HPP #include "IStateMachine.hpp" #include "AState.hpp" class AStateMachine : public IStateMachine { public: AStateMachine(StateId stateInit) : m_stateCurr(stateInit) { } virtual ~AStateMachine() { } void add(StateId stateId, AState *pState) { pState->registerStateMachine(this); m_states[stateId] = pState; } void setState(StateId stateId) { bool isTransition = (m_stateCurr != stateId); m_stateCurr = stateId; if (isTransition) { m_states[m_stateCurr]->onTransition(); } } protected: StateId m_stateCurr; AState *m_states[NUM_STATES]; }; #endif /* ASTATEMACHINE_HPP */