SeExpr
ExprMultiExpr.h
Go to the documentation of this file.
1 /*
2  Copyright Disney Enterprises, Inc. All rights reserved.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License
6  and the following modification to it: Section 6 Trademarks.
7  deleted and replaced with:
8 
9  6. Trademarks. This License does not grant permission to use the
10  trade names, trademarks, service marks, or product names of the
11  Licensor and its affiliates, except as required for reproducing
12  the content of the NOTICE file.
13 
14  You may obtain a copy of the License at
15  http://www.apache.org/licenses/LICENSE-2.0
16 */
17 #include "Expression.h"
18 
19 namespace SeExpr2 {
20 
21 class DExpression;
22 class GlobalVal;
24 
25 typedef std::set<GlobalVal*>::iterator VariableHandle;
26 typedef std::set<GlobalVal*>::iterator VariableSetHandle;
27 typedef std::set<DExpression*>::iterator ExprHandle;
28 typedef std::pair<ExprHandle, std::vector<DExpression*> > ExprEvalHandle;
29 
30 class DExpression : public Expression {
32 
33  public:
34  DExpression(const std::string& varName,
36  const std::string& e,
37  const ExprType& type = ExprType().FP(3),
39 
40  mutable std::set<DExpression*> operandExprs;
41  mutable std::set<GlobalVal*> operandVars;
42 
44  const std::string& name() const;
45  ExprVarRef* resolveVar(const std::string& name) const;
46  void eval();
47 };
48 
49 class Expressions {
50  std::set<DExpression*> exprToEval;
51  std::set<DExpression*> exprEvaled;
52 
53  public:
54  std::set<DExpression*> AllExprs;
55  std::set<GlobalVal*> AllExternalVars;
56 
57  // Expressions(int numberOfEvals=1);
59  ~Expressions();
60 
61  VariableHandle addExternalVariable(const std::string& variableName, ExprType seTy);
62  ExprHandle addExpression(const std::string& varName, ExprType seTy, const std::string& expr);
63 
65  void setLoopVariable(VariableSetHandle handle, double* values, unsigned dim);
66  void setLoopVariable(VariableSetHandle handle, double value) { setLoopVariable(handle, &value, 1); }
67  void setLoopVariable(VariableSetHandle handle, const char* values);
68 
69  void setVariable(VariableHandle handle, double* values, unsigned dim);
70  void setVariable(VariableHandle handle, double value) { setVariable(handle, &value, 1); }
71  void setVariable(VariableHandle handle, const char* values);
72 
73  bool isValid() const;
74  void getErrors(std::vector<std::string>& errors) const;
75  // bool isVariableUsed(VariableHandle variableHandle) const;
76 
78  const std::vector<double>& evalFP(ExprEvalHandle eeh);
79  const char* evalStr(ExprEvalHandle eeh);
80 
81  void resetEval() {
82  exprToEval.clear();
83  exprEvaled.clear();
84  }
85 
86  void reset() {
87  resetEval();
88  AllExprs.clear();
89  AllExternalVars.clear();
90  }
91 };
92 }
std::set< DExpression * > operandExprs
Definition: ExprMultiExpr.h:40
EvaluationStrategy
Types of evaluation strategies that are available.
Definition: Expression.h:79
</pre >< h2 > Evaluating expressions</h2 > Evaluating an expression is pretty easy But before we can do that we need to make an instance< pre > GrapherExpr expr("x+x^2")
VariableHandle addExternalVariable(const std::string &variableName, ExprType seTy)
void setVariable(VariableHandle handle, double *values, unsigned dim)
std::set< GlobalVal * > AllExternalVars
Definition: ExprMultiExpr.h:55
std::pair< ExprHandle, std::vector< DExpression * > > ExprEvalHandle
Definition: ExprMultiExpr.h:28
ExprHandle addExpression(const std::string &varName, ExprType seTy, const std::string &expr)
Expressions & context
Definition: ExprMultiExpr.h:31
std::set< GlobalVal * >::iterator VariableHandle
Definition: ExprMultiExpr.h:23
std::set< DExpression * > exprToEval
Definition: ExprMultiExpr.h:50
std::set< DExpression * > exprEvaled
Definition: ExprMultiExpr.h:51
void setLoopVariable(VariableSetHandle handle, double *values, unsigned dim)
For any rgb or hsl value(except for negative s values)
const Context & context() const
Definition: Expression.h:216
void setVariable(VariableHandle handle, double value)
Definition: ExprMultiExpr.h:70
const char * evalStr(ExprEvalHandle eeh)
void setLoopVariable(VariableSetHandle handle, double value)
Definition: ExprMultiExpr.h:66
main expression class
Definition: Expression.h:76
std::set< DExpression * >::iterator ExprHandle
Definition: ExprMultiExpr.h:27
ExprEvalHandle getExprEvalHandle(ExprHandle eh)
DExpression(const std::string &varName, Expressions &context, const std::string &e, const ExprType &type=ExprType().FP(3), EvaluationStrategy be=defaultEvaluationStrategy)
< b ></b >< br >< b ></b ></td >< td > vector constructor< br > vector component access n must be
Definition: userdoc.txt:504
const std::string & name() const
void getErrors(std::vector< std::string > &errors) const
std::set< GlobalVal * >::iterator VariableSetHandle
Definition: ExprMultiExpr.h:26
std::set< GlobalVal * > operandVars
Definition: ExprMultiExpr.h:41
VariableSetHandle getLoopVarSetHandle(VariableHandle vh)
static EvaluationStrategy defaultEvaluationStrategy
What evaluation strategy to use by default.
Definition: Expression.h:84
abstract class for implementing variable references
Definition: Expression.h:45
const std::vector< double > & evalFP(ExprEvalHandle eeh)
ExprVarRef * resolveVar(const std::string &name) const
std::set< DExpression * > AllExprs
Definition: ExprMultiExpr.h:54