From 0d8badfef119eda9fb1d09c01b87675e36e34f8d Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Sat, 24 Jan 2015 12:07:40 +0000 Subject: [PATCH] - removed IStateMachine.hpp git-svn-id: http://moon:8086/svn/software/trunk/projects/FsmEval@135 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- AState.hpp | 7 +++--- AStateMachine.hpp | 8 +++---- IStateMachine.hpp | 29 ------------------------ main.cpp | 43 ++++++++++++++++++++++-------------- nbproject/configurations.xml | 5 ----- 5 files changed, 32 insertions(+), 60 deletions(-) delete mode 100644 IStateMachine.hpp diff --git a/AState.hpp b/AState.hpp index fa449f3..f176ba0 100644 --- a/AState.hpp +++ b/AState.hpp @@ -8,8 +8,7 @@ #ifndef ASTATE_HPP #define ASTATE_HPP -#include "IStateMachine.hpp" - +template class AStateMachine; template class AState { @@ -29,7 +28,7 @@ public: return m_id; } - void registerStateMachine(IStateMachine *pStateMachine) + void registerStateMachine(AStateMachine *pStateMachine) { m_pStateMachine = pStateMachine; } @@ -48,7 +47,7 @@ protected: } } private: - IStateMachine *m_pStateMachine; + AStateMachine *m_pStateMachine; IdType m_id; }; diff --git a/AStateMachine.hpp b/AStateMachine.hpp index 595825c..e4f7549 100644 --- a/AStateMachine.hpp +++ b/AStateMachine.hpp @@ -8,11 +8,10 @@ #ifndef ASTATEMACHINE_HPP #define ASTATEMACHINE_HPP -#include "IStateMachine.hpp" #include "AState.hpp" template -class AStateMachine : public IStateMachine +class AStateMachine { public: @@ -55,7 +54,6 @@ public: if (!m_firstState) { m_firstState = pState; -// m_currState = pState; } else { @@ -69,7 +67,7 @@ public: pState->registerStateMachine(this); } - void setState(StateId stateId) + void setState(IdType stateId) { AState *pStateNext = findById(stateId); @@ -92,7 +90,7 @@ private: AState *m_firstState; AState *m_currState; - AState* findById(StateId stateId) + AState* findById(IdType stateId) { AState *pStateNext = m_firstState; diff --git a/IStateMachine.hpp b/IStateMachine.hpp deleted file mode 100644 index 5d98872..0000000 --- a/IStateMachine.hpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * File: IStateMachine.hpp - * Author: jens - * - * Created on 22. Januar 2015, 08:39 - */ - -#ifndef ISTATEMACHINE_HPP -#define ISTATEMACHINE_HPP - -class IStateMachine -{ -public: - enum StateId - { - INIT=0, - IDLE, - ACTIVE_0, - ACTIVE_1, - NUM_STATES - }; - IStateMachine() {} - ~IStateMachine() {} - - virtual void setState(StateId stateId) = 0; -}; - -#endif /* ISTATEMACHINE_HPP */ - diff --git a/main.cpp b/main.cpp index 83e8082..ef928d8 100644 --- a/main.cpp +++ b/main.cpp @@ -51,7 +51,16 @@ public: }; -class StateMachine : public AStateMachine +enum StateId +{ + INIT=0, + IDLE, + ACTIVE_0, + ACTIVE_1, + NUM_STATES +}; + +class StateMachine : public AStateMachine { public: @@ -71,10 +80,10 @@ public: }; -class StateInit : public AState, public IState +class StateInit : public AState, public IState { public: - StateInit(IStateMachine::StateId id, Context &context) + StateInit(StateId id, Context &context) : AState(id) , m_context(context) { @@ -86,17 +95,17 @@ public: void process(int x) { printf("%s() x=%d\n", __PRETTY_FUNCTION__, x); - setState(IStateMachine::IDLE); + setState(IDLE); } private: Context &m_context; }; -class StateIdle : public AState, public IState +class StateIdle : public AState, public IState { public: - StateIdle(IStateMachine::StateId id, Context &context) + StateIdle(StateId id, Context &context) : AState(id) , m_context(context) { @@ -116,7 +125,7 @@ public: printf("%s() x=%d\n", __PRETTY_FUNCTION__, x); if (x >= 10) { - setState(IStateMachine::ACTIVE_0); + setState(ACTIVE_0); } } @@ -124,10 +133,10 @@ private: Context &m_context; }; -class StateActive0 : public AState, public IState +class StateActive0 : public AState, public IState { public: - StateActive0(IStateMachine::StateId id, Context &context) + StateActive0(StateId id, Context &context) : AState(id) , m_context(context) { @@ -149,7 +158,7 @@ public: m_context.m_count++; if (m_context.m_count == 10) { - setState(IStateMachine::ACTIVE_1); + setState(ACTIVE_1); } } @@ -157,10 +166,10 @@ private: Context &m_context; }; -class StateActive1 : public AState, public IState +class StateActive1 : public AState, public IState { public: - StateActive1(IStateMachine::StateId id, Context &context) + StateActive1(StateId id, Context &context) : AState(id) , m_context(context) { @@ -181,7 +190,7 @@ public: m_context.m_count--; if (m_context.m_count == 0) { - setState(IStateMachine::ACTIVE_0); + setState(ACTIVE_0); } } @@ -193,10 +202,10 @@ int main(int argc, char** argv) { Context ctx; StateMachine fsm; - StateInit init(IStateMachine::INIT, ctx); - StateIdle idle(IStateMachine::IDLE, ctx); - StateActive0 active0(IStateMachine::ACTIVE_0, ctx); - StateActive1 active1(IStateMachine::ACTIVE_1, ctx); + StateInit init(INIT, ctx); + StateIdle idle(IDLE, ctx); + StateActive0 active0(ACTIVE_0, ctx); + StateActive1 active1(ACTIVE_1, ctx); fsm.add(&init); fsm.add(&idle); diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 865d6f3..5630851 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -6,7 +6,6 @@ projectFiles="true"> AState.hpp AStateMachine.hpp - IStateMachine.hpp - - @@ -72,8 +69,6 @@ - -