diff options
Diffstat (limited to 'node')
47 files changed, 1526 insertions, 1587 deletions
diff --git a/node/bind.cpp b/node/bind.cpp index 9598c45..6695166 100644 --- a/node/bind.cpp +++ b/node/bind.cpp @@ -1,76 +1,75 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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. * + ***************************************************************************/ #include "bind.h" -BindNode::BindNode() - : m_diceResult(new DiceResult()) +BindNode::BindNode() : m_diceResult(new DiceResult()) { - m_result = m_diceResult; + m_result= m_diceResult; } void BindNode::run(ExecutionNode* previous) { - m_previousNode = previous; + m_previousNode= previous; if(nullptr == m_previousNode) return; m_result->setPrevious(previous->getResult()); for(auto start : *m_startList) { - ExecutionNode* last = getLatestNode(start); - if(nullptr!=last) + ExecutionNode* last= getLatestNode(start); + if(nullptr != last) { - auto tmpResult = last->getResult(); - while(nullptr!=tmpResult) + auto tmpResult= last->getResult(); + while(nullptr != tmpResult) { - DiceResult* dice = dynamic_cast<DiceResult*>(tmpResult); - if(nullptr!=dice) + DiceResult* dice= dynamic_cast<DiceResult*>(tmpResult); + if(nullptr != dice) { m_diceResult->setHomogeneous(false); for(auto& die : dice->getResultList()) { if(!die->hasBeenDisplayed()) { - Die* tmpdie = new Die(*die); + Die* tmpdie= new Die(*die); die->displayed(); m_diceResult->getResultList().append(tmpdie); } } } - tmpResult = tmpResult->getPrevious(); + tmpResult= tmpResult->getPrevious(); } } } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } } ExecutionNode* BindNode::getLatestNode(ExecutionNode* node) { - ExecutionNode* next = node; - while(nullptr != next->getNextNode() && (next->getNextNode()!=this)) + ExecutionNode* next= node; + while(nullptr != next->getNextNode() && (next->getNextNode() != this)) { - next = next->getNextNode(); + next= next->getNextNode(); } return next; } @@ -87,29 +86,29 @@ QString BindNode::toString(bool withLabel) const } qint64 BindNode::getPriority() const { - qint64 priority=0; - if(nullptr!=m_previousNode) + qint64 priority= 0; + if(nullptr != m_previousNode) { - priority = m_previousNode->getPriority(); + priority= m_previousNode->getPriority(); } return priority; } ExecutionNode* BindNode::getCopy() const { - BindNode* node = new BindNode(); - if(nullptr!=m_nextNode) + BindNode* node= new BindNode(); + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; } -std::vector<ExecutionNode *>* BindNode::getStartList() const +std::vector<ExecutionNode*>* BindNode::getStartList() const { return m_startList; } -void BindNode::setStartList(std::vector<ExecutionNode *>* startList) +void BindNode::setStartList(std::vector<ExecutionNode*>* startList) { - m_startList = startList; + m_startList= startList; } diff --git a/node/bind.h b/node/bind.h index b960e3f..45e1bee 100644 --- a/node/bind.h +++ b/node/bind.h @@ -1,24 +1,24 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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 BINDNODE_H #define BINDNODE_H @@ -33,18 +33,18 @@ class BindNode : public ExecutionNode public: BindNode(); void run(ExecutionNode* previous); - virtual QString toString(bool withLabel)const; + virtual QString toString(bool withLabel) const; virtual qint64 getPriority() const; - virtual ExecutionNode *getCopy() const; - std::vector<ExecutionNode *>* getStartList() const; - void setStartList(std::vector<ExecutionNode *>* startList); + virtual ExecutionNode* getCopy() const; + std::vector<ExecutionNode*>* getStartList() const; + void setStartList(std::vector<ExecutionNode*>* startList); private: - ExecutionNode *getLatestNode(ExecutionNode *node); + ExecutionNode* getLatestNode(ExecutionNode* node); private: DiceResult* m_diceResult; - std::vector<ExecutionNode *>* m_startList; + std::vector<ExecutionNode*>* m_startList; }; #endif // NUMBERNODE_H diff --git a/node/countexecutenode.cpp b/node/countexecutenode.cpp index d76c115..bc8e3b3 100644 --- a/node/countexecutenode.cpp +++ b/node/countexecutenode.cpp @@ -1,88 +1,82 @@ #include "countexecutenode.h" #include "result/diceresult.h" - - -CountExecuteNode::CountExecuteNode() - : m_scalarResult(new ScalarResult()),m_validator(nullptr) +CountExecuteNode::CountExecuteNode() : m_scalarResult(new ScalarResult()), m_validator(nullptr) { - m_result = m_scalarResult; + m_result= m_scalarResult; } void CountExecuteNode::setValidator(Validator* validator) { - m_validator = validator; + m_validator= validator; } CountExecuteNode::~CountExecuteNode() { - if(nullptr!=m_validator) - { - delete m_validator; - } + if(nullptr != m_validator) + { + delete m_validator; + } } -void CountExecuteNode::run(ExecutionNode *previous) +void CountExecuteNode::run(ExecutionNode* previous) { - m_previousNode = previous; - if(nullptr==previous) - { - return; - } - DiceResult* previousResult = dynamic_cast<DiceResult*>(previous->getResult()); - if(nullptr!=previousResult) - { + m_previousNode= previous; + if(nullptr == previous) + { + return; + } + DiceResult* previousResult= dynamic_cast<DiceResult*>(previous->getResult()); + if(nullptr != previousResult) + { m_result->setPrevious(previousResult); - QList<Die*> diceList=previousResult->getResultList(); - qint64 sum = 0; - for(Die* dice:diceList) - { - if(nullptr!=m_validator) + QList<Die*> diceList= previousResult->getResultList(); + qint64 sum= 0; + for(Die* dice : diceList) + { + if(nullptr != m_validator) { - sum+=m_validator->hasValid(dice,true,true); + sum+= m_validator->hasValid(dice, true, true); } - } - m_scalarResult->setValue(sum); + } + m_scalarResult->setValue(sum); - - if(nullptr!=m_nextNode) - { - m_nextNode->run(this); - } - } + if(nullptr != m_nextNode) + { + m_nextNode->run(this); + } + } } QString CountExecuteNode::toString(bool withlabel) const { - if(withlabel) - { - return QString("%1 [label=\"CountExecuteNode %2\"]").arg(m_id,m_validator->toString()); - } - else - { - return m_id; - } + if(withlabel) + { + return QString("%1 [label=\"CountExecuteNode %2\"]").arg(m_id, m_validator->toString()); + } + else + { + return m_id; + } } qint64 CountExecuteNode::getPriority() const { - qint64 priority=0; - if(nullptr!=m_nextNode) - { - priority = m_nextNode->getPriority(); - } - + qint64 priority= 0; + if(nullptr != m_nextNode) + { + priority= m_nextNode->getPriority(); + } return priority; } ExecutionNode* CountExecuteNode::getCopy() const { - CountExecuteNode* node = new CountExecuteNode(); - if(nullptr!=m_validator) + CountExecuteNode* node= new CountExecuteNode(); + if(nullptr != m_validator) { node->setValidator(m_validator->getCopy()); } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; - } diff --git a/node/countexecutenode.h b/node/countexecutenode.h index 8a6132b..8969a41 100644 --- a/node/countexecutenode.h +++ b/node/countexecutenode.h @@ -3,8 +3,8 @@ #include "executionnode.h" -#include "validator.h" #include "result/scalarresult.h" +#include "validator.h" /** * @brief The CountExecuteNode class @@ -16,7 +16,7 @@ public: * @brief CountExecuteNode */ CountExecuteNode(); - virtual ~CountExecuteNode(); + virtual ~CountExecuteNode(); /** * @brief run * @param previous @@ -25,12 +25,12 @@ public: /** * @brief setValidator */ - virtual void setValidator(Validator* ); + virtual void setValidator(Validator*); /** * @brief toString * @return */ - virtual QString toString(bool withLabel)const; + virtual QString toString(bool withLabel) const; /** * @brief getPriority * @return @@ -41,6 +41,7 @@ public: * @return */ virtual ExecutionNode* getCopy() const; + private: ScalarResult* m_scalarResult; Validator* m_validator; diff --git a/node/dicerollernode.h b/node/dicerollernode.h index 8831c8e..a59f97c 100644 --- a/node/dicerollernode.h +++ b/node/dicerollernode.h @@ -12,41 +12,41 @@ class DiceRollerNode : public ExecutionNode { public: - /** - * @brief DiceRollerNode builds an instance - * @param faces, number of faces of dices - * @param offset, first value of dice. - */ - DiceRollerNode(qint64 max, qint64 min = 1); - - /** - * @brief run - starts to roll dice. - */ + /** + * @brief DiceRollerNode builds an instance + * @param faces, number of faces of dices + * @param offset, first value of dice. + */ + DiceRollerNode(qint64 max, qint64 min= 1); + + /** + * @brief run - starts to roll dice. + */ virtual void run(ExecutionNode*); - /** - * @brief getFaces accessor - * @return the face count - */ + /** + * @brief getFaces accessor + * @return the face count + */ quint64 getFaces() const; - std::pair<qint64,qint64> getRange() const; - - /** - * @brief toString - * @param wl - * @return use to generate dot tree; - */ - virtual QString toString(bool wl)const; - /** - * @brief getPriority - * @return priority for dice roll: 4 (higher) - */ - virtual qint64 getPriority() const; + std::pair<qint64, qint64> getRange() const; + + /** + * @brief toString + * @param wl + * @return use to generate dot tree; + */ + virtual QString toString(bool wl) const; + /** + * @brief getPriority + * @return priority for dice roll: 4 (higher) + */ + virtual qint64 getPriority() const; virtual ExecutionNode* getCopy() const; -//private members + // private members Die::ArithmeticOperator getOperator() const; - void setOperator(const Die::ArithmeticOperator & dieOperator); + void setOperator(const Die::ArithmeticOperator& dieOperator); bool getUnique() const; void setUnique(bool unique); diff --git a/node/executionnode.cpp b/node/executionnode.cpp index 5b001fb..5bee091 100644 --- a/node/executionnode.cpp +++ b/node/executionnode.cpp @@ -3,21 +3,24 @@ #include <QUuid> ExecutionNode::ExecutionNode() - : m_previousNode(nullptr),m_result(nullptr),m_nextNode(nullptr),m_errors(QMap<ExecutionNode::DICE_ERROR_CODE,QString>()),m_id(QString("\"%1\"").arg(QUuid::createUuid().toString())) + : m_previousNode(nullptr) + , m_result(nullptr) + , m_nextNode(nullptr) + , m_errors(QMap<ExecutionNode::DICE_ERROR_CODE, QString>()) + , m_id(QString("\"%1\"").arg(QUuid::createUuid().toString())) { - } ExecutionNode::~ExecutionNode() { - if(nullptr!=m_result) + if(nullptr != m_result) { delete m_result; - m_result = nullptr; + m_result= nullptr; } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { delete m_nextNode; - m_nextNode = nullptr; + m_nextNode= nullptr; } } @@ -27,24 +30,24 @@ Result* ExecutionNode::getResult() } void ExecutionNode::setNextNode(ExecutionNode* node) { - m_nextNode = node; + m_nextNode= node; } void ExecutionNode::setPreviousNode(ExecutionNode* node) { - m_previousNode = node; + m_previousNode= node; } ExecutionNode* ExecutionNode::getNextNode() { return m_nextNode; } -QMap<ExecutionNode::DICE_ERROR_CODE,QString> ExecutionNode::getExecutionErrorMap() +QMap<ExecutionNode::DICE_ERROR_CODE, QString> ExecutionNode::getExecutionErrorMap() { - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { - auto const& keys = m_nextNode->getExecutionErrorMap().keys(); - for(auto& key: keys) + auto const& keys= m_nextNode->getExecutionErrorMap().keys(); + for(auto& key : keys) { - m_errors.insert(key,m_nextNode->getExecutionErrorMap().value(key)); + m_errors.insert(key, m_nextNode->getExecutionErrorMap().value(key)); } } return m_errors; @@ -59,13 +62,13 @@ ExecutionNode* ExecutionNode::getPreviousNode() const } void ExecutionNode::generateDotTree(QString& s) { - auto str = toString(true); + auto str= toString(true); if(s.contains(str)) return; s.append(toString(true)); s.append(";\n"); - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { s.append(toString(false)); s.append(" -> "); @@ -80,7 +83,7 @@ void ExecutionNode::generateDotTree(QString& s) s.append(" -> "); s.append("nullptr;\n"); } - if(nullptr!=m_result) + if(nullptr != m_result) { s.append(toString(false)); s.append(" ->"); @@ -89,7 +92,6 @@ void ExecutionNode::generateDotTree(QString& s) if(nullptr == m_nextNode) m_result->generateDotTree(s); } - } qint64 ExecutionNode::getScalarResult() { diff --git a/node/executionnode.h b/node/executionnode.h index d1a44c4..e8eca1f 100644 --- a/node/executionnode.h +++ b/node/executionnode.h @@ -10,15 +10,21 @@ class ExecutionNode { public: - enum DICE_ERROR_CODE {NO_DICE_ERROR, - DIE_RESULT_EXPECTED, - BAD_SYNTAXE, - ENDLESS_LOOP_ERROR, - DIVIDE_BY_ZERO, - NOTHING_UNDERSTOOD, - NO_DICE_TO_ROLL, - TOO_MANY_DICE,NO_VARIBALE, - INVALID_INDEX,UNEXPECTED_CHARACTER, NO_PREVIOUS_ERROR}; + enum DICE_ERROR_CODE + { + NO_DICE_ERROR, + DIE_RESULT_EXPECTED, + BAD_SYNTAXE, + ENDLESS_LOOP_ERROR, + DIVIDE_BY_ZERO, + NOTHING_UNDERSTOOD, + NO_DICE_TO_ROLL, + TOO_MANY_DICE, + NO_VARIBALE, + INVALID_INDEX, + UNEXPECTED_CHARACTER, + NO_PREVIOUS_ERROR + }; /** * @brief ExecutionNode */ @@ -31,7 +37,7 @@ public: * @brief run * @param previous */ - virtual void run(ExecutionNode* previous = nullptr)=0; + virtual void run(ExecutionNode* previous= nullptr)= 0; /** * @brief getResult * @return @@ -56,17 +62,17 @@ public: * @brief toString * @return */ - virtual QString toString(bool withLabel)const=0; + virtual QString toString(bool withLabel) const= 0; /** * @brief getPriority * @return */ - virtual qint64 getPriority() const=0; + virtual qint64 getPriority() const= 0; /** * @brief getErrorList * @return */ - virtual QMap<ExecutionNode::DICE_ERROR_CODE,QString> getExecutionErrorMap(); + virtual QMap<ExecutionNode::DICE_ERROR_CODE, QString> getExecutionErrorMap(); /** * @brief generateDotTree @@ -83,7 +89,7 @@ public: * @brief getCopy * @return should return a copy of that node. */ - virtual ExecutionNode* getCopy() const = 0; + virtual ExecutionNode* getCopy() const= 0; virtual qint64 getScalarResult(); @@ -99,11 +105,11 @@ protected: /** * @brief m_nextNode */ - ExecutionNode* m_nextNode = nullptr; + ExecutionNode* m_nextNode= nullptr; /** * @brief m_errors */ - QMap<ExecutionNode::DICE_ERROR_CODE,QString> m_errors; + QMap<ExecutionNode::DICE_ERROR_CODE, QString> m_errors; QString m_id; }; diff --git a/node/explodedicenode.cpp b/node/explodedicenode.cpp index 210f042..6df64ba 100644 --- a/node/explodedicenode.cpp +++ b/node/explodedicenode.cpp @@ -1,39 +1,38 @@ #include "explodedicenode.h" -ExplodeDiceNode::ExplodeDiceNode() - : m_diceResult(new DiceResult()),m_validator(nullptr) +ExplodeDiceNode::ExplodeDiceNode() : m_diceResult(new DiceResult()), m_validator(nullptr) { - m_result = m_diceResult; + m_result= m_diceResult; } void ExplodeDiceNode::run(ExecutionNode* previous) { - m_previousNode = previous; - if((nullptr!=previous)&&(nullptr!=previous->getResult())) + m_previousNode= previous; + if((nullptr != previous) && (nullptr != previous->getResult())) { - DiceResult* previous_result = dynamic_cast<DiceResult*>(previous->getResult()); + DiceResult* previous_result= dynamic_cast<DiceResult*>(previous->getResult()); m_result->setPrevious(previous_result); - if(nullptr!=previous_result) + if(nullptr != previous_result) { - for(auto& die: previous_result->getResultList()) + for(auto& die : previous_result->getResultList()) { - Die* tmpdie = new Die(); - *tmpdie=*die; + Die* tmpdie= new Die(); + *tmpdie= *die; m_diceResult->insertResult(tmpdie); die->displayed(); } - QList<Die*> list = m_diceResult->getResultList(); + QList<Die*> list= m_diceResult->getResultList(); - for(auto& die: list) + for(auto& die : list) { - while(m_validator->hasValid(die,false)) + while(m_validator->hasValid(die, false)) { die->roll(true); } } - // m_diceResult->setResultList(list); + // m_diceResult->setResultList(list); - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } @@ -42,44 +41,44 @@ void ExplodeDiceNode::run(ExecutionNode* previous) } ExplodeDiceNode::~ExplodeDiceNode() { - if(nullptr!=m_validator) - { - delete m_validator; - } + if(nullptr != m_validator) + { + delete m_validator; + } } void ExplodeDiceNode::setValidator(Validator* val) { - m_validator = val; + m_validator= val; } QString ExplodeDiceNode::toString(bool withlabel) const { - if(withlabel) - { + if(withlabel) + { return QString("%1 [label=\"ExplodeDiceNode %2\"]").arg(m_id, m_validator->toString()); - } - else - { - return m_id; - } + } + else + { + return m_id; + } } qint64 ExplodeDiceNode::getPriority() const { - qint64 priority=0; - if(nullptr!=m_previousNode) + qint64 priority= 0; + if(nullptr != m_previousNode) { - priority = m_previousNode->getPriority(); + priority= m_previousNode->getPriority(); } return priority; } ExecutionNode* ExplodeDiceNode::getCopy() const { - ExplodeDiceNode* node = new ExplodeDiceNode(); - if(nullptr!=m_validator) + ExplodeDiceNode* node= new ExplodeDiceNode(); + if(nullptr != m_validator) { node->setValidator(m_validator->getCopy()); } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/explodedicenode.h b/node/explodedicenode.h index feea86f..e72298a 100644 --- a/node/explodedicenode.h +++ b/node/explodedicenode.h @@ -13,13 +13,14 @@ class ExplodeDiceNode : public ExecutionNode { public: ExplodeDiceNode(); - virtual ~ExplodeDiceNode(); - virtual void run(ExecutionNode* previous = nullptr); - virtual void setValidator(Validator* ); - virtual QString toString(bool )const; + virtual ~ExplodeDiceNode(); + virtual void run(ExecutionNode* previous= nullptr); + virtual void setValidator(Validator*); + virtual QString toString(bool) const; virtual qint64 getPriority() const; - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; + protected: DiceResult* m_diceResult; Validator* m_validator; diff --git a/node/filternode.cpp b/node/filternode.cpp index b2a2db9..bda9c20 100644 --- a/node/filternode.cpp +++ b/node/filternode.cpp @@ -1,43 +1,41 @@ #include "filternode.h" -FilterNode::FilterNode() - : m_diceResult(new DiceResult()),m_eachValue(false) +FilterNode::FilterNode() : m_diceResult(new DiceResult()), m_eachValue(false) { - m_result = m_diceResult; + m_result= m_diceResult; } FilterNode::~FilterNode() { - if(nullptr!=m_validator) + if(nullptr != m_validator) { delete m_validator; } } void FilterNode::setValidator(Validator* validator) { - m_validator = validator; + m_validator= validator; } void FilterNode::run(ExecutionNode* previous) { - m_previousNode = previous; - if(nullptr==previous) + m_previousNode= previous; + if(nullptr == previous) { return; } - DiceResult* previousDiceResult = dynamic_cast<DiceResult*>(previous->getResult()); + DiceResult* previousDiceResult= dynamic_cast<DiceResult*>(previous->getResult()); m_result->setPrevious(previousDiceResult); - if(nullptr!=previousDiceResult) + if(nullptr != previousDiceResult) { - QList<Die*> diceList=previousDiceResult->getResultList(); + QList<Die*> diceList= previousDiceResult->getResultList(); QList<Die*> diceList2; - for(Die* tmp : diceList) { - if(m_validator->hasValid(tmp,m_eachValue)) + if(m_validator->hasValid(tmp, m_eachValue)) { - Die* tmpdie = new Die(); - *tmpdie=*tmp; + Die* tmpdie= new Die(); + *tmpdie= *tmp; diceList2.append(tmpdie); tmp->displayed(); } @@ -48,7 +46,7 @@ void FilterNode::run(ExecutionNode* previous) } m_diceResult->setResultList(diceList2); - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } @@ -68,23 +66,22 @@ QString FilterNode::toString(bool wl) const } qint64 FilterNode::getPriority() const { - qint64 priority=0; - if(nullptr!=m_nextNode) + qint64 priority= 0; + if(nullptr != m_nextNode) { - priority = m_nextNode->getPriority(); + priority= m_nextNode->getPriority(); } - return priority; } ExecutionNode* FilterNode::getCopy() const { - FilterNode* node = new FilterNode(); - if(nullptr!=m_validator) + FilterNode* node= new FilterNode(); + if(nullptr != m_validator) { node->setValidator(m_validator->getCopy()); } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/filternode.h b/node/filternode.h index 02e37af..77ae7b6 100644 --- a/node/filternode.h +++ b/node/filternode.h @@ -3,8 +3,8 @@ #include "executionnode.h" -#include "validator.h" #include "result/diceresult.h" +#include "validator.h" class FilterNode : public ExecutionNode { @@ -16,12 +16,12 @@ public: /** * @brief setValidator */ - virtual void setValidator(Validator* ); + virtual void setValidator(Validator*); /** * @brief toString * @return */ - virtual QString toString(bool withLabel)const; + virtual QString toString(bool withLabel) const; /** * @brief getPriority * @return @@ -29,6 +29,7 @@ public: virtual qint64 getPriority() const; virtual ExecutionNode* getCopy() const; + private: DiceResult* m_diceResult; Validator* m_validator; diff --git a/node/groupnode.cpp b/node/groupnode.cpp index 00bb15e..681db47 100644 --- a/node/groupnode.cpp +++ b/node/groupnode.cpp @@ -1,40 +1,40 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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. * + ***************************************************************************/ #include "groupnode.h" #include "result/diceresult.h" //------------------------------- int DieGroup::getSum() const { - int sum =0; + int sum= 0; for(int i : *this) { - sum += i; + sum+= i; } return sum; } void DieGroup::removeValue(DieGroup i) { - for(auto x : i ) + for(auto x : i) { removeOne(x); } @@ -42,7 +42,7 @@ void DieGroup::removeValue(DieGroup i) int DieGroup::getLost() const { - return getSum()-m_exceptedValue; + return getSum() - m_exceptedValue; } qint64 DieGroup::getExceptedValue() const @@ -52,40 +52,36 @@ qint64 DieGroup::getExceptedValue() const void DieGroup::setExceptedValue(qint64 exceptedValue) { - m_exceptedValue = exceptedValue; + m_exceptedValue= exceptedValue; } - - - //--------------------- -GroupNode::GroupNode() - : m_scalarResult(new ScalarResult()) +GroupNode::GroupNode() : m_scalarResult(new ScalarResult()) { - m_result = m_scalarResult; + m_result= m_scalarResult; } void GroupNode::run(ExecutionNode* previous) { - m_previousNode = previous; + m_previousNode= previous; if(nullptr != previous) { m_result->setPrevious(previous->getResult()); - Result* tmpResult = previous->getResult(); + Result* tmpResult= previous->getResult(); if(nullptr != tmpResult) { - DiceResult* dice = dynamic_cast<DiceResult*>(tmpResult); + DiceResult* dice= dynamic_cast<DiceResult*>(tmpResult); if(nullptr != dice) { - auto list = dice->getResultList(); + auto list= dice->getResultList(); DieGroup allResult; for(auto& die : list) { allResult << die->getListValue(); } - std::sort(allResult.begin(),allResult.end(), std::greater<qint64>()); + std::sort(allResult.begin(), allResult.end(), std::greater<qint64>()); if(allResult.getSum() > m_groupValue) { - auto const die =getGroup(allResult); + auto const die= getGroup(allResult); m_scalarResult->setValue(die.size()); } else @@ -95,7 +91,7 @@ void GroupNode::run(ExecutionNode* previous) } } } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } @@ -114,22 +110,21 @@ QString GroupNode::toString(bool withLabel) const } qint64 GroupNode::getPriority() const { - qint64 priority=0; - if(nullptr!=m_nextNode) + qint64 priority= 0; + if(nullptr != m_nextNode) { - priority = m_nextNode->getPriority(); + priority= m_nextNode->getPriority(); } return priority; } ExecutionNode* GroupNode::getCopy() const { - GroupNode* node = new GroupNode(); - if(nullptr!=m_nextNode) + GroupNode* node= new GroupNode(); + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; - } int GroupNode::getGroupValue() const @@ -139,12 +134,12 @@ int GroupNode::getGroupValue() const void GroupNode::setGroupValue(qint64 groupValue) { - m_groupValue = groupValue; + m_groupValue= groupValue; } bool GroupNode::composeWithPrevious(DieGroup previous, qint64 first, qint64 current, DieGroup& addValue) { - if(previous.getSum()+first+current == m_groupValue) + if(previous.getSum() + first + current == m_groupValue) { addValue.append(previous); addValue.append(first); @@ -155,8 +150,8 @@ bool GroupNode::composeWithPrevious(DieGroup previous, qint64 first, qint64 curr if(previous.isEmpty()) return false; - int maxComboLength = previous.size(); - bool hasReachMax = false; + int maxComboLength= previous.size(); + bool hasReachMax= false; QList<DieGroup> possibleUnion; for(auto va : previous) @@ -168,7 +163,7 @@ bool GroupNode::composeWithPrevious(DieGroup previous, qint64 first, qint64 curr while(!hasReachMax) { - auto tmpValues = previous; + auto tmpValues= previous; QList<DieGroup> possibleTmp; for(auto& diaG : possibleUnion) { @@ -181,31 +176,30 @@ bool GroupNode::composeWithPrevious(DieGroup previous, qint64 first, qint64 curr DieGroup dia; dia.append(diaG); dia.append(value); - if(dia.size() >= maxComboLength-1) - hasReachMax = true; + if(dia.size() >= maxComboLength - 1) + hasReachMax= true; else possibleTmp.append(dia); } } if(possibleTmp.isEmpty()) - hasReachMax = true; + hasReachMax= true; else { possibleTmp.append(possibleUnion); - possibleUnion = possibleTmp; + possibleUnion= possibleTmp; } } - std::sort(possibleUnion.begin(),possibleUnion.end(),[=](const DieGroup& a, const DieGroup& b){ - return a.getLost() > b.getLost(); - }); - bool found = false; - for(int i = 0;(!found && i < possibleUnion.size()); ++i) + std::sort(possibleUnion.begin(), possibleUnion.end(), + [=](const DieGroup& a, const DieGroup& b) { return a.getLost() > b.getLost(); }); + bool found= false; + for(int i= 0; (!found && i < possibleUnion.size()); ++i) { - auto& value = possibleUnion.at(i); + auto& value= possibleUnion.at(i); if(value.getSum() + current + first >= m_groupValue) { addValue << value << current << first; - found = true; + found= true; } } return found; @@ -216,62 +210,62 @@ QList<DieGroup> GroupNode::getGroup(DieGroup values) if(values.isEmpty()) return {}; - auto first = values.takeFirst(); + auto first= values.takeFirst(); QList<DieGroup> result; - QMap<qint64,DieGroup> loseMap; + QMap<qint64, DieGroup> loseMap; if(first >= m_groupValue) { DieGroup group; - group << first ; - loseMap[0] = group; + group << first; + loseMap[0]= group; } else { - DieGroup::reverse_iterator it = values.rbegin(); - bool foundPerfect = false; - qint64 cumuledValue = 0; + DieGroup::reverse_iterator it= values.rbegin(); + bool foundPerfect= false; + qint64 cumuledValue= 0; DieGroup previousValue; while((values.rend() != it) && !foundPerfect) { - if(first+*it == m_groupValue) + if(first + *it == m_groupValue) { - foundPerfect = true; + foundPerfect= true; DieGroup group; group << first << *it; - loseMap[0] = group; + loseMap[0]= group; } - else if(first+*it > m_groupValue) + else if(first + *it > m_groupValue) { DieGroup group; group << first << *it; - loseMap[first+*it-m_groupValue]=group; + loseMap[first + *it - m_groupValue]= group; } - else if(first+*it+cumuledValue == m_groupValue) + else if(first + *it + cumuledValue == m_groupValue) { DieGroup group; group << first << *it << previousValue; - foundPerfect = true; - loseMap[0] = group; + foundPerfect= true; + loseMap[0]= group; } - else if(first+*it+cumuledValue > m_groupValue) + else if(first + *it + cumuledValue > m_groupValue) { DieGroup group; group.setExceptedValue(m_groupValue); - auto b = composeWithPrevious(previousValue,first, *it, group); + auto b= composeWithPrevious(previousValue, first, *it, group); if(b) loseMap[group.getLost()]= group; } previousValue << *it; - cumuledValue += *it; + cumuledValue+= *it; ++it; } } if(!loseMap.isEmpty()) { - DieGroup die = loseMap.first(); + DieGroup die= loseMap.first(); result.append(die); - DieGroup valueToRemove = die; + DieGroup valueToRemove= die; if(!valueToRemove.isEmpty()) { valueToRemove.removeFirst(); @@ -284,7 +278,4 @@ QList<DieGroup> GroupNode::getGroup(DieGroup values) } } return result; - } - - diff --git a/node/groupnode.h b/node/groupnode.h index 4c1b74c..e09bf19 100644 --- a/node/groupnode.h +++ b/node/groupnode.h @@ -1,30 +1,30 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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 GROUPNODE_H #define GROUPNODE_H #include "node/executionnode.h" #include "result/scalarresult.h" -//typedef QList<qint64> DieGroup; +// typedef QList<qint64> DieGroup; class DieGroup : public QList<qint64> { @@ -38,8 +38,7 @@ public: void setExceptedValue(qint64 exceptedValue); private: - qint64 m_exceptedValue = 0; - + qint64 m_exceptedValue= 0; }; /** * @brief The GroupNode class is an ExecutionNode. @@ -49,16 +48,18 @@ class GroupNode : public ExecutionNode public: GroupNode(); void run(ExecutionNode* previous); - virtual QString toString(bool withLabel)const; + virtual QString toString(bool withLabel) const; virtual qint64 getPriority() const; - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; int getGroupValue() const; void setGroupValue(qint64 groupValue); QList<DieGroup> getGroup(DieGroup); + protected: bool composeWithPrevious(DieGroup previous, qint64 first, qint64 current, DieGroup& addValue); + private: ScalarResult* m_scalarResult; qint64 m_groupValue; diff --git a/node/helpnode.cpp b/node/helpnode.cpp index 969c1cf..7748012 100644 --- a/node/helpnode.cpp +++ b/node/helpnode.cpp @@ -1,36 +1,35 @@ /*************************************************************************** - * Copyright (C) 2015 by Renaud Guezennec * - * http://www.rolisteam.org/contact * - * * - * rolisteam 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. * - ***************************************************************************/ + * Copyright (C) 2015 by Renaud Guezennec * + * http://www.rolisteam.org/contact * + * * + * rolisteam 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. * + ***************************************************************************/ #include "helpnode.h" -HelpNode::HelpNode() - : m_path("https://github.com/Rolisteam/DiceParser/blob/master/HelpMe.md") +HelpNode::HelpNode() : m_path("https://github.com/Rolisteam/DiceParser/blob/master/HelpMe.md") { - m_result = new StringResult(); + m_result= new StringResult(); } void HelpNode::run(ExecutionNode* previous) { - m_previousNode = previous; - StringResult* txtResult = dynamic_cast<StringResult*>(m_result); + m_previousNode= previous; + StringResult* txtResult= dynamic_cast<StringResult*>(m_result); txtResult->setHighLight(false); - if((nullptr == previous)&&(txtResult != nullptr)) + if((nullptr == previous) && (txtResult != nullptr)) { txtResult->setText(QObject::tr("Rolisteam Dice Parser:\n" "\n" @@ -39,7 +38,8 @@ void HelpNode::run(ExecutionNode* previous) "!1d20\n" "!6d10e10k3 (L5R)\n" "\n" - "Full documentation at: %1").arg(m_path)); + "Full documentation at: %1") + .arg(m_path)); /*txtResult->setText(QObject::tr("Rolisteam Dice Parser:\n" "\n" "Example (with ! as prefix):\n" @@ -48,19 +48,22 @@ void HelpNode::run(ExecutionNode* previous) "\n" "Operator list:\n" "\n" - "k : Keep : 2d10k1 => roll two 10-sided dice and keep the higher one (kl1 for smaller one)\n" - "K : Keep And Explode : 2d10K1 => Equivalent of 2d10e10k1\n" - "s : Sort : 8d10 => roll eight 10-sided dice and sort the result list\n" - "c : Count : 8d10c[>7] => roll eight 10-sided dice and count how many dice are higher than 7\n" - "r : Reroll : 8d6r1 => roll eight 6-sided dice and reroll dice once if its result is 1. (result of the reroll can be 1)\n" - "e : Explode : 8d10e10 => roll eight 10-sided dice and while dice makes a 10 it is reroll. The result is added to those dice.\n" - "a : Reroll and add : 8d6a1 => roll eight 6-sided dice and reroll dice once and the result is added at 1\n" - "m : Merge : 1d20;1d10mk1 => roll one 20-side die and one 10-sided die and keep the higher die\n" - "i : if : 1d100i[=100]{\"jackpot\"} => Roll one 100-side die and display \"jackpot\" if the die result is 100.\n" - "f : filter : 4d10f[!=4] => roll four 10-sided dice and ignore all dice with 4 as result" - "; : Next instruction : 1d20;2d10;3d8 => roll one 20-sided die, two 10-sided dice and three 8-sided dice \n" - "g : Group : 8d10g10 => count how many group of 10 it is possible to do (according to rule of 7th sea).\n" - "# : Comment : 1d2 #flip coin=> display flip coin as comment of 1 or 2 result.\n" + "k : Keep : 2d10k1 => roll two 10-sided dice and keep the + higher one (kl1 for smaller one)\n" "K : Keep And Explode : 2d10K1 => Equivalent of 2d10e10k1\n" "s : + Sort : 8d10 => roll eight 10-sided dice and sort the result list\n" "c : Count : + 8d10c[>7] => roll eight 10-sided dice and count how many dice are higher than 7\n" "r : Reroll : + 8d6r1 => roll eight 6-sided dice and reroll dice once if its result is 1. (result of the reroll can be + 1)\n" "e : Explode : 8d10e10 => roll eight 10-sided dice and while dice makes a 10 it is + reroll. The result is added to those dice.\n" "a : Reroll and add : 8d6a1 => roll eight 6-sided dice + and reroll dice once and the result is added at 1\n" "m : Merge : 1d20;1d10mk1 => roll one 20-side + die and one 10-sided die and keep the higher die\n" "i : if : 1d100i[=100]{\"jackpot\"} => Roll + one 100-side die and display \"jackpot\" if the die result is 100.\n" "f : filter : 4d10f[!=4] => + roll four 10-sided dice and ignore all dice with 4 as result" + "; : Next instruction : 1d20;2d10;3d8 => roll one 20-sided die, two 10-sided + dice and three 8-sided dice \n" "g : Group : 8d10g10 => count how many group of 10 it is + possible to do (according to rule of 7th sea).\n" + "# : Comment : 1d2 #flip coin=> display flip coin as comment of 1 or 2 + result.\n" "\n" "Validator:\n" "\n" @@ -71,13 +74,15 @@ void HelpNode::run(ExecutionNode* previous) "\n" "c[>7 & %2=0] : count how many dice are higher than 7 and even\n" "c[>7 | %2=0] : count how many dice are higher than 7 or even\n" - "c[>7 ^ %2=0] : count how many dice are higher than 7 or even but not higher than 7 and even\n" + "c[>7 ^ %2=0] : count how many dice are higher than 7 or even but not higher + than 7 and even\n" "\n" "List:\n" "\n" "1L[green,blue] => pick value from the list (green or blue)\n" - "2L[green,blue] => pick two values from the list (green,green | green,blue | blue,green | blue,blue)\n" - "2Lu[green,blue] => pick two unique values from the list (green,blue | blue,green)\n" + "2L[green,blue] => pick two values from the list (green,green | green,blue | + blue,green | blue,blue)\n" "2Lu[green,blue] => pick two unique values from the list (green,blue | + blue,green)\n" "\n" "Arithmetic\n" "\n" @@ -87,7 +92,8 @@ void HelpNode::run(ExecutionNode* previous) "7/2 => 3.5\n" "2^4 => 16\n" "1d6+6 => roll one 6-sided die and add 6 to its result\n" - "(2d4+2)d10 => roll two 4-sided dice, add 2 to the result[2;8] then roll from four to ten 10-sided dice\n" + "(2d4+2)d10 => roll two 4-sided dice, add 2 to the result[2;8] then roll from + four to ten 10-sided dice\n" "\n" "Full documentation at: %1").arg(m_path));*/ m_result->setPrevious(nullptr); @@ -98,21 +104,21 @@ void HelpNode::run(ExecutionNode* previous) m_result->setPrevious(previous->getResult()); } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } } QString HelpNode::toString(bool wl) const { - if(wl) - { - return QString("%1 [label=\"Rolisteam Dice Parser:\nFull documentation at: %2\"]").arg(m_id, m_path); - } - else - { - return m_id; - } + if(wl) + { + return QString("%1 [label=\"Rolisteam Dice Parser:\nFull documentation at: %2\"]").arg(m_id, m_path); + } + else + { + return m_id; + } } qint64 HelpNode::getPriority() const @@ -121,13 +127,13 @@ qint64 HelpNode::getPriority() const } void HelpNode::setHelpPath(QString path) { - m_path = path; + m_path= path; } ExecutionNode* HelpNode::getCopy() const { - HelpNode* node = new HelpNode(); - if(nullptr!=m_nextNode) + HelpNode* node= new HelpNode(); + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/helpnode.h b/node/helpnode.h index 2b82af0..a333c6d 100644 --- a/node/helpnode.h +++ b/node/helpnode.h @@ -1,22 +1,22 @@ /*************************************************************************** - * Copyright (C) 2015 by Renaud Guezennec * - * http:://www.rolisteam.org/contact * - * * - * rolisteam 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. * - ***************************************************************************/ + * Copyright (C) 2015 by Renaud Guezennec * + * http:://www.rolisteam.org/contact * + * * + * rolisteam 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 HELPNODE_H #define HELPNODE_H #include "executionnode.h" @@ -45,7 +45,7 @@ public: * @brief toString * @return */ - virtual QString toString(bool )const; + virtual QString toString(bool) const; /** * @brief getPriority * @return @@ -61,9 +61,9 @@ public: * @return */ virtual ExecutionNode* getCopy() const; + private: QString m_path; - }; #endif // HELPNODE_H diff --git a/node/ifnode.cpp b/node/ifnode.cpp index 3a2cd95..fbcd9b9 100644 --- a/node/ifnode.cpp +++ b/node/ifnode.cpp @@ -1,137 +1,135 @@ /*************************************************************************** - * Copyright (C) 2016 by Renaud Guezennec * - * http://www.rolisteam.org/contact * - * * - * rolisteam 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. * - ***************************************************************************/ + * Copyright (C) 2016 by Renaud Guezennec * + * http://www.rolisteam.org/contact * + * * + * rolisteam 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. * + ***************************************************************************/ #include "ifnode.h" #include "result/diceresult.h" -IfNode::IfNode() - : m_validator(nullptr),m_conditionType(AllOfThem),m_true(nullptr),m_false(nullptr) +IfNode::IfNode() : m_validator(nullptr), m_conditionType(AllOfThem), m_true(nullptr), m_false(nullptr) { - //m_result = new DiceResult(); + // m_result = new DiceResult(); } IfNode::~IfNode() { - m_result=nullptr; + m_result= nullptr; } -void IfNode::run(ExecutionNode *previous) +void IfNode::run(ExecutionNode* previous) { - m_previousNode = previous; - if(nullptr==previous) + m_previousNode= previous; + if(nullptr == previous) { return; } - ExecutionNode* previousLoop = previous; - ExecutionNode* nextNode = nullptr; - bool runNext = (nullptr==m_nextNode) ? false : true; - Result* previousResult = previous->getResult(); - m_result = previousResult; + ExecutionNode* previousLoop= previous; + ExecutionNode* nextNode= nullptr; + bool runNext= (nullptr == m_nextNode) ? false : true; + Result* previousResult= previous->getResult(); + m_result= previousResult; - if(nullptr!=m_result) + if(nullptr != m_result) { - qreal value = previousResult->getResult(Result::SCALAR).toReal(); + qreal value= previousResult->getResult(Result::SCALAR).toReal(); - if(nullptr!=m_validator) + if(nullptr != m_validator) { - DiceResult* previousDiceResult = dynamic_cast<DiceResult*>(previousResult); - if(nullptr!=previousDiceResult) + DiceResult* previousDiceResult= dynamic_cast<DiceResult*>(previousResult); + if(nullptr != previousDiceResult) { - QList<Die*> diceList=previousDiceResult->getResultList(); + QList<Die*> diceList= previousDiceResult->getResultList(); if(m_conditionType == OnEach) { for(Die* dice : diceList) { - if(m_validator->hasValid(dice,true,true)) + if(m_validator->hasValid(dice, true, true)) { - nextNode = (nullptr==m_true) ? nullptr: m_true->getCopy(); + nextNode= (nullptr == m_true) ? nullptr : m_true->getCopy(); } else { - nextNode = (nullptr==m_false) ? nullptr: m_false->getCopy(); + nextNode= (nullptr == m_false) ? nullptr : m_false->getCopy(); } - if(nullptr!=nextNode) + if(nullptr != nextNode) { - if(nullptr==previousLoop->getNextNode()) + if(nullptr == previousLoop->getNextNode()) { previousLoop->setNextNode(nextNode); } - if(nullptr==m_nextNode) + if(nullptr == m_nextNode) { - m_nextNode = nextNode; + m_nextNode= nextNode; } nextNode->run(previousLoop); - previousLoop = getLeafNode(nextNode); + previousLoop= getLeafNode(nextNode); } } } - else if((m_conditionType == OneOfThem)||(m_conditionType == AllOfThem)) + else if((m_conditionType == OneOfThem) || (m_conditionType == AllOfThem)) { - bool trueForAll=true; - bool falseForAll=true; + bool trueForAll= true; + bool falseForAll= true; - bool oneIsTrue=false; - bool oneIsFalse=false; + bool oneIsTrue= false; + bool oneIsFalse= false; for(Die* dice : diceList) { - bool result = m_validator->hasValid(dice,true,true); - trueForAll = trueForAll ? result : false; - falseForAll = falseForAll ? result : false; + bool result= m_validator->hasValid(dice, true, true); + trueForAll= trueForAll ? result : false; + falseForAll= falseForAll ? result : false; - oneIsTrue |= result; - oneIsFalse = !result ? true : oneIsFalse; + oneIsTrue|= result; + oneIsFalse= !result ? true : oneIsFalse; } - if(m_conditionType==OneOfThem) + if(m_conditionType == OneOfThem) { if(oneIsTrue) { - nextNode = (nullptr==m_true) ? nullptr: m_true->getCopy(); + nextNode= (nullptr == m_true) ? nullptr : m_true->getCopy(); } - else //if(oneIsFalse) + else // if(oneIsFalse) { - nextNode = (nullptr==m_false) ? nullptr: m_false->getCopy(); + nextNode= (nullptr == m_false) ? nullptr : m_false->getCopy(); } } - else if(m_conditionType==AllOfThem) + else if(m_conditionType == AllOfThem) { if(trueForAll) { - nextNode = (nullptr==m_true) ? nullptr: m_true->getCopy(); + nextNode= (nullptr == m_true) ? nullptr : m_true->getCopy(); } - else //if(falseForAll) + else // if(falseForAll) { - nextNode = (nullptr==m_false) ? nullptr: m_false->getCopy(); + nextNode= (nullptr == m_false) ? nullptr : m_false->getCopy(); } } - - if(nullptr!=nextNode) + if(nullptr != nextNode) { - if(nullptr==m_nextNode) + if(nullptr == m_nextNode) { - m_nextNode = nextNode; + m_nextNode= nextNode; } nextNode->run(previousLoop); - previousLoop = getLeafNode(nextNode); + previousLoop= getLeafNode(nextNode); } } } @@ -139,31 +137,31 @@ void IfNode::run(ExecutionNode *previous) if(m_conditionType == OnScalar) { - Die* dice = new Die(); + Die* dice= new Die(); dice->setValue(value); dice->insertRollValue(value); dice->setMaxValue(value); - if(m_validator->hasValid(dice,true,true)) + if(m_validator->hasValid(dice, true, true)) { - nextNode=m_true; + nextNode= m_true; } else { - nextNode=m_false; + nextNode= m_false; } - if(nullptr!=nextNode) + if(nullptr != nextNode) { - if(nullptr==m_nextNode) + if(nullptr == m_nextNode) { - m_nextNode = nextNode; + m_nextNode= nextNode; } nextNode->run(previousLoop); - previousLoop = getLeafNode(nextNode); + previousLoop= getLeafNode(nextNode); } } } - if((nullptr!=m_nextNode)&&(runNext)) + if((nullptr != m_nextNode) && (runNext)) { m_nextNode->run(previousLoop); } @@ -171,32 +169,32 @@ void IfNode::run(ExecutionNode *previous) void IfNode::setValidator(Validator* val) { - m_validator = val; + m_validator= val; } void IfNode::setInstructionTrue(ExecutionNode* node) { - m_true = node; + m_true= node; } void IfNode::setInstructionFalse(ExecutionNode* node) { - m_false = node; + m_false= node; } void IfNode::generateDotTree(QString& s) { s.append(toString(true)); s.append(";\n"); - if((nullptr!=m_true)&&(m_true != m_nextNode)) + if((nullptr != m_true) && (m_true != m_nextNode)) { s.append(toString(false)); s.append(" -> "); s.append(m_true->toString(false)); - s.append("[label=\"true"+m_validator->toString()+"\"];\n"); + s.append("[label=\"true" + m_validator->toString() + "\"];\n"); m_true->generateDotTree(s); } - if((nullptr!=m_false)&&(m_false != m_nextNode)) + if((nullptr != m_false) && (m_false != m_nextNode)) { s.append(toString(false)); s.append(" -> "); @@ -205,7 +203,7 @@ void IfNode::generateDotTree(QString& s) m_false->generateDotTree(s); } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { s.append(toString(false)); s.append(" -> "); @@ -219,9 +217,8 @@ void IfNode::generateDotTree(QString& s) s.append(" -> "); s.append("nullptr;\n"); - if(nullptr!=m_result) + if(nullptr != m_result) { - s.append(toString(false)); s.append(" ->"); s.append(m_result->toString(false)); @@ -231,7 +228,7 @@ void IfNode::generateDotTree(QString& s) } } -QString IfNode::toString(bool wl) const +QString IfNode::toString(bool wl) const { if(wl) { @@ -250,10 +247,10 @@ qint64 IfNode::getPriority() const ExecutionNode* IfNode::getLeafNode(ExecutionNode* node) { - ExecutionNode* next = node; - while(nullptr != next->getNextNode() ) + ExecutionNode* next= node; + while(nullptr != next->getNextNode()) { - next = next->getNextNode(); + next= next->getNextNode(); } return next; } @@ -263,31 +260,30 @@ IfNode::ConditionType IfNode::getConditionType() const return m_conditionType; } -void IfNode::setConditionType(const IfNode::ConditionType &conditionType) +void IfNode::setConditionType(const IfNode::ConditionType& conditionType) { - m_conditionType = conditionType; + m_conditionType= conditionType; } ExecutionNode* IfNode::getCopy() const { - IfNode* node = new IfNode(); + IfNode* node= new IfNode(); node->setConditionType(m_conditionType); - if(nullptr!=m_validator) + if(nullptr != m_validator) { node->setValidator(m_validator->getCopy()); } - if(nullptr!=m_false) + if(nullptr != m_false) { node->setInstructionFalse(m_false->getCopy()); } - if(nullptr!=m_true) + if(nullptr != m_true) { node->setInstructionTrue(m_true->getCopy()); } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; - } diff --git a/node/ifnode.h b/node/ifnode.h index 29fcec3..b4dcd76 100644 --- a/node/ifnode.h +++ b/node/ifnode.h @@ -1,22 +1,22 @@ /*************************************************************************** - * Copyright (C) 2015 by Renaud Guezennec * - * http:://www.rolisteam.org/contact * - * * - * rolisteam 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. * - ***************************************************************************/ + * Copyright (C) 2015 by Renaud Guezennec * + * http:://www.rolisteam.org/contact * + * * + * rolisteam 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 IFNODE_H #define IFNODE_H @@ -34,7 +34,13 @@ public: /** * @brief The ConditionType enum */ - enum ConditionType {OnEach,OneOfThem,AllOfThem,OnScalar}; + enum ConditionType + { + OnEach, + OneOfThem, + AllOfThem, + OnScalar + }; /** * @brief IfNode */ @@ -47,11 +53,11 @@ public: * @brief run * @param previous */ - virtual void run(ExecutionNode* previous = nullptr); + virtual void run(ExecutionNode* previous= nullptr); /** * @brief setValidator */ - virtual void setValidator(Validator* ); + virtual void setValidator(Validator*); /** * @brief setInstructionTrue */ @@ -64,14 +70,13 @@ public: * @brief toString * @return */ - virtual QString toString(bool )const; + virtual QString toString(bool) const; /** * @brief getPriority * @return */ virtual qint64 getPriority() const; - /** * @brief generateDotTree */ @@ -81,7 +86,7 @@ public: * @brief getCopy * @return */ - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; /** * @brief getConditionType * @return @@ -92,10 +97,10 @@ public: * @brief setConditionType * @param conditionType */ - void setConditionType(const IfNode::ConditionType &conditionType); + void setConditionType(const IfNode::ConditionType& conditionType); protected: - ExecutionNode *getLeafNode(ExecutionNode *node); + ExecutionNode* getLeafNode(ExecutionNode* node); protected: Validator* m_validator; diff --git a/node/jumpbackwardnode.cpp b/node/jumpbackwardnode.cpp index 2f04bb8..83bdb1e 100644 --- a/node/jumpbackwardnode.cpp +++ b/node/jumpbackwardnode.cpp @@ -23,44 +23,42 @@ JumpBackwardNode::JumpBackwardNode() { - m_previousNode=nullptr; - m_backwardNode = nullptr; - m_diceResult =new DiceResult(); - m_result = m_diceResult; + m_previousNode= nullptr; + m_backwardNode= nullptr; + m_diceResult= new DiceResult(); + m_result= m_diceResult; } - - qint64 JumpBackwardNode::getPriority() const { return 4; } QString JumpBackwardNode::toString(bool wl) const { - if(wl) - { - return QString("%1 [label=\"JumpBackwardNode\"]").arg(m_id); - } - else - { - return m_id; - } + if(wl) + { + return QString("%1 [label=\"JumpBackwardNode\"]").arg(m_id); + } + else + { + return m_id; + } } void JumpBackwardNode::generateDotTree(QString& s) { s.append(toString(true)); s.append(";\n"); - if(nullptr!=m_backwardNode) + if(nullptr != m_backwardNode) { s.append(toString(false)); s.append(" -> "); s.append(m_backwardNode->toString(false)); s.append("[label=\"backward\"];\n"); - //m_backwardNode->generateDotTree(s); + // m_backwardNode->generateDotTree(s); } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { s.append(toString(false)); s.append(" -> "); @@ -74,7 +72,7 @@ void JumpBackwardNode::generateDotTree(QString& s) s.append(" -> "); s.append("nullptr;\n"); - if(nullptr!=m_result) + if(nullptr != m_result) { s.append(toString(false)); s.append(" ->"); @@ -83,90 +81,87 @@ void JumpBackwardNode::generateDotTree(QString& s) m_result->generateDotTree(s); } } - } void JumpBackwardNode::run(ExecutionNode* previous) { - m_previousNode = previous; - ExecutionNode* parent = previous; - bool found=false; - //int i = 3; - Result* result=nullptr; - while((nullptr!=parent)&&(!found)) - { - - result = parent->getResult(); - if(nullptr!=result) - { - //--i; - if(/*(i==0)&&*/(result->hasResultOfType(Result::DICE_LIST))) - { - found =true; - m_backwardNode = parent; - } - else + m_previousNode= previous; + ExecutionNode* parent= previous; + bool found= false; + // int i = 3; + Result* result= nullptr; + while((nullptr != parent) && (!found)) + { + result= parent->getResult(); + if(nullptr != result) + { + //--i; + if(/*(i==0)&&*/ (result->hasResultOfType(Result::DICE_LIST))) + { + found= true; + m_backwardNode= parent; + } + else + { + JumpBackwardNode* jpNode= dynamic_cast<JumpBackwardNode*>(parent); + if(nullptr != jpNode) { - JumpBackwardNode* jpNode = dynamic_cast<JumpBackwardNode*>(parent); - if(nullptr!=jpNode) - { - found = true; - m_backwardNode = parent; - } + found= true; + m_backwardNode= parent; } - } - if(!found) - { - parent = parent->getPreviousNode(); } - - } - if(nullptr==result) + } + if(!found) { - m_errors.insert(DIE_RESULT_EXPECTED,QObject::tr(" The @ operator expects dice result. Please check the documentation to fix your command.")); + parent= parent->getPreviousNode(); } - else + } + if(nullptr == result) + { + m_errors.insert(DIE_RESULT_EXPECTED, + QObject::tr(" The @ operator expects dice result. Please check the documentation to fix your command.")); + } + else + { + DiceResult* diceResult= dynamic_cast<DiceResult*>(result); + if(nullptr != diceResult) { - DiceResult* diceResult = dynamic_cast<DiceResult*>(result); - if(nullptr!=diceResult) + for(auto& die : diceResult->getResultList()) { - for(auto& die : diceResult->getResultList()) - { - Die* tmpdie = new Die(); - *tmpdie=*die; - m_diceResult->insertResult(tmpdie); - die->displayed(); - } + Die* tmpdie= new Die(); + *tmpdie= *die; + m_diceResult->insertResult(tmpdie); + die->displayed(); } + } - m_result->setPrevious(previous->getResult()); + m_result->setPrevious(previous->getResult()); - if(nullptr!=m_nextNode) - { - m_nextNode->run(this); - } - if(nullptr!=diceResult) + if(nullptr != m_nextNode) + { + m_nextNode->run(this); + } + if(nullptr != diceResult) + { + for(int i= 0; i < diceResult->getResultList().size(); ++i) { - for(int i =0;i<diceResult->getResultList().size();++i) + Die* tmp= diceResult->getResultList().at(i); + Die* tmp2= m_diceResult->getResultList().at(i); + if(tmp->isHighlighted()) { - Die* tmp =diceResult->getResultList().at(i); - Die* tmp2 =m_diceResult->getResultList().at(i); - if(tmp->isHighlighted()) - { - tmp2->setHighlighted(true); - } + tmp2->setHighlighted(true); } } } + } } ExecutionNode* JumpBackwardNode::getCopy() const { - JumpBackwardNode* node = new JumpBackwardNode(); - if(nullptr!=m_nextNode) + JumpBackwardNode* node= new JumpBackwardNode(); + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; - } diff --git a/node/jumpbackwardnode.h b/node/jumpbackwardnode.h index eda71f1..b6b467b 100644 --- a/node/jumpbackwardnode.h +++ b/node/jumpbackwardnode.h @@ -32,37 +32,37 @@ public: /** * @brief JumpBackwardNode allows to get result from remote node in the execution tree. */ - JumpBackwardNode(); + JumpBackwardNode(); /** * @brief run - performs the actions * @param previous */ - virtual void run(ExecutionNode* previous = nullptr); + virtual void run(ExecutionNode* previous= nullptr); - /** - * @brief toString - * @return - */ - virtual QString toString(bool) const; - /** - * @brief getPriority - * @return - */ + /** + * @brief toString + * @return + */ + virtual QString toString(bool) const; + /** + * @brief getPriority + * @return + */ virtual qint64 getPriority() const; /** * @brief generateDotTree * @param s */ - virtual void generateDotTree(QString &s); + virtual void generateDotTree(QString& s); /** * @brief getCopy * @return */ - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; + private: DiceResult* m_diceResult; ExecutionNode* m_backwardNode; - }; #endif // JUMPBACKWARDNODE_H diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp index 40fd227..c1fe44b 100644 --- a/node/keepdiceexecnode.cpp +++ b/node/keepdiceexecnode.cpp @@ -20,62 +20,56 @@ *************************************************************************/ #include <QList> - #include "keepdiceexecnode.h" - -KeepDiceExecNode::KeepDiceExecNode() - : m_diceResult(new DiceResult()) +KeepDiceExecNode::KeepDiceExecNode() : m_diceResult(new DiceResult()) { - m_result = m_diceResult; -} -KeepDiceExecNode::~KeepDiceExecNode() -{ - + m_result= m_diceResult; } +KeepDiceExecNode::~KeepDiceExecNode() {} void KeepDiceExecNode::run(ExecutionNode* previous) { - m_previousNode = previous; - if(nullptr==previous) + m_previousNode= previous; + if(nullptr == previous) { return; } - DiceResult* previousDiceResult = dynamic_cast<DiceResult*>(previous->getResult()); + DiceResult* previousDiceResult= dynamic_cast<DiceResult*>(previous->getResult()); m_result->setPrevious(previousDiceResult); - if(nullptr!=previousDiceResult) + if(nullptr != previousDiceResult) { - QList<Die*> diceList=previousDiceResult->getResultList(); + QList<Die*> diceList= previousDiceResult->getResultList(); if(m_numberOfDice < 0) { - m_numberOfDice = diceList.size() + m_numberOfDice; + m_numberOfDice= diceList.size() + m_numberOfDice; } - QList<Die*> diceList3= diceList.mid(0,static_cast<int>(m_numberOfDice)); + QList<Die*> diceList3= diceList.mid(0, static_cast<int>(m_numberOfDice)); QList<Die*> diceList2; for(Die* die : diceList3) { - Die* tmpdie = new Die(); - *tmpdie=*die; + Die* tmpdie= new Die(); + *tmpdie= *die; diceList2.append(tmpdie); die->displayed(); } - - if(m_numberOfDice > static_cast<qint64>(diceList.size())) { - m_errors.insert(TOO_MANY_DICE,QObject::tr(" You ask to keep %1 dice but the result only has %2").arg(m_numberOfDice).arg(diceList.size())); + m_errors.insert(TOO_MANY_DICE, QObject::tr(" You ask to keep %1 dice but the result only has %2") + .arg(m_numberOfDice) + .arg(diceList.size())); } - for(auto& tmp : diceList.mid(static_cast<int>(m_numberOfDice),-1)) + for(auto& tmp : diceList.mid(static_cast<int>(m_numberOfDice), -1)) { tmp->setHighlighted(false); } m_diceResult->setResultList(diceList2); - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } @@ -83,39 +77,37 @@ void KeepDiceExecNode::run(ExecutionNode* previous) } void KeepDiceExecNode::setDiceKeepNumber(qint64 n) { - m_numberOfDice = n; + m_numberOfDice= n; } QString KeepDiceExecNode::toString(bool wl) const { - if(wl) - { - return QString("%1 [label=\"KeepDiceExecNode %2\"]").arg(m_id).arg(m_numberOfDice); - } - else - { - return m_id; - } + if(wl) + { + return QString("%1 [label=\"KeepDiceExecNode %2\"]").arg(m_id).arg(m_numberOfDice); + } + else + { + return m_id; + } } qint64 KeepDiceExecNode::getPriority() const { - qint64 priority=0; - if(nullptr!=m_nextNode) + qint64 priority= 0; + if(nullptr != m_nextNode) { - priority = m_nextNode->getPriority(); + priority= m_nextNode->getPriority(); } - return priority; } ExecutionNode* KeepDiceExecNode::getCopy() const { - KeepDiceExecNode* node = new KeepDiceExecNode(); + KeepDiceExecNode* node= new KeepDiceExecNode(); node->setDiceKeepNumber(m_numberOfDice); - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; - } diff --git a/node/keepdiceexecnode.h b/node/keepdiceexecnode.h index 72d3de4..ab9913d 100644 --- a/node/keepdiceexecnode.h +++ b/node/keepdiceexecnode.h @@ -24,8 +24,8 @@ #include "executionnode.h" #include "result/diceresult.h" /** - * @brief The KeepDiceExecNode class splits the dice result to get the m_numberOfDice dice from the beginning of the dice result. - * Usually the pervious node of an KeepDiceExecNode is an SortNode. + * @brief The KeepDiceExecNode class splits the dice result to get the m_numberOfDice dice from the beginning of the + * dice result. Usually the pervious node of an KeepDiceExecNode is an SortNode. */ class KeepDiceExecNode : public ExecutionNode { @@ -33,11 +33,12 @@ public: KeepDiceExecNode(); virtual ~KeepDiceExecNode(); - virtual void run(ExecutionNode *previous); - virtual void setDiceKeepNumber(qint64 ); - virtual QString toString(bool)const; + virtual void run(ExecutionNode* previous); + virtual void setDiceKeepNumber(qint64); + virtual QString toString(bool) const; virtual qint64 getPriority() const; - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; + private: qint64 m_numberOfDice; DiceResult* m_diceResult; diff --git a/node/listaliasnode.cpp b/node/listaliasnode.cpp index a15bfbc..7aa1c32 100644 --- a/node/listaliasnode.cpp +++ b/node/listaliasnode.cpp @@ -20,67 +20,65 @@ *************************************************************************/ #include "listaliasnode.h" -ListAliasNode::ListAliasNode(QList<DiceAlias*>* apAlias) - : m_aliasList(apAlias) +ListAliasNode::ListAliasNode(QList<DiceAlias*>* apAlias) : m_aliasList(apAlias) { - m_result = new StringResult(); + m_result= new StringResult(); } -void ListAliasNode::run(ExecutionNode* previous ) +void ListAliasNode::run(ExecutionNode* previous) { - m_previousNode = previous; - StringResult* txtResult = dynamic_cast<StringResult*>(m_result); + m_previousNode= previous; + StringResult* txtResult= dynamic_cast<StringResult*>(m_result); txtResult->setHighLight(false); txtResult->setText(buildList()); if(nullptr != previous) { - //txtResult->setText(previous->getHelp()); - m_result->setPrevious(previous->getResult()); - } + // txtResult->setText(previous->getHelp()); + m_result->setPrevious(previous->getResult()); + } - if(nullptr!=m_nextNode) - { - m_nextNode->run(this); - } + if(nullptr != m_nextNode) + { + m_nextNode->run(this); + } } QString ListAliasNode::buildList() const { - QString result(QObject::tr("List of Alias:\n")); - for(auto& key: *m_aliasList) - { - result+=QString("%1 : %2 # %3\n").arg(key->getCommand(),key->getValue(),key->getComment()); - } - return result; + QString result(QObject::tr("List of Alias:\n")); + for(auto& key : *m_aliasList) + { + result+= QString("%1 : %2 # %3\n").arg(key->getCommand(), key->getValue(), key->getComment()); + } + return result; } QString ListAliasNode::toString(bool wl) const { - QStringList resultList; - for(auto& key: *m_aliasList) - { - resultList << "{" <<key->getCommand() << key->getValue()<< "}"; - } + QStringList resultList; + for(auto& key : *m_aliasList) + { + resultList << "{" << key->getCommand() << key->getValue() << "}"; + } - if(wl) - { + if(wl) + { return QString("%1 [label=\"ListAliasNode %2\"]").arg(m_id, resultList.join(",")); - } - else - { - return m_id; - } + } + else + { + return m_id; + } } qint64 ListAliasNode::getPriority() const { - return 0; + return 0; } ExecutionNode* ListAliasNode::getCopy() const { - ListAliasNode* node = new ListAliasNode(m_aliasList); - if(nullptr!=m_nextNode) + ListAliasNode* node= new ListAliasNode(m_aliasList); + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; - } diff --git a/node/listaliasnode.h b/node/listaliasnode.h index 493aa1e..44635e0 100644 --- a/node/listaliasnode.h +++ b/node/listaliasnode.h @@ -21,9 +21,9 @@ #ifndef LISTALIASNODE_H #define LISTALIASNODE_H +#include "dicealias.h" #include "executionnode.h" #include "result/stringresult.h" -#include "dicealias.h" /** * @brief The ListAliasNode class is dedicated to display the list of the current aliases. @@ -32,29 +32,29 @@ class ListAliasNode : public ExecutionNode { public: ListAliasNode(QList<DiceAlias*>* mapAlias); - /** - * @brief run - * @param previous - */ - virtual void run(ExecutionNode* previous = nullptr); + /** + * @brief run + * @param previous + */ + virtual void run(ExecutionNode* previous= nullptr); - /** - * @brief toString - * @return - */ - virtual QString toString(bool) const; + /** + * @brief toString + * @return + */ + virtual QString toString(bool) const; /** * @brief buildList * @return */ virtual QString buildList() const; - /** - * @brief getPriority - * @return - */ - virtual qint64 getPriority() const; + /** + * @brief getPriority + * @return + */ + virtual qint64 getPriority() const; - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; private: QList<DiceAlias*>* m_aliasList; diff --git a/node/listsetrollnode.cpp b/node/listsetrollnode.cpp index 8771866..ffa0f03 100644 --- a/node/listsetrollnode.cpp +++ b/node/listsetrollnode.cpp @@ -21,18 +21,17 @@ #include "listsetrollnode.h" #include "die.h" -ListSetRollNode::ListSetRollNode() - :m_diceResult(new DiceResult()),m_stringResult(new StringResult()),m_unique(false) +ListSetRollNode::ListSetRollNode() : m_diceResult(new DiceResult()), m_stringResult(new StringResult()), m_unique(false) { - m_result = m_stringResult; + m_result= m_stringResult; } ListSetRollNode::~ListSetRollNode() { - if(nullptr!=m_diceResult) - { - delete m_diceResult; - m_diceResult =nullptr; - } + if(nullptr != m_diceResult) + { + delete m_diceResult; + m_diceResult= nullptr; + } } QStringList ListSetRollNode::getList() const @@ -41,49 +40,49 @@ QStringList ListSetRollNode::getList() const } QString ListSetRollNode::toString(bool wl) const { - if(wl) - { - return QString("%1 [label=\"ListSetRoll list:%2\"]").arg(m_id,m_values.join(",")); - } - else - { - return m_id; - } - + if(wl) + { + return QString("%1 [label=\"ListSetRoll list:%2\"]").arg(m_id, m_values.join(",")); + } + else + { + return m_id; + } } qint64 ListSetRollNode::getPriority() const { - qint64 priority=4; + qint64 priority= 4; return priority; } void ListSetRollNode::run(ExecutionNode* previous) { - m_previousNode = previous; - if(nullptr!=previous) + m_previousNode= previous; + if(nullptr != previous) { - Result* result=previous->getResult(); - if(nullptr!=result) + Result* result= previous->getResult(); + if(nullptr != result) { - quint64 diceCount = result->getResult(Result::SCALAR).toReal(); + quint64 diceCount= result->getResult(Result::SCALAR).toReal(); if(diceCount > static_cast<quint64>(m_values.size()) && m_unique) { - m_errors.insert(TOO_MANY_DICE,QObject::tr("More unique values asked than possible values (L operator)")); + m_errors.insert( + TOO_MANY_DICE, QObject::tr("More unique values asked than possible values (L operator)")); } else { m_result->setPrevious(result); QStringList rollResult; - for(quint64 i=0; i < diceCount ; ++i) + for(quint64 i= 0; i < diceCount; ++i) { - Die* die = new Die(); + Die* die= new Die(); computeFacesNumber(die); die->roll(); m_diceResult->insertResult(die); - getValueFromDie(die,rollResult); + getValueFromDie(die, rollResult); } m_stringResult->setText(rollResult.join(",")); } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } @@ -92,15 +91,15 @@ void ListSetRollNode::run(ExecutionNode* previous) } void ListSetRollNode::setListValue(QStringList lirs) { - m_values = lirs; + m_values= lirs; } void ListSetRollNode::setUnique(bool u) { - m_unique = u; + m_unique= u; } void ListSetRollNode::setRangeList(QList<Range>& ranges) { - m_rangeList = ranges; + m_rangeList= ranges; } void ListSetRollNode::computeFacesNumber(Die* die) { @@ -112,10 +111,10 @@ void ListSetRollNode::computeFacesNumber(Die* die) { Q_ASSERT(m_values.size() == m_rangeList.size()); qint64 max; - int i=0; - for(Range& range: m_rangeList) + int i= 0; + for(Range& range : m_rangeList) { - if(((i==0)||(max<range.getEnd()))&&(range.isFullyDefined())) + if(((i == 0) || (max < range.getEnd())) && (range.isFullyDefined())) { max= range.getEnd(); } @@ -123,19 +122,18 @@ void ListSetRollNode::computeFacesNumber(Die* die) } die->setMaxValue(max); } - } -void ListSetRollNode::getValueFromDie(Die* die,QStringList& rollResult) +void ListSetRollNode::getValueFromDie(Die* die, QStringList& rollResult) { if(m_rangeList.isEmpty()) { - if(die->getValue()-1<m_values.size()) + if(die->getValue() - 1 < m_values.size()) { - auto str = m_values[die->getValue()-1]; + auto str= m_values[die->getValue() - 1]; while(m_unique && rollResult.contains(str)) { die->roll(false); - str = m_values[die->getValue()-1]; + str= m_values[die->getValue() - 1]; } rollResult << str; } @@ -143,20 +141,19 @@ void ListSetRollNode::getValueFromDie(Die* die,QStringList& rollResult) else { Q_ASSERT(m_values.size() == m_rangeList.size()); - bool found = false; + bool found= false; while(!found) { - int i=0; - for (Range& range: m_rangeList) + int i= 0; + for(Range& range : m_rangeList) { - auto it = std::find(m_rangeIndexResult.begin(),m_rangeIndexResult.end(),i); - auto isValid = range.hasValid(die,false); - if((isValid && !m_unique)|| - (isValid && it == m_rangeIndexResult.end())) + auto it= std::find(m_rangeIndexResult.begin(), m_rangeIndexResult.end(), i); + auto isValid= range.hasValid(die, false); + if((isValid && !m_unique) || (isValid && it == m_rangeIndexResult.end())) { m_rangeIndexResult.push_back(i); rollResult << m_values[i]; - found=true; + found= true; } ++i; } @@ -169,15 +166,14 @@ void ListSetRollNode::getValueFromDie(Die* die,QStringList& rollResult) } ExecutionNode* ListSetRollNode::getCopy() const { - ListSetRollNode* node = new ListSetRollNode(); - QList<Range> dataList = m_rangeList; + ListSetRollNode* node= new ListSetRollNode(); + QList<Range> dataList= m_rangeList; node->setRangeList(dataList); node->setUnique(m_unique); node->setListValue(m_values); - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; - } diff --git a/node/listsetrollnode.h b/node/listsetrollnode.h index 15d00e4..5c2c340 100644 --- a/node/listsetrollnode.h +++ b/node/listsetrollnode.h @@ -21,13 +21,12 @@ #ifndef LISTSETROLLNODE_H #define LISTSETROLLNODE_H - #include <QStringList> #include "executionnode.h" +#include "range.h" #include "result/diceresult.h" #include "result/stringresult.h" -#include "range.h" /** * @brief The ListSetRollNode class is dedicated to pick up item from list. */ @@ -35,19 +34,19 @@ class ListSetRollNode : public ExecutionNode { public: ListSetRollNode(); - virtual ~ListSetRollNode(); - virtual void run(ExecutionNode* previous = nullptr); - virtual QString toString(bool)const; + virtual ~ListSetRollNode(); + virtual void run(ExecutionNode* previous= nullptr); + virtual QString toString(bool) const; virtual qint64 getPriority() const; QStringList getList() const; void setListValue(QStringList); - void setUnique(bool ); + void setUnique(bool); void setRangeList(QList<Range>&); - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; private: - void getValueFromDie(Die* die,QStringList& rollResult); + void getValueFromDie(Die* die, QStringList& rollResult); void computeFacesNumber(Die* die); private: diff --git a/node/mergenode.cpp b/node/mergenode.cpp index f866db6..e708cef 100644 --- a/node/mergenode.cpp +++ b/node/mergenode.cpp @@ -1,30 +1,29 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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. * + ***************************************************************************/ #include "mergenode.h" -MergeNode::MergeNode() - : m_diceResult(new DiceResult()) +MergeNode::MergeNode() : m_diceResult(new DiceResult()) { - m_result = m_diceResult; + m_result= m_diceResult; } void MergeNode::run(ExecutionNode* previous) { @@ -34,73 +33,72 @@ void MergeNode::run(ExecutionNode* previous) return; } - m_previousNode = previous; + m_previousNode= previous; m_result->setPrevious(previous->getResult()); - ExecutionNode* previousLast =nullptr; + ExecutionNode* previousLast= nullptr; std::vector<Result*> pastResult; for(auto start : *m_startList) { - ExecutionNode* last = getLatestNode(start); - if(nullptr!=last) + ExecutionNode* last= getLatestNode(start); + if(nullptr != last) { if(nullptr != previousLast) { - auto startResult = start->getResult(); + auto startResult= start->getResult(); startResult->setPrevious(previousLast->getResult()); previousLast->setNextNode(start); } - previousLast = last; - Result* tmpResult = last->getResult(); - while(nullptr!=tmpResult) + previousLast= last; + Result* tmpResult= last->getResult(); + while(nullptr != tmpResult) { - DiceResult* dice = dynamic_cast<DiceResult*>(tmpResult); - if(nullptr!=dice) + DiceResult* dice= dynamic_cast<DiceResult*>(tmpResult); + if(nullptr != dice) { ///@todo TODO improve here to set homogeneous while is really m_diceResult->setHomogeneous(false); for(auto& die : dice->getResultList()) { - if(!m_diceResult->getResultList().contains(die)&&(!die->hasBeenDisplayed())) + if(!m_diceResult->getResultList().contains(die) && (!die->hasBeenDisplayed())) { - Die* tmpdie = new Die(); - *tmpdie=*die; + Die* tmpdie= new Die(); + *tmpdie= *die; die->displayed(); m_diceResult->getResultList().append(tmpdie); } } } - auto it = std::find_if(pastResult.begin(),pastResult.end(),[tmpResult](const Result* a){ - return (a == tmpResult->getPrevious()); - }); + auto it= std::find_if(pastResult.begin(), pastResult.end(), + [tmpResult](const Result* a) { return (a == tmpResult->getPrevious()); }); if(it == pastResult.end()) { pastResult.push_back(previousLast->getResult()); - tmpResult = tmpResult->getPrevious(); + tmpResult= tmpResult->getPrevious(); } else { tmpResult->setPrevious(nullptr); - tmpResult = nullptr; + tmpResult= nullptr; } } } } - auto first = m_startList->front(); + auto first= m_startList->front(); m_startList->clear(); m_startList->push_back(first); - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } } ExecutionNode* MergeNode::getLatestNode(ExecutionNode* node) { - ExecutionNode* next = node; - while(nullptr != next->getNextNode() && (next->getNextNode()!=this)) + ExecutionNode* next= node; + while(nullptr != next->getNextNode() && (next->getNextNode() != this)) { - next = next->getNextNode(); + next= next->getNextNode(); } return next; } @@ -117,29 +115,29 @@ QString MergeNode::toString(bool withLabel) const } qint64 MergeNode::getPriority() const { - qint64 priority=0; - if(nullptr!=m_previousNode) + qint64 priority= 0; + if(nullptr != m_previousNode) { - priority = m_previousNode->getPriority(); + priority= m_previousNode->getPriority(); } return priority; } ExecutionNode* MergeNode::getCopy() const { - MergeNode* node = new MergeNode(); - if(nullptr!=m_nextNode) + MergeNode* node= new MergeNode(); + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; } -std::vector<ExecutionNode *>* MergeNode::getStartList() const +std::vector<ExecutionNode*>* MergeNode::getStartList() const { return m_startList; } -void MergeNode::setStartList(std::vector<ExecutionNode *>* startList) +void MergeNode::setStartList(std::vector<ExecutionNode*>* startList) { - m_startList = startList; + m_startList= startList; } diff --git a/node/mergenode.h b/node/mergenode.h index 34f1200..f14ff1e 100644 --- a/node/mergenode.h +++ b/node/mergenode.h @@ -1,24 +1,24 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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 MERGENODE_H #define MERGENODE_H @@ -33,18 +33,18 @@ class MergeNode : public ExecutionNode public: MergeNode(); void run(ExecutionNode* previous); - virtual QString toString(bool withLabel)const; + virtual QString toString(bool withLabel) const; virtual qint64 getPriority() const; - virtual ExecutionNode *getCopy() const; - std::vector<ExecutionNode *>* getStartList() const; - void setStartList(std::vector<ExecutionNode *>* startList); + virtual ExecutionNode* getCopy() const; + std::vector<ExecutionNode*>* getStartList() const; + void setStartList(std::vector<ExecutionNode*>* startList); private: - ExecutionNode *getLatestNode(ExecutionNode *node); + ExecutionNode* getLatestNode(ExecutionNode* node); private: DiceResult* m_diceResult; - std::vector<ExecutionNode *>* m_startList; + std::vector<ExecutionNode*>* m_startList; }; #endif // NUMBERNODE_H diff --git a/node/numbernode.cpp b/node/numbernode.cpp index 6636c31..428376d 100644 --- a/node/numbernode.cpp +++ b/node/numbernode.cpp @@ -1,30 +1,29 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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. * + ***************************************************************************/ #include "numbernode.h" -NumberNode::NumberNode() - : m_scalarResult(new ScalarResult()) +NumberNode::NumberNode() : m_scalarResult(new ScalarResult()) { - m_result = m_scalarResult; + m_result= m_scalarResult; } NumberNode::~NumberNode() { @@ -38,12 +37,12 @@ NumberNode::~NumberNode() void NumberNode::run(ExecutionNode* previous) { - m_previousNode = previous; - if(nullptr!=previous) + m_previousNode= previous; + if(nullptr != previous) { m_result->setPrevious(previous->getResult()); } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } @@ -52,36 +51,35 @@ void NumberNode::run(ExecutionNode* previous) void NumberNode::setNumber(qint64 a) { m_scalarResult->setValue(a); - m_number = a; + m_number= a; } QString NumberNode::toString(bool withLabel) const { if(withLabel) - { - return QString("%1 [label=\"NumberNode %2\"]").arg(m_id).arg(m_number); - } - else - { - return m_id; - } + { + return QString("%1 [label=\"NumberNode %2\"]").arg(m_id).arg(m_number); + } + else + { + return m_id; + } } qint64 NumberNode::getPriority() const { - qint64 priority=0; - if(nullptr!=m_nextNode) + qint64 priority= 0; + if(nullptr != m_nextNode) { - priority = m_nextNode->getPriority(); + priority= m_nextNode->getPriority(); } return priority; } ExecutionNode* NumberNode::getCopy() const { - NumberNode* node = new NumberNode(); + NumberNode* node= new NumberNode(); node->setNumber(m_number); - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; - } diff --git a/node/numbernode.h b/node/numbernode.h index 80cbace..ce0f686 100644 --- a/node/numbernode.h +++ b/node/numbernode.h @@ -1,24 +1,24 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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 NUMBERNODE_H #define NUMBERNODE_H @@ -35,9 +35,10 @@ public: virtual ~NumberNode(); void run(ExecutionNode* previous); void setNumber(qint64); - virtual QString toString(bool withLabel)const; + virtual QString toString(bool withLabel) const; virtual qint64 getPriority() const; - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; + private: qint64 m_number; ScalarResult* m_scalarResult; diff --git a/node/paintnode.cpp b/node/paintnode.cpp index 8fea3f4..02c7230 100644 --- a/node/paintnode.cpp +++ b/node/paintnode.cpp @@ -1,29 +1,25 @@ /*************************************************************************** - * Copyright (C) 2015 by Renaud Guezennec * - * http:://www.rolisteam.org/contact * - * * - * rolisteam 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. * - ***************************************************************************/ + * Copyright (C) 2015 by Renaud Guezennec * + * http:://www.rolisteam.org/contact * + * * + * rolisteam 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. * + ***************************************************************************/ #include "paintnode.h" -ColorItem::ColorItem(QString str, int val) - : m_colorNumber(val),m_color(str) -{ - -} +ColorItem::ColorItem(QString str, int val) : m_colorNumber(val), m_color(str) {} int ColorItem::colorNumber() const { @@ -32,7 +28,7 @@ int ColorItem::colorNumber() const void ColorItem::setColorNumber(int colorNumber) { - m_colorNumber = colorNumber; + m_colorNumber= colorNumber; } QString ColorItem::color() const @@ -40,50 +36,46 @@ QString ColorItem::color() const return m_color; } -void ColorItem::setColor(const QString &color) +void ColorItem::setColor(const QString& color) { - m_color = color; + m_color= color; } - /////////////////////////////////// /// @brief PainterNode::PainterNode /////////////////////////////////// -PainterNode::PainterNode() - : ExecutionNode() +PainterNode::PainterNode() : ExecutionNode() { - m_result = nullptr; - m_nextNode = nullptr; + m_result= nullptr; + m_nextNode= nullptr; } - PainterNode::~PainterNode() { - m_result = nullptr; + m_result= nullptr; } - void PainterNode::run(ExecutionNode* previous) { - m_previousNode = previous; - if(nullptr==previous) + m_previousNode= previous; + if(nullptr == previous) { m_errors.insert(ExecutionNode::NO_PREVIOUS_ERROR, QObject::tr("No previous node before Paint operator")); return; } - Result* previousResult = previous->getResult(); - //m_result = previousResult; - DiceResult* previousDiceResult = dynamic_cast<DiceResult*>(previousResult); - if(nullptr!=previousDiceResult) + Result* previousResult= previous->getResult(); + // m_result = previousResult; + DiceResult* previousDiceResult= dynamic_cast<DiceResult*>(previousResult); + if(nullptr != previousDiceResult) { - QList<Die*> diceList=previousDiceResult->getResultList(); - int pastDice=0; + QList<Die*> diceList= previousDiceResult->getResultList(); + int pastDice= 0; for(ColorItem& item : m_colors) { - int current=item.colorNumber(); + int current= item.colorNumber(); QList<Die*>::iterator it; - for(it = diceList.begin()+pastDice; it != diceList.end() && current>0 ; ++it) + for(it= diceList.begin() + pastDice; it != diceList.end() && current > 0; ++it) { (*it)->setColor(item.color()); --current; @@ -91,14 +83,14 @@ void PainterNode::run(ExecutionNode* previous) } } } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(previous); } } Result* PainterNode::getResult() { - return (nullptr != m_previousNode) ? m_previousNode->getResult() : nullptr ; + return (nullptr != m_previousNode) ? m_previousNode->getResult() : nullptr; } QString PainterNode::toString(bool wl) const @@ -113,22 +105,20 @@ QString PainterNode::toString(bool wl) const } } - qint64 PainterNode::getPriority() const { return 4; } - void PainterNode::insertColorItem(QString color, int value) { - ColorItem item(color,value); + ColorItem item(color, value); m_colors.append(item); } ExecutionNode* PainterNode::getCopy() const { - PainterNode* node = new PainterNode(); - if(nullptr!=m_nextNode) + PainterNode* node= new PainterNode(); + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/paintnode.h b/node/paintnode.h index 3d45b9a..2675285 100644 --- a/node/paintnode.h +++ b/node/paintnode.h @@ -1,22 +1,22 @@ /*************************************************************************** - * Copyright (C) 2015 by Renaud Guezennec * - * http:://www.rolisteam.org/contact * - * * - * rolisteam 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. * - ***************************************************************************/ + * Copyright (C) 2015 by Renaud Guezennec * + * http:://www.rolisteam.org/contact * + * * + * rolisteam 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 PAINTERNODE_H #define PAINTERNODE_H @@ -24,17 +24,15 @@ #include "result/diceresult.h" #include <QString> - class ColorItem { - public: - ColorItem(QString str,int val); + ColorItem(QString str, int val); int colorNumber() const; void setColorNumber(int colorNumber); QString color() const; - void setColor(const QString &color); + void setColor(const QString& color); private: int m_colorNumber; @@ -48,12 +46,13 @@ class PainterNode : public ExecutionNode public: PainterNode(); virtual ~PainterNode(); - virtual void run(ExecutionNode* previous = nullptr); + virtual void run(ExecutionNode* previous= nullptr); Result* getResult(); - virtual QString toString(bool )const; + virtual QString toString(bool) const; virtual qint64 getPriority() const; void insertColorItem(QString color, int value); - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; + protected: QList<ColorItem> m_colors; }; diff --git a/node/parenthesesnode.cpp b/node/parenthesesnode.cpp index b6c4c06..24c650e 100644 --- a/node/parenthesesnode.cpp +++ b/node/parenthesesnode.cpp @@ -1,50 +1,46 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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. * + ***************************************************************************/ #include "parenthesesnode.h" -ParenthesesNode::ParenthesesNode() - : m_internalNode(nullptr) -{ - -} +ParenthesesNode::ParenthesesNode() : m_internalNode(nullptr) {} void ParenthesesNode::setInternelNode(ExecutionNode* node) { - m_internalNode = node; + m_internalNode= node; } void ParenthesesNode::run(ExecutionNode* previous) { - m_previousNode = previous; - if(nullptr!=m_internalNode) + m_previousNode= previous; + if(nullptr != m_internalNode) { - m_internalNode->run(this); - ExecutionNode* temp=m_internalNode; - while(nullptr!=temp->getNextNode()) - { - temp=temp->getNextNode(); - } - m_result = temp->getResult(); + m_internalNode->run(this); + ExecutionNode* temp= m_internalNode; + while(nullptr != temp->getNextNode()) + { + temp= temp->getNextNode(); + } + m_result= temp->getResult(); } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } @@ -62,27 +58,26 @@ QString ParenthesesNode::toString(bool b) const } qint64 ParenthesesNode::getPriority() const { - qint64 priority=3; + qint64 priority= 3; return priority; } ExecutionNode* ParenthesesNode::getCopy() const { - ParenthesesNode* node = new ParenthesesNode(); - if(nullptr!=m_internalNode) + ParenthesesNode* node= new ParenthesesNode(); + if(nullptr != m_internalNode) { node->setInternelNode(m_internalNode->getCopy()); } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; - } -void ParenthesesNode::generateDotTree(QString & s) +void ParenthesesNode::generateDotTree(QString& s) { - auto str = toString(true); + auto str= toString(true); if(s.contains(str)) return; s.append(str); @@ -95,16 +90,15 @@ void ParenthesesNode::generateDotTree(QString & s) s.append(m_internalNode->toString(false)); s.append("[label=\"internal\"];\n"); m_internalNode->generateDotTree(s); - } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { s.append(toString(false)); s.append(" -> "); s.append(m_nextNode->toString(false)); s.append(" [label=\"next\"];\n"); -// s.append(" [label=\"nextNode\"];\n"); + // s.append(" [label=\"nextNode\"];\n"); m_nextNode->generateDotTree(s); } else @@ -112,17 +106,14 @@ void ParenthesesNode::generateDotTree(QString & s) s.append(toString(false)); s.append(" -> "); s.append("nullptr;\n"); - } - if(nullptr!=m_result) + if(nullptr != m_result) { - - s.append(toString(false)); - s.append(" ->"); - s.append(m_result->toString(false)); - s.append(" [label=\"Result\", style=\"dashed\"];\n"); - if(nullptr == m_nextNode) - m_result->generateDotTree(s); - + s.append(toString(false)); + s.append(" ->"); + s.append(m_result->toString(false)); + s.append(" [label=\"Result\", style=\"dashed\"];\n"); + if(nullptr == m_nextNode) + m_result->generateDotTree(s); } } diff --git a/node/parenthesesnode.h b/node/parenthesesnode.h index 5f841ab..7cc08af 100644 --- a/node/parenthesesnode.h +++ b/node/parenthesesnode.h @@ -1,43 +1,44 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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 PARENTHESESNODE_H #define PARENTHESESNODE_H #include "executionnode.h" /** - * @brief The ParenthesesNode class is an ExecutionNode. It is dedicated to manage expression which was inside ParenthesesNode. - * It is acting just like an StartingNode by for an internal execution tree. + * @brief The ParenthesesNode class is an ExecutionNode. It is dedicated to manage expression which was inside + * ParenthesesNode. It is acting just like an StartingNode by for an internal execution tree. */ class ParenthesesNode : public ExecutionNode { public: ParenthesesNode(); - virtual void run(ExecutionNode* previous = nullptr); + virtual void run(ExecutionNode* previous= nullptr); void setInternelNode(ExecutionNode* node); - virtual QString toString(bool)const; + virtual QString toString(bool) const; virtual qint64 getPriority() const; - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; virtual void generateDotTree(QString&); + private: ExecutionNode* m_internalNode; }; diff --git a/node/rerolldicenode.cpp b/node/rerolldicenode.cpp index 471404e..659e9c0 100644 --- a/node/rerolldicenode.cpp +++ b/node/rerolldicenode.cpp @@ -2,55 +2,52 @@ #include "parsingtoolbox.h" RerollDiceNode::RerollDiceNode(bool reroll, bool addingMode) - : m_diceResult(new DiceResult()) - , m_validator(nullptr) - , m_reroll(reroll) - , m_adding(addingMode) + : m_diceResult(new DiceResult()), m_validator(nullptr), m_reroll(reroll), m_adding(addingMode) { - m_result=m_diceResult; + m_result= m_diceResult; } RerollDiceNode::~RerollDiceNode() { - if(nullptr!=m_validator) - { - delete m_validator; - m_validator = nullptr; - } + if(nullptr != m_validator) + { + delete m_validator; + m_validator= nullptr; + } } void RerollDiceNode::run(ExecutionNode* previous) { - m_previousNode = previous; - if((nullptr!=previous)&&(nullptr!=previous->getResult())) + m_previousNode= previous; + if((nullptr != previous) && (nullptr != previous->getResult())) { - DiceResult* previous_result = dynamic_cast<DiceResult*>(previous->getResult()); + DiceResult* previous_result= dynamic_cast<DiceResult*>(previous->getResult()); m_result->setPrevious(previous_result); - if(nullptr!=previous_result) + if(nullptr != previous_result) { - for(auto& die: previous_result->getResultList()) + for(auto& die : previous_result->getResultList()) { - Die* tmpdie = new Die(); - *tmpdie=*die; + Die* tmpdie= new Die(); + *tmpdie= *die; m_diceResult->insertResult(tmpdie); die->displayed(); } - //m_diceResult->setResultList(list); + // m_diceResult->setResultList(list); - QList<Die*>& list = m_diceResult->getResultList(); + QList<Die*>& list= m_diceResult->getResultList(); QList<Die*> toRemove; - for(int i = 0; i < list.size() ; ++i) + for(int i= 0; i < list.size(); ++i) { - auto die = list.at(i); - bool finished = false; - while(m_validator->hasValid(die,false) && !finished) + auto die= list.at(i); + bool finished= false; + while(m_validator->hasValid(die, false) && !finished) { if(m_instruction != nullptr) { m_instruction->run(this); - auto lastNode = ParsingToolBox::getLatestNode(m_instruction); + auto lastNode= ParsingToolBox::getLatestNode(m_instruction); if(lastNode != nullptr) { - auto lastResult = dynamic_cast<DiceResult*>(lastNode->getResult()); + auto lastResult= dynamic_cast<DiceResult*>(lastNode->getResult()); if(lastResult != nullptr) { toRemove.append(die); @@ -65,18 +62,17 @@ void RerollDiceNode::run(ExecutionNode* previous) } if(m_reroll) { - finished = true; + finished= true; } } } - for(auto die: toRemove) + for(auto die : toRemove) { - list.removeOne(die); + list.removeOne(die); } - - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } @@ -84,54 +80,54 @@ void RerollDiceNode::run(ExecutionNode* previous) else { m_errors.insert(ExecutionNode::DIE_RESULT_EXPECTED, - QObject::tr(" The a operator expects dice result. Please check the documentation and fix your command.")); + QObject::tr( + " The a operator expects dice result. Please check the documentation and fix your command.")); } } } void RerollDiceNode::setValidator(Validator* val) { - m_validator = val; + m_validator= val; } QString RerollDiceNode::toString(bool wl) const { - if(wl) - { + if(wl) + { return QString("%1 [label=\"RerollDiceNode validatior: %2\"]").arg(m_id, m_validator->toString()); - } - else - { - return m_id; - } - //return QString("RerollDiceNode [label=\"RerollDiceNode validatior:%1\""); + } + else + { + return m_id; + } + // return QString("RerollDiceNode [label=\"RerollDiceNode validatior:%1\""); } qint64 RerollDiceNode::getPriority() const { - qint64 priority=0; - if(nullptr!=m_nextNode) + qint64 priority= 0; + if(nullptr != m_nextNode) { - priority = m_nextNode->getPriority(); + priority= m_nextNode->getPriority(); } - return priority; } ExecutionNode* RerollDiceNode::getCopy() const { - RerollDiceNode* node = new RerollDiceNode(m_reroll, m_adding); + RerollDiceNode* node= new RerollDiceNode(m_reroll, m_adding); node->setValidator(m_validator); - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; } -ExecutionNode *RerollDiceNode::getInstruction() const +ExecutionNode* RerollDiceNode::getInstruction() const { return m_instruction; } -void RerollDiceNode::setInstruction(ExecutionNode *instruction) +void RerollDiceNode::setInstruction(ExecutionNode* instruction) { - m_instruction = instruction; + m_instruction= instruction; } diff --git a/node/rerolldicenode.h b/node/rerolldicenode.h index 8bef6dd..32fad79 100644 --- a/node/rerolldicenode.h +++ b/node/rerolldicenode.h @@ -1,7 +1,6 @@ #ifndef REROLLDICENODE_H #define REROLLDICENODE_H - #include "executionnode.h" #include "result/diceresult.h" #include "validator.h" @@ -10,41 +9,45 @@ */ class RerollDiceNode : public ExecutionNode { - public: - /** - * @brief The ReRollMode enum - */ - enum ReRollMode {EQUAL,LESSER,GREATER}; - /** - * @brief RerollDiceNode - * @param reroll If true reroll the dice only once, otherwise until the condition is false - */ + /** + * @brief The ReRollMode enum + */ + enum ReRollMode + { + EQUAL, + LESSER, + GREATER + }; + /** + * @brief RerollDiceNode + * @param reroll If true reroll the dice only once, otherwise until the condition is false + */ RerollDiceNode(bool reroll, bool addingMode); - /** - * @brief ~RerollDiceNode - */ - virtual ~RerollDiceNode(); - /** - * @brief run - * @param previous - */ + /** + * @brief ~RerollDiceNode + */ + virtual ~RerollDiceNode(); + /** + * @brief run + * @param previous + */ virtual void run(ExecutionNode* previous); - /** - * @brief setValidator - */ - virtual void setValidator(Validator* ); - /** - * @brief toString - * @return - */ - virtual QString toString(bool )const; - /** - * @brief getPriority - * @return - */ + /** + * @brief setValidator + */ + virtual void setValidator(Validator*); + /** + * @brief toString + * @return + */ + virtual QString toString(bool) const; + /** + * @brief getPriority + * @return + */ virtual qint64 getPriority() const; /** @@ -53,13 +56,13 @@ public: */ virtual ExecutionNode* getCopy() const; - ExecutionNode *getInstruction() const; - void setInstruction(ExecutionNode *instruction); + ExecutionNode* getInstruction() const; + void setInstruction(ExecutionNode* instruction); private: - DiceResult* m_diceResult = nullptr; - Validator* m_validator = nullptr; - ExecutionNode* m_instruction = nullptr; + DiceResult* m_diceResult= nullptr; + Validator* m_validator= nullptr; + ExecutionNode* m_instruction= nullptr; const bool m_reroll; const bool m_adding; diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp index d73f066..3a26fc7 100644 --- a/node/scalaroperatornode.cpp +++ b/node/scalaroperatornode.cpp @@ -1,68 +1,67 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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. * + ***************************************************************************/ #include "scalaroperatornode.h" -#include <QDebug> #include "result/diceresult.h" - +#include <QDebug> ScalarOperatorNode::ScalarOperatorNode() - : m_internalNode(nullptr),m_scalarResult(new ScalarResult()),m_arithmeticOperator(Die::PLUS) + : m_internalNode(nullptr), m_scalarResult(new ScalarResult()), m_arithmeticOperator(Die::PLUS) { - m_result = m_scalarResult; + m_result= m_scalarResult; } ScalarOperatorNode::~ScalarOperatorNode() { - if(nullptr!=m_internalNode) + if(nullptr != m_internalNode) { delete m_internalNode; - m_internalNode = nullptr; + m_internalNode= nullptr; } } void ScalarOperatorNode::run(ExecutionNode* previous) { - m_previousNode = previous; - if(nullptr!=m_internalNode) + m_previousNode= previous; + if(nullptr != m_internalNode) { m_internalNode->run(this); } - if(nullptr!=previous) + if(nullptr != previous) { - auto previousResult = previous->getResult(); + auto previousResult= previous->getResult(); - if(nullptr!=previousResult) + if(nullptr != previousResult) { - ExecutionNode* internal = m_internalNode; + ExecutionNode* internal= m_internalNode; if(nullptr != internal) { - while(nullptr != internal->getNextNode() ) + while(nullptr != internal->getNextNode()) { - internal = internal->getNextNode(); + internal= internal->getNextNode(); } - Result* internalResult = internal->getResult(); + Result* internalResult= internal->getResult(); m_result->setPrevious(internalResult); - if(nullptr!=m_internalNode->getResult()) + if(nullptr != m_internalNode->getResult()) { m_internalNode->getResult()->setPrevious(previousResult); } @@ -70,34 +69,38 @@ void ScalarOperatorNode::run(ExecutionNode* previous) switch(m_arithmeticOperator) { case Die::PLUS: - m_scalarResult->setValue(add(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); + m_scalarResult->setValue(add(previousResult->getResult(Result::SCALAR).toReal(), + internalResult->getResult(Result::SCALAR).toReal())); break; case Die::MINUS: - m_scalarResult->setValue(substract(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); + m_scalarResult->setValue(substract(previousResult->getResult(Result::SCALAR).toReal(), + internalResult->getResult(Result::SCALAR).toReal())); break; case Die::MULTIPLICATION: - m_scalarResult->setValue(multiple(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); + m_scalarResult->setValue(multiple(previousResult->getResult(Result::SCALAR).toReal(), + internalResult->getResult(Result::SCALAR).toReal())); break; case Die::DIVIDE: - m_scalarResult->setValue(divide(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); + m_scalarResult->setValue(divide(previousResult->getResult(Result::SCALAR).toReal(), + internalResult->getResult(Result::SCALAR).toReal())); break; case Die::INTEGER_DIVIDE: - m_scalarResult->setValue(static_cast<int>(divide(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal()))); + m_scalarResult->setValue(static_cast<int>(divide(previousResult->getResult(Result::SCALAR).toReal(), + internalResult->getResult(Result::SCALAR).toReal()))); break; case Die::POW: - m_scalarResult->setValue(pow(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); + m_scalarResult->setValue(pow(previousResult->getResult(Result::SCALAR).toReal(), + internalResult->getResult(Result::SCALAR).toReal())); break; - } } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } } } - } /*bool ScalarOperatorNode::setOperatorChar(QChar c) { @@ -111,65 +114,65 @@ void ScalarOperatorNode::run(ExecutionNode* previous) void ScalarOperatorNode::setInternalNode(ExecutionNode* node) { - m_internalNode = node; + m_internalNode= node; } -qint64 ScalarOperatorNode::add(qreal a,qreal b) +qint64 ScalarOperatorNode::add(qreal a, qreal b) { - return static_cast<qint64>(a+b); + return static_cast<qint64>(a + b); } -qint64 ScalarOperatorNode::substract(qreal a,qreal b) +qint64 ScalarOperatorNode::substract(qreal a, qreal b) { - return static_cast<qint64>(a-b); + return static_cast<qint64>(a - b); } -qreal ScalarOperatorNode::divide(qreal a,qreal b) +qreal ScalarOperatorNode::divide(qreal a, qreal b) { - if(qFuzzyCompare(b,0)) + if(qFuzzyCompare(b, 0)) { - m_errors.insert(DIVIDE_BY_ZERO,QObject::tr("Division by zero")); + m_errors.insert(DIVIDE_BY_ZERO, QObject::tr("Division by zero")); return 0; } - return static_cast<qreal>(a/b); + return static_cast<qreal>(a / b); } -qint64 ScalarOperatorNode::multiple(qreal a,qreal b) +qint64 ScalarOperatorNode::multiple(qreal a, qreal b) { - return static_cast<qint64>(a*b); + return static_cast<qint64>(a * b); } -qint64 ScalarOperatorNode::pow(qreal a,qreal b) +qint64 ScalarOperatorNode::pow(qreal a, qreal b) { - return static_cast<qint64>(std::pow(a,b)); + return static_cast<qint64>(std::pow(a, b)); } Die::ArithmeticOperator ScalarOperatorNode::getArithmeticOperator() const { return m_arithmeticOperator; } -void ScalarOperatorNode::setArithmeticOperator(const Die::ArithmeticOperator &arithmeticOperator) +void ScalarOperatorNode::setArithmeticOperator(const Die::ArithmeticOperator& arithmeticOperator) { - m_arithmeticOperator = arithmeticOperator; + m_arithmeticOperator= arithmeticOperator; } QString ScalarOperatorNode::toString(bool wl) const { - QString op=""; + QString op= ""; switch(m_arithmeticOperator) { case Die::PLUS: - op="+"; + op= "+"; break; case Die::MINUS: - op="-"; + op= "-"; break; case Die::MULTIPLICATION: - op="*"; + op= "*"; break; case Die::DIVIDE: - op="/"; + op= "/"; break; case Die::INTEGER_DIVIDE: - op="|"; + op= "|"; break; case Die::POW: - op="^"; + op= "^"; break; } if(wl) @@ -183,7 +186,7 @@ QString ScalarOperatorNode::toString(bool wl) const } qint64 ScalarOperatorNode::getPriority() const { - if((m_arithmeticOperator==Die::PLUS)||(m_arithmeticOperator==Die::MINUS)) + if((m_arithmeticOperator == Die::PLUS) || (m_arithmeticOperator == Die::MINUS)) { return 1; } @@ -194,13 +197,13 @@ qint64 ScalarOperatorNode::getPriority() const } void ScalarOperatorNode::generateDotTree(QString& s) { - auto id = toString(true); + auto id= toString(true); if(s.contains(id)) return; s.append(id); s.append(";\n"); - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { s.append(toString(false)); s.append(" -> "); @@ -216,7 +219,7 @@ void ScalarOperatorNode::generateDotTree(QString& s) s.append(" [label=\"nextNode\"];\n"); } - if(nullptr!=m_result) + if(nullptr != m_result) { s.append(toString(false)); s.append(" ->"); @@ -227,7 +230,7 @@ void ScalarOperatorNode::generateDotTree(QString& s) } QString str; str.append("\n"); - if(nullptr!=m_internalNode) + if(nullptr != m_internalNode) { str.append(toString(false)); str.append(" -> "); @@ -237,32 +240,32 @@ void ScalarOperatorNode::generateDotTree(QString& s) } s.append(str); } -QMap<ExecutionNode::DICE_ERROR_CODE,QString> ScalarOperatorNode::getExecutionErrorMap() +QMap<ExecutionNode::DICE_ERROR_CODE, QString> ScalarOperatorNode::getExecutionErrorMap() { - if(nullptr!=m_internalNode) + if(nullptr != m_internalNode) { - auto keys = m_internalNode->getExecutionErrorMap().keys(); - for (ExecutionNode::DICE_ERROR_CODE& key: keys) + auto keys= m_internalNode->getExecutionErrorMap().keys(); + for(ExecutionNode::DICE_ERROR_CODE& key : keys) { - m_errors.insert(key,m_internalNode->getExecutionErrorMap().value(key)); + m_errors.insert(key, m_internalNode->getExecutionErrorMap().value(key)); } } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { - auto keys = m_nextNode->getExecutionErrorMap().keys(); - for (ExecutionNode::DICE_ERROR_CODE& key: keys) + auto keys= m_nextNode->getExecutionErrorMap().keys(); + for(ExecutionNode::DICE_ERROR_CODE& key : keys) { - m_errors.insert(key,m_nextNode->getExecutionErrorMap().value(key)); + m_errors.insert(key, m_nextNode->getExecutionErrorMap().value(key)); } } return m_errors; } ExecutionNode* ScalarOperatorNode::getCopy() const { - ScalarOperatorNode* node = new ScalarOperatorNode(); + ScalarOperatorNode* node= new ScalarOperatorNode(); node->setInternalNode(m_internalNode->getCopy()); node->setArithmeticOperator(m_arithmeticOperator); - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/scalaroperatornode.h b/node/scalaroperatornode.h index 04c3c23..2ac89b0 100644 --- a/node/scalaroperatornode.h +++ b/node/scalaroperatornode.h @@ -1,34 +1,33 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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 SCALAROPERATORNODE_H #define SCALAROPERATORNODE_H -#include <QMap> #include <QChar> +#include <QMap> +#include "die.h" #include "executionnode.h" #include "result/scalarresult.h" -#include "die.h" - /** * @brief The ScalarOperatorNode class @@ -39,7 +38,7 @@ public: /** * @brief The ArithmeticOperator enum */ - //enum ArithmeticOperator {PLUS,MINUS,DIVIDE,MULTIPLICATION}; + // enum ArithmeticOperator {PLUS,MINUS,DIVIDE,MULTIPLICATION}; /** * @brief ScalarOperatorNode */ @@ -62,7 +61,7 @@ public: * @param wl * @return */ - virtual QString toString(bool wl)const; + virtual QString toString(bool wl) const; /** * @brief getPriority * @return @@ -77,7 +76,7 @@ public: * @brief getErrorList * @return */ - virtual QMap<ExecutionNode::DICE_ERROR_CODE,QString> getExecutionErrorMap(); + virtual QMap<ExecutionNode::DICE_ERROR_CODE, QString> getExecutionErrorMap(); /** * @brief getArithmeticOperator * @return @@ -87,35 +86,35 @@ public: * @brief setArithmeticOperator * @param arithmeticOperator */ - void setArithmeticOperator(const Die::ArithmeticOperator &arithmeticOperator); + void setArithmeticOperator(const Die::ArithmeticOperator& arithmeticOperator); /** * @brief getCopy * @return */ - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; private: /** * @brief add * @return */ - static qint64 add(qreal,qreal); + static qint64 add(qreal, qreal); /** * @brief substract * @return */ - static qint64 substract(qreal,qreal); + static qint64 substract(qreal, qreal); /** * @brief divide not static because of error management * @return */ - qreal divide(qreal,qreal); + qreal divide(qreal, qreal); /** * @brief multiple * @return */ - static qint64 multiple(qreal,qreal); + static qint64 multiple(qreal, qreal); static qint64 pow(qreal a, qreal b); @@ -126,4 +125,3 @@ private: }; #endif // SCALAROPERATORNODE_H - diff --git a/node/sortresult.cpp b/node/sortresult.cpp index 69611df..76fae2b 100644 --- a/node/sortresult.cpp +++ b/node/sortresult.cpp @@ -1,162 +1,154 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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. * + ***************************************************************************/ #include "sortresult.h" -#include <QDebug> #include "die.h" +#include <QDebug> -SortResultNode::SortResultNode() - : m_diceResult(new DiceResult) +SortResultNode::SortResultNode() : m_diceResult(new DiceResult) { - m_ascending = true; - m_result = m_diceResult; - + m_ascending= true; + m_result= m_diceResult; } void SortResultNode::run(ExecutionNode* node) { - m_previousNode = node; - if(nullptr==node) + m_previousNode= node; + if(nullptr == node) { return; } - DiceResult* previousDiceResult = dynamic_cast<DiceResult*>(node->getResult()); + DiceResult* previousDiceResult= dynamic_cast<DiceResult*>(node->getResult()); m_diceResult->setPrevious(previousDiceResult); - if(nullptr!=previousDiceResult) - { - auto const& diceList=previousDiceResult->getResultList(); - QList<Die*> diceList2=m_diceResult->getResultList(); + if(nullptr != previousDiceResult) + { + auto const& diceList= previousDiceResult->getResultList(); + QList<Die*> diceList2= m_diceResult->getResultList(); - /* const auto& asce = [](const Die* a,const Die* b){ - return a->getValue() < b->getValue(); - }; - const auto& desc = [](const Die* a,const Die* b){ - return a->getValue() > b->getValue(); - }; + /* const auto& asce = [](const Die* a,const Die* b){ + return a->getValue() < b->getValue(); + }; + const auto& desc = [](const Die* a,const Die* b){ + return a->getValue() > b->getValue(); + }; - for(auto const dice : diceList) - { - Die* tmp1 = new Die(*dice); - diceList2.append(tmp1); - } - if(m_ascending) - std::sort(diceList2.begin(), diceList2.end(), asce); - else - std::sort(diceList2.begin(), diceList2.end(), desc);*/ + for(auto const dice : diceList) + { + Die* tmp1 = new Die(*dice); + diceList2.append(tmp1); + } + if(m_ascending) + std::sort(diceList2.begin(), diceList2.end(), asce); + else + std::sort(diceList2.begin(), diceList2.end(), desc);*/ // half-interval search sorting - for(int i = 0; i<diceList.size();++i) + for(int i= 0; i < diceList.size(); ++i) { - - Die* tmp1 = new Die(*diceList[i]); + Die* tmp1= new Die(*diceList[i]); //*tmp1=*diceList[i]; diceList[i]->displayed(); - int j =0; - bool found = false; - int start = 0; - int end = diceList2.size(); - Die* tmp2 = nullptr; + int j= 0; + bool found= false; + int start= 0; + int end= diceList2.size(); + Die* tmp2= nullptr; while(!found) { - int distance = end-start; - j = (start+end)/2; + int distance= end - start; + j= (start + end) / 2; if(distance == 0) { - j=end; - found=true; + j= end; + found= true; } else { - tmp2 = diceList2[j]; + tmp2= diceList2[j]; if(tmp1->getValue() < tmp2->getValue()) { - end=j; + end= j; } else { - start=j+1; + start= j + 1; } } } - diceList2.insert(j,tmp1); + diceList2.insert(j, tmp1); } if(!m_ascending) { - for(int i = 0; i< diceList2.size()/2; ++i) + for(int i= 0; i < diceList2.size() / 2; ++i) { - diceList2.swap(i,diceList2.size()-(1+i)); + diceList2.swap(i, diceList2.size() - (1 + i)); } - } m_diceResult->setResultList(diceList2); - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } } else { - //m_result = node->getResult(); - //m_errors.append(DIE_RESULT_EXPECTED); + // m_result = node->getResult(); + // m_errors.append(DIE_RESULT_EXPECTED); } - } void SortResultNode::setSortAscending(bool asc) { - m_ascending = asc; + m_ascending= asc; } QString SortResultNode::toString(bool wl) const { - if(wl) - { - auto order = m_ascending ? QStringLiteral("Ascending") : QStringLiteral("Descending"); + if(wl) + { + auto order= m_ascending ? QStringLiteral("Ascending") : QStringLiteral("Descending"); return QString("%1 [label=\"SortResultNode %2\"]").arg(m_id, order); - } - else - { - return m_id; - } - + } + else + { + return m_id; + } } qint64 SortResultNode::getPriority() const { - qint64 priority=0; - if(nullptr!=m_nextNode) + qint64 priority= 0; + if(nullptr != m_nextNode) { - priority = m_nextNode->getPriority(); + priority= m_nextNode->getPriority(); } - return priority; } ExecutionNode* SortResultNode::getCopy() const { - SortResultNode* node = new SortResultNode(); + SortResultNode* node= new SortResultNode(); node->setSortAscending(m_ascending); - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; - } diff --git a/node/sortresult.h b/node/sortresult.h index 804841d..fa26d9a 100644 --- a/node/sortresult.h +++ b/node/sortresult.h @@ -1,24 +1,24 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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 SORTRESULT_H #define SORTRESULT_H @@ -49,7 +49,7 @@ public: * @brief toString * @return */ - virtual QString toString(bool wl)const; + virtual QString toString(bool wl) const; /** * @brief getPriority * @return @@ -59,7 +59,8 @@ public: * @brief getCopy * @return */ - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; + private: bool m_ascending; DiceResult* m_diceResult; diff --git a/node/splitnode.cpp b/node/splitnode.cpp index 4ef9c8c..2e3e739 100644 --- a/node/splitnode.cpp +++ b/node/splitnode.cpp @@ -1,43 +1,42 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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. * + ***************************************************************************/ #include "splitnode.h" -SplitNode::SplitNode() - : m_diceResult(new DiceResult()) +SplitNode::SplitNode() : m_diceResult(new DiceResult()) { - m_result = m_diceResult; + m_result= m_diceResult; } void SplitNode::run(ExecutionNode* previous) { - m_previousNode = previous; - if(nullptr!=previous) + m_previousNode= previous; + if(nullptr != previous) { m_result->setPrevious(previous->getResult()); - Result* tmpResult = previous->getResult(); + Result* tmpResult= previous->getResult(); if(nullptr != tmpResult) { - DiceResult* dice = dynamic_cast<DiceResult*>(tmpResult); - if(nullptr!=dice) + DiceResult* dice= dynamic_cast<DiceResult*>(tmpResult); + if(nullptr != dice) { for(auto& oldDie : dice->getResultList()) { @@ -45,7 +44,7 @@ void SplitNode::run(ExecutionNode* previous) m_diceResult->setOperator(oldDie->getOp()); for(qint64& value : oldDie->getListValue()) { - Die* tmpdie = new Die(); + Die* tmpdie= new Die(); tmpdie->insertRollValue(value); tmpdie->setBase(oldDie->getBase()); tmpdie->setMaxValue(oldDie->getMaxValue()); @@ -53,11 +52,11 @@ void SplitNode::run(ExecutionNode* previous) tmpdie->setOp(oldDie->getOp()); m_diceResult->insertResult(tmpdie); } - } + } } } } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } @@ -76,20 +75,19 @@ QString SplitNode::toString(bool withLabel) const } qint64 SplitNode::getPriority() const { - qint64 priority=0; - if(nullptr!=m_nextNode) + qint64 priority= 0; + if(nullptr != m_nextNode) { - priority = m_nextNode->getPriority(); + priority= m_nextNode->getPriority(); } return priority; } ExecutionNode* SplitNode::getCopy() const { - SplitNode* node = new SplitNode(); - if(nullptr!=m_nextNode) + SplitNode* node= new SplitNode(); + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; - } diff --git a/node/splitnode.h b/node/splitnode.h index d9b2136..7df8982 100644 --- a/node/splitnode.h +++ b/node/splitnode.h @@ -1,24 +1,24 @@ /*************************************************************************** -* Copyright (C) 2014 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. * -***************************************************************************/ + * Copyright (C) 2014 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 SPLITNODE_H #define SPLITNODE_H @@ -33,9 +33,10 @@ class SplitNode : public ExecutionNode public: SplitNode(); void run(ExecutionNode* previous); - virtual QString toString(bool withLabel)const; + virtual QString toString(bool withLabel) const; virtual qint64 getPriority() const; - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; + private: DiceResult* m_diceResult; }; diff --git a/node/startingnode.cpp b/node/startingnode.cpp index 210606b..03563bb 100644 --- a/node/startingnode.cpp +++ b/node/startingnode.cpp @@ -1,33 +1,30 @@ /*************************************************************************** - * Copyright (C) 2015 by Renaud Guezennec * - * http://www.rolisteam.org/contact * - * * - * rolisteam 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. * - ***************************************************************************/ + * Copyright (C) 2015 by Renaud Guezennec * + * http://www.rolisteam.org/contact * + * * + * rolisteam 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. * + ***************************************************************************/ #include "startingnode.h" #include <QDebug> -StartingNode::StartingNode() -{ - -} +StartingNode::StartingNode() {} void StartingNode::run(ExecutionNode*) { - m_previousNode = nullptr; - if(nullptr!=m_nextNode) + m_previousNode= nullptr; + if(nullptr != m_nextNode) { m_nextNode->run(this); } @@ -44,23 +41,21 @@ QString StartingNode::toString(bool withlabel) const } } - qint64 StartingNode::getPriority() const { - qint64 priority=0; - if(nullptr!=m_nextNode) + qint64 priority= 0; + if(nullptr != m_nextNode) { - priority = m_nextNode->getPriority(); + priority= m_nextNode->getPriority(); } return priority; } ExecutionNode* StartingNode::getCopy() const { - StartingNode* node = new StartingNode(); - if(nullptr!=m_nextNode) + StartingNode* node= new StartingNode(); + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; - } diff --git a/node/startingnode.h b/node/startingnode.h index ff171e9..7a23de0 100644 --- a/node/startingnode.h +++ b/node/startingnode.h @@ -1,22 +1,22 @@ /*************************************************************************** - * Copyright (C) 2015 by Renaud Guezennec * - * http://www.rolisteam.org/contact * - * * - * rolisteam 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. * - ***************************************************************************/ + * Copyright (C) 2015 by Renaud Guezennec * + * http://www.rolisteam.org/contact * + * * + * rolisteam 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 STARTINGNODE_H #define STARTINGNODE_H @@ -41,7 +41,7 @@ public: * @brief toString * @return */ - virtual QString toString(bool withlabel)const; + virtual QString toString(bool withlabel) const; /** * @brief getPriority * @return @@ -51,8 +51,7 @@ public: * @brief getCopy * @return */ - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; }; #endif // STARTINGNODE_H - diff --git a/node/stringnode.cpp b/node/stringnode.cpp index 8f9796d..78b270a 100644 --- a/node/stringnode.cpp +++ b/node/stringnode.cpp @@ -1,19 +1,18 @@ #include "stringnode.h" -StringNode::StringNode() - : m_stringResult(new StringResult()) +StringNode::StringNode() : m_stringResult(new StringResult()) { - m_result = m_stringResult; + m_result= m_stringResult; } -void StringNode::run(ExecutionNode *previous) +void StringNode::run(ExecutionNode* previous) { - m_previousNode = previous; - if(nullptr!=previous) + m_previousNode= previous; + if(nullptr != previous) { m_result->setPrevious(previous->getResult()); } - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { m_nextNode->run(this); } @@ -21,16 +20,16 @@ void StringNode::run(ExecutionNode *previous) void StringNode::setString(QString str) { - m_data = str; + m_data= str; m_stringResult->setText(m_data); } QString StringNode::toString(bool withLabel) const { if(withLabel) { - QString dataCopy = m_data; + QString dataCopy= m_data; - return QString("%1 [label=\"StringNode %2\"]").arg(m_id, dataCopy.replace('%','\\')); + return QString("%1 [label=\"StringNode %2\"]").arg(m_id, dataCopy.replace('%', '\\')); } else { @@ -39,21 +38,20 @@ QString StringNode::toString(bool withLabel) const } qint64 StringNode::getPriority() const { - qint64 priority=0; - if(nullptr!=m_nextNode) + qint64 priority= 0; + if(nullptr != m_nextNode) { - priority = m_nextNode->getPriority(); + priority= m_nextNode->getPriority(); } return priority; } ExecutionNode* StringNode::getCopy() const { - StringNode* node = new StringNode(); + StringNode* node= new StringNode(); node->setString(m_data); - if(nullptr!=m_nextNode) + if(nullptr != m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; - } diff --git a/node/stringnode.h b/node/stringnode.h index f693a19..4079b7f 100644 --- a/node/stringnode.h +++ b/node/stringnode.h @@ -13,17 +13,17 @@ public: StringNode(); void run(ExecutionNode* previous); void setString(QString str); - virtual QString toString(bool withLabel)const; + virtual QString toString(bool withLabel) const; virtual qint64 getPriority() const; /** * @brief getCopy * @return */ - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; + private: QString m_data; StringResult* m_stringResult; - }; #endif // STRINGNODE_H diff --git a/node/variablenode.cpp b/node/variablenode.cpp index c0d491c..1d13a2c 100644 --- a/node/variablenode.cpp +++ b/node/variablenode.cpp @@ -1,33 +1,30 @@ #include "variablenode.h" #include "parsingtoolbox.h" -VariableNode::VariableNode() -{ - -} +VariableNode::VariableNode() {} -void VariableNode::run(ExecutionNode *previous) +void VariableNode::run(ExecutionNode* previous) { - m_previousNode = previous; - if((nullptr != m_data) && (m_data->size()>m_index)) + m_previousNode= previous; + if((nullptr != m_data) && (m_data->size() > m_index)) { - auto value= (*m_data)[m_index]; - value = ParsingToolBox::getLatestNode(value); - if(nullptr != value) - { - auto result = value->getResult(); - if(result) + auto value= (*m_data)[m_index]; + value= ParsingToolBox::getLatestNode(value); + if(nullptr != value) { - m_result = result->getCopy(); - if(nullptr!=m_nextNode) + auto result= value->getResult(); + if(result) { - m_nextNode->run(this); + m_result= result->getCopy(); + if(nullptr != m_nextNode) + { + m_nextNode->run(this); + } } } - } } else { - m_errors.insert(NO_VARIBALE,QObject::tr("No variable at index:%1").arg(m_index+1)); + m_errors.insert(NO_VARIBALE, QObject::tr("No variable at index:%1").arg(m_index + 1)); } } @@ -35,7 +32,7 @@ QString VariableNode::toString(bool withLabel) const { if(withLabel) { - return QString("%1 [label=\"VariableNode index: %2\"]").arg(m_id).arg(m_index+1); + return QString("%1 [label=\"VariableNode index: %2\"]").arg(m_id).arg(m_index + 1); } else { @@ -45,45 +42,45 @@ QString VariableNode::toString(bool withLabel) const qint64 VariableNode::getPriority() const { - qint64 priority=0; - if(nullptr!=m_previousNode) + qint64 priority= 0; + if(nullptr != m_previousNode) { - priority = m_previousNode->getPriority(); + priority= m_previousNode->getPriority(); } return priority; } -ExecutionNode *VariableNode::getCopy() const +ExecutionNode* VariableNode::getCopy() const { - VariableNode* node = new VariableNode(); - node->setIndex(m_index); - if(nullptr != m_data) - { - node->setData(m_data); - } - if(nullptr!=m_nextNode) - { - node->setNextNode(m_nextNode->getCopy()); - } - return node; + VariableNode* node= new VariableNode(); + node->setIndex(m_index); + if(nullptr != m_data) + { + node->setData(m_data); + } + if(nullptr != m_nextNode) + { + node->setNextNode(m_nextNode->getCopy()); + } + return node; } qint64 VariableNode::getIndex() const { - return m_index; + return m_index; } void VariableNode::setIndex(qint64 index) { - m_index = index; + m_index= index; } -std::vector<ExecutionNode *>* VariableNode::getData() const +std::vector<ExecutionNode*>* VariableNode::getData() const { - return m_data; + return m_data; } -void VariableNode::setData(std::vector<ExecutionNode *>* data) +void VariableNode::setData(std::vector<ExecutionNode*>* data) { - m_data = data; + m_data= data; } diff --git a/node/variablenode.h b/node/variablenode.h index c74e7ff..c26e60d 100644 --- a/node/variablenode.h +++ b/node/variablenode.h @@ -12,22 +12,22 @@ class VariableNode : public ExecutionNode public: VariableNode(); void run(ExecutionNode* previous); - virtual QString toString(bool withLabel)const; + virtual QString toString(bool withLabel) const; virtual qint64 getPriority() const; /** * @brief getCopy * @return */ - virtual ExecutionNode *getCopy() const; + virtual ExecutionNode* getCopy() const; qint64 getIndex() const; void setIndex(qint64 index); - std::vector<ExecutionNode *>* getData() const; - void setData(std::vector<ExecutionNode *>* data); + std::vector<ExecutionNode*>* getData() const; + void setData(std::vector<ExecutionNode*>* data); private: quint64 m_index; - std::vector<ExecutionNode*>* m_data = nullptr; + std::vector<ExecutionNode*>* m_data= nullptr; }; #endif // VARIABLENODE_H |