00001 #if !defined(_FSMLoader_H_)
00002 #define _FSMLoader_H_
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 #include <cstdio>
00047 #include "FiniteStateMachine.h"
00048
00050 namespace FSM {
00051
00052 class CTokenizer;
00053
00057 class CFSMLoader
00058 {
00059 public:
00060 CFSMLoader(CFiniteStateMachine *fsm);
00061 virtual ~CFSMLoader();
00062
00063 protected:
00064 CFiniteStateMachine* m_FSM;
00065 };
00066
00070 class CFSMSimpleLoaderXML : public CFSMLoader
00071 {
00072 public:
00073 CFSMSimpleLoaderXML(CFiniteStateMachine *fsm);
00074 virtual ~CFSMSimpleLoaderXML();
00075
00076
00077 bool Load(const char *filename);
00078 bool Load(FILE *inFile);
00079
00080 protected:
00081 bool LoadFSM();
00082 bool LoadVariable();
00083 bool LoadState();
00084 bool LoadParam(CFSMObject* obj);
00085 bool LoadEnterAction(CFSMState* state);
00086 bool LoadTransition(CFSMState* state);
00087 bool LoadLeaveAction(CFSMState* state);
00088 bool LoadTransAction(CFSMTransition* trans);
00089 bool LoadCondition(CFSMTransition* trans);
00090
00091 private:
00092 CTokenizer* m_Tokenizer;
00093 };
00094
00099 class CFSMLoaderXML : public CFSMLoader
00100 {
00101 public:
00102 CFSMLoaderXML(CFiniteStateMachine *fsm);
00103 virtual ~CFSMLoaderXML();
00104
00105
00106 bool Load(const char *filename);
00107
00108 protected:
00109
00110 private:
00111 };
00112
00116 class CFSMSaver
00117 {
00118 public:
00119 CFSMSaver(const CFiniteStateMachine *fsm);
00120 virtual ~CFSMSaver();
00121
00126 virtual bool SaveParameter(const char* name, const char* value) const =0;
00127
00128 protected:
00132 bool SaveParameters(const CFSMObject* obj);
00133
00134 const CFiniteStateMachine* m_FSM;
00135 };
00136
00140 class CFSMSaverXML : public CFSMSaver
00141 {
00142 public:
00143 CFSMSaverXML(const CFiniteStateMachine *fsm);
00144 virtual ~CFSMSaverXML();
00145
00146
00147 bool Save(const char *filename);
00148 bool Save(FILE *outFile);
00149
00150
00151 virtual bool SaveParameter(const char* name, const char* value);
00152
00153 protected:
00154 virtual bool SaveState(const CFSMState* state);
00155 virtual bool SaveTransition(const CFSMTransition* trans);
00156 virtual bool SaveAction(const CFSMAction *action, const char* tag="Action");
00157 virtual bool SaveCondition(const CFSMCondition *cond);
00158
00159 private:
00160 const CFiniteStateMachine* m_FSM;
00161 FILE* m_File;
00162 };
00163
00164 };
00165
00166 #endif // !defined(_FSMLoader_H_)