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 }
SeExpr2::Expressions::evalStr
const char * evalStr(ExprEvalHandle eeh)
Definition: ExprMultiExpr.cpp:263
SeExpr2::Expressions::Expressions
Expressions()
Definition: ExprMultiExpr.h:58
SeExpr2::Expression::context
const Context & context() const
Definition: Expression.h:216
SeExpr2::Expressions
Definition: ExprMultiExpr.h:49
SeExpr2::DExpression::DExpression
DExpression(const std::string &varName, Expressions &context, const std::string &e, const ExprType &type=ExprType().FP(3), EvaluationStrategy be=defaultEvaluationStrategy)
Definition: ExprMultiExpr.cpp:89
SeExpr2::Expressions::setVariable
void setVariable(VariableHandle handle, double value)
Definition: ExprMultiExpr.h:70
SeExpr2::GlobalVal
Definition: ExprMultiExpr.cpp:22
SeExpr2::Expressions::getExprEvalHandle
ExprEvalHandle getExprEvalHandle(ExprHandle eh)
Definition: ExprMultiExpr.cpp:228
SeExpr2::Expressions::setLoopVariable
void setLoopVariable(VariableSetHandle handle, double value)
Definition: ExprMultiExpr.h:66
SeExpr2::ExprEvalHandle
std::pair< ExprHandle, std::vector< DExpression * > > ExprEvalHandle
Definition: ExprMultiExpr.h:28
SeExpr2::DExpression::operandVars
std::set< GlobalVal * > operandVars
Definition: ExprMultiExpr.h:41
SeExpr2::ExprType
Definition: ExprType.h:39
SeExpr2::Expressions::~Expressions
~Expressions()
Definition: ExprMultiExpr.cpp:145
SeExpr2::Expressions::getErrors
void getErrors(std::vector< std::string > &errors) const
SeExpr2
Definition: Context.h:22
SeExpr2::Expressions::evalFP
const std::vector< double > & evalFP(ExprEvalHandle eeh)
Definition: ExprMultiExpr.cpp:251
SeExpr2::Expressions::resetEval
void resetEval()
Definition: ExprMultiExpr.h:81
SeExpr2::VariableHandle
std::set< GlobalVal * >::iterator VariableHandle
Definition: ExprMultiExpr.h:23
SeExpr2::DExpression::resolveVar
ExprVarRef * resolveVar(const std::string &name) const
Definition: ExprMultiExpr.cpp:111
SeExpr2::DExpression
Definition: ExprMultiExpr.h:30
SeExpr2::Expressions::getLoopVarSetHandle
VariableSetHandle getLoopVarSetHandle(VariableHandle vh)
Definition: ExprMultiExpr.cpp:170
SeExpr2::DExpression::operandExprs
std::set< DExpression * > operandExprs
Definition: ExprMultiExpr.h:40
SeExpr2::DExpression::name
const std::string & name() const
Definition: ExprMultiExpr.cpp:109
SeExpr2::Expressions::AllExprs
std::set< DExpression * > AllExprs
Definition: ExprMultiExpr.h:54
SeExpr2::Expression
main expression class
Definition: Expression.h:76
SeExpr2::DExpression::val
GlobalVal * val
Definition: ExprMultiExpr.h:43
SeExpr2::Expressions::setVariable
void setVariable(VariableHandle handle, double *values, unsigned dim)
Definition: ExprMultiExpr.cpp:199
be
< b ></b >< br >< b ></b ></td >< td > vector constructor< br > vector component access n must be
Definition: userdoc.txt:484
value
For any rgb or hsl value(except for negative s values)
SeExpr2::Expressions::addExternalVariable
VariableHandle addExternalVariable(const std::string &variableName, ExprType seTy)
Definition: ExprMultiExpr.cpp:151
SeExpr2::DExpression::eval
void eval()
Definition: ExprMultiExpr.cpp:132
SeExpr2::ExprHandle
std::set< DExpression * >::iterator ExprHandle
Definition: ExprMultiExpr.h:27
SeExpr2::Expressions::AllExternalVars
std::set< GlobalVal * > AllExternalVars
Definition: ExprMultiExpr.h:55
SeExpr2::Expression::EvaluationStrategy
EvaluationStrategy
Types of evaluation strategies that are available.
Definition: Expression.h:79
SeExpr2::Expressions::exprEvaled
std::set< DExpression * > exprEvaled
Definition: ExprMultiExpr.h:51
SeExpr2::DExpression::context
Expressions & context
Definition: ExprMultiExpr.h:31
SeExpr2::Expression::defaultEvaluationStrategy
static EvaluationStrategy defaultEvaluationStrategy
What evaluation strategy to use by default.
Definition: Expression.h:84
SeExpr2::Expressions::exprToEval
std::set< DExpression * > exprToEval
Definition: ExprMultiExpr.h:50
SeExpr2::Expressions::isValid
bool isValid() const
Definition: ExprMultiExpr.cpp:221
SeExpr2::Expressions::addExpression
ExprHandle addExpression(const std::string &varName, ExprType seTy, const std::string &expr)
Definition: ExprMultiExpr.cpp:164
SeExpr2::VariableSetHandle
std::set< GlobalVal * >::iterator VariableSetHandle
Definition: ExprMultiExpr.h:26
SeExpr2::Expressions::reset
void reset()
Definition: ExprMultiExpr.h:86
SeExpr2::Expressions::setLoopVariable
void setLoopVariable(VariableSetHandle handle, double *values, unsigned dim)
Definition: ExprMultiExpr.cpp:181
SeExpr2::ExprVarRef
abstract class for implementing variable references
Definition: Expression.h:45
Expression.h
expr
</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")