From 19bfac5d61c7e30a1e5bbe115d56908474546052 Mon Sep 17 00:00:00 2001 From: Renaud Guezennec Date: Tue, 26 Jan 2016 15:35:18 +0100 Subject: Implementation of the if node. Work with one if. --- node/ifnode.cpp | 39 +++++++++++++++++++++++++++++++++++---- node/ifnode.h | 3 +++ 2 files changed, 38 insertions(+), 4 deletions(-) (limited to 'node') diff --git a/node/ifnode.cpp b/node/ifnode.cpp index 80e5264..5543a93 100644 --- a/node/ifnode.cpp +++ b/node/ifnode.cpp @@ -22,7 +22,7 @@ IfNode::IfNode() { - m_result = new DiceResult(); + //m_result = new DiceResult(); } IfNode::~IfNode() @@ -37,20 +37,42 @@ void IfNode::run(ExecutionNode *previous) { return; } + ExecutionNode* previousLoop = previous; + ExecutionNode* nextNode = NULL; Result* previousResult = previous->getResult(); + m_result = previousResult; DiceResult* previousDiceResult = dynamic_cast(previousResult); if(NULL!=previousDiceResult) { qreal value = previousResult->getResult(Result::SCALAR).toReal(); + QList diceList=previousDiceResult->getResultList(); + + if(NULL!=m_validator) { if(!diceList.isEmpty()) { foreach(Die* dice,diceList) { - m_validator->hasValid(dice,true,true); + if(m_validator->hasValid(dice,true,true)) + { + nextNode=m_true; + } + else + { + nextNode=m_false; + } + if(NULL!=nextNode) + { + if(NULL==m_nextNode) + { + m_nextNode = nextNode; + } + nextNode->run(previousLoop); + previousLoop = getLeafNode(nextNode); + } } } else @@ -63,10 +85,10 @@ void IfNode::run(ExecutionNode *previous) } } - if(NULL!=m_nextNode) + /* if(NULL!=m_nextNode) { m_nextNode->run(this); - } + }*/ } void IfNode::setValidator(Validator* val) @@ -93,3 +115,12 @@ qint64 IfNode::getPriority() const return 4; } +ExecutionNode* IfNode::getLeafNode(ExecutionNode* node) +{ + ExecutionNode* next = node; + while(NULL != next->getNextNode() ) + { + next = next->getNextNode(); + } + return next; +} diff --git a/node/ifnode.h b/node/ifnode.h index ec962a2..56b23fa 100644 --- a/node/ifnode.h +++ b/node/ifnode.h @@ -40,6 +40,9 @@ public: virtual QString toString(bool )const; virtual qint64 getPriority() const; +protected: + ExecutionNode *getLeafNode(ExecutionNode *node); + protected: DiceResult* m_diceResult; Validator* m_validator; -- cgit v1.2.3-70-g09d2