Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

/home/jeroen/FOX/fox/fox-1.7.33/include/FXExpression.h
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,2012 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 #ifndef FXEXPRESSION_H
00022 #define FXEXPRESSION_H
00023 
00024 
00025 namespace FX {
00026 
00027 
00029 enum FXExpressionError {
00030   EXPRERR_OK,
00031   EXPRERR_EMPTY,             
00032   EXPRERR_MEMORY,            
00033   EXPRERR_PAREN,             
00034   EXPRERR_TOKEN,             
00035   EXPRERR_COMMA,             
00036   EXPRERR_IDENT              
00037   };
00038 
00039 
00041 class FXAPI FXExpression {
00042 private:
00043   FXuchar *code;
00044 private:
00045   static const FXuchar initial[];
00046   static const FXchar *const errors[];
00047 public:
00048 
00050   FXExpression();
00051 
00053   FXExpression(const FXExpression& orig);
00054 
00056   FXExpression(const FXchar* expression,const FXchar* variables=NULL,FXExpressionError* error=NULL);
00057 
00059   FXExpression(const FXString& expression,const FXString& variables=FXString::null,FXExpressionError* error=NULL);
00060 
00062   FXExpression& operator=(const FXExpression& orig);
00063 
00065   FXbool empty() const { return (code==initial); }
00066 
00068   FXdouble evaluate(const FXdouble *args=NULL) const;
00069 
00071   FXExpressionError parse(const FXchar* expression,const FXchar* variables=NULL);
00072 
00074   FXExpressionError parse(const FXString& expression,const FXString& variables=FXString::null);
00075 
00077   static const FXchar* getError(FXExpressionError err){ return errors[err]; }
00078 
00080   friend FXAPI FXStream& operator<<(FXStream& store,const FXExpression& s);
00081   friend FXAPI FXStream& operator>>(FXStream& store,FXExpression& s);
00082 
00084  ~FXExpression();
00085   };
00086 
00087 
00088 // Serialization
00089 extern FXAPI FXStream& operator<<(FXStream& store,const FXExpression& s);
00090 extern FXAPI FXStream& operator>>(FXStream& store,FXExpression& s);
00091 
00092 }
00093 
00094 #endif

Copyright © 1997-2011 Jeroen van der Zijp