00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_EVAL_NUM_EXPR_H
00027 #define NL_EVAL_NUM_EXPR_H
00028
00029 #include "nel/misc/types_nl.h"
00030
00031 namespace NLMISC
00032 {
00033
00037 class CEvalNumExpr
00038 {
00039 public:
00040 virtual ~CEvalNumExpr() {}
00042 enum TReturnState
00043 {
00044 NoError,
00045 UnkownValue,
00046 ValueError,
00047 UnkownFunction,
00048 FunctionError,
00049 NumberSyntaxError,
00050 UnkownOperator,
00051 MustBeOpen,
00052 MustBeClose,
00053 MustBeComa,
00054 MustBeExpression,
00055 NotUnaryOperator,
00056 MustBeEnd,
00057 MustBeDoubleQuote,
00058 ReturnValueCount
00059 };
00060
00167 TReturnState evalExpression (const char *expression, double &result, int *errorIndex, uint32 userData = 0);
00168
00170 const char* getErrorString (TReturnState state) const;
00171
00172 protected:
00173
00175
00187 virtual TReturnState evalValue (const char *value, double &result, uint32 userData);
00188
00203 virtual TReturnState evalFunction (const char *funcName, double arg0, double &result);
00204 virtual TReturnState evalFunction (const char *funcName, double arg0, double arg1, double &result);
00205
00206 private:
00207
00209
00211 enum TToken
00212 {
00213 Number,
00214 Function1,
00215 Function2,
00216 String,
00217 Operator,
00218 Open,
00219 Close,
00220 Coma,
00221 End,
00222 };
00223
00224
00225 enum TOperator
00226 {
00227 Not = 0,
00228 Tilde,
00229 Mul,
00230 Div,
00231 Remainder,
00232 Plus,
00233 Minus,
00234 ULeftShift,
00235 URightShift,
00236 SLeftShift,
00237 SRightShift,
00238 Inferior,
00239 InferiorEqual,
00240 Superior,
00241 SuperiorEqual,
00242 Equal,
00243 NotEqual,
00244 And,
00245 Or,
00246 Xor,
00247 LogicalAnd,
00248 LogicalOr,
00249 LogicalXor,
00250 OperatorCount,
00251 NotOperator,
00252 ExtOperator,
00253 };
00254
00255
00256 enum TReservedWord
00257 {
00258 Abs = 0,
00259 Acos,
00260 Asin,
00261 Atan,
00262 Atan2,
00263 Ceil,
00264 Cos,
00265 Cosh,
00266 Exp,
00267 Exponent,
00268 Floor,
00269 Int,
00270 Log,
00271 Log10,
00272 Mantissa,
00273 Max,
00274 Min,
00275 Pow,
00276 Rand,
00277 Round,
00278 Sin,
00279 Sinh,
00280 Sq,
00281 Sqrt,
00282 Tan,
00283 Tanh,
00284 ReservedWordCount,
00285 };
00286
00287
00288 enum
00289 {
00290 InternalStringLen = 32,
00291 InternalOperator = 4,
00292 };
00293
00295 TReturnState _State;
00296 const char *_ExprPtr;
00297
00299 TReturnState readDecimal (double &value);
00300
00302 void readIntegerNumberDecimal (double &value);
00303
00305
00307 TReturnState getNextToken (TToken &token);
00308
00310 TReturnState evalExpression (double &result, TToken &nextToken, uint32 userData);
00311
00313 TReservedWord _ReservedWordFound;
00314
00316 char _InternalString[InternalStringLen];
00317 std::string _InternalStlString;
00318 const char *_InternalStringPtr;
00319
00321 double _Value;
00322
00324 TOperator _Op;
00325
00327
00329 static const TToken _ReservedWordToken[ReservedWordCount];
00330 static const char *_ReservedWord[ReservedWordCount];
00331 static const TOperator _OperatorArray[128];
00332 static const bool _StringChar[128];
00333 static const char *_ErrorString[ReturnValueCount];
00334 static const int _OperatorPrecedence[];
00335
00336 public:
00337
00338 bool internalCheck ();
00339 };
00340
00341 }
00342
00343 #endif // NL_EVAL_NUM_EXPR_H