- removed IStateMachine.hpp

git-svn-id: http://moon:8086/svn/software/trunk/projects/FsmEval@135 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2015-01-24 12:07:40 +00:00
parent 251ac211bd
commit 0d8badfef1
5 changed files with 32 additions and 60 deletions
+3 -4
View File
@@ -8,8 +8,7 @@
#ifndef ASTATE_HPP #ifndef ASTATE_HPP
#define ASTATE_HPP #define ASTATE_HPP
#include "IStateMachine.hpp" template <class IdType> class AStateMachine;
template <class IdType> template <class IdType>
class AState class AState
{ {
@@ -29,7 +28,7 @@ public:
return m_id; return m_id;
} }
void registerStateMachine(IStateMachine *pStateMachine) void registerStateMachine(AStateMachine<IdType> *pStateMachine)
{ {
m_pStateMachine = pStateMachine; m_pStateMachine = pStateMachine;
} }
@@ -48,7 +47,7 @@ protected:
} }
} }
private: private:
IStateMachine *m_pStateMachine; AStateMachine<IdType> *m_pStateMachine;
IdType m_id; IdType m_id;
}; };
+3 -5
View File
@@ -8,11 +8,10 @@
#ifndef ASTATEMACHINE_HPP #ifndef ASTATEMACHINE_HPP
#define ASTATEMACHINE_HPP #define ASTATEMACHINE_HPP
#include "IStateMachine.hpp"
#include "AState.hpp" #include "AState.hpp"
template <class IdType> template <class IdType>
class AStateMachine : public IStateMachine class AStateMachine
{ {
public: public:
@@ -55,7 +54,6 @@ public:
if (!m_firstState) if (!m_firstState)
{ {
m_firstState = pState; m_firstState = pState;
// m_currState = pState;
} }
else else
{ {
@@ -69,7 +67,7 @@ public:
pState->registerStateMachine(this); pState->registerStateMachine(this);
} }
void setState(StateId stateId) void setState(IdType stateId)
{ {
AState<IdType> *pStateNext = findById(stateId); AState<IdType> *pStateNext = findById(stateId);
@@ -92,7 +90,7 @@ private:
AState<IdType> *m_firstState; AState<IdType> *m_firstState;
AState<IdType> *m_currState; AState<IdType> *m_currState;
AState<IdType>* findById(StateId stateId) AState<IdType>* findById(IdType stateId)
{ {
AState<IdType> *pStateNext = m_firstState; AState<IdType> *pStateNext = m_firstState;
-29
View File
@@ -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 */
+26 -17
View File
@@ -51,7 +51,16 @@ public:
}; };
class StateMachine : public AStateMachine<IStateMachine::StateId> enum StateId
{
INIT=0,
IDLE,
ACTIVE_0,
ACTIVE_1,
NUM_STATES
};
class StateMachine : public AStateMachine<StateId>
{ {
public: public:
@@ -71,10 +80,10 @@ public:
}; };
class StateInit : public AState<IStateMachine::StateId>, public IState class StateInit : public AState<StateId>, public IState
{ {
public: public:
StateInit(IStateMachine::StateId id, Context &context) StateInit(StateId id, Context &context)
: AState(id) : AState(id)
, m_context(context) , m_context(context)
{ {
@@ -86,17 +95,17 @@ public:
void process(int x) void process(int x)
{ {
printf("%s() x=%d\n", __PRETTY_FUNCTION__, x); printf("%s() x=%d\n", __PRETTY_FUNCTION__, x);
setState(IStateMachine::IDLE); setState(IDLE);
} }
private: private:
Context &m_context; Context &m_context;
}; };
class StateIdle : public AState<IStateMachine::StateId>, public IState class StateIdle : public AState<StateId>, public IState
{ {
public: public:
StateIdle(IStateMachine::StateId id, Context &context) StateIdle(StateId id, Context &context)
: AState(id) : AState(id)
, m_context(context) , m_context(context)
{ {
@@ -116,7 +125,7 @@ public:
printf("%s() x=%d\n", __PRETTY_FUNCTION__, x); printf("%s() x=%d\n", __PRETTY_FUNCTION__, x);
if (x >= 10) if (x >= 10)
{ {
setState(IStateMachine::ACTIVE_0); setState(ACTIVE_0);
} }
} }
@@ -124,10 +133,10 @@ private:
Context &m_context; Context &m_context;
}; };
class StateActive0 : public AState<IStateMachine::StateId>, public IState class StateActive0 : public AState<StateId>, public IState
{ {
public: public:
StateActive0(IStateMachine::StateId id, Context &context) StateActive0(StateId id, Context &context)
: AState(id) : AState(id)
, m_context(context) , m_context(context)
{ {
@@ -149,7 +158,7 @@ public:
m_context.m_count++; m_context.m_count++;
if (m_context.m_count == 10) if (m_context.m_count == 10)
{ {
setState(IStateMachine::ACTIVE_1); setState(ACTIVE_1);
} }
} }
@@ -157,10 +166,10 @@ private:
Context &m_context; Context &m_context;
}; };
class StateActive1 : public AState<IStateMachine::StateId>, public IState class StateActive1 : public AState<StateId>, public IState
{ {
public: public:
StateActive1(IStateMachine::StateId id, Context &context) StateActive1(StateId id, Context &context)
: AState(id) : AState(id)
, m_context(context) , m_context(context)
{ {
@@ -181,7 +190,7 @@ public:
m_context.m_count--; m_context.m_count--;
if (m_context.m_count == 0) 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; Context ctx;
StateMachine fsm; StateMachine fsm;
StateInit init(IStateMachine::INIT, ctx); StateInit init(INIT, ctx);
StateIdle idle(IStateMachine::IDLE, ctx); StateIdle idle(IDLE, ctx);
StateActive0 active0(IStateMachine::ACTIVE_0, ctx); StateActive0 active0(ACTIVE_0, ctx);
StateActive1 active1(IStateMachine::ACTIVE_1, ctx); StateActive1 active1(ACTIVE_1, ctx);
fsm.add(&init); fsm.add(&init);
fsm.add(&idle); fsm.add(&idle);
-5
View File
@@ -6,7 +6,6 @@
projectFiles="true"> projectFiles="true">
<itemPath>AState.hpp</itemPath> <itemPath>AState.hpp</itemPath>
<itemPath>AStateMachine.hpp</itemPath> <itemPath>AStateMachine.hpp</itemPath>
<itemPath>IStateMachine.hpp</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="ResourceFiles" <logicalFolder name="ResourceFiles"
displayName="Resource Files" displayName="Resource Files"
@@ -43,8 +42,6 @@
</item> </item>
<item path="AStateMachine.hpp" ex="false" tool="3" flavor2="0"> <item path="AStateMachine.hpp" ex="false" tool="3" flavor2="0">
</item> </item>
<item path="IStateMachine.hpp" ex="false" tool="3" flavor2="0">
</item>
<item path="main.cpp" ex="false" tool="1" flavor2="0"> <item path="main.cpp" ex="false" tool="1" flavor2="0">
</item> </item>
</conf> </conf>
@@ -72,8 +69,6 @@
</item> </item>
<item path="AStateMachine.hpp" ex="false" tool="3" flavor2="0"> <item path="AStateMachine.hpp" ex="false" tool="3" flavor2="0">
</item> </item>
<item path="IStateMachine.hpp" ex="false" tool="3" flavor2="0">
</item>
<item path="main.cpp" ex="false" tool="1" flavor2="0"> <item path="main.cpp" ex="false" tool="1" flavor2="0">
</item> </item>
</conf> </conf>