Gin
Loading...
Searching...
No Matches
Public Member Functions | List of all members
EquationParser Class Reference

Mathematical equation parser and evaluator with variable and function support. More...

#include <gin_equationparser.h>

Inheritance diagram for EquationParser:

Public Member Functions

 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
 

Detailed Description

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:

Supported Operations:

Usage:

// Add variables
double x = 5.0;
parser.addVariable("x", &x);
// Add constants
parser.addConstant("pi", 3.14159265359);
// Set equation
parser.setEquation("2 * x + pi");
// Evaluate
double result = parser.evaluate(); // Returns 13.14159...
// Change variable and re-evaluate
x = 10.0;
result = parser.evaluate(); // Returns 23.14159...
// Check for errors
if (parser.hasError())
DBG("Error: " + parser.getError());
Mathematical equation parser and evaluator with variable and function support.
Definition gin_equationparser.h:74
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)
double evaluate()
bool hasError() const
A lightweight 2D point class for projects that don't use juce_graphics.
Definition gin_point.h:25

Custom Functions:

parser.addFunction("myFunc", [](int id, double a, double b) {
return a * a + b;
});
parser.setEquation("myFunc(3, 4)");
double result = parser.evaluate(); // Returns 13.0
void addFunction(const juce::String &name, std::function< double(int id, const juce::String &)> fun)
See also
muParser documentation for expression syntax details

Constructor & Destructor Documentation

◆ EquationParser() [1/2]

EquationParser::EquationParser ( )

◆ EquationParser() [2/2]

EquationParser::EquationParser ( const juce::String &  equation)

◆ ~EquationParser()

EquationParser::~EquationParser ( )

Member Function Documentation

◆ 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: