|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #pragma once
-
- class LFR_StateMachine;
-
- class LFR_State
- {
- public:
- virtual void enter(LFR_StateMachine* stateMachine) = 0;
- virtual void exit(LFR_StateMachine* stateMachine) = 0;
- virtual ~LFR_State() {}
- };
-
-
- namespace State
- {
- class Idle: public LFR_State
- {
- Idle() {}
- Idle(const Idle& other) {};
- Idle& operator= (const Idle& other);
-
- public:
- void enter(LFR_StateMachine*);
- void exit(LFR_StateMachine*);
- static LFR_State& getInstance();
- };
-
-
- class Autonomous: public LFR_State
- {
- Autonomous() {}
- Autonomous(const Autonomous& other) {};
- Autonomous& operator= (const Autonomous& other);
-
- public:
- void enter(LFR_StateMachine*);
- void exit(LFR_StateMachine*);
- static LFR_State& getInstance();
- };
-
-
- class Manual: public LFR_State
- {
- Manual() {}
- Manual(const Manual& other) {};
- Manual& operator= (const Manual& other);
-
- public:
- void enter(LFR_StateMachine*);
- void exit(LFR_StateMachine*);
- static LFR_State& getInstance();
- };
- }
-
- class LFR_StateMachine
- {
- LFR_State* currentState;
- public:
- LFR_StateMachine(){
- setState(State::Idle::getInstance());
- }
- inline LFR_State* getCurrentState() const {return currentState;}
- void setState(LFR_State& newState)
- {
- currentState->exit(this);
- currentState = &newState;
- currentState->enter(this);
- }
- };
|