aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node/scalaroperatornode.cpp
diff options
context:
space:
mode:
authorrenaud guezennec <renaud@rolisteam.org>2019-07-29 20:35:52 +0000
committerrenaud guezennec <renaud@rolisteam.org>2019-07-29 20:35:52 +0000
commit1a902d383eef1e042d4462cd07b9384fcdf4d118 (patch)
tree766b8ab720fa5da11730d2fc2388f51b9d14de49 /node/scalaroperatornode.cpp
parentf5906125576a8323a731c9456ce3dfc53b67ef59 (diff)
parent0d4b68221bda594cc695d216dfa21306ddb69c85 (diff)
downloadOneRoll-1a902d383eef1e042d4462cd07b9384fcdf4d118.tar.gz
OneRoll-1a902d383eef1e042d4462cd07b9384fcdf4d118.zip
Merge branch 'liberation' into 'master'
Add fuzzer on the DiceParser See merge request kde/rolisteam-diceparser!2
Diffstat (limited to 'node/scalaroperatornode.cpp')
-rw-r--r--node/scalaroperatornode.cpp40
1 files changed, 24 insertions, 16 deletions
diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp
index 3a26fc7..821150b 100644
--- a/node/scalaroperatornode.cpp
+++ b/node/scalaroperatornode.cpp
@@ -66,31 +66,39 @@ void ScalarOperatorNode::run(ExecutionNode* previous)
m_internalNode->getResult()->setPrevious(previousResult);
}
+ if(internalResult == nullptr)
+ {
+ m_errors.insert(Dice::ERROR_CODE::NO_VALID_RESULT,
+ QObject::tr("No Valid result in arithmetic operatoion: %1").arg(toString(true)));
+ return;
+ }
+
switch(m_arithmeticOperator)
{
case Die::PLUS:
- m_scalarResult->setValue(add(previousResult->getResult(Result::SCALAR).toReal(),
- internalResult->getResult(Result::SCALAR).toReal()));
+ m_scalarResult->setValue(add(previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal(),
+ internalResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal()));
break;
case Die::MINUS:
- m_scalarResult->setValue(substract(previousResult->getResult(Result::SCALAR).toReal(),
- internalResult->getResult(Result::SCALAR).toReal()));
+ m_scalarResult->setValue(substract(previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal(),
+ internalResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal()));
break;
case Die::MULTIPLICATION:
- m_scalarResult->setValue(multiple(previousResult->getResult(Result::SCALAR).toReal(),
- internalResult->getResult(Result::SCALAR).toReal()));
+ m_scalarResult->setValue(multiple(previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal(),
+ internalResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal()));
break;
case Die::DIVIDE:
- m_scalarResult->setValue(divide(previousResult->getResult(Result::SCALAR).toReal(),
- internalResult->getResult(Result::SCALAR).toReal()));
+ m_scalarResult->setValue(divide(previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal(),
+ internalResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal()));
break;
case Die::INTEGER_DIVIDE:
- m_scalarResult->setValue(static_cast<int>(divide(previousResult->getResult(Result::SCALAR).toReal(),
- internalResult->getResult(Result::SCALAR).toReal())));
+ m_scalarResult->setValue(
+ static_cast<int>(divide(previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal(),
+ internalResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal())));
break;
case Die::POW:
- m_scalarResult->setValue(pow(previousResult->getResult(Result::SCALAR).toReal(),
- internalResult->getResult(Result::SCALAR).toReal()));
+ m_scalarResult->setValue(pow(previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal(),
+ internalResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal()));
break;
}
}
@@ -128,7 +136,7 @@ qreal ScalarOperatorNode::divide(qreal a, qreal b)
{
if(qFuzzyCompare(b, 0))
{
- m_errors.insert(DIVIDE_BY_ZERO, QObject::tr("Division by zero"));
+ m_errors.insert(Dice::ERROR_CODE::DIVIDE_BY_ZERO, QObject::tr("Division by zero"));
return 0;
}
return static_cast<qreal>(a / b);
@@ -240,12 +248,12 @@ void ScalarOperatorNode::generateDotTree(QString& s)
}
s.append(str);
}
-QMap<ExecutionNode::DICE_ERROR_CODE, QString> ScalarOperatorNode::getExecutionErrorMap()
+QMap<Dice::ERROR_CODE, QString> ScalarOperatorNode::getExecutionErrorMap()
{
if(nullptr != m_internalNode)
{
auto keys= m_internalNode->getExecutionErrorMap().keys();
- for(ExecutionNode::DICE_ERROR_CODE& key : keys)
+ for(const auto& key : keys)
{
m_errors.insert(key, m_internalNode->getExecutionErrorMap().value(key));
}
@@ -253,7 +261,7 @@ QMap<ExecutionNode::DICE_ERROR_CODE, QString> ScalarOperatorNode::getExecutionEr
if(nullptr != m_nextNode)
{
auto keys= m_nextNode->getExecutionErrorMap().keys();
- for(ExecutionNode::DICE_ERROR_CODE& key : keys)
+ for(auto const& key : keys)
{
m_errors.insert(key, m_nextNode->getExecutionErrorMap().value(key));
}