00001 #if !defined(AFX_FSMTRANSITION_H__0E355DD5_595A_429E_950B_03A7F175172E__INCLUDED_)
00002 #define AFX_FSMTRANSITION_H__0E355DD5_595A_429E_950B_03A7F175172E__INCLUDED_
00003
00004 #if _MSC_VER > 1000
00005 #pragma once
00006 #endif // _MSC_VER > 1000
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 #include "FSMObject.h"
00066
00068 namespace FSM {
00069
00070
00071 class CFiniteStateMachine;
00072 class CFSMAction;
00073 class CFSMCondition;
00074
00075 typedef list< CFSMAction* > Action_List;
00076 typedef list< CFSMCondition* > Condition_List;
00077
00081 class CFSMTransition : public CFSMObject
00082 {
00083 public:
00084 friend class CFSMState;
00085 friend class CFiniteStateMachine;
00086
00087
00088 CFSMAction* AddAction(const char *className);
00090 CFSMAction* GetAction(int index) const;
00091 bool DeleteAction(CFSMAction *action);
00092
00098 Action_List::const_iterator GetActionsBegin() const;
00099
00101 Action_List::const_iterator GetActionsEnd() const;
00102
00103
00104 CFSMCondition* AddCondition(const char *className="TestVariable");
00106 CFSMCondition* GetCondition(int index) const;
00107 bool DeleteCondition(CFSMCondition *condition);
00108
00114 Condition_List::const_iterator GetConditionsBegin() const;
00115
00117 Condition_List::const_iterator GetConditionsEnd() const;
00118
00119
00120 CFSMState* GetFromState() const;
00121 const char * GetOnEvent() const;
00122 void SetOnEvent(const char* event="ANY");
00123
00124 protected:
00125
00126
00127 void SetFromState(const char *stateName);
00128
00130
00135 virtual bool Check(bool &result, const char *event, void *a, void *b);
00136
00141 virtual bool Execute(const char* event, void *a, void *b);
00142
00147 virtual bool Activate();
00148
00153 virtual bool Deactivate();
00154
00155 CFSMTransition();
00156 virtual ~CFSMTransition();
00157 private:
00158
00159 Action_List m_Actions;
00160 Condition_List m_Conditions;
00161 string m_FromState;
00162 string m_ToState;
00163 string m_Event;
00164 };
00165
00169 class CFSMSimpleTransition : public CFSMTransition
00170 {
00171 public:
00172 friend class CFSMState;
00173 friend class CFiniteStateMachine;
00174
00175
00176 CFSMState* GetToState() const;
00177 void SetToState(const char *stateName);
00178
00179 virtual bool SetParameter(const char* paramName, const char* paramValue);
00180
00181 protected:
00182
00183 static CFSMObject *Create();
00184 virtual void DeleteThis();
00185
00186
00188
00192 virtual bool SaveParameters(CFSMSaver* out) const;
00193
00198 virtual bool Execute(const char* event, void *a, void *b);
00199
00200 CFSMSimpleTransition();
00201 virtual ~CFSMSimpleTransition();
00202 private:
00203
00204 string m_ToState;
00205 };
00206
00210 class CFSMPushTransition : public CFSMSimpleTransition
00211 {
00212 public:
00213 friend class CFSMState;
00214 friend class CFiniteStateMachine;
00215
00216 protected:
00217
00218 static CFSMObject *Create();
00219 virtual void DeleteThis();
00220
00221
00223
00228 virtual bool Execute(const char* event, void *a, void *b);
00229
00230 CFSMPushTransition();
00231 virtual ~CFSMPushTransition();
00232 private:
00233
00234 };
00235
00239 class CFSMPopTransition : public CFSMTransition
00240 {
00241 public:
00242 friend class CFSMState;
00243 friend class CFiniteStateMachine;
00244
00245 protected:
00246
00247 static CFSMObject *Create();
00248 virtual void DeleteThis();
00249
00250
00252
00257 virtual bool Execute(const char* event, void *a, void *b);
00258
00259 CFSMPopTransition();
00260 virtual ~CFSMPopTransition();
00261 private:
00262
00263 };
00264
00265 };
00266
00267 #endif // !defined(AFX_FSMTRANSITION_H__0E355DD5_595A_429E_950B_03A7F175172E__INCLUDED_)