From 49e3f9a3a7acba5db5ea415e4487c3d200d26454 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Tue, 28 Feb 2017 18:58:12 +0100 Subject: -Add : compare operator to ask the if operator to compare the scalar result. --- node/ifnode.cpp | 40 +++++++++++++++++++++------------------- node/ifnode.h | 2 +- parsingtoolbox.cpp | 5 +++++ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/node/ifnode.cpp b/node/ifnode.cpp index 27b588f..91ad199 100644 --- a/node/ifnode.cpp +++ b/node/ifnode.cpp @@ -81,7 +81,7 @@ void IfNode::run(ExecutionNode *previous) } } } - else + else if((m_conditionType == OneOfThem)||(m_conditionType == AllOfThem)) { bool trueForAll=true; bool falseForAll=true; @@ -133,28 +133,30 @@ void IfNode::run(ExecutionNode *previous) } } } + } + + if(m_conditionType == OnScalar) + { + Die* dice = new Die(); + dice->setValue(value); + dice->insertRollValue(value); + dice->setMaxValue(value); + if(m_validator->hasValid(dice,true,true)) + { + nextNode=m_true; + } else { - Die* dice = new Die(); - dice->setValue(value); - dice->setMaxValue(value); - if(m_validator->hasValid(dice,true,true)) - { - nextNode=m_true; - } - else - { - nextNode=m_false; - } - if(NULL!=nextNode) + nextNode=m_false; + } + if(NULL!=nextNode) + { + if(NULL==m_nextNode) { - if(NULL==m_nextNode) - { - m_nextNode = nextNode; - } - nextNode->run(previousLoop); - previousLoop = getLeafNode(nextNode); + m_nextNode = nextNode; } + nextNode->run(previousLoop); + previousLoop = getLeafNode(nextNode); } } } diff --git a/node/ifnode.h b/node/ifnode.h index da8bb0b..7376101 100644 --- a/node/ifnode.h +++ b/node/ifnode.h @@ -34,7 +34,7 @@ public: /** * @brief The ConditionType enum */ - enum ConditionType {OnEach,OneOfThem,AllOfThem}; + enum ConditionType {OnEach,OneOfThem,AllOfThem,OnScalar}; /** * @brief IfNode */ diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index 3d2d2c3..1e8819c 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -213,6 +213,11 @@ IfNode::ConditionType ParsingToolBox::readConditionType(QString& str) str=str.remove(0,1); type = IfNode::AllOfThem; } + else if(str.startsWith(':')) + { + str=str.remove(0,1); + type = IfNode::OnScalar; + } return type; } -- cgit v1.2.3-70-g09d2 From 6fdd7dad0a24cff8bd20907425a7b9f91e33fdd8 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Mon, 6 Mar 2017 10:36:09 +0100 Subject: add fail reason --- parsingtoolbox.cpp | 19 ++++++++++++++++--- parsingtoolbox.h | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index 1e8819c..e04dcbe 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -316,7 +316,8 @@ bool ParsingToolBox::readNumber(QString& str, qint64& myNumber) if(number.isEmpty()) { - return readVariable(str,myNumber); + QString reason; + return readVariable(str,myNumber,reason); } bool ok; @@ -381,7 +382,7 @@ bool ParsingToolBox::readString(QString &str, QString& strResult) return false; } -bool ParsingToolBox::readVariable(QString &str, qint64 &myNumber) +bool ParsingToolBox::readVariable(QString &str, qint64 &myNumber, QString& reasonFail) { if(str.isEmpty()) return false; @@ -395,6 +396,7 @@ bool ParsingToolBox::readVariable(QString &str, qint64 &myNumber) if(NULL!=m_variableHash) { + qDebug() << m_variableHash->keys(); if(m_variableHash->contains(key)) { QString value = m_variableHash->value(key); @@ -406,10 +408,21 @@ bool ParsingToolBox::readVariable(QString &str, qint64 &myNumber) str=str.remove(0,post+1); return true; } + else + { + reasonFail = QStringLiteral("Variable value is %1, not a number").arg(value); + } } + else + { + reasonFail = QStringLiteral("Variable not found"); + } + } + else + { + reasonFail = QStringLiteral("No Variables are defined"); } - return false; diff --git a/parsingtoolbox.h b/parsingtoolbox.h index 75c01c2..6bfffd0 100644 --- a/parsingtoolbox.h +++ b/parsingtoolbox.h @@ -110,7 +110,7 @@ public: * @param myNumber * @return */ - static bool readVariable(QString& str,qint64& myNumber); + static bool readVariable(QString& str,qint64& myNumber, QString& reasonFail); /** * @brief readOpenParentheses * @param str -- cgit v1.2.3-70-g09d2