diff options
Diffstat (limited to 'node/mergenode.cpp')
| -rw-r--r-- | node/mergenode.cpp | 106 |
1 files changed, 52 insertions, 54 deletions
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; } |