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

FXExpression.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * E x p r e s s i o n E v a l u a t o r *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1998,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXExpression.h,v 1.13 2006/03/21 01:41:43 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXEXPRESSION_H
25 #define FXEXPRESSION_H
26 
27 
28 namespace FX {
29 
30 
31 /// Expression error codes
32 enum FXExpressionError {
33  EXPRERR_OK,
34  EXPRERR_EMPTY, /// Empty input
35  EXPRERR_MEMORY, /// Out of memory
36  EXPRERR_PAREN, /// Unmatched parentheses
37  EXPRERR_TOKEN, /// Illegal token
38  EXPRERR_COMMA, /// Expected comma
39  EXPRERR_IDENT /// Unknown identifier
40  };
41 
42 
43 /// Expression
44 class FXAPI FXExpression {
45 private:
46  FXuchar *code;
47 private:
48  static const FXuchar initial[];
49  static const FXchar *const errors[];
50 public:
51 
52  /// Construct empty expression object
53  FXExpression();
54 
55  /// Copy expression object
56  FXExpression(const FXExpression& orig);
57 
58  /// Compile expression; if error is not NULL, error code is returned
59  FXExpression(const FXchar* expression,const FXchar* variables=NULL,FXExpressionError* error=NULL);
60 
61  /// Compile expression; if error is not NULL, error code is returned
62  FXExpression(const FXString& expression,const FXString& variables=FXString::null,FXExpressionError* error=NULL);
63 
64  /// Assign another expression to this one
65  FXExpression& operator=(const FXExpression& orig);
66 
67  /// See if expression is empty
68  bool empty() const { return (code==initial); }
69 
70  /// Evaluate expression with given arguments, if any
71  FXdouble evaluate(const FXdouble *args=NULL);
72 
73  /// Parse expression, return error code if syntax error is found
74  FXExpressionError parse(const FXchar* expression,const FXchar* variables=NULL);
75 
76  /// Parse expression, return error code if syntax error is found
77  FXExpressionError parse(const FXString& expression,const FXString& variables=FXString::null);
78 
79  /// Returns error code for given error
80  static const FXchar* getError(FXExpressionError err){ return errors[err]; }
81 
82  /// Delete
84  };
85 
86 }
87 
88 #endif
Definition: FXExpression.h:36
char FXchar
Definition: fxdefs.h:380
Illegal token.
Definition: FXExpression.h:40
Unknown identifier.
Definition: FXExpression.h:42
#define FXAPI
Definition: fxdefs.h:122
#define NULL
Definition: fxdefs.h:41
double FXdouble
Definition: fxdefs.h:392
FXExpressionError
Expression error codes.
Definition: FXExpression.h:35
Definition: FX4Splitter.h:31
Empty input.
Definition: FXExpression.h:37
unsigned char FXuchar
Definition: fxdefs.h:385
static const FXchar null[]
Definition: FXString.h:35
Expected comma.
Definition: FXExpression.h:41
Out of memory.
Definition: FXExpression.h:38
Expression.
Definition: FXExpression.h:52
Unmatched parentheses.
Definition: FXExpression.h:39
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33

Copyright © 1997-2005 Jeroen van der Zijp