From cb1dcb5ee28994a2cd691ad696a5ba4c3c3802ea Mon Sep 17 00:00:00 2001 From: Renaud Guezennec Date: Wed, 23 Oct 2024 15:42:08 +0200 Subject: Add execute node. --- src/libparser/node/uniquenode.cpp | 52 ++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 28 deletions(-) (limited to 'src/libparser/node/uniquenode.cpp') diff --git a/src/libparser/node/uniquenode.cpp b/src/libparser/node/uniquenode.cpp index c4668be..e5ede7b 100644 --- a/src/libparser/node/uniquenode.cpp +++ b/src/libparser/node/uniquenode.cpp @@ -27,38 +27,34 @@ UniqueNode::UniqueNode() : m_diceResult(new DiceResult()) } void UniqueNode::run(ExecutionNode* previous) { + if(isValid(!previous, Dice::ERROR_CODE::NO_PREVIOUS_ERROR, tr("No Previous node"))) + return; m_previousNode= previous; - if(nullptr != previous) + + m_result->setPrevious(previous->getResult()); + Result* tmpResult= previous->getResult(); + if(isValid(!tmpResult, Dice::ERROR_CODE::NO_VALID_RESULT, tr("No Valid result"))) + return; + + DiceResult* dice= dynamic_cast(tmpResult); + if(isValid(!dice, Dice::ERROR_CODE::NO_VALID_RESULT, tr("No Valid dice result"))) + return; + + auto const& resultList= dice->getResultList(); + std::vector formerValues; + formerValues.reserve(resultList.size()); + for(auto& oldDie : resultList) { - m_result->setPrevious(previous->getResult()); - Result* tmpResult= previous->getResult(); - if(nullptr != tmpResult) - { - DiceResult* dice= dynamic_cast(tmpResult); - if(nullptr != dice) - { - auto const& resultList= dice->getResultList(); - std::vector formerValues; - formerValues.reserve(resultList.size()); - for(auto& oldDie : resultList) - { - auto value= oldDie->getValue(); - auto it= std::find(formerValues.begin(), formerValues.end(), value); + auto value= oldDie->getValue(); + auto it= std::find(formerValues.begin(), formerValues.end(), value); - if(it == formerValues.end()) - { - auto die= new Die(*oldDie); - m_diceResult->insertResult(die); - formerValues.push_back(value); - } - oldDie->displayed(); - } - } + if(it == formerValues.end()) + { + auto die= new Die(*oldDie); + m_diceResult->insertResult(die); + formerValues.push_back(value); } - } - if(nullptr != m_nextNode) - { - m_nextNode->run(this); + oldDie->displayed(); } } -- cgit v1.2.3-70-g09d2