- 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:
+3
-4
@@ -8,8 +8,7 @@
|
||||
#ifndef ASTATE_HPP
|
||||
#define ASTATE_HPP
|
||||
|
||||
#include "IStateMachine.hpp"
|
||||
|
||||
template <class IdType> class AStateMachine;
|
||||
template <class IdType>
|
||||
class AState
|
||||
{
|
||||
@@ -29,7 +28,7 @@ public:
|
||||
return m_id;
|
||||
}
|
||||
|
||||
void registerStateMachine(IStateMachine *pStateMachine)
|
||||
void registerStateMachine(AStateMachine<IdType> *pStateMachine)
|
||||
{
|
||||
m_pStateMachine = pStateMachine;
|
||||
}
|
||||
@@ -48,7 +47,7 @@ protected:
|
||||
}
|
||||
}
|
||||
private:
|
||||
IStateMachine *m_pStateMachine;
|
||||
AStateMachine<IdType> *m_pStateMachine;
|
||||
IdType m_id;
|
||||
|
||||
};
|
||||
|
||||
+3
-5
@@ -8,11 +8,10 @@
|
||||
#ifndef ASTATEMACHINE_HPP
|
||||
#define ASTATEMACHINE_HPP
|
||||
|
||||
#include "IStateMachine.hpp"
|
||||
#include "AState.hpp"
|
||||
|
||||
template <class IdType>
|
||||
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<IdType> *pStateNext = findById(stateId);
|
||||
|
||||
@@ -92,7 +90,7 @@ private:
|
||||
AState<IdType> *m_firstState;
|
||||
AState<IdType> *m_currState;
|
||||
|
||||
AState<IdType>* findById(StateId stateId)
|
||||
AState<IdType>* findById(IdType stateId)
|
||||
{
|
||||
AState<IdType> *pStateNext = m_firstState;
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -71,10 +80,10 @@ public:
|
||||
|
||||
};
|
||||
|
||||
class StateInit : public AState<IStateMachine::StateId>, public IState
|
||||
class StateInit : public AState<StateId>, 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<IStateMachine::StateId>, public IState
|
||||
class StateIdle : public AState<StateId>, 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<IStateMachine::StateId>, public IState
|
||||
class StateActive0 : public AState<StateId>, 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<IStateMachine::StateId>, public IState
|
||||
class StateActive1 : public AState<StateId>, 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);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
projectFiles="true">
|
||||
<itemPath>AState.hpp</itemPath>
|
||||
<itemPath>AStateMachine.hpp</itemPath>
|
||||
<itemPath>IStateMachine.hpp</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="ResourceFiles"
|
||||
displayName="Resource Files"
|
||||
@@ -43,8 +42,6 @@
|
||||
</item>
|
||||
<item path="AStateMachine.hpp" ex="false" tool="3" flavor2="0">
|
||||
</item>
|
||||
<item path="IStateMachine.hpp" ex="false" tool="3" flavor2="0">
|
||||
</item>
|
||||
<item path="main.cpp" ex="false" tool="1" flavor2="0">
|
||||
</item>
|
||||
</conf>
|
||||
@@ -72,8 +69,6 @@
|
||||
</item>
|
||||
<item path="AStateMachine.hpp" ex="false" tool="3" flavor2="0">
|
||||
</item>
|
||||
<item path="IStateMachine.hpp" ex="false" tool="3" flavor2="0">
|
||||
</item>
|
||||
<item path="main.cpp" ex="false" tool="1" flavor2="0">
|
||||
</item>
|
||||
</conf>
|
||||
|
||||
Reference in New Issue
Block a user