OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
juce::Expression Class Reference

`#include <juce_Expression.h>`

## Classes
class | Scope
struct | Symbol

## Public Types
enum | Type { constantType , functionType , operatorType , symbolType }

## Public Member Functions
| Expression ()
| ~Expression ()
| Expression (const Expression &)
Expression & | operator= (const Expression &)
| Expression (Expression &&) noexcept
Expression & | operator= (Expression &&) noexcept
| Expression (double constant)
| Expression (const String &stringToParse, String &parseError)
String | toString () const
Expression | operator+ (const Expression &) const
Expression | operator- (const Expression &) const
Expression | operator* (const Expression &) const
Expression | operator/ (const Expression &) const
Expression | operator- () const
double | evaluate () const
double | evaluate (const Scope &scope) const
double | evaluate (const Scope &scope, String &evaluationError) const
Expression | adjustedToGiveNewResult (double targetValue, const Scope &scope) const
Expression | withRenamedSymbol (const Symbol &oldSymbol, const String &newName, const Scope &scope) const
bool | referencesSymbol (const Symbol &symbol, const Scope &scope) const
bool | usesAnySymbols () const
void | findReferencedSymbols (Array< Symbol > &results, const Scope &scope) const
Type | getType () const noexcept
String | getSymbolOrFunction () const
int | getNumInputs () const
Expression | getInput (int index) const

## Static Public Member Functions
static Expression | symbol (const String &symbol)
static Expression | function (const String &functionName, const Array< Expression > &parameters)
static Expression | parse (String::CharPointerType &stringToParse, String &parseError)

## Detailed Description

A class for dynamically evaluating simple numeric expressions.

This class can parse a simple C-style string expression involving floating point numbers, named symbols and functions. The basic arithmetic operations of +, -, *, / are supported, as well as parentheses, and any alphanumeric identifiers are assumed to be named symbols which will be resolved when the expression is evaluated.

Expressions which use identifiers and functions require a subclass of Expression::Scope to be supplied when evaluating them, and this object is expected to be able to resolve the symbol names and perform the functions that are used.

Definition at line 43 of file juce_Expression.h.

## Member Enumeration Documentation

## ◆ Type

enum juce::Expression::Type

Expression type.

See also
  Expression::getType()

Definition at line 218 of file juce_Expression.h.

## Constructor & Destructor Documentation

## ◆ Expression() [1/5]

juce::Expression::Expression | ( |  | ) |

Creates a simple expression with a value of 0.

Definition at line 926 of file juce_Expression.cpp.

Referenced by adjustedToGiveNewResult(), function(), getInput(), juce::Expression::Scope::getSymbolValue(), operator*(), operator+(), operator-(), operator-(), operator/(), and symbol().

## ◆ ~Expression()

juce::Expression::~Expression | ( |  | ) |

Destructor.

Definition at line 931 of file juce_Expression.cpp.

## ◆ Expression() [2/5]

juce::Expression::Expression | ( | const Expression & | other | ) |

Creates a copy of an expression.

Definition at line 945 of file juce_Expression.cpp.

## ◆ Expression() [3/5]

juce::Expression::Expression | ( | Expression && | other | ) |
| noexcept

Move constructor

Definition at line 956 of file juce_Expression.cpp.

## ◆ Expression() [4/5]

juce::Expression::Expression | ( | double | constant | ) |
| explicit

Creates a simple expression with a specified constant value.

Definition at line 940 of file juce_Expression.cpp.

## ◆ Expression() [5/5]

juce::Expression::Expression | ( | const String & | stringToParse,
|  | String & | parseError )

Attempts to create an expression by parsing a string. Any errors are returned in the parseError argument provided.

Definition at line 967 of file juce_Expression.cpp.

## Member Function Documentation

## ◆ adjustedToGiveNewResult()

Expression juce::Expression::adjustedToGiveNewResult | ( | double | targetValue,
|  | const Scope & | scope ) const

Attempts to return an expression which is a copy of this one, but with a constant adjusted to make the expression resolve to a target value.

E.g. if the expression is "x + 10" and x is 5, then asking for a target value of 8 will return the expression "x + 3". Obviously some expressions can't be reversed in this way, in which case they might just be adjusted by adding a constant to the original expression.

Exceptions

  Expression::EvaluationError |

Definition at line 1020 of file juce_Expression.cpp.

## ◆ evaluate() [1/3]

double juce::Expression::evaluate | ( |  | ) | const

Evaluates this expression, without using a Scope. Without a Scope, no symbols can be used, and only basic functions such as sin, cos, tan, min, max are available. To find out about any errors during evaluation, use the other version of this method which takes a String parameter.

Definition at line 983 of file juce_Expression.cpp.

Referenced by evaluate(), and evaluate().

## ◆ evaluate() [2/3]

double juce::Expression::evaluate | ( | const Scope & | scope | ) | const

Evaluates this expression, providing a scope that should be able to evaluate any symbols or functions that it uses. To find out about any errors during evaluation, use the other version of this method which takes a String parameter.

Definition at line 988 of file juce_Expression.cpp.

## ◆ evaluate() [3/3]

