aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node/countexecutenode.cpp
blob: 1050efcde9cb19857583829586a954e0af0a99c6 (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
#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* previous_result = dynamic_cast<DiceResult*>(previous->getResult());
    if(NULL!=previous_result)
    {
        m_result->setPrevious(previous_result);
        QList<Die*> diceList=previous_result->getResultList();
        qint64 sum = 0;
        foreach(Die* dice,diceList)
        {
            sum+=m_validator->hasValid(dice,true);
        }
        m_scalarResult->setValue(sum);


        if(NULL!=m_nextNode)
        {
            m_nextNode->run(this);
        }
    }
}
QString CountExecuteNode::toString() const
{
    return "CountExecuteNode"+m_validator->toString();
}
qint64 CountExecuteNode::getPriority() const
{
    qint64 priority=0;
    if(NULL!=m_nextNode)
    {
        priority = m_nextNode->getPriority();
    }


    return priority;
}