Mathematical equation parser and evaluator with variable and function support.
More...
#include <gin_equationparser.h>
|
| | EquationParser () |
| | EquationParser (const juce::String &equation) |
| | ~EquationParser () |
| void | defineNameChars (const juce::String &chars) |
| void | setEquation (const juce::String &equation) |
| void | clearVariables () |
| void | addVariable (const juce::String &name, double *value) |
| void | setVarFactory (std::function< double *(const char *)> fun) |
| juce::StringArray | getUsedVariables () |
| void | clearConstants () |
| void | addConstant (const juce::String &name, double value) |
| void | addFunction (const juce::String &name, std::function< double(int id, const juce::String &)> fun) |
| void | addFunction (const juce::String &name, std::function< double(int id)> fun) |
| void | addFunction (const juce::String &name, std::function< double(int id, double)> fun) |
| void | addFunction (const juce::String &name, std::function< double(int id, double, double)> fun) |
| void | addFunction (const juce::String &name, std::function< double(int id, double, double, double)> fun) |
| void | addFunction (const juce::String &name, std::function< double(int id, double, double, double, double)> fun) |
| double | evaluate () |
| bool | hasError () const |
| juce::String | getError () const |
Mathematical equation parser and evaluator with variable and function support.
EquationParser provides a flexible system for parsing and evaluating mathematical expressions at runtime. It supports variables, constants, custom functions, and standard mathematical operations. Built on top of muParser library.
Key Features:
- Parse and evaluate mathematical expressions
- Dynamic variable binding (pointers to live values)
- Named constants
- Custom functions with 0-4 parameters or string parameters
- Variable factory for on-demand variable creation
- Comprehensive error handling
- Query which variables are used in an equation
Supported Operations:
- Basic arithmetic: +, -, *, /, ^
- Parentheses for grouping
- Standard math functions (via custom function registration)
- User-defined functions and variables
Usage:
double x = 5.0;
x = 10.0;
void addVariable(const juce::String &name, double *value)
juce::String getError() const
void setEquation(const juce::String &equation)
void addConstant(const juce::String &name, double value)
Custom Functions:
parser.
addFunction(
"myFunc", [](
int id,
double a,
double b) {
return a * a + b;
});
void addFunction(const juce::String &name, std::function< double(int id, const juce::String &)> fun)
- See also
- muParser documentation for expression syntax details
◆ EquationParser() [1/2]
| EquationParser::EquationParser |
( |
| ) |
|
◆ EquationParser() [2/2]
| EquationParser::EquationParser |
( |
const juce::String & | equation | ) |
|
◆ ~EquationParser()
| EquationParser::~EquationParser |
( |
| ) |
|
◆ defineNameChars()
| void EquationParser::defineNameChars |
( |
const juce::String & | chars | ) |
|
◆ setEquation()
| void EquationParser::setEquation |
( |
const juce::String & | equation | ) |
|
◆ clearVariables()
| void EquationParser::clearVariables |
( |
| ) |
|
◆ addVariable()
| void EquationParser::addVariable |
( |
const juce::String & | name, |
|
|
double * | value ) |
◆ setVarFactory()
| void EquationParser::setVarFactory |
( |
std::function< double *(const char *)> | fun | ) |
|
◆ getUsedVariables()
| juce::StringArray EquationParser::getUsedVariables |
( |
| ) |
|
◆ clearConstants()
| void EquationParser::clearConstants |
( |
| ) |
|
◆ addConstant()
| void EquationParser::addConstant |
( |
const juce::String & | name, |
|
|
double | value ) |
◆ addFunction() [1/6]
| void EquationParser::addFunction |
( |
const juce::String & | name, |
|
|
std::function< double(int id, const juce::String &)> | fun ) |
◆ addFunction() [2/6]
| void EquationParser::addFunction |
( |
const juce::String & | name, |
|
|
std::function< double(int id)> | fun ) |
◆ addFunction() [3/6]
| void EquationParser::addFunction |
( |
const juce::String & | name, |
|
|
std::function< double(int id, double)> | fun ) |
◆ addFunction() [4/6]
| void EquationParser::addFunction |
( |
const juce::String & | name, |
|
|
std::function< double(int id, double, double)> | fun ) |
◆ addFunction() [5/6]
| void EquationParser::addFunction |
( |
const juce::String & | name, |
|
|
std::function< double(int id, double, double, double)> | fun ) |
◆ addFunction() [6/6]
| void EquationParser::addFunction |
( |
const juce::String & | name, |
|
|
std::function< double(int id, double, double, double, double)> | fun ) |
◆ evaluate()
| double EquationParser::evaluate |
( |
| ) |
|
◆ hasError()
| bool EquationParser::hasError |
( |
| ) |
const |
◆ getError()
| juce::String EquationParser::getError |
( |
| ) |
const |
The documentation for this class was generated from the following file: