/* * 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() : m_stateCurr(NUM_STATES) , m_stateNext(INIT) { } virtual ~AStateMachine() { } void add(StateId stateId, AState *pState) { pState->registerStateMachine(this); m_states[stateId] = pState; } void setState(StateId stateId) { m_stateNext = stateId; } bool transition() { bool isTransition = (m_stateNext != m_stateCurr); m_stateCurr = m_stateNext; return isTransition; } protected: StateId m_stateCurr; StateId m_stateNext; AState *m_states[NUM_STATES]; }; #endif /* ASTATEMACHINE_HPP */