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,2025 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 
83 class FXAPI FXExpression {
84 private:
85  FXuchar *code;
86 private:
87  static const FXuchar initial[];
88  static const FXchar *const errors[];
89 public:
90 
92  enum Error {
93  ErrOK,
103  ErrLong
104  };
105 
106 public:
107 
109  FXExpression();
110 
112  FXExpression(const FXExpression& orig);
113 
115  FXExpression(const FXchar* expression,const FXchar* variables=nullptr,Error* error=nullptr);
116 
118  FXExpression(const FXString& expression,const FXchar* variables=nullptr,Error* error=nullptr);
119 
121  FXExpression(const FXString& expression,const FXString& variables,Error* error=nullptr);
122 
124  FXExpression& operator=(const FXExpression& orig);
125 
127  FXbool empty() const { return (code==initial); }
128 
134  FXdouble evaluate(const FXdouble *args=nullptr) const;
135 
143  Error parse(const FXchar* expression,const FXchar* variables=nullptr);
144  Error parse(const FXString& expression,const FXchar* variables=nullptr);
145  Error parse(const FXString& expression,const FXString& variables);
146 
148  static const FXchar* getError(Error err){ return errors[err]; }
149 
151  friend FXAPI FXStream& operator<<(FXStream& store,const FXExpression& s);
152  friend FXAPI FXStream& operator>>(FXStream& store,FXExpression& s);
153 
155  void clear();
156 
158  ~FXExpression();
159  };
160 
161 
162 // Serialization
163 extern FXAPI FXStream& operator<<(FXStream& store,const FXExpression& s);
164 extern FXAPI FXStream& operator>>(FXStream& store,FXExpression& s);
165 
166 }
167 
168 #endif
More characters after input.
Definition: FXExpression.h:96
Unknown identifier.
Definition: FXExpression.h:101
static const FXchar * getError(Error err)
Returns error code for given error.
Definition: FXExpression.h:148
Illegal token.
Definition: FXExpression.h:99
Out of memory.
Definition: FXExpression.h:97
Expected comma.
Definition: FXExpression.h:100
Empty input.
Definition: FXExpression.h:95
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:98
FXbool empty() const
See if expression is empty.
Definition: FXExpression.h:127
Error
Expression error codes.
Definition: FXExpression.h:92
No errors.
Definition: FXExpression.h:94
Expression compiles a simple numerical expression into efficient byte-code for repeated evaluation...
Definition: FXExpression.h:83
Expected colon.
Definition: FXExpression.h:102
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2022 Jeroen van der Zijp