19 #include <SeExpression.h>
22 struct SimpleVar:
public SeExprScalarVarRef
25 void eval(
const SeExprVarNode* ,SeVec3d& result)
31 class GrapherExpr:
public SeExpression
33 const std::map<std::string,SimpleVar>& vars;
36 GrapherExpr(
const std::string&
expr,
const std::map<std::string,SimpleVar>& vars)
37 :SeExpression(expr),vars(vars)
41 void setX(
double x_input)
49 SeExprVarRef*
resolveVar(
const std::string& name)
const
52 if(name ==
"x")
return &
x;
54 std::map<std::string,SimpleVar>::const_iterator i=vars.find(name);
55 if(i!=vars.end())
return const_cast<SimpleVar*>(&i->second);
</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")
virtual void eval(ArgHandle args)
</pre >< h3 > A simple variable reference</h3 > This is not a very interesting subclass of expression until we add some additional variables Variables on some applications may be very dynamic In this we only need x
</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