From 0351038352f4f22f5a114abe875fb58d55183a86 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 10 Jul 2019 11:54:09 +0200 Subject: Add forloopnode - experiemental it is not compiled --- node/forloopnode.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++ node/forloopnode.h | 36 ++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 node/forloopnode.cpp create mode 100644 node/forloopnode.h diff --git a/node/forloopnode.cpp b/node/forloopnode.cpp new file mode 100644 index 0000000..f65a389 --- /dev/null +++ b/node/forloopnode.cpp @@ -0,0 +1,103 @@ +#include "forloopnode.h" + +#include "die.h" + +MockNode::MockNode() {} + +void MockNode::run(ExecutionNode* node) +{ + return; +} + +void MockNode::setResult(Result* result) +{ + m_result= result; +} + +QString MockNode::toString(bool) const +{ + return {}; +}; +qint64 MockNode::getPriority() const +{ + return 0; +} +ExecutionNode* MockNode::getCopy() const +{ + return new MockNode(); +} +// end mocknode + +ForLoopNode::ForLoopNode() : m_diceResult(new DiceResult) {} + +void ForLoopNode::setInternal(ExecutionNode* node) +{ + m_internal.reset(node); +} + +void ForLoopNode::run(ExecutionNode* previous) +{ + if(nullptr != previous) + { + auto prevResult= dynamic_cast(previous->getResult()); + if(nullptr != prevResult) + { + m_diceResult->setPrevious(prevResult); + QList diceList= prevResult->getResultList(); + for(Die* dice : diceList) + { + MockNode node; + DiceResult diceResult; + diceResult.insertResult(dice); + node.setResult(&diceResult); + m_internal->run(&node); + + auto tmp= m_internal.get(); + while(nullptr != tmp->getNextNode()) + { + tmp= tmp->getNextNode(); + } + Result* internalResult= tmp->getResult(); + auto value= internalResult->getResult(Result::SCALAR).toInt(); + + Die* neodie= new Die(); + *neodie= *dice; + neodie->setValue(value); + m_diceResult->insertResult(neodie); + node.setResult(nullptr); + diceResult.clear(); + dice->displayed(); + } + } + } + m_result= m_diceResult; + if(m_nextNode != nullptr) + m_nextNode->run(this); +} + +qint64 ForLoopNode::getPriority() const +{ + return 2; +} + +QString ForLoopNode::toString(bool withLabel) const +{ + if(withLabel) + { + return QString("%1 [label=\"ForLoopNode Node\"]").arg(m_id); + } + else + { + return m_id; + } +} + +ExecutionNode* ForLoopNode::getCopy() const +{ + auto node= new ForLoopNode(); + if(m_internal) + { + node->setInternal(m_internal->getCopy()); + } + return node; +} diff --git a/node/forloopnode.h b/node/forloopnode.h new file mode 100644 index 0000000..a9acf20 --- /dev/null +++ b/node/forloopnode.h @@ -0,0 +1,36 @@ +#ifndef FORLOOPNODE_H +#define FORLOOPNODE_H + +#include "executionnode.h" +#include "result/diceresult.h" +#include + +class MockNode : public ExecutionNode +{ +public: + MockNode(); + void run(ExecutionNode* node); + void setResult(Result* result); + QString toString(bool withLabel) const; + qint64 getPriority() const; + ExecutionNode* getCopy() const; +}; + +class ForLoopNode : public ExecutionNode +{ +public: + ForLoopNode(); + void run(ExecutionNode* previous); + + void setInternal(ExecutionNode* internal); + + QString toString(bool withLabel) const; + qint64 getPriority() const; + ExecutionNode* getCopy() const; + +private: + std::unique_ptr m_internal; + DiceResult* m_diceResult; +}; + +#endif // FORLOOPNODE_H -- cgit v1.2.3-70-g09d2