00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef SeExprNode_h
00012 #define SeExprNode_h
00013
00014 #ifndef MAKEDEPEND
00015 #include <string.h>
00016 #include <string>
00017 #include <vector>
00018 #endif
00019
00020 #include "SeExpression.h"
00021 #include "SeVec3d.h"
00022
00023 class SeExprFunc;
00024
00026 class SeExprNode {
00027 public:
00028 SeExprNode(const SeExpression* expr);
00030 SeExprNode(const SeExpression* expr, SeExprNode* a);
00031 SeExprNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b);
00032 SeExprNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b, SeExprNode* c);
00033 virtual ~SeExprNode();
00034
00036 bool isVec() const { return _isVec; }
00037
00039 virtual void eval(SeVec3d& v) const;
00040
00042 const SeExpression* expr() const { return _expr; }
00043
00045 const SeExprNode* parent() const { return _parent; }
00047 int numChildren() const { return _children.size(); }
00048 const SeExprNode* child(int i) const { return _children[i]; }
00049 SeExprNode* child(int i) { return _children[i]; }
00050
00052 void addChild(SeExprNode* child);
00053
00055 void addChildren(SeExprNode* surrogate);
00056
00060 virtual bool prep(bool wantVec);
00061
00063 inline void setPosition(const short int startPos,const short int endPos)
00064 {_startPos=startPos;_endPos=endPos;}
00065
00067 inline void addError(const std::string& error)
00068 {_expr->addError(error,_startPos,_endPos);}
00069
00070 protected:
00072 const SeExpression* _expr;
00073
00075 SeExprNode* _parent;
00076
00078 std::vector<SeExprNode*> _children;
00079
00081 bool _isVec;
00082
00084 unsigned short int _startPos,_endPos;
00085 };
00086
00087
00089 class SeExprBlockNode : public SeExprNode
00090 {
00091 public:
00092 SeExprBlockNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00093 SeExprNode(expr, a, b) {}
00094
00095 virtual bool prep(bool wantVec);
00096 virtual void eval(SeVec3d& result) const;
00097 };
00098
00099
00101 class SeExprIfThenElseNode : public SeExprNode
00102 {
00103 public:
00104 SeExprIfThenElseNode(const SeExpression* expr,
00105 SeExprNode* a, SeExprNode* b, SeExprNode* c) :
00106 SeExprNode(expr, a, b, c) {}
00107
00108 virtual bool prep(bool wantVec);
00109 virtual void eval(SeVec3d& result) const;
00110 };
00111
00112
00114 class SeExprAssignNode : public SeExprNode
00115 {
00116 public:
00117 SeExprAssignNode(const SeExpression* expr, const char* name, SeExprNode* e) :
00118 SeExprNode(expr, e), _name(name), _var(0) {}
00119
00120 virtual bool prep(bool wantVec);
00121 virtual void eval(SeVec3d& result) const;
00122
00123 private:
00124 const char* _name;
00125 SeExprLocalVarRef* _var;
00126 };
00127
00128
00130 class SeExprVecNode : public SeExprNode
00131 {
00132 public:
00133 SeExprVecNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b, SeExprNode* c) :
00134 SeExprNode(expr, a, b, c) {}
00135
00136 virtual bool prep(bool wantVec);
00137 virtual void eval(SeVec3d& result) const;
00138 };
00139
00140
00142 class SeExprNegNode : public SeExprNode
00143 {
00144 public:
00145 SeExprNegNode(const SeExpression* expr, SeExprNode* a) :
00146 SeExprNode(expr, a) {}
00147
00148 virtual void eval(SeVec3d& result) const;
00149 };
00150
00152 class SeExprInvertNode : public SeExprNode
00153 {
00154 public:
00155 SeExprInvertNode(const SeExpression* expr, SeExprNode* a) :
00156 SeExprNode(expr, a) {}
00157
00158 virtual void eval(SeVec3d& result) const;
00159 };
00160
00161
00163 class SeExprNotNode : public SeExprNode
00164 {
00165 public:
00166 SeExprNotNode(const SeExpression* expr, SeExprNode* a) :
00167 SeExprNode(expr, a) {}
00168
00169 virtual void eval(SeVec3d& result) const;
00170 };
00171
00172
00174 class SeExprCondNode : public SeExprNode
00175 {
00176 public:
00177 SeExprCondNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b, SeExprNode* c) :
00178 SeExprNode(expr, a, b, c) {}
00179
00180 virtual bool prep(bool wantVec);
00181 virtual void eval(SeVec3d& result) const;
00182 };
00183
00184
00186 class SeExprAndNode : public SeExprNode
00187 {
00188 public:
00189 SeExprAndNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00190 SeExprNode(expr, a, b) {}
00191
00192 virtual bool prep(bool wantVec);
00193 virtual void eval(SeVec3d& result) const;
00194 };
00195
00196
00198 class SeExprOrNode : public SeExprNode
00199 {
00200 public:
00201 SeExprOrNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00202 SeExprNode(expr, a, b) {}
00203
00204 virtual bool prep(bool wantVec);
00205 virtual void eval(SeVec3d& result) const;
00206 };
00207
00208
00210 class SeExprSubscriptNode : public SeExprNode
00211 {
00212 public:
00213 SeExprSubscriptNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00214 SeExprNode(expr, a, b) {}
00215
00216 virtual bool prep(bool wantVec);
00217 virtual void eval(SeVec3d& result) const;
00218 };
00219
00220
00222 class SeExprCompareEqNode : public SeExprNode
00223 {
00224 public:
00225 SeExprCompareEqNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00226 SeExprNode(expr, a, b) {}
00227
00228 virtual bool prep(bool wantVec);
00229 };
00230
00231
00233 class SeExprCompareNode : public SeExprNode
00234 {
00235 public:
00236 SeExprCompareNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00237 SeExprNode(expr, a, b) {}
00238
00239 virtual bool prep(bool wantVec);
00240 };
00241
00242
00244 class SeExprEqNode : public SeExprCompareEqNode
00245 {
00246 public:
00247 SeExprEqNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00248 SeExprCompareEqNode(expr, a, b) {}
00249
00250 virtual void eval(SeVec3d& result) const;
00251 };
00252
00253
00255 class SeExprNeNode : public SeExprCompareEqNode
00256 {
00257 public:
00258 SeExprNeNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00259 SeExprCompareEqNode(expr, a, b) {}
00260
00261 virtual void eval(SeVec3d& result) const;
00262 };
00263
00264
00266 class SeExprLtNode : public SeExprCompareNode
00267 {
00268 public:
00269 SeExprLtNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00270 SeExprCompareNode(expr, a, b) {}
00271
00272 virtual void eval(SeVec3d& result) const;
00273 };
00274
00275
00277 class SeExprGtNode : public SeExprCompareNode
00278 {
00279 public:
00280 SeExprGtNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00281 SeExprCompareNode(expr, a, b) {}
00282
00283 virtual void eval(SeVec3d& result) const;
00284 };
00285
00286
00288 class SeExprLeNode : public SeExprCompareNode
00289 {
00290 public:
00291 SeExprLeNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00292 SeExprCompareNode(expr, a, b) {}
00293
00294 virtual void eval(SeVec3d& result) const;
00295 };
00296
00297
00299 class SeExprGeNode : public SeExprCompareNode
00300 {
00301 public:
00302 SeExprGeNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00303 SeExprCompareNode(expr, a, b) {}
00304
00305 virtual void eval(SeVec3d& result) const;
00306 };
00307
00308
00310 class SeExprAddNode : public SeExprNode
00311 {
00312 public:
00313 SeExprAddNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00314 SeExprNode(expr, a, b) {}
00315
00316 virtual void eval(SeVec3d& result) const;
00317 };
00318
00319
00321 class SeExprSubNode : public SeExprNode
00322 {
00323 public:
00324 SeExprSubNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00325 SeExprNode(expr, a, b) {}
00326
00327 virtual void eval(SeVec3d& result) const;
00328 };
00329
00330
00332 class SeExprMulNode : public SeExprNode
00333 {
00334 public:
00335 SeExprMulNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00336 SeExprNode(expr, a, b) {}
00337
00338 virtual void eval(SeVec3d& result) const;
00339 };
00340
00341
00343 class SeExprDivNode : public SeExprNode
00344 {
00345 public:
00346 SeExprDivNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00347 SeExprNode(expr, a, b) {}
00348
00349 virtual void eval(SeVec3d& result) const;
00350 };
00351
00352
00354 class SeExprModNode : public SeExprNode
00355 {
00356 public:
00357 SeExprModNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00358 SeExprNode(expr, a, b) {}
00359
00360 virtual void eval(SeVec3d& result) const;
00361 };
00362
00363
00365 class SeExprExpNode : public SeExprNode
00366 {
00367 public:
00368 SeExprExpNode(const SeExpression* expr, SeExprNode* a, SeExprNode* b) :
00369 SeExprNode(expr, a, b) {}
00370
00371 virtual void eval(SeVec3d& result) const;
00372 };
00373
00375 class SeExprVarNode : public SeExprNode
00376 {
00377 public:
00378 SeExprVarNode(const SeExpression* expr, const char* name) :
00379 SeExprNode(expr), _name(name), _var(0), _data(0)
00380 { expr->addVar(name); }
00381
00382 virtual bool prep(bool wantVec);
00383 virtual void eval(SeVec3d& result) const;
00384 const char* name() const { return _name; }
00385
00387 struct Data { virtual ~Data() {} };
00388 void setData(Data* data) const { _data = data; }
00389 Data* getData() const { return _data; }
00390
00391 private:
00392 const char* _name;
00393 SeExprVarRef* _var;
00394 mutable Data* _data;
00395 };
00396
00397
00399 class SeExprNumNode : public SeExprNode
00400 {
00401 public:
00402 SeExprNumNode(const SeExpression* expr, double val) :
00403 SeExprNode(expr), _val(val) {}
00404
00405 virtual void eval(SeVec3d& result) const { result[0] = _val; }
00406
00407 private:
00408 double _val;
00409 };
00410
00411
00413 class SeExprStrNode : public SeExprNode
00414 {
00415 public:
00416 SeExprStrNode(const SeExpression* expr, const char* str) :
00417 SeExprNode(expr), _str(str) {}
00418
00419 virtual bool prep(bool )
00420 { addError("Invalid string parameter: "+_str); return 0; }
00421
00422 virtual void eval(SeVec3d& result) const { result[0] = 0; }
00423 const char* str() const { return _str.c_str(); }
00424
00425 private:
00426 std::string _str;
00427 };
00428
00429
00431 class SeExprFuncNode : public SeExprNode
00432 {
00433 public:
00434 SeExprFuncNode(const SeExpression* expr, const char* name) :
00435 SeExprNode(expr), _name(name), _func(0), _nargs(0), _data(0)
00436 {
00437 expr->addFunc(name);
00438 }
00439 virtual ~SeExprFuncNode() { delete _data; }
00440
00441 virtual bool prep(bool wantVec);
00442 virtual void eval(SeVec3d& result) const;
00443 void setIsVec(bool isVec) { _isVec = isVec; }
00444 const char* name() const { return _name.c_str(); }
00445
00446
00448 int nargs() const { return _nargs; }
00449
00450 double* scalarArgs() const { return &_scalarArgs[0]; }
00451 SeVec3d* vecArgs() const { return &_vecArgs[0]; }
00452
00454 SeVec3d* evalArgs() const;
00455
00457 SeVec3d evalArg(int n) const;
00458
00460 bool isStrArg(int n) const;
00461
00463 std::string getStrArg(int n) const;
00464
00466 struct Data { virtual ~Data() {} };
00467
00469
00470
00471
00472
00473
00474
00475
00476 void setData(Data* data) const { _data = data; }
00477
00479
00480
00481
00482
00483 Data* getData() const { return _data; }
00484
00485 private:
00486 std::string _name;
00487 const SeExprFunc* _func;
00488 int _nargs;
00489 mutable std::vector<double> _scalarArgs;
00490 mutable std::vector<SeVec3d> _vecArgs;
00491 mutable Data* _data;
00492 };
00493
00494 #endif