From 4de8cf5796446b7f8b09d776e4a6a6d6b8e95cb6 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sat, 4 Jan 2014 16:24:54 +0100 Subject: -Adding range, booleancondition and countexecutenode. --- node/countexecutenode.cpp | 33 +++++++++++++++++++++++++++++++++ node/countexecutenode.h | 22 ++++++++++++++++++++++ node/keepdiceexecnode.cpp | 27 +++++++++++++++++++++++++++ node/keepdiceexecnode.h | 17 +++++++++++++++++ node/node.pri | 10 ++++++++-- node/sortresult.cpp | 37 +++++++++++++++++++++++++++++++++++++ node/sortresult.h | 18 ++++++++++++++++++ 7 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 node/countexecutenode.cpp create mode 100644 node/countexecutenode.h create mode 100644 node/keepdiceexecnode.cpp create mode 100644 node/keepdiceexecnode.h create mode 100644 node/sortresult.cpp create mode 100644 node/sortresult.h (limited to 'node') diff --git a/node/countexecutenode.cpp b/node/countexecutenode.cpp new file mode 100644 index 0000000..fff00f2 --- /dev/null +++ b/node/countexecutenode.cpp @@ -0,0 +1,33 @@ +#include "countexecutenode.h" + +CountExecuteNode::CountExecuteNode() +{ +} +void CountExecuteNode::setValidator(Validator* validator) +{ + m_validator = validator; +} + +void CountExecuteNode::run(ExecutionNode *previous) +{ + if(NULL==previous) + { + return; + } + QList diceList=previous->getResult()->getResultList(); + qint64 sum = 0; + foreach(qint64 dice,diceList) + { + if(m_validator->isValid(dice)) + { + ++sum; + } + } + m_result.insertResult(sum); + + + if(NULL!=m_nextNode) + { + m_nextNode->run(this); + } +} diff --git a/node/countexecutenode.h b/node/countexecutenode.h new file mode 100644 index 0000000..6c971ea --- /dev/null +++ b/node/countexecutenode.h @@ -0,0 +1,22 @@ +#ifndef COUNTEXECUTENODE_H +#define COUNTEXECUTENODE_H + +#include "executionnode.h" + +#include "validator.h" + +class CountExecuteNode : public ExecutionNode +{ +public: + CountExecuteNode(); + virtual void run(ExecutionNode* previous); + + + virtual void setValidator(Validator* ); + +private: + Validator* m_validator; + +}; + +#endif // COUNTEXECUTENODE_H diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp new file mode 100644 index 0000000..cd2b76e --- /dev/null +++ b/node/keepdiceexecnode.cpp @@ -0,0 +1,27 @@ +#include "keepdiceexecnode.h" + +KeepDiceExecNode::KeepDiceExecNode() +{ +} + +void KeepDiceExecNode::run(ExecutionNode* previous) +{ + if(NULL==previous) + { + return; + } + QList diceList=previous->getResult()->getResultList(); + QList diceList2=m_result.getResultList(); + + + diceList2 = diceList.mid(0,m_numberOfDice); + m_result.setResultList(diceList2); + if(NULL!=m_nextNode) + { + m_nextNode->run(this); + } +} +void KeepDiceExecNode::setDiceKeepNumber(quint64 n) +{ + m_numberOfDice = n; +} diff --git a/node/keepdiceexecnode.h b/node/keepdiceexecnode.h new file mode 100644 index 0000000..28c637d --- /dev/null +++ b/node/keepdiceexecnode.h @@ -0,0 +1,17 @@ +#ifndef KEEPDICEEXECNODE_H +#define KEEPDICEEXECNODE_H + +#include "executionnode.h" + +class KeepDiceExecNode : public ExecutionNode +{ +public: + KeepDiceExecNode(); + + virtual void run(ExecutionNode *previous); + virtual void setDiceKeepNumber(quint64 ); +private: + quint64 m_numberOfDice; +}; + +#endif // KEEPDICEEXECNODE_H diff --git a/node/node.pri b/node/node.pri index c3e1d65..fb2d9ad 100644 --- a/node/node.pri +++ b/node/node.pri @@ -4,7 +4,10 @@ HEADERS += \ node/rerolldicenode.h \ node/startingnode.h \ node/scalaroperatornode.h \ - node/numbernode.h + node/numbernode.h \ + node/sortresult.h \ + node/keepdiceexecnode.h \ + node/countexecutenode.h SOURCES += \ node/dicerollernode.cpp \ @@ -12,4 +15,7 @@ SOURCES += \ node/startingnode.cpp \ node/rerolldicenode.cpp \ node/scalaroperatornode.cpp \ - node/numbernode.cpp + node/numbernode.cpp \ + node/sortresult.cpp \ + node/keepdiceexecnode.cpp \ + node/countexecutenode.cpp diff --git a/node/sortresult.cpp b/node/sortresult.cpp new file mode 100644 index 0000000..f4364fa --- /dev/null +++ b/node/sortresult.cpp @@ -0,0 +1,37 @@ +#include "sortresult.h" + +#include + +SortResultNode::SortResultNode() +{ + m_ascending = true; +} +void SortResultNode::run(ExecutionNode* node) +{ + if(NULL==node) + { + return; + } + QList diceList=node->getResult()->getResultList(); + QList diceList2=m_result.getResultList(); + + diceList2 = diceList; + if(!m_ascending) + { + qSort(diceList2.begin(), diceList2.end(), qGreater()); + } + else + { + qSort(diceList2.begin(), diceList2.end(), qLess()); + } + m_result.setResultList(diceList2); + if(NULL!=m_nextNode) + { + m_nextNode->run(this); + } + +} +void SortResultNode::setSortAscending(bool asc) +{ + m_ascending = asc; +} diff --git a/node/sortresult.h b/node/sortresult.h new file mode 100644 index 0000000..8433eba --- /dev/null +++ b/node/sortresult.h @@ -0,0 +1,18 @@ +#ifndef SORTRESULT_H +#define SORTRESULT_H + +#include "executionnode.h" + +class SortResultNode : public ExecutionNode +{ +public: + SortResultNode(); + virtual void run(ExecutionNode*); + + + void setSortAscending(bool asc); +private: + bool m_ascending; +}; + +#endif // SORTRESULT_H -- cgit v1.2.3-70-g09d2