diff options
| author | 2020-06-19 08:54:57 +0200 | |
|---|---|---|
| committer | 2020-08-21 22:50:44 +0200 | |
| commit | 62b7114ce29af10395273acec8dffeb41f255145 (patch) | |
| tree | b15ccf438ea03c0d7673e8efb174b3a1042e92aa | |
| parent | 80ab093722485fe7ac577415ae401f347907623c (diff) | |
| download | OneRoll-62b7114ce29af10395273acec8dffeb41f255145.tar.gz OneRoll-62b7114ce29af10395273acec8dffeb41f255145.zip | |
change the way diceparser is giving its result.
| -rw-r--r-- | diceparser.cpp | 69 | ||||
| -rw-r--r-- | diceroller.cpp | 11 | ||||
| -rw-r--r-- | include/diceparser.h | 126 |
3 files changed, 97 insertions, 109 deletions
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<DiceAlias*>& DiceParser::getAliases() const +const QList<DiceAlias*>& DiceParser::constAliases() const { return m_parsingToolbox->getAliases(); } @@ -103,7 +103,7 @@ void DiceParser::start() } } -QList<qreal> DiceParser::getLastIntegerResults() +/*QList<qreal> DiceParser::lastIntegerResults() const { QList<qreal> resultValues; QStringList alreadyVisitedNode; @@ -128,7 +128,7 @@ QList<qreal> 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<ExportedDiceResult>& resultList) +void DiceParser::diceResultFromEachInstruction(QList<ExportedDiceResult>& resultList) const { for(auto start : m_parsingToolbox->getStartNodes()) { @@ -262,7 +262,7 @@ void DiceParser::getDiceResultFromAllInstruction(QList<ExportedDiceResult>& resu // qDebug() << resultList.size(); } -void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& diceValuesList, bool& homogeneous) +/*void DiceParser::lastDiceResult(QList<ExportedDiceResult>& diceValuesList, bool& homogeneous) const { QSet<QString> alreadySeenDice; for(auto start : m_parsingToolbox->getStartNodes()) @@ -326,13 +326,14 @@ void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& 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<qreal> DiceParser::getSumOfDiceResult() + +/*QList<qreal> DiceParser::sumOfDiceResult() const { QList<qreal> resultValues; for(auto node : m_parsingToolbox->getStartNodes()) @@ -413,13 +415,14 @@ QList<qreal> DiceParser::getSumOfDiceResult() resultValues << resultValue; } return resultValues; -} -int DiceParser::getStartNodeCount() const +}*/ + +int DiceParser::startNodeCount() const { return static_cast<int>(m_parsingToolbox->getStartNodes().size()); } -QString DiceParser::getComment() const +QString DiceParser::comment() const { return m_parsingToolbox->getComment(); } @@ -439,35 +442,30 @@ QMap<Dice::ERROR_CODE, QString> 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<Dice::ERROR_CODE, QString> 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<Dice::ERROR_CODE, QString> 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<Dice::ERROR_CODE, QString> 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()) diff --git a/diceroller.cpp b/diceroller.cpp index 3d91f3e..cba24df 100644 --- a/diceroller.cpp +++ b/diceroller.cpp @@ -101,14 +101,14 @@ QString DiceRoller::diceToText(QList<ExportedDiceResult>& diceList) } void DiceRoller::start() { - if(m_diceparser.parseLine(m_command)) + /*if(m_diceparser.parseLine(m_command)) { m_diceparser.start(); - if(m_diceparser.getErrorMap().isEmpty()) + if(m_diceparser.errorMap().isEmpty()) { bool homogeneous; QList<ExportedDiceResult> list; - m_diceparser.getLastDiceResult(list, homogeneous); + m_diceparser.lastDiceResult(list, homogeneous); QString diceText= diceToText(list); QString scalarText; QString str; @@ -117,7 +117,7 @@ void DiceRoller::start() QString resultStr; if(m_diceparser.hasIntegerResultNotInFirst()) { - auto values= m_diceparser.getLastIntegerResults(); + auto values= m_diceparser.lastIntegerResults(); QStringList strLst; for(auto& val : values) { @@ -169,7 +169,7 @@ void DiceRoller::start() { auto errors= m_diceparser.getErrorMap(); setError(errors.first()); - } + }*/ } QString DiceRoller::getError() const @@ -185,4 +185,3 @@ void DiceRoller::setError(const QString& error) m_error= error; emit errorOccurs(); } - diff --git a/include/diceparser.h b/include/diceparser.h index 7cc4018..eb4dee4 100644 --- a/include/diceparser.h +++ b/include/diceparser.h @@ -22,6 +22,7 @@ #ifndef DICEPARSER_H #define DICEPARSER_H +#include <QJsonObject> #include <QMap> #include <QString> #include <QVariant> @@ -63,6 +64,7 @@ public: */ virtual ~DiceParser(); + // Command process methods /** * @brief parseLine, method to call for starting the dice roll. It will parse the command and run the execution * tree. @@ -70,93 +72,65 @@ public: * @return bool every thing is fine or not */ bool parseLine(QString str, bool allowAlias= true); - QString convertAlias(const QString& cmd) const; - /** - * @brief getStartNodeCount - * @return - */ - int getStartNodeCount() const; - /** - * @brief Start running the execution tree - * - */ void start(); - /** - * @brief displayDotTree - Write the execution tree into file using dot format. - * @param filepath absolute or relative path to the tree file. - */ + void cleanAll(); + + // debug void writeDownDotTree(QString filepath); + + // control methods + bool hasIntegerResultNotInFirst() const; + bool hasDiceResult() const; + bool hasStringResult() const; + bool hasSeparator() const; + + // alias management + const QList<DiceAlias*>& constAliases() const; + QList<DiceAlias*>* aliases() const; + void cleanAliases(); + void insertAlias(DiceAlias*, int); /** - * @brief getLastIntegerResults - * @return - */ - QList<qreal> getLastIntegerResults(); - /** - * @brief getSumOfDiceResult - * @return - */ - QList<qreal> getSumOfDiceResult(); - /** - * @brief getLastDiceResult - * @return - */ - void getLastDiceResult(QList<ExportedDiceResult>& diceValues, bool& homogeneous); - /** - * @brief hasIntegerResultNotInFirst - * @return - */ - bool hasIntegerResultNotInFirst(); - /** - * @brief hasDiceResult - * @return - */ - bool hasDiceResult(); - /** - * @brief getDiceCommand - * @return - */ - QString getDiceCommand() const; - /** - * @brief hasStringResult + * @brief getErrorList * @return */ - bool hasStringResult(); + QMap<Dice::ERROR_CODE, QString> errorMap() const; /** - * @brief getStringResult - * @return + * @brief setPathToHelp set the path to the documentation, this path must be adatped to the lang of application etc… + * @param l the path. */ - QStringList getStringResult(); + void setPathToHelp(QString l); /** - * @brief humanReadableError + * @brief allFirstResultAsString * @return */ - QString humanReadableError(); + QStringList allFirstResultAsString(bool& hasAlias); /** - * @brief getAliases + * @brief getAllDiceResult + * @param hasAlias * @return */ - const QList<DiceAlias*>& getAliases() const; - QList<DiceAlias*>* aliases() const; - void cleanAliases(); + QStringList getAllDiceResult(bool& hasAlias); /** - * @brief insertAlias + * @brief hasSeparator allows to know if the current command has separator. + * @return true when the command has separator, false otherwise. */ - void insertAlias(DiceAlias*, int); + bool hasSeparator() const; +// beginning of strange code ||||||| parent of af8b69b... change the way diceparser is giving its result. /** * @brief getErrorList * @return */ - QMap<Dice::ERROR_CODE, QString> errorMap() const; + QMap<Dice::ERROR_CODE, QString> getErrorMap(); /** * @brief setPathToHelp set the path to the documentation, this path must be adatped to the lang of application etc… * @param l the path. */ void setPathToHelp(QString l); /** - * @brief allFirstResultAsString + * @brief getAllStringResult * @return */ - QStringList allFirstResultAsString(bool& hasAlias); + QStringList getAllStringResult(bool& hasAlias); /** * @brief getAllDiceResult * @param hasAlias @@ -168,19 +142,31 @@ public: * @return true when the command has separator, false otherwise. */ bool hasSeparator() const; +// END of strange code + QString convertAlias(const QString& cmd) const; - /** - * @brief setVariableDictionary - * @param variables - */ - void setVariableDictionary(const QHash<QString, QString>& variables); - QString getComment() const; - void setComment(const QString& comment); + // Accessors + int startNodeCount() const; + QList<qreal> scalarResultsFromEachInstruction() const; + QStringList stringResultFromEachInstruction(bool& hasAlias) const; + void diceResultFromEachInstruction(QList<ExportedDiceResult>& resultList) const; - void getDiceResultFromAllInstruction(QList<ExportedDiceResult>& resultList); - QString humanReadableWarning(); + QString diceCommand() const; + QMap<Dice::ERROR_CODE, QString> errorMap() const; + QString comment() const; + QString humanReadableWarning() const; + QString humanReadableError() const; + QJsonObject exportResult() const; - void cleanAll(); + // QStringList stringResult() const; + // QStringList allDiceResult(bool& hasAlias) const; + // void lastDiceResult(QList<ExportedDiceResult>& diceValues, bool& homogeneous) const; + // QList<qreal> sumOfDiceResult() const; + + // setters + void setPathToHelp(QString l); + void setVariableDictionary(const QHash<QString, QString>& variables); + void setComment(const QString& comment); private: /** |