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

FXExpression.h

Go to the documentation of this file.
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,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (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 GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXExpression.h,v 1.13 2006/03/21 01:41:43 fox Exp $                      *
00023 ********************************************************************************/
00024 #ifndef FXEXPRESSION_H
00025 #define FXEXPRESSION_H
00026 
00027 
00028 namespace FX {
00029 
00030 
00031 /// Expression error codes
00032 enum FXExpressionError {
00033   EXPRERR_OK,
00034   EXPRERR_EMPTY,             /// Empty input
00035   EXPRERR_MEMORY,            /// Out of memory
00036   EXPRERR_PAREN,             /// Unmatched parentheses
00037   EXPRERR_TOKEN,             /// Illegal token
00038   EXPRERR_COMMA,             /// Expected comma
00039   EXPRERR_IDENT              /// Unknown identifier
00040   };
00041 
00042 
00043 /// Expression
00044 class FXAPI FXExpression {
00045 private:
00046   FXuchar *code;
00047 private:
00048   static const FXuchar initial[];
00049   static const FXchar *const errors[];
00050 public:
00051 
00052   /// Construct empty expression object
00053   FXExpression();
00054 
00055   /// Copy expression object
00056   FXExpression(const FXExpression& orig);
00057 
00058   /// Compile expression; if error is not NULL, error code is returned
00059   FXExpression(const FXchar* expression,const FXchar* variables=NULL,FXExpressionError* error=NULL);
00060 
00061   /// Compile expression; if error is not NULL, error code is returned
00062   FXExpression(const FXString& expression,const FXString& variables=FXString::null,FXExpressionError* error=NULL);
00063 
00064   /// Assign another expression to this one
00065   FXExpression& operator=(const FXExpression& orig);
00066 
00067   /// See if expression is empty
00068   bool empty() const { return (code==initial); }
00069 
00070   /// Evaluate expression with given arguments, if any
00071   FXdouble evaluate(const FXdouble *args=NULL);
00072 
00073   /// Parse expression, return error code if syntax error is found
00074   FXExpressionError parse(const FXchar* expression,const FXchar* variables=NULL);
00075 
00076   /// Parse expression, return error code if syntax error is found
00077   FXExpressionError parse(const FXString& expression,const FXString& variables=FXString::null);
00078 
00079   /// Returns error code for given error
00080   static const FXchar* getError(FXExpressionError err){ return errors[err]; }
00081 
00082   /// Delete
00083  ~FXExpression();
00084   };
00085 
00086 }
00087 
00088 #endif

Copyright © 1997-2005 Jeroen van der Zijp