aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node/countexecutenode.cpp
blob: adcde2589a5e9f161734e82c9a769c9554bfd43b (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
#include "countexecutenode.h"
#include "diceresult.h"



CountExecuteNode::CountExecuteNode()
    : m_scalarResult(new ScalarResult())
{
    m_result = m_scalarResult;
}
void CountExecuteNode::setValidator(Validator* validator)
{
    m_validator = validator;
}

void CountExecuteNode::run(ExecutionNode *previous)
{
    if(NULL==previous)
    {
        return;
    }
    DiceResult* previous_result = static_cast<DiceResult*>(previous->getResult());
    if(NULL!=previous_result)
    {
        QList<Die*> diceList=previous_result->getResultList();
        qint64 sum = 0;
        foreach(Die* dice,diceList)
        {
            if(m_validator->isValid(dice))
            {
                ++sum;
            }
        }
        m_scalarResult->setValue(sum);


        if(NULL!=m_nextNode)
        {
            m_nextNode->run(this);
        }
    }
}