OpenShot Audio Library | OpenShotAudio  0.3.1
juce_Expression.h
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2017 - ROLI Ltd.
6 
7  JUCE is an open source library subject to commercial or open-source
8  licensing.
9 
10  The code included in this file is provided under the terms of the ISC license
11  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12  To use, copy, modify, and/or distribute this software for any purpose with or
13  without fee is hereby granted provided that the above copyright notice and
14  this permission notice appear in all copies.
15 
16  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18  DISCLAIMED.
19 
20  ==============================================================================
21 */
22 
23 namespace juce
24 {
25 
26 //==============================================================================
43 class JUCE_API Expression
44 {
45 public:
46  //==============================================================================
48  Expression();
49 
51  ~Expression();
52 
54  Expression (const Expression&);
55 
57  Expression& operator= (const Expression&);
58 
60  Expression (Expression&&) noexcept;
61 
63  Expression& operator= (Expression&&) noexcept;
64 
66  explicit Expression (double constant);
67 
71  Expression (const String& stringToParse, String& parseError);
72 
74  String toString() const;
75 
77  Expression operator+ (const Expression&) const;
79  Expression operator- (const Expression&) const;
81  Expression operator* (const Expression&) const;
83  Expression operator/ (const Expression&) const;
85  Expression operator-() const;
86 
88  static Expression symbol (const String& symbol);
89 
91  static Expression function (const String& functionName, const Array<Expression>& parameters);
92 
102  static Expression parse (String::CharPointerType& stringToParse, String& parseError);
103 
104  //==============================================================================
108  class JUCE_API Scope
109  {
110  public:
111  Scope();
112  virtual ~Scope();
113 
115  virtual String getScopeUID() const;
116 
123  virtual Expression getSymbolValue (const String& symbol) const;
124 
129  virtual double evaluateFunction (const String& functionName,
130  const double* parameters, int numParameters) const;
131 
136  class Visitor
137  {
138  public:
139  virtual ~Visitor() = default;
140  virtual void visit (const Scope&) = 0;
141  };
142 
150  virtual void visitRelativeScope (const String& scopeName, Visitor& visitor) const;
151  };
152 
159  double evaluate() const;
160 
166  double evaluate (const Scope& scope) const;
167 
171  double evaluate (const Scope& scope, String& evaluationError) const;
172 
182  Expression adjustedToGiveNewResult (double targetValue, const Scope& scope) const;
183 
185  struct Symbol
186  {
187  Symbol (const String& scopeUID, const String& symbolName);
188  bool operator== (const Symbol&) const noexcept;
189  bool operator!= (const Symbol&) const noexcept;
190 
193  };
194 
196  Expression withRenamedSymbol (const Symbol& oldSymbol, const String& newName, const Scope& scope) const;
197 
206  bool referencesSymbol (const Symbol& symbol, const Scope& scope) const;
207 
209  bool usesAnySymbols() const;
210 
212  void findReferencedSymbols (Array<Symbol>& results, const Scope& scope) const;
213 
214  //==============================================================================
218  enum Type
219  {
220  constantType,
221  functionType,
222  operatorType,
223  symbolType
224  };
225 
227  Type getType() const noexcept;
228 
230  String getSymbolOrFunction() const;
231 
235  int getNumInputs() const;
236 
240  Expression getInput (int index) const;
241 
242 private:
243  //==============================================================================
244  class Term;
245  struct Helpers;
247 
248  explicit Expression (Term*);
249 };
250 
251 } // namespace juce