22#ifndef BasicExpression_h
23#define BasicExpression_h
36 void eval(
const char** result) { assert(
false); }
42 void eval(
double* result) {
43 for (
int k = 0; k < 3; k++) result[k] =
value[k];
45 void eval(
const char** result) {
59 for (
int i = 0; i < nargs; i++)
69 double* out = &args.
outFp;
70 for (
int i = 0; i < 3; i++) out[i] = 0.0;
79 typedef std::map<std::string, VectorRef*>
VARMAP;
81 typedef std::map<std::string, bool>
FUNCMAP;
89 void setExpr(
const std::string& str);
SeExpr2::ExprFunc dummyFunc
SeExpr2::ExprFunc * resolveFunc(const std::string &name) const
virtual ~BasicExpression()
BasicExpression::DummyFuncX dummyFuncX
std::map< std::string, VectorRef * > VARMAP
std::map< std::string, bool > FUNCMAP
BasicExpression(const std::string &expr, const SeExpr2::ExprType &type=SeExpr2::ExprType().FP(3))
void setExpr(const std::string &str)
Node that calls a function.
bool checkArg(int argIndex, ExprType type, ExprVarEnvBuilder &envBuilder)
ExprFuncSimple(const bool threadSafe)
Function Definition, used in parse tree and func table.
int numChildren() const
Number of children.
ExprType & FP(int d)
Mutate this into a floating point type of dimension d.
ExprType & Error()
Mutate this into an error type.
ExprType & Varying()
Mutate this into a varying lifetime.
ExprType & Constant()
Mutate this into a constant lifetime.
Variable scope builder is used by the type checking and code gen to track visiblity of variables and ...
abstract class for implementing variable references
virtual SeExpr2::ExprFuncNode::Data * evalConstant(const SeExpr2::ExprFuncNode *node, ArgHandle args) const
virtual SeExpr2::ExprType prep(SeExpr2::ExprFuncNode *node, bool scalarWanted, SeExpr2::ExprVarEnvBuilder &envBuilder) const
virtual void eval(ArgHandle args)
void eval(double *result)
returns this variable's value by setting result
void eval(const char **result)
void eval(const char **result)
void eval(double *result)
returns this variable's value by setting result
base class for custom instance data
</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")
</pre > Once we have this we need an instance to store our variable and provide a reference to that We make it because resolveVar() is const . One does not need to store a variable reference in a given expression. In fact