diff options
| author | 2016-11-05 00:11:19 +0100 | |
|---|---|---|
| committer | 2016-11-05 00:11:19 +0100 | |
| commit | 3799c71dee9e8d73858c727873d550adc0649c64 (patch) | |
| tree | 87813e160bdbb3bad51b1a6c448bdeeaa475c2fc /node | |
| parent | d5876d9b88c2f695592338335308a32e584d86a4 (diff) | |
| parent | b977d3e2a2765f5b91ac7bf5c34ea8891969cda9 (diff) | |
| download | OneRoll-3799c71dee9e8d73858c727873d550adc0649c64.tar.gz OneRoll-3799c71dee9e8d73858c727873d550adc0649c64.zip | |
add filter node
Diffstat (limited to 'node')
| -rw-r--r-- | node/filternode.cpp | 76 | ||||
| -rw-r--r-- | node/filternode.h | 37 | ||||
| -rw-r--r-- | node/ifnode.cpp | 6 |
3 files changed, 116 insertions, 3 deletions
diff --git a/node/filternode.cpp b/node/filternode.cpp new file mode 100644 index 0000000..8fe99c3 --- /dev/null +++ b/node/filternode.cpp @@ -0,0 +1,76 @@ +#include "filternode.h" + +FilterNode::FilterNode() + : m_diceResult(new DiceResult()),m_eachValue(false) +{ + m_result = m_diceResult; +} + +FilterNode::~FilterNode() +{ + if(NULL!=m_validator) + { + delete m_validator; + } +} +void FilterNode::setValidator(Validator* validator) +{ + m_validator = validator; +} +void FilterNode::run(ExecutionNode* previous) +{ + m_previousNode = previous; + if(NULL==previous) + { + return; + } + DiceResult* previousDiceResult = static_cast<DiceResult*>(previous->getResult()); + m_result->setPrevious(previousDiceResult); + if(NULL!=previousDiceResult) + { + QList<Die*> diceList=previousDiceResult->getResultList(); + QList<Die*> diceList2; + + + for(Die* tmp : diceList) + { + if(m_validator->hasValid(tmp,m_eachValue)) + { + diceList2.append(tmp); + } + else + { + tmp->setHighlighted(false); + } + } + + m_diceResult->setResultList(diceList2); + if(NULL!=m_nextNode) + { + m_nextNode->run(this); + } + } +} + +QString FilterNode::toString(bool wl) const +{ + if(wl) + { + return QString("%1 [label=\"FilterNode\"]").arg(m_id); + } + else + { + return m_id; + } +} +qint64 FilterNode::getPriority() const +{ + qint64 priority=0; + if(NULL!=m_nextNode) + { + priority = m_nextNode->getPriority(); + } + + + return priority; +} diff --git a/node/filternode.h b/node/filternode.h new file mode 100644 index 0000000..ca08c3b --- /dev/null +++ b/node/filternode.h @@ -0,0 +1,37 @@ +#ifndef FILTERNODE_H +#define FILTERNODE_H + +#include "executionnode.h" + +#include "validator.h" +#include "result/diceresult.h" + +class FilterNode : public ExecutionNode +{ +public: + FilterNode(); + virtual ~FilterNode(); + + virtual void run(ExecutionNode* previous); + /** + * @brief setValidator + */ + virtual void setValidator(Validator* ); + /** + * @brief toString + * @return + */ + virtual QString toString(bool withLabel)const; + /** + * @brief getPriority + * @return + */ + virtual qint64 getPriority() const; + +private: + DiceResult* m_diceResult; + Validator* m_validator; + bool m_eachValue; +}; + +#endif // FILTERNODE_H diff --git a/node/ifnode.cpp b/node/ifnode.cpp index 8605dcf..8cf667c 100644 --- a/node/ifnode.cpp +++ b/node/ifnode.cpp @@ -86,10 +86,10 @@ void IfNode::run(ExecutionNode *previous) } } - /* if(NULL!=m_nextNode) + if(NULL!=m_nextNode) { - m_nextNode->run(this); - }*/ + m_nextNode->run(previousLoop); + } } void IfNode::setValidator(Validator* val) |