From 6ba9324cf4864ebd2e2cdec8098b0889ceaea0a8 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sat, 16 Apr 2022 01:58:40 +0200 Subject: Make sure Windows compilation works --- CMakeLists.txt | 52 ++-- booleancondition.cpp | 40 +-- booleancondition.h | 17 +- diceParser.pro | 71 ------ dicealias.cpp | 2 +- diceparser.cpp | 27 +- diceparser.pri | 108 -------- diceroller.cpp | 27 +- diceroller.h | 72 ------ die.cpp | 18 +- die.h | 20 +- highlightdice.cpp | 2 +- include/dicealias.h | 120 --------- include/diceparser.h | 129 ---------- include/diceparser/dicealias.h | 122 +++++++++ include/diceparser/diceparser.h | 130 ++++++++++ include/diceparser/diceparser_global.h | 11 + include/diceparser/diceparserhelper.h | 96 +++++++ include/diceparser/highlightdice.h | 68 +++++ include/diceparser/parsingtoolbox.h | 284 +++++++++++++++++++++ .../diceparser_qobject/diceparser_qobject_global.h | 11 + include/diceparser_qobject/diceroller.h | 74 ++++++ include/diceparser_qobject/qmltypesregister.h | 27 ++ include/diceparserhelper.h | 63 ----- include/highlightdice.h | 66 ----- include/parsingtoolbox.h | 274 -------------------- node/dicerollernode.cpp | 6 +- node/dicerollernode.h | 10 +- node/executionnode.h | 2 +- node/ifnode.h | 2 +- node/listaliasnode.h | 3 +- node/mergenode.cpp | 2 +- node/repeaternode.cpp | 29 ++- node/replacevaluenode.cpp | 2 +- node/rerolldicenode.cpp | 4 +- node/scalaroperatornode.cpp | 35 +-- node/scalaroperatornode.h | 6 +- node/switchcasenode.cpp | 2 +- node/variablenode.cpp | 4 +- operationcondition.cpp | 11 +- operationcondition.h | 8 +- parsingtoolbox.cpp | 100 ++++---- qmltypesregister.cpp | 4 +- qmltypesregister.h | 25 -- result/diceresult.cpp | 18 +- result/diceresult.h | 7 +- result/result.h | 2 +- tests/dice/CMakeLists.txt | 2 +- validator.h | 3 +- validatorlist.cpp | 49 ++-- validatorlist.h | 14 +- 51 files changed, 1098 insertions(+), 1183 deletions(-) delete mode 100644 diceParser.pro delete mode 100644 diceparser.pri delete mode 100644 diceroller.h delete mode 100644 include/dicealias.h delete mode 100644 include/diceparser.h create mode 100644 include/diceparser/dicealias.h create mode 100644 include/diceparser/diceparser.h create mode 100644 include/diceparser/diceparser_global.h create mode 100644 include/diceparser/diceparserhelper.h create mode 100644 include/diceparser/highlightdice.h create mode 100644 include/diceparser/parsingtoolbox.h create mode 100644 include/diceparser_qobject/diceparser_qobject_global.h create mode 100644 include/diceparser_qobject/diceroller.h create mode 100644 include/diceparser_qobject/qmltypesregister.h delete mode 100644 include/diceparserhelper.h delete mode 100644 include/highlightdice.h delete mode 100644 include/parsingtoolbox.h delete mode 100644 qmltypesregister.h diff --git a/CMakeLists.txt b/CMakeLists.txt index da59749..ff96097 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,16 @@ option(BUILD_IRC OFF) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(dice_header_path include/diceparser) + +set(dice_public_headers ${dice_header_path}/diceparser_global.h +${dice_header_path}/dicealias.h +${dice_header_path}/diceparser.h +${dice_header_path}/diceparserhelper.h +${dice_header_path}/highlightdice.h +${dice_header_path}/parsingtoolbox.h # should no be public… +) + SET( dice_sources ${CMAKE_CURRENT_SOURCE_DIR}/diceparser.cpp @@ -75,10 +85,14 @@ endif() set(documentation README.md HelpMe.md CHANGELOG) -add_library(diceparser_shared SHARED ${dice_sources} ${documentation}) - -target_include_directories(diceparser_shared PRIVATE include ./) +add_library(diceparser_shared SHARED ${dice_sources} ${documentation} ${dice_public_headers}) +set_target_properties(diceparser_shared PROPERTIES PUBLIC_HEADER "${public_header_widget}") +target_compile_definitions(diceparser_shared PRIVATE DICEPARSER_LIBRARY) +target_include_directories(diceparser_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PUBLIC + $ + $) SET_TARGET_PROPERTIES(diceparser_shared PROPERTIES OUTPUT_NAME diceparser CLEAN_DIRECT_OUTPUT 1) target_link_libraries(diceparser_shared PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Svg) @@ -86,8 +100,6 @@ target_link_libraries(diceparser_shared PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${Q set_target_properties(diceparser_shared PROPERTIES VERSION ${PROJECT_VERSION}) set_target_properties(diceparser_shared PROPERTIES SOVERSION 1) -set_target_properties(diceparser_shared PROPERTIES PUBLIC_HEADER "include/diceparser.h;include/highlightdice.h;include/parsingtoolbox.h;include/dicealias.h;include/diceparserhelper.h") - IF(BUILD_CLI) add_subdirectory(cli) ENDIF() @@ -96,7 +108,9 @@ IF(BUILD_IRC) add_subdirectory(irc) ENDIF() +if(TESTS) add_subdirectory( tests ) +endif() include(GNUInstallDirs) @@ -109,15 +123,21 @@ configure_file(diceparser.pc.in diceparser.pc @ONLY) install(FILES ${CMAKE_BINARY_DIR}/diceparser.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) -if(Qt6Qml_FOUND) -set(dice_header_qobject qmltypesregister.h diceroller.h) -set(dice_source_qobject qmltypesregister.cpp diceroller.cpp) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTOUIC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_INCLUDE_CURRENT_DIR ON) -add_library(diceparser_qobject SHARED ${dice_header_qobject} ${dice_source_qobject}) -target_link_libraries(diceparser_qobject PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Svg Qt${QT_VERSION_MAJOR}::Qml Qt${QT_VERSION_MAJOR}::Concurrent PRIVATE diceparser_shared) -message("Messages diceparser ${CMAKE_CURRENT_SOURCE_DIR}/include") -target_include_directories(diceparser_qobject PRIVATE include ./ ${CMAKE_CURRENT_SOURCE_DIR}/include) +if(Qt${QT_VERSION_MAJOR}Qml_FOUND) + set(dice_header_qobject include/diceparser_qobject/diceparser_qobject_global.h include/diceparser_qobject/qmltypesregister.h include/diceparser_qobject/diceroller.h) + set(dice_source_qobject qmltypesregister.cpp diceroller.cpp) + set(CMAKE_AUTOMOC ON) + set(CMAKE_AUTOUIC ON) + set(CMAKE_AUTORCC ON) + set(CMAKE_INCLUDE_CURRENT_DIR ON) + add_library(diceparser_qobject SHARED ${dice_header_qobject} ${dice_source_qobject}) + set_target_properties(diceparser_qobject PROPERTIES PUBLIC_HEADER "${dice_header_qobject}") + target_compile_definitions(diceparser_qobject PRIVATE DICEPARSER_QOBJECT_LIBRARY) + target_link_libraries(diceparser_qobject PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Svg Qt${QT_VERSION_MAJOR}::Qml Qt${QT_VERSION_MAJOR}::Concurrent PRIVATE diceparser_shared) + message("Messages diceparser ${CMAKE_CURRENT_SOURCE_DIR}/include") + + target_include_directories(diceparser_qobject PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PUBLIC + $ + $) endif() diff --git a/booleancondition.cpp b/booleancondition.cpp index 1c992c2..91be35c 100644 --- a/booleancondition.cpp +++ b/booleancondition.cpp @@ -81,7 +81,7 @@ Dice::CONDITION_STATE testDifferent(bool inside, const std::pair return Dice::CONDITION_STATE::REACHABLE; } -BooleanCondition::BooleanCondition() : m_operator(Equal) {} +BooleanCondition::BooleanCondition() : m_operator(Dice::CompareOperator::Equal) {} BooleanCondition::~BooleanCondition() { @@ -113,22 +113,22 @@ qint64 BooleanCondition::hasValid(Die* b, bool recursive, bool unhighlight) cons { switch(m_operator) { - case Equal: + case Dice::CompareOperator::Equal: sum+= (value == valueScalar) ? 1 : 0; break; - case GreaterThan: + case Dice::CompareOperator::GreaterThan: sum+= (value > valueScalar) ? 1 : 0; break; - case LesserThan: + case Dice::CompareOperator::LesserThan: sum+= (value < valueScalar) ? 1 : 0; break; - case GreaterOrEqual: + case Dice::CompareOperator::GreaterOrEqual: sum+= (value >= valueScalar) ? 1 : 0; break; - case LesserOrEqual: + case Dice::CompareOperator::LesserOrEqual: sum+= (value <= valueScalar) ? 1 : 0; break; - case Different: + case Dice::CompareOperator::Different: sum+= (value != valueScalar) ? 1 : 0; break; } @@ -145,7 +145,7 @@ qint64 BooleanCondition::hasValid(Die* b, bool recursive, bool unhighlight) cons return sum; } -void BooleanCondition::setOperator(LogicOperator m) +void BooleanCondition::setOperator(Dice::CompareOperator m) { m_operator= m; } @@ -159,22 +159,22 @@ QString BooleanCondition::toString() QString str(""); switch(m_operator) { - case Equal: + case Dice::CompareOperator::Equal: str.append(QStringLiteral("=")); break; - case GreaterThan: + case Dice::CompareOperator::GreaterThan: str.append(QStringLiteral(">")); break; - case LesserThan: + case Dice::CompareOperator::LesserThan: str.append(QStringLiteral("<")); break; - case GreaterOrEqual: + case Dice::CompareOperator::GreaterOrEqual: str.append(QStringLiteral(">=")); break; - case LesserOrEqual: + case Dice::CompareOperator::LesserOrEqual: str.append(QStringLiteral("<=")); break; - case Different: + case Dice::CompareOperator::Different: str.append(QStringLiteral("!=")); break; } @@ -189,22 +189,22 @@ Dice::CONDITION_STATE BooleanCondition::isValidRangeSize(const std::pair @@ -32,22 +33,12 @@ class BooleanCondition : public Validator { public: - enum LogicOperator - { - Equal, - GreaterThan, - LesserThan, - GreaterOrEqual, - LesserOrEqual, - Different - }; - BooleanCondition(); virtual ~BooleanCondition() override; virtual qint64 hasValid(Die* b, bool recursive, bool unhighlight= false) const override; - void setOperator(LogicOperator m); + void setOperator(Dice::CompareOperator m); void setValueNode(ExecutionNode*); QString toString() override; @@ -62,9 +53,9 @@ private: qint64 valueToScalar() const; private: - LogicOperator m_operator; + Dice::CompareOperator m_operator; ExecutionNode* m_value= nullptr; }; -Q_DECLARE_METATYPE(BooleanCondition::LogicOperator) +// Q_DECLARE_METATYPE(BooleanCondition::LogicOperator) #endif // BOOLEANCONDITION_H diff --git a/diceParser.pro b/diceParser.pro deleted file mode 100644 index 2b5f3fd..0000000 --- a/diceParser.pro +++ /dev/null @@ -1,71 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2013-12-24T13:06:36 -# -#------------------------------------------------- - -QT += core - -QT -= gui - -include(node/node.pri) - -TARGET = diceParser -CONFIG += console -CONFIG -= app_bundle - -TEMPLATE = app - -#CONFIG+= IRC -#CONFIG+= GUI -CONFIG+= CLI -CLI { -DEFINES += CLI -include(cli/cli.pri) -} -IRC { -include(irc/irc.pri) -QT += gui widgets -DEFINES+= HAVE_IRC -message("test") -} -GUI { -include(gui/gui.pri) -QT += gui widgets -DEFINES+= HAVE_GUI -} - - -SOURCES += diceparser.cpp \ - result/diceresult.cpp \ - range.cpp \ - booleancondition.cpp \ - validator.cpp \ - die.cpp \ - result/result.cpp \ - result/scalarresult.cpp \ - parsingtoolbox.cpp \ - result/stringresult.cpp \ - dicealias.cpp \ - mobile/mainwindow.cpp - - -HEADERS += \ - diceparser.h \ - result/diceresult.h \ - range.h \ - booleancondition.h \ - validator.h \ - die.h \ - result/result.h \ - result/scalarresult.h \ - result/parsingtoolbox.h \ - result/stringresult.h \ - dicealias.h \ - mobile/mainwindow.h - -OTHER_FILES += README.md \ - HelpMe.md - - -#QMAKE_CXXFLAGS += -O0 diff --git a/dicealias.cpp b/dicealias.cpp index 2bc07be..3bce75d 100644 --- a/dicealias.cpp +++ b/dicealias.cpp @@ -19,8 +19,8 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "dicealias.h" #include +#include #include diff --git a/diceparser.cpp b/diceparser.cpp index 5b91994..af86acc 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -19,7 +19,8 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "diceparser.h" +#include + #include #include #include @@ -31,11 +32,11 @@ #include #include "booleancondition.h" -#include "dicealias.h" -#include "parsingtoolbox.h" #include "range.h" #include "result/stringresult.h" #include "validator.h" +#include +#include #define DEFAULT_FACES_NUMBER 10 @@ -176,17 +177,21 @@ QString DiceParser::humanReadableError() const { 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")); - }); + std::for_each(parsingError.begin(), parsingError.end(), + [&str](const QString& text) + { + str.append(text); + str.append(QStringLiteral("\n")); + }); /// list auto errMap= errorMap(); - std::for_each(errMap.begin(), errMap.end(), [&str](const QString& text) { - str.append(text); - str.append(QStringLiteral("\n")); - }); + std::for_each(errMap.begin(), errMap.end(), + [&str](const QString& text) + { + str.append(text); + str.append(QStringLiteral("\n")); + }); return str; } diff --git a/diceparser.pri b/diceparser.pri deleted file mode 100644 index 80c84f1..0000000 --- a/diceparser.pri +++ /dev/null @@ -1,108 +0,0 @@ - -INCLUDEPATH += $$PWD/result -INCLUDEPATH += $$PWD/node -INCLUDEPATH += $$PWD/include -INCLUDEPATH += $$PWD - -SOURCES += $$PWD/diceparser.cpp \ - $$PWD/result/diceresult.cpp \ - $$PWD/range.cpp \ - $$PWD/highlightdice.cpp \ - $$PWD/booleancondition.cpp \ - $$PWD/validator.cpp \ - $$PWD/die.cpp \ - $$PWD/result/result.cpp \ - $$PWD/result/scalarresult.cpp \ - $$PWD/parsingtoolbox.cpp \ - $$PWD/result/stringresult.cpp \ - $$PWD/compositevalidator.cpp \ - $$PWD/dicealias.cpp \ - $$PWD/operationcondition.cpp \ - $$PWD/node/stringnode.cpp \ - $$PWD/node/filternode.cpp \ - $$PWD/node/allsamenode.cpp \ - $$PWD/node/groupnode.cpp \ - $$PWD/node/dicerollernode.cpp \ - $$PWD/node/executionnode.cpp \ - $$PWD/node/startingnode.cpp \ - $$PWD/node/rerolldicenode.cpp \ - $$PWD/node/scalaroperatornode.cpp \ - $$PWD/node/numbernode.cpp \ - $$PWD/node/sortresult.cpp \ - $$PWD/node/keepdiceexecnode.cpp \ - $$PWD/node/countexecutenode.cpp \ - $$PWD/node/explodedicenode.cpp \ - $$PWD/node/parenthesesnode.cpp \ - $$PWD/node/helpnode.cpp \ - $$PWD/node/jumpbackwardnode.cpp \ - $$PWD/node/mergenode.cpp \ - $$PWD/node/listaliasnode.cpp \ - $$PWD/node/paintnode.cpp \ - $$PWD/node/ifnode.cpp \ - $$PWD/node/splitnode.cpp \ - $$PWD/node/valueslistnode.cpp \ - $$PWD/node/uniquenode.cpp \ - $$PWD/node/repeaternode.cpp \ - $$PWD/node/listsetrollnode.cpp\ - $$PWD/node/variablenode.cpp\ - $$PWD/node/bind.cpp\ - $$PWD/node/occurencecountnode.cpp\ - $$PWD/diceroller.cpp\ - $$PWD/validatorlist.cpp\ - $$PWD/qmltypesregister.cpp - - -HEADERS += \ - $$PWD/include/diceparser.h \ - $$PWD/result/diceresult.h \ - $$PWD/range.h \ - $$PWD/booleancondition.h \ - $$PWD/include/highlightdice.h \ - $$PWD/validator.h \ - $$PWD/die.h \ - $$PWD/result/result.h \ - $$PWD/result/scalarresult.h \ - $$PWD/include/parsingtoolbox.h \ - $$PWD/result/stringresult.h \ - $$PWD/compositevalidator.h \ - $$PWD/include/dicealias.h \ - $$PWD/operationcondition.h \ - $$PWD/node/stringnode.h \ - $$PWD/node/filternode.h\ - $$PWD/node/allsamenode.h\ - $$PWD/node/groupnode.h \ - $$PWD/node/variablenode.h\ - $$PWD/node/dicerollernode.h \ - $$PWD/node/executionnode.h \ - $$PWD/node/rerolldicenode.h \ - $$PWD/node/startingnode.h \ - $$PWD/node/scalaroperatornode.h \ - $$PWD/node/numbernode.h \ - $$PWD/node/sortresult.h \ - $$PWD/node/keepdiceexecnode.h \ - $$PWD/node/countexecutenode.h \ - $$PWD/node/explodedicenode.h \ - $$PWD/node/valueslistnode.h \ - $$PWD/node/parenthesesnode.h \ - $$PWD/node/helpnode.h \ - $$PWD/node/jumpbackwardnode.h \ - $$PWD/node/mergenode.h \ - $$PWD/node/listaliasnode.h \ - $$PWD/node/ifnode.h \ - $$PWD/node/bind.h\ - $$PWD/node/splitnode.h \ - $$PWD/node/repeaternode.h \ - $$PWD/node/uniquenode.h \ - $$PWD/node/paintnode.h \ - $$PWD/node/listsetrollnode.h \ - $$PWD/node/occurencecountnode.h\ - $$PWD/diceroller.h \ - $$PWD/validatorlist.cpp\ - $$PWD/include/diceparserhelper.h \ - $$PWD/qmltypesregister.h - - - - -OTHER_FILES += \ - $$PWD/HelpMe.md diff --git a/diceroller.cpp b/diceroller.cpp index af6921c..e1c8ded 100644 --- a/diceroller.cpp +++ b/diceroller.cpp @@ -17,7 +17,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "diceroller.h" +#include #include #include @@ -61,18 +61,21 @@ void DiceRoller::readErrorAndWarning() void DiceRoller::start() { - auto future= QtConcurrent::run([this]() { - if(m_diceparser.parseLine(m_command)) + auto future= QtConcurrent::run( + [this]() { - m_diceparser.start(); - readErrorAndWarning(); - auto jsonstr= m_diceparser.resultAsJSon([](const QString& value, const QString&, bool) { return value; }); - QJsonDocument doc= QJsonDocument::fromJson(jsonstr.toLocal8Bit()); - auto json= doc.object(); - m_result= json["scalar"].toString().toDouble(); - emit resultChanged(); - } - }); + if(m_diceparser.parseLine(m_command)) + { + m_diceparser.start(); + readErrorAndWarning(); + auto jsonstr + = m_diceparser.resultAsJSon([](const QString& value, const QString&, bool) { return value; }); + QJsonDocument doc= QJsonDocument::fromJson(jsonstr.toLocal8Bit()); + auto json= doc.object(); + m_result= json["scalar"].toString().toDouble(); + emit resultChanged(); + } + }); } QString DiceRoller::error() const diff --git a/diceroller.h b/diceroller.h deleted file mode 100644 index 02d8e3e..0000000 --- a/diceroller.h +++ /dev/null @@ -1,72 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2017 by Renaud Guezennec * - * https://rolisteam.org/contact * - * * - * Rolisteam is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef DICEROLLER_H -#define DICEROLLER_H - -#include "diceparser.h" -#include - -class DiceRoller : public QObject -{ - Q_OBJECT - Q_PROPERTY(qreal result READ result NOTIFY resultChanged) - Q_PROPERTY(QString dicelist READ diceList NOTIFY diceListChanged) - Q_PROPERTY(QString resultStr READ resultStr NOTIFY resultStrChanged) - Q_PROPERTY(QString command READ command WRITE setCommand NOTIFY commandChanged) - Q_PROPERTY(QString error READ error WRITE setError NOTIFY errorOccurs) - -public: - DiceRoller(QObject* parent= nullptr); - - QString diceList() const; - QString resultStr() const; - QString command() const; - qreal result() const; - QString error() const; - QList* aliases() const; - - DiceParser* parser(); - -signals: - void resultChanged(); - void diceListChanged(); - void resultStrChanged(); - void commandChanged(); - void errorOccurs(); - -public slots: - void start(); - void readErrorAndWarning(); - void setCommand(const QString& cmd); - void setError(const QString& error); - - /*protected: - QString diceToText(QList& diceList);*/ - -private: - DiceParser m_diceparser; - qreal m_result; - QString m_diceList; - QString m_resultStr; - QString m_command; - QString m_error; -}; - -#endif // DICEROLLER_H diff --git a/die.cpp b/die.cpp index 19bc4df..4214b97 100644 --- a/die.cpp +++ b/die.cpp @@ -51,7 +51,7 @@ Die::Die() , m_highlighted(true) , m_base(1) , m_color("") - , m_op(Die::PLUS) //,m_mt(m_randomDevice) + , m_op(Dice::ArithmeticOperator::PLUS) //,m_mt(m_randomDevice) { buildSeed(); } @@ -109,17 +109,17 @@ qint64 Die::getValue() const { switch(m_op) { - case PLUS: + case Dice::ArithmeticOperator::PLUS: value+= tmp; break; - case MULTIPLICATION: + case Dice::ArithmeticOperator::MULTIPLICATION: value*= tmp; break; - case MINUS: + case Dice::ArithmeticOperator::MINUS: value-= tmp; break; - case INTEGER_DIVIDE: - case DIVIDE: + case Dice::ArithmeticOperator::INTEGER_DIVIDE: + case Dice::ArithmeticOperator::DIVIDE: if(tmp != 0) { value/= tmp; @@ -129,7 +129,7 @@ qint64 Die::getValue() const // error(); } break; - case POW: + case Dice::ArithmeticOperator::POW: value= static_cast(std::pow(value, tmp)); break; } @@ -237,12 +237,12 @@ void Die::setMaxValue(const qint64& maxValue) m_maxValue= maxValue; } -Die::ArithmeticOperator Die::getOp() const +Dice::ArithmeticOperator Die::getOp() const { return m_op; } -void Die::setOp(const Die::ArithmeticOperator& op) +void Die::setOp(const Dice::ArithmeticOperator& op) { m_op= op; } diff --git a/die.h b/die.h index ff4ccf5..2da2006 100644 --- a/die.h +++ b/die.h @@ -25,6 +25,8 @@ #include #include #include + +#include "diceparser/diceparserhelper.h" /** * @brief The Die class implements all methods required from a die. You must set the Faces first, then you can roll it * and roll it again, to add or replace the previous result. @@ -32,18 +34,6 @@ class Die { public: - /** - * @brief The ArithmeticOperator enum - */ - enum ArithmeticOperator - { - PLUS, - MINUS, - DIVIDE, - MULTIPLICATION, - INTEGER_DIVIDE, - POW - }; /** * @brief Die */ @@ -140,8 +130,8 @@ public: qint64 getMaxValue() const; void setMaxValue(const qint64& maxValue); - Die::ArithmeticOperator getOp() const; - void setOp(const Die::ArithmeticOperator& op); + Dice::ArithmeticOperator getOp() const; + void setOp(const Dice::ArithmeticOperator& op); void setDisplayed(bool b); QString getUuid() const; @@ -162,7 +152,7 @@ private: qint64 m_occurence{1}; QString m_color; - Die::ArithmeticOperator m_op; + Dice::ArithmeticOperator m_op; static std::mt19937 s_rng; }; diff --git a/highlightdice.cpp b/highlightdice.cpp index d0c9faa..e92451f 100644 --- a/highlightdice.cpp +++ b/highlightdice.cpp @@ -17,7 +17,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "include/highlightdice.h" +#include HighLightDice::HighLightDice(QList result, bool isHighlighted, QString color, bool displayed, quint64 faces, const QString& uuid) diff --git a/include/dicealias.h b/include/dicealias.h deleted file mode 100644 index c390d21..0000000 --- a/include/dicealias.h +++ /dev/null @@ -1,120 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2014 by Renaud Guezennec * - * https://rolisteam.org/contact * - * * - * This file is part of DiceParser * - * * - * DiceParser is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef DICEALIAS_H -#define DICEALIAS_H - -#include -/** - * @brief The DiceAlias class is dedicated to store aliases, alias is mainly two QString. The Alias and its replacement. - * The replacement can be a simple QString or a RegExp. - */ -class DiceAlias -{ -public: - enum RESOLUTION_TYPE - { - REPLACE, - REGEXP - }; - /** - * @brief DiceAlias - * @param cmd - * @param key - * @param isReplace - */ - DiceAlias(QString pattern, QString command, QString comment= QString{}, bool isReplace= true, bool isEnable= true); - DiceAlias(const DiceAlias& alias); - /** - * @brief ~DiceAlias - */ - virtual ~DiceAlias(); - /** - * @brief resolved - * @param str - * @return - */ - bool resolved(QString& str); - /** - * @brief setCommand - * @param key - */ - void setPattern(const QString& pattern); - /** - * @brief setValue - * @param value - */ - void setCommand(QString command); - /** - * @brief setType - */ - void setType(RESOLUTION_TYPE); - - /** - * @brief getCommand - * @return - */ - QString pattern() const; - /** - * @brief getValue - * @return - */ - QString command() const; - /** - * @brief isReplace - * @return - */ - bool isReplace() const; - /** - * @brief setReplace - */ - void setReplace(bool); - - /** - * @brief isEnable - * @return - */ - bool isEnable() const; - /** - * @brief setEnable - * @param b - */ - void setEnable(bool b); - /** - * @brief getComment - * @return - */ - QString comment() const; - /** - * @brief setComment - * @param comment - */ - void setComment(const QString& comment); - -private: - QString m_pattern; - QString m_command; - QString m_comment; - RESOLUTION_TYPE m_type; - bool m_isEnable; -}; - -#endif // DICEALIAS_H diff --git a/include/diceparser.h b/include/diceparser.h deleted file mode 100644 index 3c42bcc..0000000 --- a/include/diceparser.h +++ /dev/null @@ -1,129 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2014 by Renaud Guezennec * - * https://rolisteam.org/contact * - * * - * This file is part of DiceParser * - * * - * DiceParser is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef DICEPARSER_H -#define DICEPARSER_H - -#include -#include -#include -#include -#include -#include - -#include "diceparserhelper.h" -#include "highlightdice.h" -//#include "node/executionnode.h" - -class ExplodeDiceNode; -class ParsingToolBox; -class DiceRollerNode; -class DiceAlias; -class ExecutionNode; -/** - * @page DiceParser Dice Parser - * - * @section Intro Introduction - * Diceparser is the software component dedicated to compute dice command in rolisteam.
- * - * @section grammar The Grammar - * - * The grammar is described in Readme.md - */ - -/** - * @brief The DiceParser class facade class, it receives a command and return a DiceResult class (not yet implemented). - */ -class DiceParser -{ -public: - /** - * @brief DiceParser default constructor - */ - DiceParser(); - /** - * @brief ~DiceParser - */ - 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. - * @param str dice command - * @return bool every thing is fine or not - */ - bool parseLine(QString str, bool allowAlias= true); - void start(); - 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& constAliases() const; - QList* aliases() const; - void cleanAliases(); - void insertAlias(DiceAlias*, int); - QString convertAlias(const QString& cmd) const; - - QStringList allFirstResultAsString(bool& hasAlias); - QStringList getAllDiceResult(bool& hasAlias); - - // Accessors - int startNodeCount() const; - QList scalarResultsFromEachInstruction() const; - QStringList stringResultFromEachInstruction(bool& hasAlias) const; - void diceResultFromEachInstruction(QList& resultList) const; - QString finalStringResult(std::function colorize) const; - - QString diceCommand() const; - QMap errorMap() const; - QString comment() const; - QString humanReadableWarning() const; - QString humanReadableError() const; - QString resultAsJSon(std::function colorize, - bool removeUnhighligthed= false) const; - - // QStringList stringResult() const; - // QStringList allDiceResult(bool& hasAlias) const; - // void lastDiceResult(QList& diceValues, bool& homogeneous) const; - - // setters - void setPathToHelp(QString l); - void setVariableDictionary(const QHash& variables); - void setComment(const QString& comment); - -private: - bool readBlocInstruction(QString& str, ExecutionNode*& resultnode); - -private: - std::unique_ptr m_parsingToolbox; - QString m_command; -}; - -#endif // DICEPARSER_H diff --git a/include/diceparser/dicealias.h b/include/diceparser/dicealias.h new file mode 100644 index 0000000..05d5a0b --- /dev/null +++ b/include/diceparser/dicealias.h @@ -0,0 +1,122 @@ +/*************************************************************************** + * Copyright (C) 2014 by Renaud Guezennec * + * https://rolisteam.org/contact * + * * + * This file is part of DiceParser * + * * + * DiceParser is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef DICEALIAS_H +#define DICEALIAS_H + +#include + +#include +/** + * @brief The DiceAlias class is dedicated to store aliases, alias is mainly two QString. The Alias and its replacement. + * The replacement can be a simple QString or a RegExp. + */ +class DICEPARSER_EXPORT DiceAlias +{ +public: + enum RESOLUTION_TYPE + { + REPLACE, + REGEXP + }; + /** + * @brief DiceAlias + * @param cmd + * @param key + * @param isReplace + */ + DiceAlias(QString pattern, QString command, QString comment= QString{}, bool isReplace= true, bool isEnable= true); + DiceAlias(const DiceAlias& alias); + /** + * @brief ~DiceAlias + */ + virtual ~DiceAlias(); + /** + * @brief resolved + * @param str + * @return + */ + bool resolved(QString& str); + /** + * @brief setCommand + * @param key + */ + void setPattern(const QString& pattern); + /** + * @brief setValue + * @param value + */ + void setCommand(QString command); + /** + * @brief setType + */ + void setType(RESOLUTION_TYPE); + + /** + * @brief getCommand + * @return + */ + QString pattern() const; + /** + * @brief getValue + * @return + */ + QString command() const; + /** + * @brief isReplace + * @return + */ + bool isReplace() const; + /** + * @brief setReplace + */ + void setReplace(bool); + + /** + * @brief isEnable + * @return + */ + bool isEnable() const; + /** + * @brief setEnable + * @param b + */ + void setEnable(bool b); + /** + * @brief getComment + * @return + */ + QString comment() const; + /** + * @brief setComment + * @param comment + */ + void setComment(const QString& comment); + +private: + QString m_pattern; + QString m_command; + QString m_comment; + RESOLUTION_TYPE m_type; + bool m_isEnable; +}; + +#endif // DICEALIAS_H diff --git a/include/diceparser/diceparser.h b/include/diceparser/diceparser.h new file mode 100644 index 0000000..bf2d570 --- /dev/null +++ b/include/diceparser/diceparser.h @@ -0,0 +1,130 @@ +/*************************************************************************** + * Copyright (C) 2014 by Renaud Guezennec * + * https://rolisteam.org/contact * + * * + * This file is part of DiceParser * + * * + * DiceParser is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef DICEPARSER_H +#define DICEPARSER_H + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +class ExplodeDiceNode; +class ParsingToolBox; +class DiceRollerNode; +class DiceAlias; +class ExecutionNode; +/** + * @page DiceParser Dice Parser + * + * @section Intro Introduction + * Diceparser is the software component dedicated to compute dice command in rolisteam.
+ * + * @section grammar The Grammar + * + * The grammar is described in Readme.md + */ + +/** + * @brief The DiceParser class facade class, it receives a command and return a DiceResult class (not yet implemented). + */ +class DICEPARSER_EXPORT DiceParser +{ +public: + /** + * @brief DiceParser default constructor + */ + DiceParser(); + /** + * @brief ~DiceParser + */ + 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. + * @param str dice command + * @return bool every thing is fine or not + */ + bool parseLine(QString str, bool allowAlias= true); + void start(); + 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& constAliases() const; + QList* aliases() const; + void cleanAliases(); + void insertAlias(DiceAlias*, int); + QString convertAlias(const QString& cmd) const; + + QStringList allFirstResultAsString(bool& hasAlias); + QStringList getAllDiceResult(bool& hasAlias); + + // Accessors + int startNodeCount() const; + QList scalarResultsFromEachInstruction() const; + QStringList stringResultFromEachInstruction(bool& hasAlias) const; + void diceResultFromEachInstruction(QList& resultList) const; + QString finalStringResult(std::function colorize) const; + + QString diceCommand() const; + QMap errorMap() const; + QString comment() const; + QString humanReadableWarning() const; + QString humanReadableError() const; + QString resultAsJSon(std::function colorize, + bool removeUnhighligthed= false) const; + + // QStringList stringResult() const; + // QStringList allDiceResult(bool& hasAlias) const; + // void lastDiceResult(QList& diceValues, bool& homogeneous) const; + + // setters + void setPathToHelp(QString l); + void setVariableDictionary(const QHash& variables); + void setComment(const QString& comment); + +private: + bool readBlocInstruction(QString& str, ExecutionNode*& resultnode); + +private: + std::unique_ptr m_parsingToolbox; + QString m_command; +}; + +#endif // DICEPARSER_H diff --git a/include/diceparser/diceparser_global.h b/include/diceparser/diceparser_global.h new file mode 100644 index 0000000..47829cc --- /dev/null +++ b/include/diceparser/diceparser_global.h @@ -0,0 +1,11 @@ +#ifndef DICEPARSER_GLOBAL_H +#define DICEPARSER_GLOBAL_H + +#include + +#if defined(DICEPARSER_LIBRARY) +#define DICEPARSER_EXPORT Q_DECL_EXPORT +#else +#define DICEPARSER_EXPORT Q_DECL_IMPORT +#endif +#endif // DICEPARSER_GLOBAL_H diff --git a/include/diceparser/diceparserhelper.h b/include/diceparser/diceparserhelper.h new file mode 100644 index 0000000..6190df2 --- /dev/null +++ b/include/diceparser/diceparserhelper.h @@ -0,0 +1,96 @@ +#ifndef DICEPARSERHELPER_H +#define DICEPARSERHELPER_H + +class ValidatorList; +class ExecutionNode; + +#include + +namespace Dice +{ +enum class CONDITION_STATE : int +{ + ERROR_STATE, + ALWAYSTRUE, + UNREACHABLE, + REACHABLE +}; + +enum class ERROR_CODE : int +{ + NO_DICE_ERROR, + DIE_RESULT_EXPECTED, + BAD_SYNTAXE, + ENDLESS_LOOP_ERROR, + DIVIDE_BY_ZERO, + NOTHING_UNDERSTOOD, + NO_DICE_TO_ROLL, + TOO_MANY_DICE, + NO_VARIBALE, + INVALID_INDEX, + UNEXPECTED_CHARACTER, + NO_PREVIOUS_ERROR, + NO_VALID_RESULT, + SCALAR_RESULT_EXPECTED +}; + +/** + * @brief The RESULT_TYPE enum or combinaison + */ +enum class RESULT_TYPE : int +{ + NONE= 0, + SCALAR= 1, + STRING= 2, + DICE_LIST= 4 +}; +/** + * @brief The ConditionType enum defines compare method + */ +enum ConditionType +{ + OnEach, + OnEachValue, + OneOfThem, + AllOfThem, + OnScalar +}; + +enum class CompareOperator +{ + Equal, + GreaterThan, + LesserThan, + GreaterOrEqual, + LesserOrEqual, + Different +}; +enum class ArithmeticOperator +{ + PLUS, + MINUS, + DIVIDE, + MULTIPLICATION, + INTEGER_DIVIDE, + POW +}; +enum class LogicOperation +{ + OR, + EXCLUSIVE_OR, + AND, + NONE +}; + +enum class ConditionOperator +{ + Modulo +}; + +struct DICEPARSER_EXPORT CaseInfo +{ + ValidatorList* validatorList; + ExecutionNode* node; +}; +} // namespace Dice +#endif // DICEPARSERHELPER_H diff --git a/include/diceparser/highlightdice.h b/include/diceparser/highlightdice.h new file mode 100644 index 0000000..a3928a1 --- /dev/null +++ b/include/diceparser/highlightdice.h @@ -0,0 +1,68 @@ +/*************************************************************************** + * Copyright (C) 2016 by Renaud Guezennec * + * http:://www.rolisteam.org/contact * + * * + * rolisteam is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef HighLightDice_H +#define HighLightDice_H + +#include +#include +#include + +#include + +class DICEPARSER_EXPORT HighLightDice +{ +public: + HighLightDice(QList result, bool isHighlighted, QString color, bool displayed, quint64 faces, + const QString& uuid); + virtual ~HighLightDice(); + + QList result() const; + void setResult(const QList& result); + + bool isHighlighted() const; + void setHighlight(bool hasHighlight); + + QString color() const; + void setColor(const QString& color); + + bool displayed() const; + void setDisplayed(bool displayed); + + quint64 faces() const; + void setFaces(const quint64& faces); + + QString getResultString() const; + + QString uuid() const; + void setUuid(const QString& uuid); + +private: + QList m_result; + bool m_hasHighlight= true; + QString m_color; + bool m_displayed= false; + quint64 m_faces; + QString m_uuid; +}; + +typedef QList ListDiceResult; +typedef QMap> ExportedDiceResult; + +#endif // HighLightDice_H diff --git a/include/diceparser/parsingtoolbox.h b/include/diceparser/parsingtoolbox.h new file mode 100644 index 0000000..69f433a --- /dev/null +++ b/include/diceparser/parsingtoolbox.h @@ -0,0 +1,284 @@ +/*************************************************************************** + * Copyright (C) 2014 by Renaud Guezennec * + * https://rolisteam.org/contact * + * * + * This file is part of DiceParser * + * * + * DiceParser is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PARSINGTOOLBOX_H +#define PARSINGTOOLBOX_H + +#include +#include +#include +#include +#include +#include +#include + +#include "diceparserhelper.h" +#include "highlightdice.h" +//#include "dicerollernode.h" +//#include "executionnode.h" +//#include "node/ifnode.h" +//#include "node/paintnode.h" +//#include "node/scalaroperatornode.h" +//#include "operationcondition.h" +//#include "range.h" +//#include "validatorlist.h" + +#include +class Range; +class RepeaterNode; +class DiceAlias; +class ExplodeDiceNode; +class SwitchCaseNode; +class ReplaceValueNode; +class PainterNode; +class ValidatorList; +class Validator; +class DiceRollerNode; +class ExecutionNode; +class DICEPARSER_EXPORT SubtituteInfo +{ +public: + SubtituteInfo(); + + bool isValid() const; + + int length() const; + void setLength(int length); + + int resultIndex() const; + void setResultIndex(int valueIndex); + + int position() const; + void setPosition(int position); + + int digitNumber() const; + void setDigitNumber(int digitNumber); + + int subIndex() const; + void setSubIndex(int subindex); + +private: + int m_length= 2; + int m_digitNumber= 0; + int m_resultIndex= -1; + int m_position= -1; + int m_subIndex= -1; +}; + +/** + * @brief The ParsingToolBox is gathering many useful methods for dice parsing. + * Its goal is to make the diceparser a bit lighter. + */ +class DICEPARSER_EXPORT ParsingToolBox +{ +public: + enum LIST_OPERATOR + { + NONE= 0x00, + UNIQUE= 0x01, + NOCOMMA= 0x02, + UniqueAndNoComma= 0x03 + }; + + enum Function + { + REPEAT + }; + enum OptionOperator + { + KeepAndExplode, // K + Keep, // k + Reroll, // r + RerollUntil, // R + Explode, // e + Sort, // s + Count, // c + RerollAndAdd, // a + Merge, // m + ifOperator, // i + Painter, // p + Filter, // f + Split, // y + Group, // g + Occurences, // o + Unique, // u + Bind, // b + AllSameExplode, // t + SwitchCaseOption, // S + TransformOption // T + }; + enum DiceOperator + { + D, + L + }; + enum NodeAction + { + JumpBackward + }; + ParsingToolBox(); + ParsingToolBox(const ParsingToolBox& data); + virtual ~ParsingToolBox(); + void clearUp(); + + // Build execution tree + DiceRollerNode* getDiceRollerNode(ExecutionNode* previous); + DiceRollerNode* addRollDiceNode(qint64 faces, ExecutionNode*); + ExplodeDiceNode* addExplodeDiceNode(qint64 faces, ExecutionNode* previous); + Dice::CONDITION_STATE isValidValidator(ExecutionNode* previous, ValidatorList* val); + ExecutionNode* addSort(ExecutionNode* e, bool b); + + // parsing tools + static bool readAscending(QString& str); + static bool readStopAtFirst(QString& str); + bool readLogicOperator(QString& str, Dice::CompareOperator& op); + Validator* readValidator(QString& str, bool hasSquare= false); + ValidatorList* readValidatorList(QString& str); + static bool readNumber(QString& str, qint64& myNumber); + static bool readString(QString& str, QString& strresult); + static bool readVariable(QString& str, qint64& myNumber, QString& reasonFail); + static bool readOpenParentheses(QString& str); + static bool readCloseParentheses(QString& str); + + static bool readDynamicVariable(QString& str, qint64& index); + bool readList(QString& str, QStringList& list, QList& ranges); + bool readDiceRange(QString& str, qint64& start, qint64& end); + static LIST_OPERATOR readListOperator(QString& str); + void readProbability(QStringList& str, QList& ranges); + bool readLogicOperation(QString& str, Dice::LogicOperation& op); + bool readDiceLogicOperator(QString& str, Dice::ConditionOperator& op); + bool readArithmeticOperator(QString& str, Dice::ArithmeticOperator& op); + std::vector readInstructionList(QString& str, bool startNode); + static Dice::ConditionType readConditionType(QString& str); + bool readComment(QString& str, QString&, QString&); + bool readOperand(QString& str, ExecutionNode*& node); + static int findClosingCharacterIndexOf(QChar open, QChar closing, const QString& str, int offset); + static void readSubtitutionParameters(SubtituteInfo& info, QString& rest); + static bool readPainterParameter(PainterNode* painter, QString& str); + static bool readComma(QString& str); + bool readReaperArguments(RepeaterNode* node, QString& source); + bool readExpression(QString& str, ExecutionNode*& node); + bool readInstructionOperator(QChar c); + bool readNode(QString& str, ExecutionNode*& node); + /** + * @brief readIfInstruction reads the current command to build if node with proper parameters. + * @param str is the command string, if IF istruction is found, the str will be changed, in other case the string is + * unmodified + * @param trueNode is the branch's beginning to be executed if the IfNode is true. + * @param falseNode is the branch's beginning to be executed if the IfNode is false. + * @return true, ifNode has been found, false otherwise + */ + bool readIfInstruction(QString& str, ExecutionNode*& trueNode, ExecutionNode*& falseNode); + bool readOptionFromNull(QString& str, ExecutionNode*& node); + bool readOperatorFromNull(QString& str, ExecutionNode*& node); + bool readParameterNode(QString& str, ExecutionNode*& node); + bool readFunction(QString& str, ExecutionNode*& node); + bool readDice(QString& str, ExecutionNode*& node); + bool readDiceOperator(QString&, DiceOperator&); + bool readDiceExpression(QString&, ExecutionNode*& node); + bool readOperator(QString&, ExecutionNode* previous); + bool readCommand(QString& str, ExecutionNode*& node); + bool readBlocInstruction(QString& str, ExecutionNode*& resultnode); + bool readOption(QString&, ExecutionNode* node); // OptionOperator& option, + bool readValuesList(QString& str, ExecutionNode*& node); + bool readSwitchCaseNode(QString& str, SwitchCaseNode* node); + bool readReplaceValueNode(QString& str, ReplaceValueNode* node); + + // Error + bool hasError() const; + void addError(Dice::ERROR_CODE code, const QString& msg); + void addWarning(Dice::ERROR_CODE code, const QString& msg); + const QMap& getErrorList() const; + const QMap& getWarningList() const; + + // Traversal functions + static QString number(qreal value); + static ExecutionNode* getLeafNode(ExecutionNode* start); + const std::vector& getStartNodes(); + static void setStartNodes(std::vector* startNodes); + std::pair hasResultOfType(Dice::RESULT_TYPE, ExecutionNode* node, bool notthelast= false) const; + QList scalarResultsFromEachInstruction() const; + std::pair finalScalarResult() const; + QString finalStringResult(std::function colorize, + bool removeUnhighlighted= false) const; + QStringList allFirstResultAsString(bool& hasAlias) const; + QList sumOfDiceResult() const; + QList diceResultFromEachInstruction() const; + bool hasIntegerResultNotInFirst() const; + bool hasDiceResult() const; + bool hasStringResult() const; + + // result + static QString replaceVariableToValue(const QString& source, QStringList values, + QMap& errorMap); + static QString replacePlaceHolderToValue(const QString& source, const QList& list, + bool removeUnhighlighted, + std::function colorize); + static SubtituteInfo readVariableFromString(const QString& source, int& start); + static SubtituteInfo readPlaceHolderFromString(const QString& source, int& start); + static ExportedDiceResult finalDiceResultFromInstruction(ExecutionNode* start); + static ExportedDiceResult allDiceResultFromInstruction(ExecutionNode* start); + void addResultInJson(QJsonObject& obj, Dice::RESULT_TYPE type, const QString& key, ExecutionNode* start, bool b); + void addDiceResultInJson(QJsonObject& obj, ExecutionNode* start, + std::function colorize); + + // accessors + void setComment(const QString& comment); + QString getComment() const; + void setHelpPath(const QString& path); + static QHash getVariableHash(); + static void setVariableHash(const QHash& variableHash); + void setStartNodes(std::vector nodes); + + // Aliases + QString convertAlias(QString str); + void insertAlias(DiceAlias* dice, int i); + const QList& getAliases() const; + QList* aliases(); + void setAliases(const QList list); + void cleanUpAliases(); + + static bool readStringResultParameter(QString& str); + static QString replacePlaceHolderFromJson(const QString& source, const QJsonObject& obj); + +private: + QMap m_logicOp; + QMap m_logicOperation; + QMap m_conditionOperation; + std::vector> m_arithmeticOperation; + QMap m_mapDiceOp; + QMap m_OptionOp; + QMap m_nodeActionMap; + std::map m_functionMap; + QStringList m_commandList; + + QMap m_errorMap; + QMap m_warningMap; + std::vector m_startNodes; + + QString m_comment; + + static QHash m_variableHash; + QString m_helpPath; + QList m_aliasList; +}; + +#endif // PARSINGTOOLBOX_H diff --git a/include/diceparser_qobject/diceparser_qobject_global.h b/include/diceparser_qobject/diceparser_qobject_global.h new file mode 100644 index 0000000..ea49727 --- /dev/null +++ b/include/diceparser_qobject/diceparser_qobject_global.h @@ -0,0 +1,11 @@ +#ifndef DICEPARSER_QOBJECT_GLOBAL_H +#define DICEPARSER_QOBJECT_GLOBAL_H + +#include + +#if defined(DICEPARSER_QOBJECT_LIBRARY) +#define DICEPARSER_QOBJECT_EXPORT Q_DECL_EXPORT +#else +#define DICEPARSER_QOBJECT_EXPORT Q_DECL_IMPORT +#endif +#endif // DICEPARSER_QOBJECT_GLOBAL_H diff --git a/include/diceparser_qobject/diceroller.h b/include/diceparser_qobject/diceroller.h new file mode 100644 index 0000000..72c4e10 --- /dev/null +++ b/include/diceparser_qobject/diceroller.h @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (C) 2017 by Renaud Guezennec * + * https://rolisteam.org/contact * + * * + * Rolisteam is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef DICEROLLER_H +#define DICEROLLER_H + +#include +#include + +#include + +class DICEPARSER_QOBJECT_EXPORT DiceRoller : public QObject +{ + Q_OBJECT + Q_PROPERTY(qreal result READ result NOTIFY resultChanged) + Q_PROPERTY(QString dicelist READ diceList NOTIFY diceListChanged) + Q_PROPERTY(QString resultStr READ resultStr NOTIFY resultStrChanged) + Q_PROPERTY(QString command READ command WRITE setCommand NOTIFY commandChanged) + Q_PROPERTY(QString error READ error WRITE setError NOTIFY errorOccurs) + +public: + DiceRoller(QObject* parent= nullptr); + + QString diceList() const; + QString resultStr() const; + QString command() const; + qreal result() const; + QString error() const; + QList* aliases() const; + + DiceParser* parser(); + +signals: + void resultChanged(); + void diceListChanged(); + void resultStrChanged(); + void commandChanged(); + void errorOccurs(); + +public slots: + void start(); + void readErrorAndWarning(); + void setCommand(const QString& cmd); + void setError(const QString& error); + + /*protected: + QString diceToText(QList& diceList);*/ + +private: + DiceParser m_diceparser; + qreal m_result; + QString m_diceList; + QString m_resultStr; + QString m_command; + QString m_error; +}; + +#endif // DICEROLLER_H diff --git a/include/diceparser_qobject/qmltypesregister.h b/include/diceparser_qobject/qmltypesregister.h new file mode 100644 index 0000000..e0b1a09 --- /dev/null +++ b/include/diceparser_qobject/qmltypesregister.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * Copyright (C) 2017 by Renaud Guezennec * + * https://rolisteam.org/contact * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef REGISTER_QML_TYPE_H +#define REGISTER_QML_TYPE_H + +#include + +DICEPARSER_QOBJECT_EXPORT void registerQmlTypes(); + +#endif // REGISTER_QML_TYPE_H diff --git a/include/diceparserhelper.h b/include/diceparserhelper.h deleted file mode 100644 index 1ae5c3f..0000000 --- a/include/diceparserhelper.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef DICEPARSERHELPER_H -#define DICEPARSERHELPER_H - -class ValidatorList; -class ExecutionNode; - -namespace Dice -{ -enum class CONDITION_STATE : int -{ - ERROR_STATE, - ALWAYSTRUE, - UNREACHABLE, - REACHABLE -}; - -enum class ERROR_CODE : int -{ - NO_DICE_ERROR, - DIE_RESULT_EXPECTED, - BAD_SYNTAXE, - ENDLESS_LOOP_ERROR, - DIVIDE_BY_ZERO, - NOTHING_UNDERSTOOD, - NO_DICE_TO_ROLL, - TOO_MANY_DICE, - NO_VARIBALE, - INVALID_INDEX, - UNEXPECTED_CHARACTER, - NO_PREVIOUS_ERROR, - NO_VALID_RESULT, - SCALAR_RESULT_EXPECTED -}; - -/** - * @brief The RESULT_TYPE enum or combinaison - */ -enum class RESULT_TYPE : int -{ - NONE= 0, - SCALAR= 1, - STRING= 2, - DICE_LIST= 4 -}; -/** - * @brief The ConditionType enum defines compare method - */ -enum ConditionType -{ - OnEach, - OnEachValue, - OneOfThem, - AllOfThem, - OnScalar -}; - -struct CaseInfo -{ - ValidatorList* validatorList; - ExecutionNode* node; -}; -} // namespace Dice -#endif // DICEPARSERHELPER_H diff --git a/include/highlightdice.h b/include/highlightdice.h deleted file mode 100644 index 66bd445..0000000 --- a/include/highlightdice.h +++ /dev/null @@ -1,66 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2016 by Renaud Guezennec * - * http:://www.rolisteam.org/contact * - * * - * rolisteam is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef HighLightDice_H -#define HighLightDice_H - -#include -#include -#include - -class HighLightDice -{ -public: - HighLightDice(QList result, bool isHighlighted, QString color, bool displayed, quint64 faces, - const QString& uuid); - virtual ~HighLightDice(); - - QList result() const; - void setResult(const QList& result); - - bool isHighlighted() const; - void setHighlight(bool hasHighlight); - - QString color() const; - void setColor(const QString& color); - - bool displayed() const; - void setDisplayed(bool displayed); - - quint64 faces() const; - void setFaces(const quint64& faces); - - QString getResultString() const; - - QString uuid() const; - void setUuid(const QString& uuid); - -private: - QList m_result; - bool m_hasHighlight= true; - QString m_color; - bool m_displayed= false; - quint64 m_faces; - QString m_uuid; -}; - -typedef QList ListDiceResult; -typedef QMap> ExportedDiceResult; - -#endif // HighLightDice_H diff --git a/include/parsingtoolbox.h b/include/parsingtoolbox.h deleted file mode 100644 index 08e876a..0000000 --- a/include/parsingtoolbox.h +++ /dev/null @@ -1,274 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2014 by Renaud Guezennec * - * https://rolisteam.org/contact * - * * - * This file is part of DiceParser * - * * - * DiceParser is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef PARSINGTOOLBOX_H -#define PARSINGTOOLBOX_H - -#include -#include -#include - -#include "booleancondition.h" -#include "highlightdice.h" -#include "node/dicerollernode.h" -#include "node/executionnode.h" -#include "node/ifnode.h" -#include "node/paintnode.h" -#include "node/scalaroperatornode.h" -#include "operationcondition.h" -#include "range.h" -#include "validatorlist.h" - -class RepeaterNode; -class DiceAlias; -class ExplodeDiceNode; -class SwitchCaseNode; -class ReplaceValueNode; - -class SubtituteInfo -{ -public: - SubtituteInfo(); - - bool isValid() const; - - int length() const; - void setLength(int length); - - int resultIndex() const; - void setResultIndex(int valueIndex); - - int position() const; - void setPosition(int position); - - int digitNumber() const; - void setDigitNumber(int digitNumber); - - int subIndex() const; - void setSubIndex(int subindex); - -private: - int m_length= 2; - int m_digitNumber= 0; - int m_resultIndex= -1; - int m_position= -1; - int m_subIndex= -1; -}; - -/** - * @brief The ParsingToolBox is gathering many useful methods for dice parsing. - * Its goal is to make the diceparser a bit lighter. - */ -class ParsingToolBox -{ -public: - enum LIST_OPERATOR - { - NONE= 0x00, - UNIQUE= 0x01, - NOCOMMA= 0x02, - UniqueAndNoComma= 0x03 - }; - - enum Function - { - REPEAT - }; - enum OptionOperator - { - KeepAndExplode, // K - Keep, // k - Reroll, // r - RerollUntil, // R - Explode, // e - Sort, // s - Count, // c - RerollAndAdd, // a - Merge, // m - ifOperator, // i - Painter, // p - Filter, // f - Split, // y - Group, // g - Occurences, // o - Unique, // u - Bind, // b - AllSameExplode, // t - SwitchCaseOption, // S - TransformOption // T - }; - enum DiceOperator - { - D, - L - }; - enum NodeAction - { - JumpBackward - }; - ParsingToolBox(); - ParsingToolBox(const ParsingToolBox& data); - virtual ~ParsingToolBox(); - void clearUp(); - - // Build execution tree - DiceRollerNode* getDiceRollerNode(ExecutionNode* previous); - DiceRollerNode* addRollDiceNode(qint64 faces, ExecutionNode*); - ExplodeDiceNode* addExplodeDiceNode(qint64 faces, ExecutionNode* previous); - Dice::CONDITION_STATE isValidValidator(ExecutionNode* previous, ValidatorList* val); - ExecutionNode* addSort(ExecutionNode* e, bool b); - - // parsing tools - static bool readAscending(QString& str); - static bool readStopAtFirst(QString& str); - bool readLogicOperator(QString& str, BooleanCondition::LogicOperator& op); - Validator* readValidator(QString& str, bool hasSquare= false); - ValidatorList* readValidatorList(QString& str); - static bool readNumber(QString& str, qint64& myNumber); - static bool readString(QString& str, QString& strresult); - static bool readVariable(QString& str, qint64& myNumber, QString& reasonFail); - static bool readOpenParentheses(QString& str); - static bool readCloseParentheses(QString& str); - - static bool readDynamicVariable(QString& str, qint64& index); - bool readList(QString& str, QStringList& list, QList& ranges); - bool readDiceRange(QString& str, qint64& start, qint64& end); - static LIST_OPERATOR readListOperator(QString& str); - void readProbability(QStringList& str, QList& ranges); - bool readLogicOperation(QString& str, ValidatorList::LogicOperation& op); - bool readDiceLogicOperator(QString& str, OperationCondition::ConditionOperator& op); - bool readArithmeticOperator(QString& str, Die::ArithmeticOperator& op); - std::vector readInstructionList(QString& str, bool startNode); - static Dice::ConditionType readConditionType(QString& str); - bool readComment(QString& str, QString&, QString&); - bool readOperand(QString& str, ExecutionNode*& node); - static int findClosingCharacterIndexOf(QChar open, QChar closing, const QString& str, int offset); - static void readSubtitutionParameters(SubtituteInfo& info, QString& rest); - static bool readPainterParameter(PainterNode* painter, QString& str); - static bool readComma(QString& str); - bool readReaperArguments(RepeaterNode* node, QString& source); - bool readExpression(QString& str, ExecutionNode*& node); - bool readInstructionOperator(QChar c); - bool readNode(QString& str, ExecutionNode*& node); - /** - * @brief readIfInstruction reads the current command to build if node with proper parameters. - * @param str is the command string, if IF istruction is found, the str will be changed, in other case the string is - * unmodified - * @param trueNode is the branch's beginning to be executed if the IfNode is true. - * @param falseNode is the branch's beginning to be executed if the IfNode is false. - * @return true, ifNode has been found, false otherwise - */ - bool readIfInstruction(QString& str, ExecutionNode*& trueNode, ExecutionNode*& falseNode); - bool readOptionFromNull(QString& str, ExecutionNode*& node); - bool readOperatorFromNull(QString& str, ExecutionNode*& node); - bool readParameterNode(QString& str, ExecutionNode*& node); - bool readFunction(QString& str, ExecutionNode*& node); - bool readDice(QString& str, ExecutionNode*& node); - bool readDiceOperator(QString&, DiceOperator&); - bool readDiceExpression(QString&, ExecutionNode*& node); - bool readOperator(QString&, ExecutionNode* previous); - bool readCommand(QString& str, ExecutionNode*& node); - bool readBlocInstruction(QString& str, ExecutionNode*& resultnode); - bool readOption(QString&, ExecutionNode* node); // OptionOperator& option, - bool readValuesList(QString& str, ExecutionNode*& node); - bool readSwitchCaseNode(QString& str, SwitchCaseNode* node); - bool readReplaceValueNode(QString& str, ReplaceValueNode* node); - - // Error - bool hasError() const; - void addError(Dice::ERROR_CODE code, const QString& msg); - void addWarning(Dice::ERROR_CODE code, const QString& msg); - const QMap& getErrorList() const; - const QMap& getWarningList() const; - - // Traversal functions - static QString number(qreal value); - static ExecutionNode* getLeafNode(ExecutionNode* start); - const std::vector& getStartNodes(); - static void setStartNodes(std::vector* startNodes); - std::pair hasResultOfType(Dice::RESULT_TYPE, ExecutionNode* node, bool notthelast= false) const; - QList scalarResultsFromEachInstruction() const; - std::pair finalScalarResult() const; - QString finalStringResult(std::function colorize, - bool removeUnhighlighted= false) const; - QStringList allFirstResultAsString(bool& hasAlias) const; - QList sumOfDiceResult() const; - QList diceResultFromEachInstruction() const; - bool hasIntegerResultNotInFirst() const; - bool hasDiceResult() const; - bool hasStringResult() const; - - // result - static QString replaceVariableToValue(const QString& source, QStringList values, - QMap& errorMap); - static QString replacePlaceHolderToValue(const QString& source, const QList& list, - bool removeUnhighlighted, - std::function colorize); - static SubtituteInfo readVariableFromString(const QString& source, int& start); - static SubtituteInfo readPlaceHolderFromString(const QString& source, int& start); - static ExportedDiceResult finalDiceResultFromInstruction(ExecutionNode* start); - static ExportedDiceResult allDiceResultFromInstruction(ExecutionNode* start); - void addResultInJson(QJsonObject& obj, Dice::RESULT_TYPE type, const QString& key, ExecutionNode* start, bool b); - void addDiceResultInJson(QJsonObject& obj, ExecutionNode* start, - std::function colorize); - - // accessors - void setComment(const QString& comment); - QString getComment() const; - void setHelpPath(const QString& path); - static QHash getVariableHash(); - static void setVariableHash(const QHash& variableHash); - void setStartNodes(std::vector nodes); - - // Aliases - QString convertAlias(QString str); - void insertAlias(DiceAlias* dice, int i); - const QList& getAliases() const; - QList* aliases(); - void setAliases(const QList list); - void cleanUpAliases(); - - static bool readStringResultParameter(QString& str); - static QString replacePlaceHolderFromJson(const QString& source, const QJsonObject& obj); - -private: - QMap m_logicOp; - QMap m_logicOperation; - QMap m_conditionOperation; - std::vector> m_arithmeticOperation; - QMap m_mapDiceOp; - QMap m_OptionOp; - QMap m_nodeActionMap; - std::map m_functionMap; - QStringList m_commandList; - - QMap m_errorMap; - QMap m_warningMap; - std::vector m_startNodes; - - QString m_comment; - - static QHash m_variableHash; - QString m_helpPath; - QList m_aliasList; -}; - -#endif // PARSINGTOOLBOX_H diff --git a/node/dicerollernode.cpp b/node/dicerollernode.cpp index f87908f..2b00c0a 100644 --- a/node/dicerollernode.cpp +++ b/node/dicerollernode.cpp @@ -7,7 +7,7 @@ #include DiceRollerNode::DiceRollerNode(qint64 max, qint64 min) - : m_max(max), m_diceResult(new DiceResult()), m_min(min), m_operator(Die::PLUS) + : m_max(max), m_diceResult(new DiceResult()), m_min(min), m_operator(Dice::ArithmeticOperator::PLUS) { m_result= m_diceResult; } @@ -99,12 +99,12 @@ ExecutionNode* DiceRollerNode::getCopy() const return node; } -Die::ArithmeticOperator DiceRollerNode::getOperator() const +Dice::ArithmeticOperator DiceRollerNode::getOperator() const { return m_operator; } -void DiceRollerNode::setOperator(const Die::ArithmeticOperator& dieOperator) +void DiceRollerNode::setOperator(const Dice::ArithmeticOperator& dieOperator) { m_operator= dieOperator; m_diceResult->setOperator(dieOperator); diff --git a/node/dicerollernode.h b/node/dicerollernode.h index 67d4074..52178cb 100644 --- a/node/dicerollernode.h +++ b/node/dicerollernode.h @@ -45,8 +45,8 @@ public: virtual ExecutionNode* getCopy() const; // private members - Die::ArithmeticOperator getOperator() const; - void setOperator(const Die::ArithmeticOperator& dieOperator); + Dice::ArithmeticOperator getOperator() const; + void setOperator(const Dice::ArithmeticOperator& dieOperator); bool getUnique() const; void setUnique(bool unique); @@ -54,10 +54,10 @@ public: private: quint64 m_diceCount; qint64 m_max; /// faces - DiceResult* m_diceResult; + DiceResult* m_diceResult{nullptr}; qint64 m_min; - Die::ArithmeticOperator m_operator; - bool m_unique = false; + Dice::ArithmeticOperator m_operator; + bool m_unique{false}; }; #endif // DICEROLLERNODE_H diff --git a/node/executionnode.h b/node/executionnode.h index 6321c83..d1bdf66 100644 --- a/node/executionnode.h +++ b/node/executionnode.h @@ -1,8 +1,8 @@ #ifndef EXECUTIONNODE_H #define EXECUTIONNODE_H -#include "diceparserhelper.h" #include "result/result.h" +#include /** * @brief The ExecutionNode class diff --git a/node/ifnode.h b/node/ifnode.h index f0046f0..912d65c 100644 --- a/node/ifnode.h +++ b/node/ifnode.h @@ -20,9 +20,9 @@ #ifndef IFNODE_H #define IFNODE_H -#include "diceparserhelper.h" #include "executionnode.h" #include "result/diceresult.h" +#include class ValidatorList; class PartialDiceRollNode : public ExecutionNode diff --git a/node/listaliasnode.h b/node/listaliasnode.h index b8b549c..2a6f96e 100644 --- a/node/listaliasnode.h +++ b/node/listaliasnode.h @@ -21,7 +21,8 @@ #ifndef LISTALIASNODE_H #define LISTALIASNODE_H -#include "dicealias.h" +#include + #include "executionnode.h" #include "result/stringresult.h" diff --git a/node/mergenode.cpp b/node/mergenode.cpp index 7a521e3..096bb8c 100644 --- a/node/mergenode.cpp +++ b/node/mergenode.cpp @@ -21,7 +21,7 @@ ***************************************************************************/ #include "mergenode.h" -#include "parsingtoolbox.h" +#include MergeNode::MergeNode() : m_diceResult(new DiceResult()) { diff --git a/node/repeaternode.cpp b/node/repeaternode.cpp index 2010118..f93a9fe 100644 --- a/node/repeaternode.cpp +++ b/node/repeaternode.cpp @@ -21,11 +21,12 @@ ***************************************************************************/ #include "node/repeaternode.h" -#include "diceparserhelper.h" #include "executionnode.h" -#include "parsingtoolbox.h" +#include "result/scalarresult.h" #include "result/stringresult.h" #include +#include +#include using InstructionSet= std::vector; @@ -82,16 +83,18 @@ void RepeaterNode::run(ExecutionNode* previousNode) for(int i= 0; i < timeCount; ++i) { m_startingNodes.push_back(cmd); - std::for_each(cmd.begin(), cmd.end(), [this, &resultVec](ExecutionNode* node) { - node->run(this); - auto end= ParsingToolBox::getLeafNode(node); - auto leafResult= end->getResult(); - - if(nullptr == leafResult) - return; - - resultVec.push_back(leafResult); - }); + std::for_each(cmd.begin(), cmd.end(), + [this, &resultVec](ExecutionNode* node) + { + node->run(this); + auto end= ParsingToolBox::getLeafNode(node); + auto leafResult= end->getResult(); + + if(nullptr == leafResult) + return; + + resultVec.push_back(leafResult); + }); cmd= makeCopy(m_cmd); } if(m_sumAll) @@ -121,7 +124,7 @@ void RepeaterNode::run(ExecutionNode* previousNode) m_result= string; - //qDebug().noquote() << listOfStrResult.join('\n'); + // qDebug().noquote() << listOfStrResult.join('\n'); } if(nullptr != m_nextNode) diff --git a/node/replacevaluenode.cpp b/node/replacevaluenode.cpp index fbad5df..c313fb0 100644 --- a/node/replacevaluenode.cpp +++ b/node/replacevaluenode.cpp @@ -20,8 +20,8 @@ #include "replacevaluenode.h" #include "diceresult.h" -#include "parsingtoolbox.h" #include +#include ReplaceValueNode::ReplaceValueNode() : m_diceResult(new DiceResult) { diff --git a/node/rerolldicenode.cpp b/node/rerolldicenode.cpp index e7bf0f0..fd8c258 100644 --- a/node/rerolldicenode.cpp +++ b/node/rerolldicenode.cpp @@ -1,5 +1,7 @@ +#include + #include "rerolldicenode.h" -#include "parsingtoolbox.h" +#include "validatorlist.h" #include RerollDiceNode::RerollDiceNode(bool reroll, bool addingMode) diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp index 268d6b8..c1c4dc5 100644 --- a/node/scalaroperatornode.cpp +++ b/node/scalaroperatornode.cpp @@ -25,7 +25,7 @@ #include ScalarOperatorNode::ScalarOperatorNode() - : m_internalNode(nullptr), m_scalarResult(new ScalarResult()), m_arithmeticOperator(Die::PLUS) + : m_internalNode(nullptr), m_scalarResult(new ScalarResult()), m_arithmeticOperator(Dice::ArithmeticOperator::PLUS) { m_result= m_scalarResult; } @@ -75,28 +75,28 @@ void ScalarOperatorNode::run(ExecutionNode* previous) switch(m_arithmeticOperator) { - case Die::PLUS: + case Dice::ArithmeticOperator::PLUS: m_scalarResult->setValue(add(previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal(), internalResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal())); break; - case Die::MINUS: + case Dice::ArithmeticOperator::MINUS: m_scalarResult->setValue(substract(previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal(), internalResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal())); break; - case Die::MULTIPLICATION: + case Dice::ArithmeticOperator::MULTIPLICATION: m_scalarResult->setValue(multiple(previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal(), internalResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal())); break; - case Die::DIVIDE: + case Dice::ArithmeticOperator::DIVIDE: m_scalarResult->setValue(divide(previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal(), internalResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal())); break; - case Die::INTEGER_DIVIDE: + case Dice::ArithmeticOperator::INTEGER_DIVIDE: m_scalarResult->setValue( static_cast(divide(previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal(), internalResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal()))); break; - case Die::POW: + case Dice::ArithmeticOperator::POW: m_scalarResult->setValue(pow(previousResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal(), internalResult->getResult(Dice::RESULT_TYPE::SCALAR).toReal())); break; @@ -149,12 +149,12 @@ qint64 ScalarOperatorNode::pow(qreal a, qreal b) { return static_cast(std::pow(a, b)); } -Die::ArithmeticOperator ScalarOperatorNode::getArithmeticOperator() const +Dice::ArithmeticOperator ScalarOperatorNode::getArithmeticOperator() const { return m_arithmeticOperator; } -void ScalarOperatorNode::setArithmeticOperator(const Die::ArithmeticOperator& arithmeticOperator) +void ScalarOperatorNode::setArithmeticOperator(const Dice::ArithmeticOperator& arithmeticOperator) { m_arithmeticOperator= arithmeticOperator; } @@ -164,22 +164,22 @@ QString ScalarOperatorNode::toString(bool wl) const QString op= ""; switch(m_arithmeticOperator) { - case Die::PLUS: + case Dice::ArithmeticOperator::PLUS: op= "+"; break; - case Die::MINUS: + case Dice::ArithmeticOperator::MINUS: op= "-"; break; - case Die::MULTIPLICATION: + case Dice::ArithmeticOperator::MULTIPLICATION: op= "*"; break; - case Die::DIVIDE: + case Dice::ArithmeticOperator::DIVIDE: op= "/"; break; - case Die::INTEGER_DIVIDE: + case Dice::ArithmeticOperator::INTEGER_DIVIDE: op= "|"; break; - case Die::POW: + case Dice::ArithmeticOperator::POW: op= "^"; break; } @@ -194,11 +194,12 @@ QString ScalarOperatorNode::toString(bool wl) const } qint64 ScalarOperatorNode::getPriority() const { - if((m_arithmeticOperator == Die::PLUS) || (m_arithmeticOperator == Die::MINUS)) + if((m_arithmeticOperator == Dice::ArithmeticOperator::PLUS) + || (m_arithmeticOperator == Dice::ArithmeticOperator::MINUS)) { return 1; } - else if(m_arithmeticOperator == Die::POW) + else if(m_arithmeticOperator == Dice::ArithmeticOperator::POW) { return 3; } diff --git a/node/scalaroperatornode.h b/node/scalaroperatornode.h index 5902433..57a1049 100644 --- a/node/scalaroperatornode.h +++ b/node/scalaroperatornode.h @@ -81,12 +81,12 @@ public: * @brief getArithmeticOperator * @return */ - Die::ArithmeticOperator getArithmeticOperator() const; + Dice::ArithmeticOperator getArithmeticOperator() const; /** * @brief setArithmeticOperator * @param arithmeticOperator */ - void setArithmeticOperator(const Die::ArithmeticOperator& arithmeticOperator); + void setArithmeticOperator(const Dice::ArithmeticOperator& arithmeticOperator); /** * @brief getCopy @@ -121,7 +121,7 @@ private: private: ExecutionNode* m_internalNode; ScalarResult* m_scalarResult; - Die::ArithmeticOperator m_arithmeticOperator; + Dice::ArithmeticOperator m_arithmeticOperator; }; #endif // SCALAROPERATORNODE_H diff --git a/node/switchcasenode.cpp b/node/switchcasenode.cpp index 61938a9..880fa4d 100644 --- a/node/switchcasenode.cpp +++ b/node/switchcasenode.cpp @@ -19,9 +19,9 @@ ***************************************************************************/ #include "switchcasenode.h" -#include "parsingtoolbox.h" #include "stringresult.h" #include +#include SwitchCaseNode::SwitchCaseNode() : m_stringResult(new StringResult) { diff --git a/node/variablenode.cpp b/node/variablenode.cpp index ce8af29..709ab46 100644 --- a/node/variablenode.cpp +++ b/node/variablenode.cpp @@ -1,5 +1,7 @@ #include "variablenode.h" -#include "parsingtoolbox.h" + +#include "diceresult.h" +#include VariableNode::VariableNode() {} diff --git a/operationcondition.cpp b/operationcondition.cpp index 22e6b0b..70ebab4 100644 --- a/operationcondition.cpp +++ b/operationcondition.cpp @@ -20,7 +20,10 @@ #include "operationcondition.h" -OperationCondition::OperationCondition() : m_operator(Modulo), m_boolean(nullptr), m_value(nullptr) {} +OperationCondition::OperationCondition() + : m_operator(Dice::ConditionOperator::Modulo), m_boolean(nullptr), m_value(nullptr) +{ +} OperationCondition::~OperationCondition() { if(m_value != nullptr) @@ -60,7 +63,7 @@ qint64 OperationCondition::hasValid(Die* b, bool recursive, bool unhighlight) co { switch(m_operator) { - case Modulo: + case Dice::ConditionOperator::Modulo: { Die die; die.setMaxValue(b->getMaxValue()); @@ -85,7 +88,7 @@ qint64 OperationCondition::hasValid(Die* b, bool recursive, bool unhighlight) co return sum; } -void OperationCondition::setOperator(ConditionOperator m) +void OperationCondition::setOperator(Dice::ConditionOperator m) { m_operator= m; } @@ -100,7 +103,7 @@ QString OperationCondition::toString() QString str(""); switch(m_operator) { - case Modulo: + case Dice::ConditionOperator::Modulo: str.append(QStringLiteral("\\%")); break; } diff --git a/operationcondition.h b/operationcondition.h index d9653cc..719624f 100644 --- a/operationcondition.h +++ b/operationcondition.h @@ -29,16 +29,12 @@ class OperationCondition : public Validator { public: - enum ConditionOperator - { - Modulo - }; OperationCondition(); virtual ~OperationCondition() override; virtual qint64 hasValid(Die* b, bool recursive, bool unhighlight= false) const override; - void setOperator(ConditionOperator m); + void setOperator(Dice::ConditionOperator m); // void setValue(qint64); void setValueNode(ExecutionNode* node); QString toString() override; @@ -56,7 +52,7 @@ private: qint64 valueToScalar() const; private: - ConditionOperator m_operator= Modulo; + Dice::ConditionOperator m_operator{Dice::ConditionOperator::Modulo}; BooleanCondition* m_boolean= nullptr; // qint64 m_value; ExecutionNode* m_value= nullptr; diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index e5bb579..dfde37f 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -19,7 +19,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "parsingtoolbox.h" +#include "diceparser/parsingtoolbox.h" #include #include @@ -59,36 +59,39 @@ #include "node/uniquenode.h" #include "node/valueslistnode.h" #include "node/variablenode.h" +#include "operationcondition.h" +#include "range.h" +#include "validatorlist.h" QHash ParsingToolBox::m_variableHash; ParsingToolBox::ParsingToolBox() { // m_logicOp = ; - m_logicOp.insert(">=", BooleanCondition::GreaterOrEqual); - m_logicOp.insert("<=", BooleanCondition::LesserOrEqual); - m_logicOp.insert("<", BooleanCondition::LesserThan); - m_logicOp.insert("=", BooleanCondition::Equal); - m_logicOp.insert(">", BooleanCondition::GreaterThan); - m_logicOp.insert("!=", BooleanCondition::Different); + m_logicOp.insert(">=", Dice::CompareOperator::GreaterOrEqual); + m_logicOp.insert("<=", Dice::CompareOperator::LesserOrEqual); + m_logicOp.insert("<", Dice::CompareOperator::LesserThan); + m_logicOp.insert("=", Dice::CompareOperator::Equal); + m_logicOp.insert(">", Dice::CompareOperator::GreaterThan); + m_logicOp.insert("!=", Dice::CompareOperator::Different); // m_logicOperation = ; - m_logicOperation.insert("|", ValidatorList::OR); - m_logicOperation.insert("^", ValidatorList::EXCLUSIVE_OR); - m_logicOperation.insert("&", ValidatorList::AND); + m_logicOperation.insert("|", Dice::LogicOperation::OR); + m_logicOperation.insert("^", Dice::LogicOperation::EXCLUSIVE_OR); + m_logicOperation.insert("&", Dice::LogicOperation::AND); // m_conditionOperation = ; - m_conditionOperation.insert("%", OperationCondition::Modulo); + m_conditionOperation.insert("%", Dice::ConditionOperator::Modulo); // m_arithmeticOperation = new QHash(); - m_arithmeticOperation.push_back({QStringLiteral("**"), Die::POW}); - m_arithmeticOperation.push_back({QStringLiteral("+"), Die::PLUS}); - m_arithmeticOperation.push_back({QStringLiteral("-"), Die::MINUS}); - m_arithmeticOperation.push_back({QStringLiteral("*"), Die::MULTIPLICATION}); - m_arithmeticOperation.push_back({QStringLiteral("x"), Die::MULTIPLICATION}); - m_arithmeticOperation.push_back({QStringLiteral("|"), Die::INTEGER_DIVIDE}); - m_arithmeticOperation.push_back({QStringLiteral("/"), Die::DIVIDE}); - m_arithmeticOperation.push_back({QStringLiteral("÷"), Die::DIVIDE}); + m_arithmeticOperation.push_back({QStringLiteral("**"), Dice::ArithmeticOperator::POW}); + m_arithmeticOperation.push_back({QStringLiteral("+"), Dice::ArithmeticOperator::PLUS}); + m_arithmeticOperation.push_back({QStringLiteral("-"), Dice::ArithmeticOperator::MINUS}); + m_arithmeticOperation.push_back({QStringLiteral("*"), Dice::ArithmeticOperator::MULTIPLICATION}); + m_arithmeticOperation.push_back({QStringLiteral("x"), Dice::ArithmeticOperator::MULTIPLICATION}); + m_arithmeticOperation.push_back({QStringLiteral("|"), Dice::ArithmeticOperator::INTEGER_DIVIDE}); + m_arithmeticOperation.push_back({QStringLiteral("/"), Dice::ArithmeticOperator::DIVIDE}); + m_arithmeticOperation.push_back({QStringLiteral("÷"), Dice::ArithmeticOperator::DIVIDE}); m_mapDiceOp.insert(QStringLiteral("D"), D); m_mapDiceOp.insert(QStringLiteral("L"), L); @@ -153,7 +156,7 @@ void ParsingToolBox::addWarning(Dice::ERROR_CODE code, const QString& msg) { m_warningMap.insert(code, msg); } -bool ParsingToolBox::readDiceLogicOperator(QString& str, OperationCondition::ConditionOperator& op) +bool ParsingToolBox::readDiceLogicOperator(QString& str, Dice::ConditionOperator& op) { QString longKey; auto const& keys= m_conditionOperation.keys(); @@ -177,12 +180,12 @@ bool ParsingToolBox::readDiceLogicOperator(QString& str, OperationCondition::Con return false; } -bool ParsingToolBox::readArithmeticOperator(QString& str, Die::ArithmeticOperator& op) +bool ParsingToolBox::readArithmeticOperator(QString& str, Dice::ArithmeticOperator& op) { - auto it= std::find_if( - m_arithmeticOperation.begin(), m_arithmeticOperation.end(), - [str](const std::pair& pair) { return str.startsWith(pair.first); }); + auto it= std::find_if(m_arithmeticOperation.begin(), m_arithmeticOperation.end(), + [str](const std::pair& pair) + { return str.startsWith(pair.first); }); if(it == m_arithmeticOperation.end()) return false; @@ -191,7 +194,7 @@ bool ParsingToolBox::readArithmeticOperator(QString& str, Die::ArithmeticOperato return true; } -bool ParsingToolBox::readLogicOperator(QString& str, BooleanCondition::LogicOperator& op) +bool ParsingToolBox::readLogicOperator(QString& str, Dice::CompareOperator& op) { QString longKey; auto const& keys= m_logicOp.keys(); @@ -264,10 +267,10 @@ Validator* ParsingToolBox::readValidator(QString& str, bool hasSquare) { Validator* returnVal= nullptr; auto opCompare= readConditionType(str); - BooleanCondition::LogicOperator myLogicOp= BooleanCondition::Equal; + Dice::CompareOperator myLogicOp{Dice::CompareOperator::Equal}; readLogicOperator(str, myLogicOp); - OperationCondition::ConditionOperator condiOp= OperationCondition::Modulo; + Dice::ConditionOperator condiOp{Dice::ConditionOperator::Modulo}; bool hasDiceLogicOperator= readDiceLogicOperator(str, condiOp); ExecutionNode* operandNode= nullptr; if(hasDiceLogicOperator) @@ -359,9 +362,9 @@ ValidatorList* ParsingToolBox::readValidatorList(QString& str) expectSquareBrasket= true; } Validator* tmp= readValidator(str, expectSquareBrasket); - ValidatorList::LogicOperation opLogic; + Dice::LogicOperation opLogic; - QVector operators; + QVector operators; QList validatorList; while(nullptr != tmp) @@ -396,7 +399,7 @@ ValidatorList* ParsingToolBox::readValidatorList(QString& str) return nullptr; } } -bool ParsingToolBox::readLogicOperation(QString& str, ValidatorList::LogicOperation& op) +bool ParsingToolBox::readLogicOperation(QString& str, Dice::LogicOperation& op) { QString longKey; auto const& keys= m_logicOperation.keys(); @@ -711,11 +714,13 @@ QString ParsingToolBox::finalStringResult(std::function>>& map) { + [](const std::vector>>& map) + { QStringList valuesStr; auto multiKey= (map.size() > 1); for(auto item : map) @@ -1284,18 +1290,21 @@ QString ParsingToolBox::replacePlaceHolderToValue(const QString& source, const Q QStringList resultList; std::transform( std::begin(list), std::end(list), std::back_inserter(resultList), - [removeUnhighlighted, colorize](const ExportedDiceResult& dice) { + [removeUnhighlighted, colorize](const ExportedDiceResult& dice) + { QStringList valuesStr; if(dice.size() == 1) { auto values= dice.values(); std::transform( std::begin(values), std::end(values), std::back_inserter(valuesStr), - [removeUnhighlighted, colorize](const QList& dice) { + [removeUnhighlighted, colorize](const QList& dice) + { QStringList textList; std::transform( std::begin(dice), std::end(dice), std::back_inserter(textList), - [removeUnhighlighted, colorize](const ListDiceResult& dice) { + [removeUnhighlighted, colorize](const ListDiceResult& dice) + { QStringList list; ListDiceResult values= dice; if(removeUnhighlighted) @@ -1306,9 +1315,8 @@ QString ParsingToolBox::replacePlaceHolderToValue(const QString& source, const Q } std::transform(std::begin(values), std::end(values), std::back_inserter(list), - [colorize](const HighLightDice& hl) { - return colorize(hl.getResultString(), {}, hl.isHighlighted()); - }); + [colorize](const HighLightDice& hl) + { return colorize(hl.getResultString(), {}, hl.isHighlighted()); }); return list.join(","); }); textList.removeAll(QString()); @@ -1931,7 +1939,7 @@ ExplodeDiceNode* ParsingToolBox::addExplodeDiceNode(qint64 value, ExecutionNode* BooleanCondition* condition= new BooleanCondition(); condition->setConditionType(Dice::OnEach); condition->setValueNode(node); - condition->setOperator(BooleanCondition::Equal); + condition->setOperator(Dice::CompareOperator::Equal); auto valList= new ValidatorList(); valList->setValidators(QList() << condition); auto validity= isValidValidator(previous, valList); @@ -2003,7 +2011,7 @@ bool ParsingToolBox::readBlocInstruction(QString& str, ExecutionNode*& resultnod { str= str.remove(0, 1); ExecutionNode* node= nullptr; - Die::ArithmeticOperator op; + Dice::ArithmeticOperator op; ScalarOperatorNode* scalarNode= nullptr; if(readArithmeticOperator(str, op)) { @@ -2041,7 +2049,7 @@ bool ParsingToolBox::readDice(QString& str, ExecutionNode*& node) qint64 max; qint64 min; bool unique= (ParsingToolBox::UNIQUE == readListOperator(str)) ? true : false; - Die::ArithmeticOperator op; + Dice::ArithmeticOperator op; bool hasOp= readArithmeticOperator(str, op); if(readNumber(str, max)) @@ -2201,7 +2209,7 @@ bool ParsingToolBox::readOperator(QString& str, ExecutionNode* previous) return result; } - Die::ArithmeticOperator op; + Dice::ArithmeticOperator op; if(readArithmeticOperator(str, op)) { ScalarOperatorNode* node= new ScalarOperatorNode(); diff --git a/qmltypesregister.cpp b/qmltypesregister.cpp index cc207e9..dbd2ac9 100644 --- a/qmltypesregister.cpp +++ b/qmltypesregister.cpp @@ -17,11 +17,11 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "qmltypesregister.h" +#include #include -#include "diceroller.h" +#include #if !defined(UNIT_TEST) && defined(RCSE) #include "field.h" #endif diff --git a/qmltypesregister.h b/qmltypesregister.h deleted file mode 100644 index 485c697..0000000 --- a/qmltypesregister.h +++ /dev/null @@ -1,25 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2017 by Renaud Guezennec * - * https://rolisteam.org/contact * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef REGISTER_QML_TYPE_H -#define REGISTER_QML_TYPE_H - -void registerQmlTypes(); - -#endif // REGISTER_QML_TYPE_H diff --git a/result/diceresult.cpp b/result/diceresult.cpp index 2f13210..31e316b 100644 --- a/result/diceresult.cpp +++ b/result/diceresult.cpp @@ -23,7 +23,7 @@ #include "diceresult.h" #include -DiceResult::DiceResult() : m_operator(Die::PLUS) +DiceResult::DiceResult() { m_resultTypes= (static_cast(Dice::RESULT_TYPE::DICE_LIST) | static_cast(Dice::RESULT_TYPE::SCALAR)); m_homogeneous= true; @@ -107,20 +107,20 @@ qreal DiceResult::getScalarResult() { switch(m_operator) { - case Die::PLUS: + case Dice::ArithmeticOperator::PLUS: scalar+= tmp->getValue(); break; - case Die::MULTIPLICATION: + case Dice::ArithmeticOperator::MULTIPLICATION: scalar*= tmp->getValue(); break; - case Die::MINUS: + case Dice::ArithmeticOperator::MINUS: scalar-= tmp->getValue(); break; - case Die::POW: + case Dice::ArithmeticOperator::POW: scalar= static_cast(pow(static_cast(scalar), static_cast(tmp->getValue()))); break; - case Die::DIVIDE: - case Die::INTEGER_DIVIDE: + case Dice::ArithmeticOperator::DIVIDE: + case Dice::ArithmeticOperator::INTEGER_DIVIDE: if(tmp->getValue() != 0) { scalar/= tmp->getValue(); @@ -142,7 +142,7 @@ qreal DiceResult::getScalarResult() } } -Die::ArithmeticOperator DiceResult::getOperator() const +Dice::ArithmeticOperator DiceResult::getOperator() const { return m_operator; } @@ -152,7 +152,7 @@ void DiceResult::clear() m_diceValues.clear(); } -void DiceResult::setOperator(const Die::ArithmeticOperator& dieOperator) +void DiceResult::setOperator(const Dice::ArithmeticOperator& dieOperator) { m_operator= dieOperator; } diff --git a/result/diceresult.h b/result/diceresult.h index 8f15d3b..1b35b7e 100644 --- a/result/diceresult.h +++ b/result/diceresult.h @@ -24,6 +24,7 @@ #include #include +#include "diceparser/diceparserhelper.h" #include "die.h" #include "result.h" /** @@ -76,8 +77,8 @@ public: */ virtual void setHomogeneous(bool); - Die::ArithmeticOperator getOperator() const; - void setOperator(const Die::ArithmeticOperator& dieOperator); + Dice::ArithmeticOperator getOperator() const; + void setOperator(const Dice::ArithmeticOperator& dieOperator); bool contains(Die* die, const std::function equal); void clear() override; @@ -90,7 +91,7 @@ protected: protected: QList m_diceValues; bool m_homogeneous; - Die::ArithmeticOperator m_operator= Die::ArithmeticOperator::PLUS; + Dice::ArithmeticOperator m_operator{Dice::ArithmeticOperator::PLUS}; }; Q_DECLARE_METATYPE(QList) #endif // DICERESULT_H diff --git a/result/result.h b/result/result.h index e86ed1f..4432682 100644 --- a/result/result.h +++ b/result/result.h @@ -22,9 +22,9 @@ #ifndef RESULT_H #define RESULT_H -#include "diceparserhelper.h" #include #include +#include /** * @brief The Result class */ diff --git a/tests/dice/CMakeLists.txt b/tests/dice/CMakeLists.txt index 35f255b..f07fa71 100644 --- a/tests/dice/CMakeLists.txt +++ b/tests/dice/CMakeLists.txt @@ -1,4 +1,4 @@ -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-permissive -pedantic -Wall -Wextra") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-permissive -pedantic -Wall") set(CMAKE_AUTOMOC ON) find_package(Qt6 ${QT_REQUIRED_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Svg Test) diff --git a/validator.h b/validator.h index 7180bac..ca15f67 100644 --- a/validator.h +++ b/validator.h @@ -22,7 +22,8 @@ #ifndef VALIDATOR_H #define VALIDATOR_H -#include "diceparserhelper.h" +#include + #include "die.h" #include #include diff --git a/validatorlist.cpp b/validatorlist.cpp index cb650df..f1d1ba4 100644 --- a/validatorlist.cpp +++ b/validatorlist.cpp @@ -140,7 +140,7 @@ qint64 ValidatorList::hasValid(Die* b, bool recursive, bool unhighlight) const { switch(m_operators.at(i - 1)) { - case OR: + case Dice::LogicOperation::OR: sum|= val; if(highLight) @@ -148,10 +148,10 @@ qint64 ValidatorList::hasValid(Die* b, bool recursive, bool unhighlight) const b->setHighlighted(highLight); } break; - case EXCLUSIVE_OR: + case Dice::LogicOperation::EXCLUSIVE_OR: sum^= val; /// @todo may required to be done by hand break; - case AND: + case Dice::LogicOperation::AND: sum&= val; break; default: @@ -227,9 +227,9 @@ Dice::CONDITION_STATE testXOR(Dice::CONDITION_STATE before, Dice::CONDITION_STAT Dice::CONDITION_STATE ValidatorList::isValidRangeSize(const std::pair& range) const { std::vector vec; - std::transform( - m_validatorList.begin(), m_validatorList.end(), std::back_inserter(vec), - [range](Validator* validator) -> Dice::CONDITION_STATE { return validator->isValidRangeSize(range); }); + std::transform(m_validatorList.begin(), m_validatorList.end(), std::back_inserter(vec), + [range](Validator* validator) -> Dice::CONDITION_STATE + { return validator->isValidRangeSize(range); }); auto itError= std::find(vec.begin(), vec.end(), Dice::CONDITION_STATE::ERROR_STATE); @@ -252,16 +252,16 @@ Dice::CONDITION_STATE ValidatorList::isValidRangeSize(const std::pair& m) +void ValidatorList::setOperationList(const QVector& m) { m_operators= m; } @@ -353,9 +353,9 @@ void ValidatorList::validResult(Result* result, bool recursive, bool unlight, if(nullptr == diceResult) break; auto diceList= diceResult->getResultList(); - auto all= std::all_of(diceList.begin(), diceList.end(), [validator, recursive, unlight](Die* die) { - return validator->hasValid(die, recursive, unlight); - }); + auto all= std::all_of(diceList.begin(), diceList.end(), + [validator, recursive, unlight](Die* die) + { return validator->hasValid(die, recursive, unlight); }); if(all) { validResult.setAllTrue(true); @@ -372,9 +372,9 @@ void ValidatorList::validResult(Result* result, bool recursive, bool unlight, if(nullptr == diceResult) break; auto diceList= diceResult->getResultList(); - auto any= std::any_of(diceList.begin(), diceList.end(), [validator, recursive, unlight](Die* die) { - return validator->hasValid(die, recursive, unlight); - }); + auto any= std::any_of(diceList.begin(), diceList.end(), + [validator, recursive, unlight](Die* die) + { return validator->hasValid(die, recursive, unlight); }); if(any) { validResult.setAllTrue(true); @@ -409,16 +409,16 @@ void ValidatorList::validResult(Result* result, bool recursive, bool unlight, auto op= m_operators.at(id); switch(op) { - case OR: + case Dice::LogicOperation::OR: std::copy(diceList.begin(), diceList.end(), std::back_inserter(finalResult.validDiceRef())); break; - case AND: + case Dice::LogicOperation::AND: mergeResultsAsAND(vec, finalResult); break; - case EXCLUSIVE_OR: + case Dice::LogicOperation::EXCLUSIVE_OR: mergeResultsAsExeclusiveOR(vec, finalResult); break; - case NONE: + case Dice::LogicOperation::NONE: break; } } @@ -432,9 +432,10 @@ void ValidatorList::validResult(Result* result, bool recursive, bool unlight, if(nullptr == diceResult) return; auto diceList= diceResult->getResultList(); - std::transform(diceList.begin(), diceList.end(), std::back_inserter(finalResult.validDiceRef()), [](Die* die) { - return std::pair({die, 0}); - }); + std::transform(diceList.begin(), diceList.end(), std::back_inserter(finalResult.validDiceRef()), + [](Die* die) { + return std::pair({die, 0}); + }); } for(auto die : finalResult.validDice()) diff --git a/validatorlist.h b/validatorlist.h index 1faf7e6..ad2c9d4 100644 --- a/validatorlist.h +++ b/validatorlist.h @@ -27,7 +27,7 @@ #include #include -#include "diceparserhelper.h" +#include #include class Validator; @@ -75,20 +75,12 @@ private: class ValidatorList { public: - enum LogicOperation - { - OR, - EXCLUSIVE_OR, - AND, - NONE - }; - ValidatorList(); virtual ~ValidatorList(); virtual qint64 hasValid(Die* b, bool recursive, bool unhighlight= false) const; - void setOperationList(const QVector& m); + void setOperationList(const QVector& m); void setValidators(const QList& valids); QString toString(); @@ -100,7 +92,7 @@ public: void validResult(Result* result, bool recursive, bool unlight, std::function functor) const; private: - QVector m_operators; + QVector m_operators; QList m_validatorList; }; -- cgit v1.2.3-70-g09d2