00001 /* 00002 * (c) Disney Enterprises, Inc. All rights reserved. 00003 * 00004 * This file is licensed under the terms of the Microsoft Public License (MS-PL) 00005 * as defined at: http://opensource.org/licenses/MS-PL. 00006 * 00007 * A complete copy of this license is included in this distribution as the file 00008 * LICENSE. 00009 * 00010 * @file SeExprEdExpression.h 00011 * @brief A basic expression context for the expression previewer 00012 * @author aselle 00013 */ 00014 00015 #ifndef SeExprEdExpression_h 00016 #define SeExprEdExpression_h 00017 00018 #include <map> 00019 #include <SeExpression.h> 00020 #include <SeExprFunc.h> 00021 #include <SeExprNode.h> 00022 #include <SeExprMacros.h> 00023 00024 class SeExprEdExpression : public SeExpression 00025 { 00026 public: 00027 struct ScalarRef : public SeExprScalarVarRef { 00028 double value; 00029 ScalarRef() 00030 : value(0.0) {} 00031 virtual void eval(const SeExprVarNode* node, SeVec3d& result) { 00032 UNUSED(node); 00033 result = value; 00034 } 00035 }; 00036 00037 struct VectorRef : public SeExprVectorVarRef { 00038 SeVec3d value; 00039 VectorRef() 00040 : value(0.0) {} 00041 virtual void eval(const SeExprVarNode* node, SeVec3d& result) { 00042 UNUSED(node); 00043 result = value; 00044 } 00045 }; 00046 00047 struct DummyFuncX:SeExprFuncX 00048 { 00049 DummyFuncX() 00050 :SeExprFuncX(true) 00051 {} 00052 00053 bool prep(SeExprFuncNode* node,bool wantVec) 00054 { 00055 bool valid=true; 00056 for(int i=0;i<node->numChildren();i++){ 00057 if(!node->isStrArg(i)) 00058 valid&=node->child(i)->prep(wantVec); 00059 } 00060 return true;} 00061 void eval(const SeExprFuncNode* node,SeVec3d& result) const 00062 {UNUSED(node); result=SeVec3d();} 00063 } dummyFuncX; 00064 mutable SeExprFunc dummyFunc; 00065 00066 mutable ScalarRef u; 00067 mutable ScalarRef v; 00068 mutable VectorRef P; 00069 00070 typedef std::map<std::string,VectorRef*> VARMAP; 00071 mutable VARMAP varmap; 00072 typedef std::map<std::string,bool> FUNCMAP; 00073 mutable FUNCMAP funcmap; 00074 00075 SeExprEdExpression(const std::string& expr, bool vec); 00076 virtual ~SeExprEdExpression(); 00077 00078 SeExprVarRef* resolveVar(const std::string& name) const; 00079 SeExprFunc* resolveFunc(const std::string& name) const; 00080 void setExpr(const std::string& str); 00081 void clearVars(); 00082 }; 00083 00084 00085 #endif