openshot-audio  0.1.4
juce_Expression.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the juce_core module of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission to use, copy, modify, and/or distribute this software for any purpose with
8  or without fee is hereby granted, provided that the above copyright notice and this
9  permission notice appear in all copies.
10 
11  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
12  TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
13  NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
15  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 
18  ------------------------------------------------------------------------------
19 
20  NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
21  All other JUCE modules are covered by a dual GPL/commercial license, so if you are
22  using any other modules, be sure to check that you also comply with their license.
23 
24  For more details, visit www.juce.com
25 
26  ==============================================================================
27 */
28 
29 #ifndef JUCE_EXPRESSION_H_INCLUDED
30 #define JUCE_EXPRESSION_H_INCLUDED
31 
32 
33 //==============================================================================
49 {
50 public:
51  //==============================================================================
53  Expression();
54 
56  ~Expression();
57 
59  explicit Expression (double constant);
60 
62  Expression (const Expression&);
63 
65  Expression& operator= (const Expression&);
66 
67  #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
69  Expression& operator= (Expression&&) noexcept;
70  #endif
71 
76  explicit Expression (const String& stringToParse);
77 
79  String toString() const;
80 
82  Expression operator+ (const Expression&) const;
84  Expression operator- (const Expression&) const;
86  Expression operator* (const Expression&) const;
88  Expression operator/ (const Expression&) const;
90  Expression operator-() const;
91 
93  static Expression symbol (const String& symbol);
94 
96  static Expression function (const String& functionName, const Array<Expression>& parameters);
97 
107  static Expression parse (String::CharPointerType& stringToParse);
108 
109  //==============================================================================
114  {
115  public:
116  Scope();
117  virtual ~Scope();
118 
120  virtual String getScopeUID() const;
121 
128  virtual Expression getSymbolValue (const String& symbol) const;
129 
134  virtual double evaluateFunction (const String& functionName,
135  const double* parameters, int numParameters) const;
136 
141  class Visitor
142  {
143  public:
144  virtual ~Visitor() {}
145  virtual void visit (const Scope&) = 0;
146  };
147 
155  virtual void visitRelativeScope (const String& scopeName, Visitor& visitor) const;
156  };
157 
164  double evaluate() const;
165 
171  double evaluate (const Scope& scope) const;
172 
176  double evaluate (const Scope& scope, String& evaluationError) const;
177 
187  Expression adjustedToGiveNewResult (double targetValue, const Scope& scope) const;
188 
190  struct Symbol
191  {
192  Symbol (const String& scopeUID, const String& symbolName);
193  bool operator== (const Symbol&) const noexcept;
194  bool operator!= (const Symbol&) const noexcept;
195 
198  };
199 
201  Expression withRenamedSymbol (const Symbol& oldSymbol, const String& newName, const Scope& scope) const;
202 
211  bool referencesSymbol (const Symbol& symbol, const Scope& scope) const;
212 
214  bool usesAnySymbols() const;
215 
217  void findReferencedSymbols (Array<Symbol>& results, const Scope& scope) const;
218 
219  //==============================================================================
221  class ParseError : public std::exception
222  {
223  public:
224  ParseError (const String& message);
225 
227  };
228 
229  //==============================================================================
233  enum Type
234  {
238  symbolType
239  };
240 
242  Type getType() const noexcept;
243 
245  String getSymbolOrFunction() const;
246 
250  int getNumInputs() const;
251 
255  Expression getInput (int index) const;
256 
257 private:
258  //==============================================================================
259  class Term;
260  struct Helpers;
261  friend class Term;
262  friend struct Helpers;
263  friend struct ContainerDeletePolicy<Term>;
264  friend class ReferenceCountedObjectPtr<Term>;
265  ReferenceCountedObjectPtr<Term> term;
266 
267  explicit Expression (Term*);
268 };
269 
270 #endif // JUCE_EXPRESSION_H_INCLUDED
#define noexcept
Definition: juce_CompilerSupport.h:141
Definition: juce_Expression.h:141
Definition: juce_Expression.h:113
Definition: juce_String.h:43
Definition: juce_Expression.h:237
#define JUCE_API
Definition: juce_StandardHeader.h:139
Definition: juce_Expression.h:190
Definition: juce_Expression.h:221
Definition: juce_Expression.h:48
String scopeUID
Definition: juce_Expression.h:196
Definition: juce_ReferenceCountedObject.h:227
String symbolName
Definition: juce_Expression.h:197
Type
Definition: juce_Expression.h:233
bool operator==(const var &v1, const var &v2) noexcept
Definition: juce_Variant.cpp:565
Definition: juce_ContainerDeletePolicy.h:44
virtual ~Visitor()
Definition: juce_Expression.h:144
Definition: juce_Expression.h:235
String description
Definition: juce_Expression.h:226
Definition: juce_Expression.cpp:84
Definition: juce_Expression.h:236
bool operator!=(const var &v1, const var &v2) noexcept
Definition: juce_Variant.cpp:566
Definition: juce_Expression.cpp:29