blob: 1f78fd2c690093e71484fab80c0b8f2095d6db27 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#include "countexecutenode.h"
#include "result/diceresult.h"
CountExecuteNode::CountExecuteNode()
: m_scalarResult(new ScalarResult()),m_validator(NULL)
{
m_result = m_scalarResult;
}
void CountExecuteNode::setValidator(Validator* validator)
{
m_validator = validator;
}
CountExecuteNode::~CountExecuteNode()
{
if(NULL!=m_validator)
{
delete m_validator;
}
}
void CountExecuteNode::run(ExecutionNode *previous)
{
m_previousNode = previous;
if(NULL==previous)
{
return;
}
DiceResult* previousResult = dynamic_cast<DiceResult*>(previous->getResult());
if(NULL!=previousResult)
{
m_result->setPrevious(previousResult);
QList<Die*> diceList=previousResult->getResultList();
qint64 sum = 0;
foreach(Die* dice,diceList)
{
if(NULL!=m_validator)
{
sum+=m_validator->hasValid(dice,true,true);
}
}
m_scalarResult->setValue(sum);
if(NULL!=m_nextNode)
{
m_nextNode->run(this);
}
}
}
QString CountExecuteNode::toString(bool withlabel) const
{
if(withlabel)
{
return QString("%1 [label=\"CountExecuteNode %2\"]").arg(m_id).arg(m_validator->toString());
}
else
{
return m_id;
}
}
qint64 CountExecuteNode::getPriority() const
{
qint64 priority=0;
if(NULL!=m_nextNode)
{
priority = m_nextNode->getPriority();
}
return priority;
}
ExecutionNode* CountExecuteNode::getCopy() const
{
CountExecuteNode* node = new CountExecuteNode();
if(NULL!=m_validator)
{
node->setValidator(m_validator->getCopy());
}
if(NULL!=m_nextNode)
{
node->setNextNode(m_nextNode->getCopy());
}
return node;
}
|