diff options
| author | 2017-11-28 15:42:41 +0100 | |
|---|---|---|
| committer | 2017-11-28 15:42:41 +0100 | |
| commit | ec4eea389e3fd23e5491e1609755d49b916d2db0 (patch) | |
| tree | 777bed719336597406fc81b96d1cffac78ad048a /node/variablenode.cpp | |
| parent | f0ade121f9cef3b39c41816536f4e400f43dd4af (diff) | |
| download | OneRoll-ec4eea389e3fd23e5491e1609755d49b916d2db0.tar.gz OneRoll-ec4eea389e3fd23e5491e1609755d49b916d2db0.zip | |
Add dynamic variable node
Diffstat (limited to 'node/variablenode.cpp')
| -rw-r--r-- | node/variablenode.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/node/variablenode.cpp b/node/variablenode.cpp new file mode 100644 index 0000000..aa42492 --- /dev/null +++ b/node/variablenode.cpp @@ -0,0 +1,84 @@ +#include "variablenode.h" + +VariableNode::VariableNode() +{ + +} + +void VariableNode::run(ExecutionNode *previous) +{ + m_previousNode = previous; + + if(m_index<0) + { + m_errors.insert(INVALID_INDEX,QObject::tr("Invalid index must be greater than 0 :%1").arg(m_index)); + return; + } + + if(m_data.size()>m_index) + { + auto value= m_data[m_index]; + m_result = value->getResult(); + if(nullptr!=m_nextNode) + { + m_nextNode->run(this); + } + } + else + { + m_errors.insert(NO_VARIBALE,QObject::tr("No variable at index:%1").arg(m_index)); + } +} + +QString VariableNode::toString(bool withLabel) const +{ + if(withLabel) + { + return QString("%1 [label=\"VariableNode index: %2\"]").arg(m_id).arg(m_index); + } + else + { + return m_id; + } +} + +qint64 VariableNode::getPriority() const +{ + qint64 priority=0; + if(nullptr!=m_nextNode) + { + priority = m_nextNode->getPriority(); + } + return priority; +} + +ExecutionNode *VariableNode::getCopy() const +{ + VariableNode* node = new VariableNode(); + node->setIndex(m_index); + if(nullptr!=m_nextNode) + { + node->setNextNode(m_nextNode->getCopy()); + } + return node; +} + +qint64 VariableNode::getIndex() const +{ + return m_index; +} + +void VariableNode::setIndex(qint64 index) +{ + m_index = index; +} + +std::vector<ExecutionNode *> VariableNode::getData() const +{ + return m_data; +} + +void VariableNode::setData(const std::vector<ExecutionNode *> &data) +{ + m_data = data; +} |