Loading...
Searching...
No Matches
juce_Expression.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API Expression
{
public:
//==============================================================================
Expression();
~Expression();
Expression (const Expression&);
Expression& operator= (const Expression&);
Expression (Expression&&) noexcept;
Expression& operator= (Expression&&) noexcept;
explicit 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;
static Expression symbol (const String& symbol);
static Expression function (const String& functionName, const Array<Expression>& parameters);
static Expression parse (String::CharPointerType& stringToParse, String& parseError);
//==============================================================================
class JUCE_API Scope
{
public:
Scope();
virtual ~Scope();
virtual String getScopeUID() const;
virtual Expression getSymbolValue (const String& symbol) const;
virtual double evaluateFunction (const String& functionName,
const double* parameters, int numParameters) const;
class Visitor
{
public:
virtual ~Visitor() = default;
virtual void visit (const Scope&) = 0;
};
virtual void visitRelativeScope (const String& scopeName, Visitor& visitor) 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;
struct Symbol
{
Symbol (const String& scopeUID, const String& symbolName);
bool operator== (const Symbol&) const noexcept;
bool operator!= (const Symbol&) const noexcept;
String scopeUID;
String symbolName;
};
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;
//==============================================================================
enum Type
{
constantType,
functionType,
operatorType,
symbolType
};
Type getType() const noexcept;
String getSymbolOrFunction() const;
int getNumInputs() const;
Expression getInput (int index) const;
private:
//==============================================================================
class Term;
struct Helpers;
ReferenceCountedObjectPtr<Term> term;
explicit Expression (Term*);
};
} // namespace juce
juce::Array
Definition juce_Array.h:56
juce::Expression::Scope::Visitor
Definition juce_Expression.h:137
juce::Expression::Scope
Definition juce_Expression.h:109
juce::Expression::Scope::getSymbolValue
virtual Expression getSymbolValue(const String &symbol) const
Definition juce_Expression.cpp:1122
juce::Expression::Scope::visitRelativeScope
virtual void visitRelativeScope(const String &scopeName, Visitor &visitor) const
Definition juce_Expression.cpp:1164
juce::Expression::Scope::getScopeUID
virtual String getScopeUID() const
Definition juce_Expression.cpp:1169
juce::Expression::Scope::evaluateFunction
virtual double evaluateFunction(const String &functionName, const double *parameters, int numParameters) const
Definition juce_Expression.cpp:1130
juce::Expression
Definition juce_Expression.h:44
juce::Expression::adjustedToGiveNewResult
Expression adjustedToGiveNewResult(double targetValue, const Scope &scope) const
Definition juce_Expression.cpp:1020
juce::Expression::findReferencedSymbols
void findReferencedSymbols(Array< Symbol > &results, const Scope &scope) const
Definition juce_Expression.cpp:1078
juce::Expression::function
static Expression function(const String &functionName, const Array< Expression > &parameters)
Definition juce_Expression.cpp:1015
juce::Expression::Expression
Expression()
Definition juce_Expression.cpp:926
juce::Expression::usesAnySymbols
bool usesAnySymbols() const
Definition juce_Expression.cpp:1090
juce::Expression::withRenamedSymbol
Expression withRenamedSymbol(const Symbol &oldSymbol, const String &newName, const Scope &scope) const
Definition juce_Expression.cpp:1052
juce::Expression::operator-
Expression operator-(const Expression &) const
Definition juce_Expression.cpp:1009
juce::Expression::evaluate
double evaluate() const
Definition juce_Expression.cpp:983
juce::Expression::parse
static Expression parse(String::CharPointerType &stringToParse, String &parseError)
Definition juce_Expression.cpp:975
juce::Expression::referencesSymbol
bool referencesSymbol(const Symbol &symbol, const Scope &scope) const
Definition juce_Expression.cpp:1064
juce::Expression::symbol
static Expression symbol(const String &symbol)
Definition juce_Expression.cpp:1013
juce::Expression::Type
Type
Definition juce_Expression.h:219
juce::Expression::toString
String toString() const
Definition juce_Expression.cpp:1089
juce::ReferenceCountedObjectPtr
Definition juce_ReferenceCountedObject.h:247
juce::String
Definition juce_String.h:53
juce::Expression::Symbol
Definition juce_Expression.h:186
juce::Expression::Symbol::symbolName
String symbolName
Definition juce_Expression.h:192
juce::Expression::Symbol::scopeUID
String scopeUID
Definition juce_Expression.h:191