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

FXExpression.h
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,2026 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (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 *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXEXPRESSION_H
22 #define FXEXPRESSION_H
23 
24 namespace FX {
25 
26 
88 class FXAPI FXExpression {
89 private:
90  FXuchar *code;
91 private:
92  static const FXuchar initial[];
93  static const FXchar *const errors[];
94 public:
95 
97  enum Error {
98  ErrOK,
108  ErrLong
109  };
110 
111 public:
112 
114  FXExpression();
115 
117  FXExpression(const FXExpression& orig);
118 
120  FXExpression(const FXchar* expression,const FXchar* variables=nullptr,Error* error=nullptr);
121 
123  FXExpression(const FXString& expression,const FXchar* variables=nullptr,Error* error=nullptr);
124 
126  FXExpression(const FXString& expression,const FXString& variables,Error* error=nullptr);
127 
129  FXExpression& operator=(const FXExpression& orig);
130 
132  FXbool empty() const { return (code==initial); }
133 
139  FXdouble evaluate(const FXdouble *args=nullptr) const;
140 
148  Error parse(const FXchar* expression,const FXchar* variables=nullptr);
149  Error parse(const FXString& expression,const FXchar* variables=nullptr);
150  Error parse(const FXString& expression,const FXString& variables);
151 
153  static const FXchar* getError(Error err){ return errors[err]; }
154 
156  friend FXAPI FXStream& operator<<(FXStream& store,const FXExpression& s);
157  friend FXAPI FXStream& operator>>(FXStream& store,FXExpression& s);
158 
160  void clear();
161 
163  ~FXExpression();
164  };
165 
166 
167 // Serialization
168 extern FXAPI FXStream& operator<<(FXStream& store,const FXExpression& s);
169 extern FXAPI FXStream& operator>>(FXStream& store,FXExpression& s);
170 
171 }
172 
173 #endif
More characters after input.
Definition: FXExpression.h:101
Unknown identifier.
Definition: FXExpression.h:106
static const FXchar * getError(Error err)
Returns error code for given error.
Definition: FXExpression.h:153
Illegal token.
Definition: FXExpression.h:104
Out of memory.
Definition: FXExpression.h:102
Expected comma.
Definition: FXExpression.h:105
Empty input.
Definition: FXExpression.h:100
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:81
Definition: FX4Splitter.h:28
Unmatched parentheses.
Definition: FXExpression.h:103
FXbool empty() const
See if expression is empty.
Definition: FXExpression.h:132
Error
Expression error codes.
Definition: FXExpression.h:97
No errors.
Definition: FXExpression.h:99
FXExpression compiles a simple numerical expression into efficient byte-code for repeated evaluation...
Definition: FXExpression.h:88
Expected colon.
Definition: FXExpression.h:107
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2026 Jeroen van der Zijp