#include #include #include #include #include "globals.h" #include "node.h" #include "binaryNode.h" #include "unaryNode.h" #include "bFuncNode.h" #include "OperatorMap.h" OperatorMap::OperatorMap() { myOperators["+"] = new Plus();//adds plus node myOperators["-"] = new Minus();//add minus node myOperators["*"] = new Times();//adds times node myOperators["/"] = new Divide();//adds divide node myOperators["%"] = new Mod();//adds mod node myOperators["("] = new Paren('(',OPEN_PAREN_PRECEDENCE);//adds new left paren myOperators[")"] = new Paren(')',CLOSED_PAREN_PRECEDENCE);//adds new right paren myOperators["="] = new Equals(); myOperators[","] = new Comma(); myOperators["^"] = new Pow(); myOperators["_"] = new Negative(); myOperators["!"] = new Factorial(); myOperators["sqrt"]= new Sqrt(); myOperators["abs"]= new Abs(); myOperators["sin"]= new Sin(); myOperators["cos"]= new Cos(); myOperators["tan"]=new Tan(); myOperators["log"]=new Log(); myOperators["ln"]=new LN(); myOperators["exp"]=new Exp(); myOperators["d"]=new Derivative(); myOperators["f"]= new Function(); } Node* OperatorMap::lookUpOperator(const string & operators) { //must be valid operator //returns a pointer to a Node specific to the operator looked up return(myOperators[operators]->copy()); } bool OperatorMap::isOperator(const string & operators) { //Checks to see if char is an operator returns true if found in map, false otherwise //iterate through map searching for operator for(OperatorList::const_iterator iter=myOperators.begin();iter!=myOperators.end();iter++) { OperatorPair opPair=*iter; if(opPair.first==operators) { return true; } } return false; } bool OperatorMap::isTypeOperator(const string & typeString,const int & Precedence) { //Checks to see if char is a type operator returns true if found in map, false otherwise //iterate through map searching for operator added functionality that it searches for entire strings of letters for(OperatorList::const_iterator iter=myOperators.begin();iter!=myOperators.end();iter++) { OperatorPair opPair=*iter; if(opPair.first==typeString&&opPair.second->precedence()==Precedence) { return true; } } return false; }