diff options
Diffstat (limited to 'node')
| -rw-r--r-- | node/countexecutenode.cpp | 18 | ||||
| -rw-r--r-- | node/dicerollernode.cpp | 2 | ||||
| -rw-r--r-- | node/executionnode.cpp | 2 | ||||
| -rw-r--r-- | node/explosedicenode.cpp | 16 | ||||
| -rw-r--r-- | node/filternode.cpp | 14 | ||||
| -rw-r--r-- | node/ifnode.cpp | 9 | ||||
| -rw-r--r-- | node/jumpbackwardnode.cpp | 2 | ||||
| -rw-r--r-- | node/keepdiceexecnode.cpp | 10 | ||||
| -rw-r--r-- | node/listaliasnode.cpp | 4 | ||||
| -rw-r--r-- | node/listsetrollnode.cpp | 4 | ||||
| -rw-r--r-- | node/paintnode.cpp | 2 | ||||
| -rw-r--r-- | node/rerolldicenode.cpp | 4 | ||||
| -rw-r--r-- | node/scalaroperatornode.cpp | 49 | ||||
| -rw-r--r-- | node/scalaroperatornode.h | 5 | ||||
| -rw-r--r-- | node/separatornode.cpp | 0 | ||||
| -rw-r--r-- | node/separatornode.h | 44 | ||||
| -rw-r--r-- | node/sortresult.cpp | 8 | ||||
| -rw-r--r-- | node/startingnode.cpp | 5 |
18 files changed, 121 insertions, 77 deletions
diff --git a/node/countexecutenode.cpp b/node/countexecutenode.cpp index 84946df..ca2c599 100644 --- a/node/countexecutenode.cpp +++ b/node/countexecutenode.cpp @@ -4,7 +4,7 @@ CountExecuteNode::CountExecuteNode() - : m_scalarResult(new ScalarResult()),m_validator(nullptr) + : m_scalarResult(new ScalarResult()),m_validator(nullptr) { m_result = m_scalarResult; } @@ -14,7 +14,7 @@ void CountExecuteNode::setValidator(Validator* validator) } CountExecuteNode::~CountExecuteNode() { - if(nullptr!=m_validator) + if(nullptr!=m_validator) { delete m_validator; } @@ -23,19 +23,19 @@ CountExecuteNode::~CountExecuteNode() void CountExecuteNode::run(ExecutionNode *previous) { m_previousNode = previous; - if(nullptr==previous) + if(nullptr==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; foreach(Die* dice,diceList) { - if(nullptr!=m_validator) + if(NULL!=m_validator) { sum+=m_validator->hasValid(dice,true,true); } @@ -43,7 +43,7 @@ void CountExecuteNode::run(ExecutionNode *previous) m_scalarResult->setValue(sum); - if(nullptr!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -63,7 +63,7 @@ QString CountExecuteNode::toString(bool withlabel) const qint64 CountExecuteNode::getPriority() const { qint64 priority=0; - if(nullptr!=m_nextNode) + if(nullptr!=m_previousNode) { priority = m_nextNode->getPriority(); } @@ -75,11 +75,11 @@ qint64 CountExecuteNode::getPriority() const 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/dicerollernode.cpp b/node/dicerollernode.cpp index b6db419..25b9d5a 100644 --- a/node/dicerollernode.cpp +++ b/node/dicerollernode.cpp @@ -70,8 +70,6 @@ qint64 DiceRollerNode::getPriority() const // { // priority = m_nextNode->getPriority(); // } - - return priority; } ExecutionNode* DiceRollerNode::getCopy() const diff --git a/node/executionnode.cpp b/node/executionnode.cpp index 84aa17c..94d0d46 100644 --- a/node/executionnode.cpp +++ b/node/executionnode.cpp @@ -41,7 +41,7 @@ QMap<ExecutionNode::DICE_ERROR_CODE,QString> ExecutionNode::getExecutionErrorMap { if(nullptr!=m_nextNode) { - foreach (ExecutionNode::DICE_ERROR_CODE key, m_nextNode->getExecutionErrorMap().keys()) + for (const auto& key : m_nextNode->getExecutionErrorMap().keys()) { m_errors.insert(key,m_nextNode->getExecutionErrorMap().value(key)); } diff --git a/node/explosedicenode.cpp b/node/explosedicenode.cpp index 96caaeb..81e80ee 100644 --- a/node/explosedicenode.cpp +++ b/node/explosedicenode.cpp @@ -1,18 +1,18 @@ #include "explosedicenode.h" ExploseDiceNode::ExploseDiceNode() - : m_diceResult(new DiceResult()),m_validator(nullptr) + : m_diceResult(new DiceResult()),m_validator(nullptr) { m_result = m_diceResult; } 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) { foreach(Die* die,previous_result->getResultList()) { @@ -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); } @@ -43,7 +43,7 @@ void ExploseDiceNode::run(ExecutionNode* previous) } ExploseDiceNode::~ExploseDiceNode() { - if(nullptr!=m_validator) + if(nullptr!=m_validator) { delete m_validator; } @@ -66,7 +66,7 @@ QString ExploseDiceNode::toString(bool withlabel) const qint64 ExploseDiceNode::getPriority() const { qint64 priority=0; - if(nullptr!=m_nextNode) + if(nullptr!=m_previousNode) { priority = m_nextNode->getPriority(); } @@ -78,11 +78,11 @@ qint64 ExploseDiceNode::getPriority() const 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 462774b..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); } @@ -69,7 +69,7 @@ QString FilterNode::toString(bool wl) const qint64 FilterNode::getPriority() const { qint64 priority=0; - if(nullptr!=m_nextNode) + if(nullptr!=m_previousNode) { priority = m_nextNode->getPriority(); } @@ -80,11 +80,11 @@ qint64 FilterNode::getPriority() const 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/ifnode.cpp b/node/ifnode.cpp index b40ed82..b15e203 100644 --- a/node/ifnode.cpp +++ b/node/ifnode.cpp @@ -60,7 +60,7 @@ void IfNode::run(ExecutionNode *previous) for(Die* dice : diceList) { if(m_validator->hasValid(dice,true,true)) - { + { nextNode = (nullptr==m_true) ? nullptr: m_true->getCopy(); } else @@ -245,7 +245,12 @@ QString IfNode::toString(bool wl) const qint64 IfNode::getPriority() const { - return 4; + qint64 priority=0; + if(nullptr != getPreviousNode()) + { + priority=getPreviousNode()->getPriority(); + } + return priority; } ExecutionNode* IfNode::getLeafNode(ExecutionNode* node) diff --git a/node/jumpbackwardnode.cpp b/node/jumpbackwardnode.cpp index 1309b3b..e860f99 100644 --- a/node/jumpbackwardnode.cpp +++ b/node/jumpbackwardnode.cpp @@ -130,7 +130,7 @@ void JumpBackwardNode::run(ExecutionNode* previous) DiceResult* diceResult = dynamic_cast<DiceResult*>(result); if(nullptr!=diceResult) { - foreach(Die* die,diceResult->getResultList()) + for(Die* die : diceResult->getResultList()) { Die* tmpdie = new Die(); *tmpdie=*die; diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp index a93cc11..6167632 100644 --- a/node/keepdiceexecnode.cpp +++ b/node/keepdiceexecnode.cpp @@ -36,13 +36,13 @@ 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(); @@ -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); } @@ -94,7 +94,7 @@ QString KeepDiceExecNode::toString(bool wl) const qint64 KeepDiceExecNode::getPriority() const { qint64 priority=0; - if(nullptr!=m_nextNode) + if(nullptr!=m_previousNode) { priority = m_nextNode->getPriority(); } @@ -107,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/listaliasnode.cpp b/node/listaliasnode.cpp index 642f601..4c9f9f2 100644 --- a/node/listaliasnode.cpp +++ b/node/listaliasnode.cpp @@ -53,7 +53,7 @@ void ListAliasNode::run(ExecutionNode* previous ) QString ListAliasNode::buildList() const { QString result(QObject::tr("List of Alias:\n")); - foreach(DiceAlias* key, *m_aliasList) + for(DiceAlias* key : *m_aliasList) { result+=QString("%1 : %2\n").arg(key->getCommand()).arg(key->getValue()); } @@ -62,7 +62,7 @@ QString ListAliasNode::buildList() const QString ListAliasNode::toString(bool wl) const { QStringList resultList; - foreach(DiceAlias* key, *m_aliasList) + for(DiceAlias* key : *m_aliasList) { resultList << "{" <<key->getCommand() << key->getValue()<< "}"; } diff --git a/node/listsetrollnode.cpp b/node/listsetrollnode.cpp index 21d5403..8f86332 100644 --- a/node/listsetrollnode.cpp +++ b/node/listsetrollnode.cpp @@ -106,7 +106,7 @@ void ListSetRollNode::computeFacesNumber(Die* die) Q_ASSERT(m_values.size() == m_rangeList.size()); qint64 max; int i=0; - foreach(Range range, m_rangeList) + for(Range range: m_rangeList) { if(((i==0)||(max<range.getEnd()))&&(range.isFullyDefined())) { @@ -133,7 +133,7 @@ void ListSetRollNode::getValueFromDie(Die* die,QStringList& rollResult) { Q_ASSERT(m_values.size() == m_rangeList.size()); int i=0; - foreach (Range range, m_rangeList) + for (Range range: m_rangeList) { if(range.hasValid(die,false)) { diff --git a/node/paintnode.cpp b/node/paintnode.cpp index 2770891..035334e 100644 --- a/node/paintnode.cpp +++ b/node/paintnode.cpp @@ -78,7 +78,7 @@ void PainterNode::run(ExecutionNode* previous) { QList<Die*> diceList=previousDiceResult->getResultList(); int pastDice=0; - foreach(ColorItem item, m_colors) + for(ColorItem item: m_colors) { int current=item.colorNumber(); QList<Die*>::iterator it; diff --git a/node/rerolldicenode.cpp b/node/rerolldicenode.cpp index 1f8cd7e..8e8be2c 100644 --- a/node/rerolldicenode.cpp +++ b/node/rerolldicenode.cpp @@ -23,7 +23,7 @@ void RerollDiceNode::run(ExecutionNode* previous) m_result->setPrevious(previous_result); if(nullptr!=previous_result) { - foreach(Die* die,previous_result->getResultList()) + for(Die* die : previous_result->getResultList()) { Die* tmpdie = new Die(); *tmpdie=*die; @@ -34,7 +34,7 @@ void RerollDiceNode::run(ExecutionNode* previous) QList<Die*> list = m_diceResult->getResultList(); - foreach(Die* die, list) + for(Die* die: list) { if(m_validator->hasValid(die,false)) { diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp index a9a19e3..f4884c8 100644 --- a/node/scalaroperatornode.cpp +++ b/node/scalaroperatornode.cpp @@ -38,44 +38,37 @@ ScalarOperatorNode::ScalarOperatorNode() } ScalarOperatorNode::~ScalarOperatorNode() { - if(nullptr!=m_internalNode) - { - delete m_internalNode; - m_internalNode = nullptr; - } + if(nullptr!=m_internalNode) + { + delete m_internalNode; + m_internalNode = nullptr; + } } void ScalarOperatorNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(nullptr!=m_internalNode) + if(NULL!=m_internalNode) { 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() ) - { + 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) - { + switch(m_arithmeticOperator) + { case Die::PLUS: m_scalarResult->setValue(add(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); break; @@ -94,7 +87,7 @@ void ScalarOperatorNode::run(ExecutionNode* previous) } } - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { m_nextNode->run(this); } @@ -193,7 +186,7 @@ void ScalarOperatorNode::generateDotTree(QString& s) s.append(toString(true)); s.append(";\n"); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { s.append(toString(false)); s.append(" -> "); @@ -205,12 +198,12 @@ void ScalarOperatorNode::generateDotTree(QString& s) { s.append(toString(false)); s.append(" -> "); - s.append("nullptr"); - s.append(" [label=\"nextNode\"];\n"); + 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(" -> "); @@ -222,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()) { @@ -243,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/scalaroperatornode.h b/node/scalaroperatornode.h index 0855a4c..7753a6f 100644 --- a/node/scalaroperatornode.h +++ b/node/scalaroperatornode.h @@ -115,6 +115,11 @@ private: * @return */ static qint64 multiple(qint64,qint64); + /** + * @brief power + * @return + */ + static qint64 power(qint64,qint64); private: ExecutionNode* m_internalNode; diff --git a/node/separatornode.cpp b/node/separatornode.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/node/separatornode.cpp diff --git a/node/separatornode.h b/node/separatornode.h new file mode 100644 index 0000000..0820429 --- /dev/null +++ b/node/separatornode.h @@ -0,0 +1,44 @@ +/*************************************************************************** +* Copyright (C) 2017 by Renaud Guezennec * +* http://www.rolisteam.org/contact * +* * +* This file is part of DiceParser * +* * +* DiceParser is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef SEPARATORNODE_H +#define SEPARATORNODE_H + +#include "node/executionnode.h" +#include "result/diceresult.h" + +/** + * @brief The MergeNode class is an ExecutionNode. It is dedicated to merge result of several commands. + */ +class SeparatorNode : public ExecutionNode +{ +public: + SeparatorNode(); + void run(ExecutionNode* previous); + virtual QString toString(bool withLabel)const; + virtual qint64 getPriority() const; + virtual ExecutionNode *getCopy() const; +private: + DiceResult* m_diceResult; + ExecutionNode* m_; +}; + +#endif // SEPARATORNODE_H diff --git a/node/sortresult.cpp b/node/sortresult.cpp index 5406eb6..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); } @@ -123,7 +123,7 @@ QString SortResultNode::toString(bool wl) const qint64 SortResultNode::getPriority() const { qint64 priority=0; - if(nullptr!=m_nextNode) + if(nullptr != m_previousNode) { priority = m_nextNode->getPriority(); } @@ -135,7 +135,7 @@ 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()); } diff --git a/node/startingnode.cpp b/node/startingnode.cpp index 670dc7d..43a0dd7 100644 --- a/node/startingnode.cpp +++ b/node/startingnode.cpp @@ -26,7 +26,6 @@ StartingNode::StartingNode() } void StartingNode::run(ExecutionNode*) { - m_previousNode = nullptr; if(nullptr!=m_nextNode) { m_nextNode->run(this); @@ -48,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(); } @@ -57,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()); } |