From 62b7114ce29af10395273acec8dffeb41f255145 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 19 Jun 2020 08:54:57 +0200 Subject: change the way diceparser is giving its result. --- diceparser.cpp | 69 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 33 deletions(-) (limited to 'diceparser.cpp') diff --git a/diceparser.cpp b/diceparser.cpp index 7adf610..ffd4e8b 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -38,7 +38,7 @@ DiceParser::DiceParser() : m_parsingToolbox(new ParsingToolBox()) {} DiceParser::~DiceParser() {} -const QList& DiceParser::getAliases() const +const QList& DiceParser::constAliases() const { return m_parsingToolbox->getAliases(); } @@ -103,7 +103,7 @@ void DiceParser::start() } } -QList DiceParser::getLastIntegerResults() +/*QList DiceParser::lastIntegerResults() const { QList resultValues; QStringList alreadyVisitedNode; @@ -128,7 +128,7 @@ QList DiceParser::getLastIntegerResults() } return resultValues; } -QStringList DiceParser::getStringResult() +QStringList DiceParser::stringResult() const { QStringList stringListResult; for(auto node : m_parsingToolbox->getStartNodes()) @@ -171,7 +171,7 @@ QStringList DiceParser::allFirstResultAsString(bool& hasAlias) } return stringListResult; } -QStringList DiceParser::getAllDiceResult(bool& hasAlias) +QStringList DiceParser::allDiceResult(bool& hasAlias) const { QStringList stringListResult; for(auto node : m_parsingToolbox->getStartNodes()) @@ -213,9 +213,9 @@ QStringList DiceParser::getAllDiceResult(bool& hasAlias) } return stringListResult; -} +}*/ -void DiceParser::getDiceResultFromAllInstruction(QList& resultList) +void DiceParser::diceResultFromEachInstruction(QList& resultList) const { for(auto start : m_parsingToolbox->getStartNodes()) { @@ -262,7 +262,7 @@ void DiceParser::getDiceResultFromAllInstruction(QList& resu // qDebug() << resultList.size(); } -void DiceParser::getLastDiceResult(QList& diceValuesList, bool& homogeneous) +/*void DiceParser::lastDiceResult(QList& diceValuesList, bool& homogeneous) const { QSet alreadySeenDice; for(auto start : m_parsingToolbox->getStartNodes()) @@ -326,13 +326,14 @@ void DiceParser::getLastDiceResult(QList& diceValuesList, bo diceValuesList.append(diceValues); } } -} -QString DiceParser::getDiceCommand() const +}*/ + +QString DiceParser::diceCommand() const { return m_command; } -bool DiceParser::hasIntegerResultNotInFirst() +bool DiceParser::hasIntegerResultNotInFirst() const { bool result= false; for(auto node : m_parsingToolbox->getStartNodes()) @@ -343,7 +344,7 @@ bool DiceParser::hasIntegerResultNotInFirst() return result; } -bool DiceParser::hasDiceResult() +bool DiceParser::hasDiceResult() const { bool result= false; for(auto node : m_parsingToolbox->getStartNodes()) @@ -353,7 +354,7 @@ bool DiceParser::hasDiceResult() } return result; } -bool DiceParser::hasStringResult() +bool DiceParser::hasStringResult() const { bool result= false; for(auto node : m_parsingToolbox->getStartNodes()) @@ -385,7 +386,8 @@ bool DiceParser::hasResultOfType(Dice::RESULT_TYPE type, ExecutionNode* node, QV } return scalarDone; } -QList DiceParser::getSumOfDiceResult() + +/*QList DiceParser::sumOfDiceResult() const { QList resultValues; for(auto node : m_parsingToolbox->getStartNodes()) @@ -413,13 +415,14 @@ QList DiceParser::getSumOfDiceResult() resultValues << resultValue; } return resultValues; -} -int DiceParser::getStartNodeCount() const +}*/ + +int DiceParser::startNodeCount() const { return static_cast(m_parsingToolbox->getStartNodes().size()); } -QString DiceParser::getComment() const +QString DiceParser::comment() const { return m_parsingToolbox->getComment(); } @@ -439,35 +442,30 @@ QMap DiceParser::errorMap() const auto keys= mapTmp.keys(); for(auto& key : keys) { - map.insertMulti(key, mapTmp[key]); + map.insert(key, mapTmp[key]); } } return map; } -QString DiceParser::humanReadableError() +QString DiceParser::humanReadableError() const { - auto errorList= m_parsingToolbox->getErrorList(); - QMapIterator i(errorList); - QString str(""); - while(i.hasNext()) - { - i.next(); - str.append(i.value()); + auto parsingError= m_parsingToolbox->getErrorList(); + QString str; + std::for_each(parsingError.begin(), parsingError.end(), [&str](const QString& text) { + str.append(text); str.append(QStringLiteral("\n")); - } + }); /// list - QMapIterator j(errorMap()); - while(j.hasNext()) - { - j.next(); - str.append(j.value()); + auto errMap= errorMap(); + std::for_each(errMap.begin(), errMap.end(), [&str](const QString& text) { + str.append(text); str.append(QStringLiteral("\n")); - } + }); return str; } -QString DiceParser::humanReadableWarning() +QString DiceParser::humanReadableWarning() const { auto warningMap= m_parsingToolbox->getWarningList(); QMapIterator i(warningMap); @@ -481,6 +479,11 @@ QString DiceParser::humanReadableWarning() return str; } +QJsonObject DiceParser::exportResult() const +{ + QJsonObject obj; +} + void DiceParser::writeDownDotTree(QString filepath) { if(m_parsingToolbox->getStartNodes().empty()) -- cgit v1.2.3-70-g09d2