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.cpp 00011 * @brief A basic expression context for the expression previewer 00012 * @author aselle 00013 */ 00014 00015 #include "SeExprEdExpression.h" 00016 00017 SeExprEdExpression::SeExprEdExpression(const std::string& expr,bool vec) 00018 :SeExpression(expr,vec),dummyFunc(dummyFuncX,0,16) 00019 {} 00020 00021 SeExprEdExpression::~SeExprEdExpression() 00022 { 00023 clearVars(); 00024 } 00025 00026 template<class T_MAP> void deleteAndClear(T_MAP& map){ 00027 for(typename T_MAP::iterator i=map.begin();i!=map.end();++i) delete i->second; 00028 map.clear(); 00029 } 00030 00031 void SeExprEdExpression::clearVars() 00032 { 00033 deleteAndClear(varmap); 00034 funcmap.clear(); 00035 } 00036 00037 void SeExprEdExpression::setExpr(const std::string& str) 00038 { 00039 clearVars(); 00040 SeExpression::setExpr(str); 00041 } 00042 00043 SeExprVarRef* SeExprEdExpression::resolveVar(const std::string& name) const 00044 { 00045 if(name=="u") return &u; 00046 else if(name=="v") return &v; 00047 else if(name=="P") return &P; 00048 else{ 00049 // make a variable to resolve any unknown 00050 VARMAP::iterator i=varmap.find(name); 00051 if(i!=varmap.end()) return i->second; 00052 else{ 00053 varmap[name]=new VectorRef(); 00054 return varmap[name]; 00055 } 00056 } 00057 } 00058 00059 SeExprFunc* SeExprEdExpression::resolveFunc(const std::string& name) const 00060 { 00061 // check if it is builtin so we get proper behavior 00062 if(SeExprFunc::lookup(name)) return 0; 00063 00064 funcmap[name]=true; 00065 return &dummyFunc; 00066 }