diff options
| author | 2013-12-29 02:04:19 +0100 | |
|---|---|---|
| committer | 2013-12-29 02:04:19 +0100 | |
| commit | f30020384f816b498fe1f6013758a8de37811821 (patch) | |
| tree | 7388de7fe766fe2973d94a3256f8820e3c7fbcdf /node/scalaroperatornode.cpp | |
| parent | 7a1784893af6fe986503dc67672135ed05816579 (diff) | |
| download | OneRoll-f30020384f816b498fe1f6013758a8de37811821.tar.gz OneRoll-f30020384f816b498fe1f6013758a8de37811821.zip | |
Firt commit of the new dice system for rolisteam.
Diffstat (limited to 'node/scalaroperatornode.cpp')
| -rw-r--r-- | node/scalaroperatornode.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp new file mode 100644 index 0000000..e8a2ec0 --- /dev/null +++ b/node/scalaroperatornode.cpp @@ -0,0 +1,91 @@ +#include "scalaroperatornode.h" + +#include <QDebug> + +ScalarOperatorNode::ScalarOperatorNode() + : m_internalNode(NULL) +{ + m_scalarOperationList.insert('+',PLUS); + m_scalarOperationList.insert('-',MINUS); + m_scalarOperationList.insert('x',MULTIPLICATION); + m_scalarOperationList.insert('*',MULTIPLICATION); + m_scalarOperationList.insert('/',DIVIDE); + m_scalarOperationList.insert('÷',DIVIDE); +} + +void ScalarOperatorNode::run(ExecutionNode* previous) +{ + if(NULL!=m_internalNode) + { + m_internalNode->run(this); + } + if(NULL!=previous) + { + DiceResult* previousResult = previous->getResult(); + ExecutionNode* internal = m_internalNode; + while(NULL != internal->getNextNode() ) + { + internal = internal->getNextNode(); + } + DiceResult* internalResult = internal->getResult(); + + switch(m_myOperator) + { + case PLUS: + m_result.insertResult(add(previousResult->getSum(),internalResult->getSum())); + break; + case MINUS: + m_result.insertResult(substract(previousResult->getSum(),internalResult->getSum())); + break; + case MULTIPLICATION: + m_result.insertResult(multiple(previousResult->getSum(),internalResult->getSum())); + break; + case DIVIDE: + m_result.insertResult(divide(previousResult->getSum(),internalResult->getSum())); + break; + default: + break; + + } + + if(NULL!=m_nextNode) + { + m_nextNode->run(this); + } + } + +} +bool ScalarOperatorNode::setOperatorChar(QChar c) +{ + if(m_scalarOperationList.contains(c)) + { + m_myOperator = m_scalarOperationList.value(c); + return true; + } + return false; +} + + +void ScalarOperatorNode::setInternalNode(ExecutionNode* node) +{ + m_internalNode = node; +} +qint64 ScalarOperatorNode::add(qint64 a,qint64 b) +{ + return a+b; +} + +qint64 ScalarOperatorNode::substract(qint64 a,qint64 b) +{ + return a-b; +} + +qint64 ScalarOperatorNode::divide(qint64 a,qint64 b) +{ + return a/b; +} + +qint64 ScalarOperatorNode::multiple(qint64 a,qint64 b) +{ + return a*b; +} |