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
19namespace SeExpr2 {
20
21class DExpression;
22class GlobalVal;
23class Expressions;
24
25typedef std::set<GlobalVal*>::iterator VariableHandle;
26typedef std::set<GlobalVal*>::iterator VariableSetHandle;
27typedef std::set<DExpression*>::iterator ExprHandle;
28typedef std::pair<ExprHandle, std::vector<DExpression*> > ExprEvalHandle;
29
30class 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
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);
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);
68
69 void setVariable(VariableHandle handle, double* values, unsigned dim);
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
ExprVarRef * resolveVar(const std::string &name) const
const std::string & name() const
Expressions & context
std::set< GlobalVal * > operandVars
abstract class for implementing variable references
Definition Expression.h:45
main expression class
Definition Expression.h:76
EvaluationStrategy
Types of evaluation strategies that are available.
Definition Expression.h:79
static EvaluationStrategy defaultEvaluationStrategy
What evaluation strategy to use by default.
Definition Expression.h:84
VariableSetHandle getLoopVarSetHandle(VariableHandle vh)
const std::vector< double > & evalFP(ExprEvalHandle eeh)
void getErrors(std::vector< std::string > &errors) const
void setLoopVariable(VariableSetHandle handle, double *values, unsigned dim)
std::set< GlobalVal * > AllExternalVars
ExprEvalHandle getExprEvalHandle(ExprHandle eh)
void setLoopVariable(VariableSetHandle handle, double value)
void setVariable(VariableHandle handle, double value)
ExprHandle addExpression(const std::string &varName, ExprType seTy, const std::string &expr)
std::set< DExpression * > exprEvaled
const char * evalStr(ExprEvalHandle eeh)
std::set< DExpression * > exprToEval
void setVariable(VariableHandle handle, double *values, unsigned dim)
std::set< DExpression * > AllExprs
VariableHandle addExternalVariable(const std::string &variableName, ExprType seTy)
std::set< GlobalVal * >::iterator VariableSetHandle
std::set< GlobalVal * >::iterator VariableHandle
std::pair< ExprHandle, std::vector< DExpression * > > ExprEvalHandle
std::set< DExpression * >::iterator ExprHandle
</pre >< h3 > Binding our variable reference</h3 > If we now tried to use the variable would still not be found by our expressions To make it bindable we need to override the resolveVar() function as follows</pre >< h3 > Variable setting</h3 > Next we need to make a way of setting the variable As the controlling code will use the expression it will repeatedly alternate between setting the independent variables that are used and calling evaluate(). What it has to do depends very much on the application. In this case we only need to set the independent variable x as</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")
For any rgb or hsl value(except for negative s values)