SeExpr
BasicExpression.cpp
Go to the documentation of this file.
1 /*
2 * Copyright Disney Enterprises, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License
6 * and the following modification to it: Section 6 Trademarks.
7 * deleted and replaced with:
8 *
9 * 6. Trademarks. This License does not grant permission to use the
10 * trade names, trademarks, service marks, or product names of the
11 * Licensor and its affiliates, except as required for reproducing
12 * the content of the NOTICE file.
13 *
14 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * @file BasicExpression.cpp
18 * @brief A basic expression context for the expression previewer
19 * @author aselle
20 */
21 
22 #include "BasicExpression.h"
23 
25  const SeExpr2::ExprType& type)
26  :Expression(expr,type),dummyFunc(dummyFuncX,0,16)
27 {}
28 
30 {
31  clearVars();
32 }
33 
34 template<class T_MAP> void deleteAndClear(T_MAP& map){
35  for(typename T_MAP::iterator i=map.begin();i!=map.end();++i) delete i->second;
36  map.clear();
37 }
38 
40 {
42  funcmap.clear();
43 }
44 
45 void BasicExpression::setExpr(const std::string& str)
46 {
47  clearVars();
48  Expression::setExpr(str);
49 }
50 
51 SeExpr2::ExprVarRef* BasicExpression::resolveVar(const std::string& name) const
52 {
53  if(name=="u") return &u;
54  else if(name=="v") return &v;
55  else if(name=="P") return &P;
56  else{
57  // make a variable to resolve any unknown
58  VARMAP::iterator i=varmap.find(name);
59  if(i!=varmap.end()) return i->second;
60  else{
61  varmap[name]=new VectorRef();
62  return varmap[name];
63  }
64  }
65 }
66 
67 SeExpr2::ExprFunc* BasicExpression::resolveFunc(const std::string& name) const
68 {
69  // check if it is builtin so we get proper behavior
70  if(SeExpr2::ExprFunc::lookup(name)) return 0;
71 
72  funcmap[name]=true;
73  return &dummyFunc;
74 }
void deleteAndClear(T_MAP &map)
</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")
SeExpr2::MapFuncX map
Function Definition, used in parse tree and func table.
Definition: ExprFunc.h:44
SeExpr2::ExprVarRef * resolveVar(const std::string &name) const
static const ExprFunc * lookup(const std::string &name)
Lookup a builtin function by name.
Definition: ExprFunc.cpp:121
void setExpr(const std::string &str)
virtual ~BasicExpression()
SeExpr2::ExprFunc * resolveFunc(const std::string &name) const
abstract class for implementing variable references
Definition: Expression.h:45
SeExpr2::ExprFunc dummyFunc
BasicExpression(const std::string &expr, const SeExpr2::ExprType &type=SeExpr2::ExprType().FP(3))