26 #include <SeExpr2/ExprNode.h>
27 #include <SeExpr2/ExprPatterns.h>
33 std::vector<const ControlSpec*>::iterator i =
_specList.begin();
34 std::vector<const ControlSpec*>::iterator
const e =
_specList.end();
35 for (; i != e; ++i)
delete *i;
68 inline bool isWS(
const char*
source,
int start,
int end) {
69 for (
int i = start; i < end; ++i)
70 if (source[i] !=
'\n')
return false;
77 typedef std::vector<std::pair<int, int> > Comments;
79 const std::string& s = expr.
getExpr();
82 for (Comments::const_iterator i = comments.begin(); i != comments.end(); ++i) {
84 return s.substr(i->first, i->second - i->first + 1);
94 int numParsed = sscanf(comment.c_str(),
"#%lf,%lf\n", &
_min, &
_max);
102 std::stringstream ss;
122 int numParsed = sscanf(comment.c_str(),
"#%lf,%lf\n", &
_min, &
_max);
123 if (numParsed != 2) {
130 std::stringstream ss;
145 for (
int i = 1; i < num - 2; i += 3)
147 static_cast<const ExprNumNode*>(cnode->
child(i))->
value(),
162 std::stringstream ss;
165 <<
"curve(" << _lookupText;
166 int num = _vec.size();
167 for (
int i = 0; i < num; ++i) ss << _vec[i]._pos << _vec[i]._val << (
int)_vec[i]._interp;
182 ExprCcurveAssignSpec::
190 int num = cnode->numChildren();
191 for(
int i = 1; i < num - 2; i += 3)
192 if(dynamic_cast<const ExprNumNode*>(cnode->child(i+1)))
194 static_cast<const ExprNumNode*>(cnode->child(i))->
value(),
200 ExprCcurveAssignSpec::toString()
const
202 std::stringstream ss;
208 int num = _vec.size();
209 for(
int i = 0; i < num; ++i)
215 << (
int)_vec[i]._interp;
221 const ExprCcurveAssignSpec*
222 ExprCcurveAssignSpec::match(
const ExprNode* node)
225 return new ExprCcurveAssignSpec(*assign);
234 std::stringstream ss;
256 char* name =
new char[comment.length() + 1];
257 char* type =
new char[comment.length() + 1];
258 int numMatched = sscanf(comment.c_str(),
"#%s %s\n", type, name);
261 if (numMatched == 2) {
263 if (!strcmp(type,
"string"))
265 else if (!strcmp(type,
"file"))
267 else if (!strcmp(type,
"directory"))
271 if (valid)
return new ExprStrSpec(*strnode, name, newType);
bool isWS(const char *source, int start, int end)
Returns true if no newline separates comment and node.
const ExprAssignNode * isVectorAssign(const ExprNode *testee)
std::string findComment(const ExprNode &node)
Checks if there is whitespace in the range specified in the string.
ExprStrSpec(const ExprStrNode &node, char *name, Type type)
Takes name and type comments and takes ownership of them!
const ExprAssignNode * isCcurveAssign(const ExprNode *testee)
virtual std::string toString() const
Generates a replacement string based on changes to the spec.
</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")
const ExprStrNode * isString(const ExprNode *testee)
static const ExprCurveAssignSpec * match(const ExprNode *node)
Variable equals scalar control specification.
static const ExprVectorAssignSpec * match(const ExprNode *node)
double _min
Range of values.
short int endPos() const
Access end position in input string.
double _min
Range of values.
Variable equals vector control specification.
Node that stores a string.
Generic Expression control specification.
std::string _name
Name of control.
const std::vector< std::pair< int, int > > & getComments() const
const ExprAssignNode * isCurveAssign(const ExprNode *testee)
ExprVectorAssignSpec(const ExprAssignNode &node)
For any rgb or hsl value(except for negative s values)
virtual bool examine(const ExprNode *examinee)
Curve assignment expression. Assignment of curve to a variable.
const std::string & getExpr() const
Get the string that this expression is currently set to evaluate.
Node that calls a function.
ExprScalarAssignSpec(const ExprAssignNode &node)
const Vec3d & value() const
virtual std::string toString() const
Generates a replacement string based on changes to the spec.
const ExprAssignNode * isScalarAssign(const ExprNode *testee)
std::vector< const ControlSpec * >::const_iterator begin() const
ExprCurveAssignSpec(const ExprAssignNode &node)
Node that compute a local variable assignment.
int numChildren() const
Number of children.
Node that stores a numeric constant.
static const ExprScalarAssignSpec * match(const ExprNode *node)
const Expression * expr() const
Access expression.
std::vector< const ControlSpec * > _specList
When x is within< i > range</i > of source
std::string _lookupText
Lookup subexpression text.
virtual std::string toString() const
Generates a replacement string based on changes to the spec.
const ExprNode * child(size_t i) const
Get 0 indexed child.
std::string toString() const
Access to original string representation of current expression.
InterpType
Supported interpolation types.
std::vector< typename Curve< T >::CV > _vec
Control points of curve spline.
static const ExprStrSpec * match(const ExprNode *node)
virtual std::string toString() const
Generates a replacement string based on changes to the spec.
std::vector< const ControlSpec * >::const_iterator const end() const
const std::string & name() const