85 THROW_TEXT_ERROR(Std_Err_lVariableExists, Std_Err_strVariableExists, strVarName);
105 THROW_TEXT_ERROR(Std_Err_lVariableNotExists, Std_Err_strVariableNotExists, strVarName);
125 for(i=0; i<iSize; i++)
144 int iSize=aryPostFix.GetSize(), i;
148 for(i=0; i<iSize; i++)
153 strTemp = str( boost::format(
"%f") % (
float) lpVar->
m_dblValue );
154 aryPostFix[i] = strTemp;
169 CStdArray<std::string> aryPostFix;
170 double dblVal, dblLeft, dblRight;
177 lSize = aryPostFix.GetSize();
178 for(i=0; i<lSize; i++)
180 strTemp = aryPostFix[i];
184 dblVal = pow(dblLeft, dblRight);
187 else if(strTemp ==
"*")
190 dblVal = dblLeft * dblRight;
193 else if(strTemp ==
"/")
196 if(!dblRight) THROW_ERROR(Std_Err_lDivByZero, Std_Err_strDivByZero);
197 dblVal = dblLeft / dblRight;
200 else if(strTemp ==
"%")
203 if(!dblRight) THROW_ERROR(Std_Err_lDivByZero, Std_Err_strDivByZero);
204 dblVal = ((long) dblLeft) % ((long) dblRight);
207 else if(strTemp ==
"+")
210 dblVal = dblLeft + dblRight;
213 else if(strTemp ==
"-")
216 dblVal = dblLeft - dblRight;
219 else if(strTemp ==
"cos")
222 dblVal = cos(dblRight);
225 else if(strTemp ==
"sin")
228 dblVal = sin(dblRight);
231 else if(strTemp ==
"tan")
234 dblVal = tan(dblRight);
237 else if(strTemp ==
"acos")
240 dblVal = acos(dblRight);
243 else if(strTemp ==
"asin")
246 dblVal = asin(dblRight);
249 else if(strTemp ==
"atan")
252 dblVal = atan(dblRight);
255 else if(strTemp ==
"sqrt")
258 if(!dblRight) THROW_ERROR(Std_Err_lSqrtNegNumber, Std_Err_strSqrtNegNumber);
259 dblVal = sqrt(dblRight);
262 else if(strTemp ==
"exp")
265 dblVal = exp(dblRight);
268 else if(strTemp ==
"rnd")
276 dblVal = atof(strTemp.c_str());
283 THROW_ERROR(Std_Err_lToManyParamsLeft, Std_Err_strToManyParamsLeft);
299 long lSize = strEqu.length();
305 for(i=0; i<lSize; i++)
317 if(strTemp.length() > 0)
338 THROW_PARAM_ERROR(Std_Err_lInvalidNumParams, Std_Err_strInvalidNumParams,
"NumParams", iNumParams);
void AddVariable(std::string strVarName)
Adds a variable.
A variable that is used within the CStdPostFixEval class.
void SavePostFixInArray(std::string &strEqu)
Saves a post fix in array.
CStdStack< double > m_aryStack
Stack of equation parts.
std::string m_strVariable
The variable name.
std::string Equation()
Gets the post-fix equation.
void FillInVariables(CStdArray< std::string > &aryPostFix)
Fill in variables.
std::string m_strEquation
The post-fix equation.
double Solution()
Gets the solution.
double m_dblValue
The variable value.
CStdVariable * FindVariable(std::string strVarName)
Searches for the a variable with the specified name.
double m_dblSolution
The double solution value.
virtual ~CStdPostFixEval()
Destructor.
CStdArray< std::string > m_aryPostFix
internal array used to store the equation parts.
void GetParams(double &dblLeft, double &dblRight, int iNumParams)
Gets the parameters.
Namespace for the standard utility objects.
double Std_DRand(double low, double high)
Generates a random number between two values.
double Solve()
Solves the equation using the defined variable values.
void SetVariable(std::string strVarName, double dblVal)
Sets the value of a variable.
CStdPostFixEval()
Default constructor.
std::string Std_Replace(std::string strVal, std::string strFind, std::string strReplace)
Replaces a substring with another string.
CStdPtrArray< CStdVariable > m_aryVariables
Array of variables.