SourceForge Project Site
Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

FSMAction.cpp

Go to the documentation of this file.
00001 // $Log: FSMAction.cpp,v $
00002 // Revision 1.2  2002/08/20 14:48:41  vofka
00003 // FiniteStateMachine-config.h removed from installing. Loading exported to the loader class. Saver introduced. Error codes exported to FSMErrorCodes.
00004 //
00005 // Revision 1.1  2002/07/22 17:20:59  vofka
00006 // SimpleTransition, PushTransition, PopTransition added, not implemented yet
00007 //
00008 // Revision 1.10  2002/06/20 12:22:10  bobka
00009 // LGPL license
00010 //
00011 //
00012 
00013 #ifdef _MSC_VER
00014         #pragma warning( disable : 4786 ) // 'identifier' : identifier was truncated to 'number' characters in the debug information
00015 //      #pragma warning( disable : 4503 ) // 'identifier' : decorated name length exceeded, name was truncated
00016 //      #pragma warning( disable : 4250 ) // 'class1' : inherits 'class2::member' via dominance
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 // Construction/Destruction
00036 
00037 CFSMAction::CFSMAction()
00038 {
00039 }
00040 
00041 CFSMAction::~CFSMAction()
00042 {
00043 }
00044 
00046 //    CFSMActionSetVariable
00048 
00050 //              Get/Set
00052 void CFSMActionSetVariable::SetVariable(const char* varName)
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 //              Overloaded
00075 bool CFSMActionSetVariable::Execute(const char* event, void *a, void *b)
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 //              Construction/Destruction
00109 CFSMObject* CFSMActionSetVariable::Create()
00110 {
00111         CFSMObject* res = new CFSMActionSetVariable();
00112         return res;
00113 }
00114 
00115 void CFSMActionSetVariable::DeleteThis()
00116 {
00117         delete this;
00118 }
00119 
00121 //              Overloaded
00123 bool CFSMActionSetVariable::SaveParameters(CFSMSaver *out) const
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 //      private
00135 CFSMActionSetVariable::CFSMActionSetVariable()
00136 :value(0)
00137 {
00138 }
00139 
00140 CFSMActionSetVariable::~CFSMActionSetVariable()
00141 {
00142 }
00143 
00145 //    CFSMActionIncrVariable
00147 
00149 //              Get/Set
00151 void CFSMActionIncrVariable::SetVariable(const char* varName)
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 //              Overloaded
00174 bool CFSMActionIncrVariable::Execute(const char* event, void *a, void *b)
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 //              Construction/Destruction
00215 CFSMObject* CFSMActionIncrVariable::Create()
00216 {
00217         CFSMObject* res = new CFSMActionIncrVariable();
00218         return res;
00219 }
00220 
00221 void CFSMActionIncrVariable::DeleteThis()
00222 {
00223         delete this;
00224 }
00225 
00227 //              Overloaded
00229 bool CFSMActionIncrVariable::SaveParameters(CFSMSaver* out) const
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 //      private
00241 CFSMActionIncrVariable::CFSMActionIncrVariable()
00242 :increment(1)
00243 {
00244 }
00245 
00246 CFSMActionIncrVariable::~CFSMActionIncrVariable()
00247 {
00248 }
00249 
00250 }; // namespace FSM
00251 

© 2002 by C-LAB
generated by doxygen