00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifdef _MSC_VER
00014 #pragma warning( disable : 4786 ) // 'identifier' : identifier was truncated to 'number' characters in the debug information
00015
00016
00017 #pragma warning( disable : 4251 ) // 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
00018 #endif
00019 #ifdef __INTEL_COMPILER
00020 #pragma warning( disable : 985 ) // == C4786
00021 #endif
00022
00023 #include "FSM.h"
00024 #include "FiniteStateMachine-config.h"
00025 #include "FSMErrorCodes.h"
00026
00027 namespace FSM {
00028
00029 static const char* FSM_PARAM_VARIABLE = "Variable";
00030 static const char* FSM_PARAM_VALUE = "Value";
00031 static const char* FSM_PARAM_INCREMENT = "Increment";
00032
00034
00036
00037 CFSMAction::CFSMAction()
00038 {
00039 }
00040
00041 CFSMAction::~CFSMAction()
00042 {
00043 }
00044
00046
00048
00050
00052
00053 {
00054 variableName = varName;
00055 }
00056
00057 void CFSMActionSetVariable::SetValue(int val)
00058 {
00059 value = val;
00060 }
00061
00062 const char* CFSMActionSetVariable::GetVariable() const
00063 {
00064 return variableName.c_str();
00065 }
00066
00067 int CFSMActionSetVariable::GetValue() const
00068 {
00069 return value;
00070 }
00071
00073
00075
00076 {
00077 bool res = GetFSM()->SetVariable(variableName.c_str(), value);
00078 if (!res)
00079 {
00080 iRethrow();
00081 }
00082 return res;
00083 }
00084
00085 bool CFSMActionSetVariable::SetParameter(const char* paramName, const char* paramValue)
00086 {
00087 bool res = false;
00088 if (strcmp(paramName, FSM_PARAM_VARIABLE)==0)
00089 {
00090 variableName = paramValue;
00091 res = true;
00092 } else
00093
00094 if (strcmp(paramName, FSM_PARAM_VALUE)==0)
00095 {
00096 value = atoi(paramValue);
00097 res = true;
00098 } else
00099
00100 {
00101 iThrow(CRITICAL(FSM_UNKNOWN_PARAM), paramName, GetNameOfClass());
00102 }
00103 return res;
00104 }
00105
00107
00109
00110 {
00111 CFSMObject* res = new CFSMActionSetVariable();
00112 return res;
00113 }
00114
00115 void CFSMActionSetVariable::DeleteThis()
00116 {
00117 delete this;
00118 }
00119
00121
00123
00124 {
00125 char buf[40];
00126 sprintf(buf, "%d", value);
00127 if (!out->SaveParameter(FSM_PARAM_VARIABLE, variableName.c_str())) {iRethrow(); return false;}
00128 if (!out->SaveParameter(FSM_PARAM_VALUE, buf)) {iRethrow(); return false;}
00129 return true;
00130 }
00131
00133
00135
00136 :value(0)
00137 {
00138 }
00139
00140 CFSMActionSetVariable::~CFSMActionSetVariable()
00141 {
00142 }
00143
00145
00147
00149
00151
00152 {
00153 variableName = varName;
00154 }
00155
00156 void CFSMActionIncrVariable::SetIncrement(int val)
00157 {
00158 increment = val;
00159 }
00160
00161 const char* CFSMActionIncrVariable::GetVariable() const
00162 {
00163 return variableName.c_str();
00164 }
00165
00166 int CFSMActionIncrVariable::GetIncrement() const
00167 {
00168 return increment;
00169 }
00170
00172
00174
00175 {
00176 bool res=false;
00177 int value;
00178 res = GetFSM()->GetVariable(variableName.c_str(), value);
00179 if (res)
00180 {
00181 res = GetFSM()->SetVariable(variableName.c_str(), value+increment);
00182 }
00183
00184 if (!res)
00185 {
00186 iRethrow();
00187 }
00188 return res;
00189 }
00190
00191 bool CFSMActionIncrVariable::SetParameter(const char* paramName, const char* paramValue)
00192 {
00193 bool res = false;
00194 if (strcmp(paramName, FSM_PARAM_VARIABLE)==0)
00195 {
00196 variableName = paramValue;
00197 res = true;
00198 } else
00199
00200 if (strcmp(paramName, FSM_PARAM_INCREMENT)==0)
00201 {
00202 increment = atoi(paramValue);
00203 res = true;
00204 } else
00205
00206 {
00207 iThrow(CRITICAL(FSM_UNKNOWN_PARAM), paramName, GetNameOfClass());
00208 }
00209 return res;
00210 }
00211
00213
00215
00216 {
00217 CFSMObject* res = new CFSMActionIncrVariable();
00218 return res;
00219 }
00220
00221 void CFSMActionIncrVariable::DeleteThis()
00222 {
00223 delete this;
00224 }
00225
00227
00229
00230 {
00231 char buf[40];
00232 sprintf(buf, "%d", increment);
00233 if (!out->SaveParameter(FSM_PARAM_VARIABLE, variableName.c_str())) {iRethrow(); return false;}
00234 if (!out->SaveParameter(FSM_PARAM_INCREMENT, buf)) {iRethrow(); return false;}
00235 return true;
00236 }
00237
00239
00241
00242 :increment(1)
00243 {
00244 }
00245
00246 CFSMActionIncrVariable::~CFSMActionIncrVariable()
00247 {
00248 }
00249
00250 };
00251