diff options
author | Adrian Kummerländer | 2012-03-10 19:14:27 +0100 |
---|---|---|
committer | Adrian Kummerländer | 2012-03-10 19:14:27 +0100 |
commit | 5d618cc8affb959ac64f9cf502dbddf53fb5e7c5 (patch) | |
tree | 3b53a6a641eefd82dbe6fc4c9e31fc912d5d1d67 | |
parent | 1482e7ede3133b8bf78c68c2e0618b1de90d328c (diff) | |
download | SimpleParser-5d618cc8affb959ac64f9cf502dbddf53fb5e7c5.tar SimpleParser-5d618cc8affb959ac64f9cf502dbddf53fb5e7c5.tar.gz SimpleParser-5d618cc8affb959ac64f9cf502dbddf53fb5e7c5.tar.bz2 SimpleParser-5d618cc8affb959ac64f9cf502dbddf53fb5e7c5.tar.lz SimpleParser-5d618cc8affb959ac64f9cf502dbddf53fb5e7c5.tar.xz SimpleParser-5d618cc8affb959ac64f9cf502dbddf53fb5e7c5.tar.zst SimpleParser-5d618cc8affb959ac64f9cf502dbddf53fb5e7c5.zip |
Moved static_cast needed for accessing the specific solve methods of the two derivatives of Node into a template function
-rw-r--r-- | parser.cpp | 4 | ||||
-rw-r--r-- | tree.cpp | 13 | ||||
-rw-r--r-- | tree.h | 3 |
3 files changed, 13 insertions, 7 deletions
@@ -114,7 +114,7 @@ Node* Parser::buildTree(Tree **tree, string term) vector<string> *tmpLexer; - vector<string> *lexerOutput = lexer(term); + vector<string> *lexerOutput = this->lexer(term); for ( vector<string>::iterator termIter = lexerOutput->begin(); termIter != lexerOutput->end(); termIter++ ) { priority = this->getPriority( (*termIter)[0] ); @@ -150,7 +150,7 @@ Node* Parser::buildTree(Tree **tree, string term) } } else { - tmpLexer = lexer( *termIter ); + tmpLexer = this->lexer( *termIter ); if ( tmpLexer->size() == 1 ) { operandStack->push( @@ -1,21 +1,24 @@ #include "tree.h" -#include <math.h> Node::Node() { } +template <class T> +double Node::castSolve (Node *node) { + T *tmp = static_cast<T*>( node ); + return tmp->solve(); +} + double Node::solve() { switch (this->type) { case OPERAND_NODE: { - OperandNode *tmp = static_cast<OperandNode*>( this ); - return tmp->solve(); + return this->castSolve<OperandNode>( this ); } case OPERATOR_NODE: { - OperatorNode *tmp = static_cast<OperatorNode*>( this ); - return tmp->solve(); + return this->castSolve<OperatorNode>( this ); } } } @@ -16,6 +16,9 @@ class Node public: Node(); double solve(); + + template <class T> + double castSolve(Node*); Node *leftChild; Node *rightChild; |