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,2023 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,
102  ErrLong
103  };
104 
105 public:
106 
108  FXExpression();
109 
111  FXExpression(const FXExpression& orig);
112 
114  FXExpression(const FXchar* expression,const FXchar* variables=nullptr,Error* error=nullptr);
115 
117  FXExpression(const FXString& expression,const FXString& variables=FXString::null,Error* error=nullptr);
118 
120  FXExpression& operator=(const FXExpression& orig);
121 
123  FXbool empty() const { return (code==initial); }
124 
130  FXdouble evaluate(const FXdouble *args=nullptr) const;
131 
139  Error parse(const FXchar* expression,const FXchar* variables=nullptr);
140  Error parse(const FXString& expression,const FXString& variables=FXString::null);
141 
143  static const FXchar* getError(Error err){ return errors[err]; }
144 
146  friend FXAPI FXStream& operator<<(FXStream& store,const FXExpression& s);
147  friend FXAPI FXStream& operator>>(FXStream& store,FXExpression& s);
148 
150  void clear();
151 
153  ~FXExpression();
154  };
155 
156 
157 // Serialization
158 extern FXAPI FXStream& operator<<(FXStream& store,const FXExpression& s);
159 extern FXAPI FXStream& operator>>(FXStream& store,FXExpression& s);
160 
161 }
162 
163 #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:143
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:123
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
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2022 Jeroen van der Zijp