double juce::Expression::evaluate | ( | const Scope & | scope,
|  | String & | evaluationError ) const

Evaluates this expression, providing a scope that should be able to evaluate any symbols or functions that it uses.

Definition at line 994 of file juce_Expression.cpp.

## ◆ findReferencedSymbols()

void juce::Expression::findReferencedSymbols | ( | Array< Symbol > & | results,
|  | const Scope & | scope ) const

Returns a list of all symbols that may be needed to resolve this expression in the given scope.

Definition at line 1078 of file juce_Expression.cpp.

## ◆ function()

Expression juce::Expression::function | ( | const String & | functionName,
|  | const Array< Expression > & | parameters )
| static

Returns an Expression which is a function call.

Definition at line 1015 of file juce_Expression.cpp.

## ◆ getInput()

Expression juce::Expression::getInput | ( | int | index | ) | const

Retrieves one of the inputs to this expression.

See also
  getNumInputs

Definition at line 1094 of file juce_Expression.cpp.

## ◆ getNumInputs()

int juce::Expression::getNumInputs | ( |  | ) | const

Returns the number of inputs to this expression.

See also
  getInput

Definition at line 1093 of file juce_Expression.cpp.

## ◆ getSymbolOrFunction()

String juce::Expression::getSymbolOrFunction | ( |  | ) | const

If this expression is a symbol, function or operator, this returns its identifier.

Definition at line 1092 of file juce_Expression.cpp.

## ◆ getType()

Expression::Type juce::Expression::getType | ( |  | ) | const
| noexcept

Returns the type of this expression.

Definition at line 1091 of file juce_Expression.cpp.

## ◆ operator*()

Expression juce::Expression::operator* | ( | const Expression & | other | ) | const

Returns an expression which is a multiplication operation of two existing expressions.

Definition at line 1010 of file juce_Expression.cpp.

## ◆ operator+()

Expression juce::Expression::operator+ | ( | const Expression & | other | ) | const

Returns an expression which is an addition operation of two existing expressions.

Definition at line 1008 of file juce_Expression.cpp.

## ◆ operator-() [1/2]

Expression juce::Expression::operator- | ( |  | ) | const

Returns an expression which performs a negation operation on an existing expression.

Definition at line 1012 of file juce_Expression.cpp.

## ◆ operator-() [2/2]

Expression juce::Expression::operator- | ( | const Expression & | other | ) | const

Returns an expression which is a subtraction operation of two existing expressions.

Definition at line 1009 of file juce_Expression.cpp.

## ◆ operator/()

Expression juce::Expression::operator/ | ( | const Expression & | other | ) | const

Returns an expression which is a division operation of two existing expressions.

Definition at line 1011 of file juce_Expression.cpp.

## ◆ operator=() [1/2]

Expression & juce::Expression::operator= | ( | const Expression & | other | ) |

Copies another expression.

Definition at line 950 of file juce_Expression.cpp.

## ◆ operator=() [2/2]

Expression & juce::Expression::operator= | ( | Expression && | other | ) |
| noexcept

Move assignment operator

Definition at line 961 of file juce_Expression.cpp.

## ◆ parse()

Expression juce::Expression::parse | ( | String::CharPointerType & | stringToParse,
|  | String & | parseError )
| static

Returns an Expression which parses a string from a character pointer, and updates the pointer to indicate where it finished.

The pointer is incremented so that on return, it indicates the character that follows the end of the expression that was parsed.

If there's a syntax error in parsing, the parseError argument will be set to a description of the problem.

Definition at line 975 of file juce_Expression.cpp.

## ◆ referencesSymbol()

bool juce::Expression::referencesSymbol | ( | const Symbol & | symbol,
|  | const Scope & | scope ) const

Returns true if this expression makes use of the specified symbol. If a suitable scope is supplied, the search will dereference and recursively check all symbols, so that it can be determined whether this expression relies on the given symbol at any level in its evaluation. If the scope parameter is null, this just checks whether the expression contains any direct references to the symbol.

Exceptions

  Expression::EvaluationError |

Definition at line 1064 of file juce_Expression.cpp.

## ◆ symbol()

Expression juce::Expression::symbol | ( | const String & | symbol | ) |
| static

Returns an Expression which is an identifier reference.

Definition at line 1013 of file juce_Expression.cpp.

Referenced by juce::Expression::Scope::getSymbolValue(), and symbol().

## ◆ toString()

String juce::Expression::toString | ( |  | ) | const

Returns a string version of the expression.

Definition at line 1089 of file juce_Expression.cpp.

## ◆ usesAnySymbols()

bool juce::Expression::usesAnySymbols | ( |  | ) | const

Returns true if this expression contains any symbols.

Definition at line 1090 of file juce_Expression.cpp.

## ◆ withRenamedSymbol()

Expression juce::Expression::withRenamedSymbol | ( | const Symbol & | oldSymbol,
|  | const String & | newName,
|  | const Scope & | scope ) const

Returns a copy of this expression in which all instances of a given symbol have been renamed.

Definition at line 1052 of file juce_Expression.cpp.

The documentation for this class was generated from the following files:

- juce_Expression.h
- juce_Expression.cpp