diff options
| author | 2019-05-08 17:11:29 +0200 | |
|---|---|---|
| committer | 2019-05-08 17:12:25 +0200 | |
| commit | 90cec3957ff5e61981f9068a1fac3cb44a3e7d41 (patch) | |
| tree | 6f6a245e72b83d1b774d507b446a5383a5e499bf | |
| parent | cf5bc61b43e41667a016a01666cbe6391a59cdfe (diff) | |
| download | OneRoll-90cec3957ff5e61981f9068a1fac3cb44a3e7d41.tar.gz OneRoll-90cec3957ff5e61981f9068a1fac3cb44a3e7d41.zip | |
Add test node.
| -rw-r--r-- | diceparser.pri | 2 | ||||
| -rw-r--r-- | node/testnode.cpp | 48 | ||||
| -rw-r--r-- | node/testnode.h | 44 |
3 files changed, 94 insertions, 0 deletions
diff --git a/diceparser.pri b/diceparser.pri index 933bed0..c51c96d 100644 --- a/diceparser.pri +++ b/diceparser.pri @@ -32,6 +32,7 @@ SOURCES += $$PWD/diceparser.cpp \ $$PWD/node/explodedicenode.cpp \ $$PWD/node/parenthesesnode.cpp \ $$PWD/node/helpnode.cpp \ + $$PWD/node/testnode.cpp \ $$PWD/node/jumpbackwardnode.cpp \ $$PWD/node/mergenode.cpp \ $$PWD/node/listaliasnode.cpp \ @@ -73,6 +74,7 @@ HEADERS += \ $$PWD/node/scalaroperatornode.h \ $$PWD/node/numbernode.h \ $$PWD/node/sortresult.h \ + $$PWD/node/testnode.h \ $$PWD/node/keepdiceexecnode.h \ $$PWD/node/countexecutenode.h \ $$PWD/node/explodedicenode.h \ diff --git a/node/testnode.cpp b/node/testnode.cpp new file mode 100644 index 0000000..263286b --- /dev/null +++ b/node/testnode.cpp @@ -0,0 +1,48 @@ +#include "testnode.h" +#include "die.h" + +TestNode::TestNode() {} + +TestNode::~TestNode() +{ + m_nextNode= nullptr; + m_result= nullptr; +} +void TestNode::run(ExecutionNode* previous) +{ + if(nullptr != m_nextNode) + { + m_nextNode->run(this); + } +} + +QString TestNode::toString(bool wl) const +{ + if(wl) + { + return QStringLiteral("%1 [label=\"TestNode \"]").arg(m_id); + } + else + { + return m_id; + } +} +qint64 TestNode::getPriority() const +{ + qint64 priority= 4; + return priority; +} +ExecutionNode* TestNode::getCopy() const +{ + TestNode* node= new TestNode(); + if(nullptr != m_nextNode) + { + node->setNextNode(m_nextNode->getCopy()); + } + return node; +} + +void TestNode::setResult(Result* result) +{ + m_result= result; +} diff --git a/node/testnode.h b/node/testnode.h new file mode 100644 index 0000000..5c918ee --- /dev/null +++ b/node/testnode.h @@ -0,0 +1,44 @@ +#ifndef TESTNODE_H +#define TESTNODE_H + +#include <Qt> + +#include "executionnode.h" +#include "result/diceresult.h" +#include <utility> +/** + * @brief The TestNode class replaces any kind of node for test purpose. + */ +class TestNode : public ExecutionNode +{ +public: + /** + * @brief TestNode builds an instance + * @param faces, number of faces of dices + * @param offset, first value of dice. + */ + TestNode(); + virtual ~TestNode() override; + + /** + * @brief run - starts to roll dice. + */ + virtual void run(ExecutionNode*) override; + /** + * @brief toString + * @param wl + * @return use to generate dot tree; + */ + virtual QString toString(bool wl) const override; + /** + * @brief getPriority + * @return priority for dice roll: 4 (higher) + */ + virtual qint64 getPriority() const override; + + virtual ExecutionNode* getCopy() const override; + + void setResult(Result* result); +}; + +#endif // TESTNODE_H |