![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * E x p r e s s i o n E v a l u a t o r * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1998,2009 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU Lesser General Public License as published by * 00010 * the Free Software Foundation; either version 3 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00020 ********************************************************************************* 00021 * $Id: FXExpression.h,v 1.18 2009/01/06 13:07:23 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXEXPRESSION_H 00024 #define FXEXPRESSION_H 00025 00026 00027 namespace FX { 00028 00029 00030 /// Expression error codes 00031 enum FXExpressionError { 00032 EXPRERR_OK, 00033 EXPRERR_EMPTY, /// Empty input 00034 EXPRERR_MEMORY, /// Out of memory 00035 EXPRERR_PAREN, /// Unmatched parentheses 00036 EXPRERR_TOKEN, /// Illegal token 00037 EXPRERR_COMMA, /// Expected comma 00038 EXPRERR_IDENT /// Unknown identifier 00039 }; 00040 00041 00042 /// Expression 00043 class FXAPI FXExpression { 00044 private: 00045 FXuchar *code; 00046 private: 00047 static const FXuchar initial[]; 00048 static const FXchar *const errors[]; 00049 public: 00050 00051 /// Construct empty expression object 00052 FXExpression(); 00053 00054 /// Copy expression object 00055 FXExpression(const FXExpression& orig); 00056 00057 /// Compile expression; if error is not NULL, error code is returned 00058 FXExpression(const FXchar* expression,const FXchar* variables=NULL,FXExpressionError* error=NULL); 00059 00060 /// Compile expression; if error is not NULL, error code is returned 00061 FXExpression(const FXString& expression,const FXString& variables=FXString::null,FXExpressionError* error=NULL); 00062 00063 /// Assign another expression to this one 00064 FXExpression& operator=(const FXExpression& orig); 00065 00066 /// See if expression is empty 00067 FXbool empty() const { return (code==initial); } 00068 00069 /// Evaluate expression with given arguments, if any 00070 FXdouble evaluate(const FXdouble *args=NULL); 00071 00072 /// Parse expression, return error code if syntax error is found 00073 FXExpressionError parse(const FXchar* expression,const FXchar* variables=NULL); 00074 00075 /// Parse expression, return error code if syntax error is found 00076 FXExpressionError parse(const FXString& expression,const FXString& variables=FXString::null); 00077 00078 /// Returns error code for given error 00079 static const FXchar* getError(FXExpressionError err){ return errors[err]; } 00080 00081 /// Delete 00082 ~FXExpression(); 00083 }; 00084 00085 } 00086 00087 #endif
![]() |