diff options
Diffstat (limited to 'node')
| -rw-r--r-- | node/countexecutenode.cpp | 14 | ||||
| -rw-r--r-- | node/explosedicenode.cpp | 18 | ||||
| -rw-r--r-- | node/filternode.cpp | 16 | ||||
| -rw-r--r-- | node/keepdiceexecnode.cpp | 14 | ||||
| -rw-r--r-- | node/scalaroperatornode.cpp | 121 | ||||
| -rw-r--r-- | node/sortresult.cpp | 11 | ||||
| -rw-r--r-- | node/startingnode.cpp | 6 |
7 files changed, 103 insertions, 97 deletions
diff --git a/node/countexecutenode.cpp b/node/countexecutenode.cpp index de5e457..ca2c599 100644 --- a/node/countexecutenode.cpp +++ b/node/countexecutenode.cpp @@ -28,14 +28,14 @@ void CountExecuteNode::run(ExecutionNode *previous) return; } DiceResult* previousResult = dynamic_cast<DiceResult*>(previous->getResult()); - if(nullptr!=previousResult) + if(NULL!=previousResult) { m_result->setPrevious(previousResult); QList<Die*> diceList=previousResult->getResultList(); qint64 sum = 0; - for(Die* dice : diceList) + foreach(Die* dice,diceList) { - if(nullptr!=m_validator) + if(NULL!=m_validator) { sum+=m_validator->hasValid(dice,true,true); } @@ -65,19 +65,21 @@ qint64 CountExecuteNode::getPriority() const qint64 priority=0; if(nullptr!=m_previousNode) { - priority = m_previousNode->getPriority(); + priority = m_nextNode->getPriority(); } + + return priority; } ExecutionNode* CountExecuteNode::getCopy() const { CountExecuteNode* node = new CountExecuteNode(); - if(nullptr!=m_validator) + if(NULL!=m_validator) { node->setValidator(m_validator->getCopy()); } - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/explosedicenode.cpp b/node/explosedicenode.cpp index bdde83b..81e80ee 100644 --- a/node/explosedicenode.cpp +++ b/node/explosedicenode.cpp @@ -8,13 +8,13 @@ ExploseDiceNode::ExploseDiceNode() void ExploseDiceNode::run(ExecutionNode* previous) { m_previousNode = previous; - if((nullptr!=previous)&&(nullptr!=previous->getResult())) + if((NULL!=previous)&&(NULL!=previous->getResult())) { DiceResult* previous_result = static_cast<DiceResult*>(previous->getResult()); m_result->setPrevious(previous_result); - if(nullptr!=previous_result) + if(NULL!=previous_result) { - for(Die* die : previous_result->getResultList()) + foreach(Die* die,previous_result->getResultList()) { Die* tmpdie = new Die(); *tmpdie=*die; @@ -25,7 +25,7 @@ void ExploseDiceNode::run(ExecutionNode* previous) QList<Die*> list = m_diceResult->getResultList(); - for(Die* die : list) + foreach(Die* die, list) { while(m_validator->hasValid(die,false)) { @@ -34,7 +34,7 @@ void ExploseDiceNode::run(ExecutionNode* previous) } // m_diceResult->setResultList(list); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { m_nextNode->run(this); } @@ -68,19 +68,21 @@ qint64 ExploseDiceNode::getPriority() const qint64 priority=0; if(nullptr!=m_previousNode) { - priority = m_previousNode->getPriority(); + priority = m_nextNode->getPriority(); } + + return priority; } ExecutionNode* ExploseDiceNode::getCopy() const { ExploseDiceNode* node = new ExploseDiceNode(); - if(nullptr!=m_validator) + if(NULL!=m_validator) { node->setValidator(m_validator->getCopy()); } - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/filternode.cpp b/node/filternode.cpp index 0be2e62..5153c79 100644 --- a/node/filternode.cpp +++ b/node/filternode.cpp @@ -8,7 +8,7 @@ FilterNode::FilterNode() FilterNode::~FilterNode() { - if(nullptr!=m_validator) + if(NULL!=m_validator) { delete m_validator; } @@ -20,13 +20,13 @@ void FilterNode::setValidator(Validator* validator) void FilterNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(nullptr==previous) + if(NULL==previous) { return; } DiceResult* previousDiceResult = static_cast<DiceResult*>(previous->getResult()); m_result->setPrevious(previousDiceResult); - if(nullptr!=previousDiceResult) + if(NULL!=previousDiceResult) { QList<Die*> diceList=previousDiceResult->getResultList(); QList<Die*> diceList2; @@ -48,7 +48,7 @@ void FilterNode::run(ExecutionNode* previous) } m_diceResult->setResultList(diceList2); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { m_nextNode->run(this); } @@ -71,18 +71,20 @@ qint64 FilterNode::getPriority() const qint64 priority=0; if(nullptr!=m_previousNode) { - priority = m_previousNode->getPriority(); + priority = m_nextNode->getPriority(); } + + return priority; } ExecutionNode* FilterNode::getCopy() const { FilterNode* node = new FilterNode(); - if(nullptr!=m_validator) + if(NULL!=m_validator) { node->setValidator(m_validator->getCopy()); } - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp index 355a63a..6167632 100644 --- a/node/keepdiceexecnode.cpp +++ b/node/keepdiceexecnode.cpp @@ -36,20 +36,20 @@ KeepDiceExecNode::~KeepDiceExecNode() void KeepDiceExecNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(nullptr==previous) + if(NULL==previous) { return; } DiceResult* previousDiceResult = static_cast<DiceResult*>(previous->getResult()); m_result->setPrevious(previousDiceResult); - if(nullptr!=previousDiceResult) + if(NULL!=previousDiceResult) { QList<Die*> diceList=previousDiceResult->getResultList(); QList<Die*> diceList3= diceList.mid(0,m_numberOfDice); QList<Die*> diceList2; - for(Die* die:diceList3) + foreach(Die* die,diceList3) { Die* tmpdie = new Die(); *tmpdie=*die; @@ -70,7 +70,7 @@ void KeepDiceExecNode::run(ExecutionNode* previous) } m_diceResult->setResultList(diceList2); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { m_nextNode->run(this); } @@ -96,8 +96,10 @@ qint64 KeepDiceExecNode::getPriority() const qint64 priority=0; if(nullptr!=m_previousNode) { - priority = m_previousNode->getPriority(); + priority = m_nextNode->getPriority(); } + + return priority; } @@ -105,7 +107,7 @@ ExecutionNode* KeepDiceExecNode::getCopy() const { KeepDiceExecNode* node = new KeepDiceExecNode(); node->setDiceKeepNumber(m_numberOfDice); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp index b85f23c..f4884c8 100644 --- a/node/scalaroperatornode.cpp +++ b/node/scalaroperatornode.cpp @@ -28,6 +28,12 @@ ScalarOperatorNode::ScalarOperatorNode() : m_internalNode(nullptr),m_scalarResult(new ScalarResult()),m_arithmeticOperator(Die::PLUS) { + /*m_scalarOperationList.insert('+',PLUS); + m_scalarOperationList.insert('-',MINUS); + m_scalarOperationList.insert('x',MULTIPLICATION); + m_scalarOperationList.insert('*',MULTIPLICATION); + m_scalarOperationList.insert('/',DIVIDE);*/ + m_result = m_scalarResult; } ScalarOperatorNode::~ScalarOperatorNode() @@ -42,30 +48,24 @@ ScalarOperatorNode::~ScalarOperatorNode() void ScalarOperatorNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(nullptr!=m_internalNode) + if(NULL!=m_internalNode) { - m_internalNode->run(this); + m_internalNode->run(this); } - if(nullptr!=previous) + if(NULL!=previous) { DiceResult* previousResult = static_cast<DiceResult*>(previous->getResult()); - if(nullptr!=previousResult) + if(NULL!=previousResult) { ExecutionNode* internal = m_internalNode; - if(nullptr != internal) + if(NULL != internal) { while(nullptr != internal->getNextNode() ) { internal = internal->getNextNode(); - } + } - Result* internalResult = internal->getResult(); - m_result->setPrevious(internalResult); - if(nullptr!=m_internalNode->getResult()) - { - m_internalNode->getResult()->setPrevious(previousResult); - } switch(m_arithmeticOperator) { @@ -81,16 +81,13 @@ void ScalarOperatorNode::run(ExecutionNode* previous) case Die::DIVIDE: m_scalarResult->setValue(divide(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); break; - case Die::POWER: - m_scalarResult->setValue(power(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); - break; default: break; - } + } } - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { m_nextNode->run(this); } @@ -98,6 +95,15 @@ void ScalarOperatorNode::run(ExecutionNode* previous) } } +/*bool ScalarOperatorNode::setOperatorChar(QChar c) +{ + if(m_scalarOperationList.contains(c)) + { + m_operator = m_scalarOperationList.value(c); + return true; + } + return false; +}*/ void ScalarOperatorNode::setInternalNode(ExecutionNode* node) { @@ -120,14 +126,10 @@ qreal ScalarOperatorNode::divide(qint64 a,qint64 b) } return (qreal)a/b; } -qint64 ScalarOperatorNode::multiple(qint64 a, qint64 b) +qint64 ScalarOperatorNode::multiple(qint64 a,qint64 b) { return a*b; } -qint64 ScalarOperatorNode::power(qint64 a, qint64 b) -{ - return std::pow(a,b); -} Die::ArithmeticOperator ScalarOperatorNode::getArithmeticOperator() const { return m_arithmeticOperator; @@ -148,71 +150,64 @@ QString ScalarOperatorNode::toString(bool wl) const break; case Die::MINUS: op="-"; - break; - case Die::MULTIPLICATION: - op="*"; - break; - case Die::DIVIDE: - op="/"; - break; - case Die::POWER: - op="^"; - break; - default: - break; + break; + case Die::MULTIPLICATION: + op="*"; + break; + case Die::DIVIDE: + op="/"; + break; + default: + break; } - if(wl) - { - return QString("%1 [label=\"ScalarOperatorNode %2\"]").arg(m_id).arg(op); - } - else - { - return m_id; - } + if(wl) + { + return QString("%1 [label=\"ScalarOperatorNode %2\"]").arg(m_id).arg(op); + } + else + { + return m_id; + } } qint64 ScalarOperatorNode::getPriority() const { if((m_arithmeticOperator==Die::PLUS)||(m_arithmeticOperator==Die::MINUS)) - { + { return 1; - } - else if((m_arithmeticOperator==Die::MULTIPLICATION)||(m_arithmeticOperator==Die::DIVIDE)) - { - return 2; - } + } else - { - return 3; - } + { + return 2; + } } void ScalarOperatorNode::generateDotTree(QString& s) { - s.append(toString(true)); - s.append(";\n"); + s.append(toString(true)); + s.append(";\n"); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { - s.append(toString(false)); + s.append(toString(false)); s.append(" -> "); - s.append(m_nextNode->toString(false)); + s.append(m_nextNode->toString(false)); s.append("[label=\"nextNode\"];\n"); m_nextNode->generateDotTree(s); } else { - s.append(toString(false)); + s.append(toString(false)); s.append(" -> "); s.append("nullptr"); s.append(" [label=\"nextNode\"];\n"); } QString str; str.append("\n"); - if(nullptr!=m_internalNode) + if(NULL!=m_internalNode) { - str.append(toString(false)); + str.append(toString(false)); str.append(" -> "); - str.append(m_internalNode->toString(false)); + str.append(m_internalNode->toString(false)); str.append(" [label=\"internalNode\"];\n"); m_internalNode->generateDotTree(str); } @@ -220,14 +215,14 @@ void ScalarOperatorNode::generateDotTree(QString& s) } QMap<ExecutionNode::DICE_ERROR_CODE,QString> ScalarOperatorNode::getExecutionErrorMap() { - if(nullptr!=m_internalNode) + if(NULL!=m_internalNode) { for (ExecutionNode::DICE_ERROR_CODE key: m_internalNode->getExecutionErrorMap().keys()) { m_errors.insert(key,m_internalNode->getExecutionErrorMap().value(key)); } } - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { for (ExecutionNode::DICE_ERROR_CODE key: m_nextNode->getExecutionErrorMap().keys()) { @@ -241,7 +236,7 @@ ExecutionNode* ScalarOperatorNode::getCopy() const ScalarOperatorNode* node = new ScalarOperatorNode(); node->setInternalNode(m_internalNode->getCopy()); node->setArithmeticOperator(m_arithmeticOperator); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/sortresult.cpp b/node/sortresult.cpp index e3d8d1e..062e1d2 100644 --- a/node/sortresult.cpp +++ b/node/sortresult.cpp @@ -57,7 +57,7 @@ void SortResultNode::run(ExecutionNode* node) bool found = false; int start = 0; int end = diceList2.size(); - Die* tmp2 = nullptr; + Die* tmp2 = NULL; while(!found) { int distance = end-start; @@ -92,7 +92,7 @@ void SortResultNode::run(ExecutionNode* node) } m_diceResult->setResultList(diceList2); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { m_nextNode->run(this); } @@ -125,17 +125,20 @@ qint64 SortResultNode::getPriority() const qint64 priority=0; if(nullptr != m_previousNode) { - priority = m_previousNode->getPriority(); + priority = m_nextNode->getPriority(); } + + return priority; } ExecutionNode* SortResultNode::getCopy() const { SortResultNode* node = new SortResultNode(); node->setSortAscending(m_ascending); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; + } diff --git a/node/startingnode.cpp b/node/startingnode.cpp index 3b0d660..43a0dd7 100644 --- a/node/startingnode.cpp +++ b/node/startingnode.cpp @@ -22,7 +22,7 @@ StartingNode::StartingNode() { - m_previousNode = nullptr; + } void StartingNode::run(ExecutionNode*) { @@ -47,7 +47,7 @@ QString StartingNode::toString(bool withlabel) const qint64 StartingNode::getPriority() const { qint64 priority=0; - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { priority = m_nextNode->getPriority(); } @@ -56,7 +56,7 @@ qint64 StartingNode::getPriority() const ExecutionNode* StartingNode::getCopy() const { StartingNode* node = new StartingNode(); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } |