AQUAgpusph 4.1.2
|
Tool to evaluate math expressions. More...
#include <Tokenizer/Tokenizer.h>
Public Member Functions | |
Tokenizer () | |
Constructor. | |
~Tokenizer () | |
Destructor. | |
bool | registerVariable (const std::string name, float value) |
Register a variable. | |
void | clearVariables () |
Clear/unregister all the registered variables. | |
bool | isVariable (const std::string name) |
Checks if a variable has been registered. | |
float | variable (const std::string name) |
Returns a variable value. | |
float | solve (const std::string eq) |
Solve a math expression. | |
Protected Member Functions | |
virtual void | defaultVariables () |
Register the default variables. | |
Tool to evaluate math expressions.
This tool is based in libmatheval, to learn more please visit the following web page:
Aqua::Tokenizer::Tokenizer | ( | ) |
Constructor.
Aqua::Tokenizer::~Tokenizer | ( | ) |
Destructor.
void Aqua::Tokenizer::clearVariables | ( | ) |
Clear/unregister all the registered variables.
|
protectedvirtual |
Register the default variables.
After the libmatheval implementation, variables like \( e \) or \( \pi \) are defined out of the box, but the function is retained just in case.
bool Aqua::Tokenizer::isVariable | ( | const std::string | name | ) |
Checks if a variable has been registered.
name | Name of the variable |
bool Aqua::Tokenizer::registerVariable | ( | const std::string | name, |
float | value | ||
) |
Register a variable.
In case that the variable already exist, it will be modified.
The registered variables can be used later in the expression to be evaluated.
name | Name of the variable. |
value | Value of the variable. |
float Aqua::Tokenizer::solve | ( | const std::string | eq | ) |
Solve a math expression.
eq | Math expression to solve. |
float Aqua::Tokenizer::variable | ( | const std::string | name | ) |
Returns a variable value.
name | Name of the variable |