|
SXEval 1.0.3
A generic s-expression interpreter library.
|
The SXEval class is used to evaluate s-expressions. More...
#include <SXEval.hpp>
The SXEval class is used to evaluate s-expressions.
It allows user-custom operatinos as well as user-owned variables and encapsulated variables.
It can build an expression tree from a s-expression and evaluate it. It can also compute the result of an expression without building its tree, which is much slower than the evaluation but faster than building the tree. This latter method is useful for quick/unique evaluations without the overhead of building a tree while the former is useful for repeated evaluations of the same expression.
| T | The type of the values handle by the s-expression. The supported types are int, signed char, short int, long int, unsigned int, unsigned char, unsigned long int, float, double and long double. |
|
inline |
Default constructor.
|
inline |
Build the expression tree from a s-expression.
| expression | The expression to parse. |
| resolveEncapsulated | A function to resolve encapsulated variable names to their getter functions. The function should take a string as input and return a function that returns the variable's value when called. If the encapsulated variable is not found, an exception should be thrown. |
| resolveVariable | A function to resolve variable names to their values. The function should take a string as input and return a reference to the variable's value. If the variable is not found, an exception should be thrown. |
| std::runtime_error | if a variable cannot be resolved or if the expression is invalid. |
| void sxeval::SXEval< T >::build | ( | const std::string & | expression, |
| const resolveVariable_t< T > & | resolveVariable = resolveVariable_t<T>(), |
||
| const resolveEncapsulated_t< T > & | resolveEncapsulated = resolveEncapsulated_t<T>() |
||
| ) |
Build the expression tree from a s-expression.
| expression | The expression to parse. |
| resolveVariable | A function to resolve variable names to their values. The function should take a string as input and return a reference to the variable's value. If the variable is not found, an exception should be thrown. |
| resolveEncapsulated | A function to resolve encapsulated variable names to their getter functions. The function should take a string as input and return a function that returns the variable's value when called. If the encapsulated variable is not found, an exception should be thrown. |
| std::runtime_error | if a variable cannot be resolved or if the expression is invalid. |
| T sxeval::SXEval< T >::execute | ( | ) | const |
Compute the result of the expression tree.
| std::runtime_error | if no operations have been registered or if the evaluation fails. |
|
inline |
Compute the result of an expression without building its tree.
| expression | The expression to compute. |
| resolveEncapsulated | A function to resolve encapsulated variable names to their getter functions. The function should take a string as input and return a function that returns the variable's value when called. If the encapsulated variable is not found, an exception should be thrown. |
| resolveVariable | A function to resolve variable names to their values. The function should take a string as input and return a reference to the variable's value. If the variable is not found, an exception should be thrown. |
| std::runtime_error | if a variable cannot be resolved or if the expression is invalid. |
| T sxeval::SXEval< T >::interpret | ( | const std::string & | expression, |
| const resolveVariable_t< T > & | resolveVariable = resolveVariable_t<T>(), |
||
| const resolveEncapsulated_t< T > & | resolveEncapsulated = resolveEncapsulated_t<T>() |
||
| ) | const |
Compute the result of an expression without building its tree.
| expression | The expression to compute. |
| resolveVariable | A function to resolve variable names to their values. The function should take a string as input and return a reference to the variable's value. If the variable is not found, an exception should be thrown. |
| resolveEncapsulated | A function to resolve encapsulated variable names to their getter functions. The function should take a string as input and return a function that returns the variable's value when called. If the encapsulated variable is not found, an exception should be thrown. |
| std::runtime_error | if a variable cannot be resolved or if the expression is invalid. |
Register an operation.
| OP | The operation to register. The operation must inherit from sxeval::AOperation<T>. |
| std::string sxeval::SXEval< T >::toString | ( | ) | const |
Convert the expression tree to a string representation.