From 9fb08a03b5630952cc07dfaeaca4f4958f76c8b7 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 25 Oct 2017 15:33:42 +0200 Subject: Update HelpMe.md make documentation clearer --- HelpMe.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/HelpMe.md b/HelpMe.md index 4db864e..3c16e8d 100644 --- a/HelpMe.md +++ b/HelpMe.md @@ -183,9 +183,9 @@ There are 3 different methods. * **One Of Them** : at least one die must fit the condition to trigger the true instruction. If no dices fit the condition the false instruction is run. * **On Scalar** : the condition is evaluated on the scalar result of the dice roll. -To switch the operator to act in **All Of Them** method you must add **\*** character as compare method position. -To switch the operator to act in **One Of Them** method you must add **.** character as compare method position. -To switch the operator to act in **On Scalar** method you must add **:** character as compare method position. +To switch the operator to act in **All Of Them** method you must add ```*``` character as compare method position. +To switch the operator to act in **One Of Them** method you must add ```.``` character as compare method position. +To switch the operator to act in **On Scalar** method you must add ```:``` character as compare method position. ## example: -- cgit v1.2.3-70-g09d2 From 1ba9e7b6d9948a7b1477792eca4016b2e8e346d9 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 25 Oct 2017 16:21:58 +0200 Subject: Update HelpMe.md more details about if. --- HelpMe.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/HelpMe.md b/HelpMe.md index 3c16e8d..c6ed209 100644 --- a/HelpMe.md +++ b/HelpMe.md @@ -187,6 +187,9 @@ To switch the operator to act in **All Of Them** method you must add ```*``` cha To switch the operator to act in **One Of Them** method you must add ```.``` character as compare method position. To switch the operator to act in **On Scalar** method you must add ```:``` character as compare method position. +If you plan to use if operator to display text message. You must surround text with ```"```. Example available below. + + ## example: @@ -206,11 +209,17 @@ if at least one die is equal to 6, then roll another d6 and add it to the result if all dice are equal to 6, then roll another d6 and add it to the result. +> 2d10i:[>15]{"Success"}{"Fail"} + +if the sum of two dice is greater than 15, It displays "Success", override it displays "Fail". + +> 2d10i:[>15]{"Success %1 "}{"Fail %1"} -> 2d10i:[>15]{"Success"} +Same as above, but the final result is displayed beside Success or Fail. -if the sum of two dice is greater than 15, It displays "Success". +> 2d10i:[>15]{"Success %1 [%2]"}{"Fail %1 [%2]"} +Same as above, but the result of each die is displayed inside square brackets. ## Arithmetic -- cgit v1.2.3-70-g09d2 From 6446492416e2ce3912d9d3c8006682883726f6a9 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 26 Oct 2017 09:59:54 +0200 Subject: Update HelpMe.md Add limitations and differences between diceparser platform. --- HelpMe.md | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/HelpMe.md b/HelpMe.md index c6ed209..cb8d297 100644 --- a/HelpMe.md +++ b/HelpMe.md @@ -13,10 +13,43 @@ make make install ``` -## Irc and Chat +## DiceParser : What is it ? + +DiceParser is a software component dedicated to roll dice through simple commands. This software component is available on different platform. +Such as: Irc bot, discord bot, included in Rolisteam, web server, on twitter etc. + +Each platform has its own limitations. +Let's take a look about it: + + +### Roll dice on each platform + Please, remember it is important to prefix all you command by `!`. This will allow the system to identify your command. To clarify the documentation, the `!` is not repeated before all commands. +| platform | start character(s) | more information | +|---|---|--- | +| Rolisteam |```!```| [Documentation](http://wiki.rolisteam.org/index.php/En:Dice) | +| Discord |```!```| | +| Twitter | ```#roll``` | Twit any message starting with #roll following by dice command (e.g: ```#roll 2d6```) | +| IrcBot |```!```| | +| webserver | nothing | No public published yet. Has dedicated text field | +| dice | nothing | dice is a command line application to roll dice: ```dice "2d6"``` | + + +### Known Limitations + +| platform | descriptions | +|---|---| +| Rolisteam | no support for comments yet. Rolisteam is a big software. You may not have all the most recent feature from diceparser. | +| Discord | no support for p operator. Color are badly managed by discord so we can't waste time about it. If the command takes too much time. It is cancel | +| Twitter | Result such be short | +| IrcBot | | +| webserver| | +| dice | | + + + ## How to roll a die It is real simple. you have to call: @@ -378,3 +411,5 @@ Old World in darkness system. Exalted 2nd edition system. + + -- cgit v1.2.3-70-g09d2 From 5a7d52ee7121be6e963b15e3d0c013805e1cb0a4 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 26 Oct 2017 10:16:35 +0200 Subject: Update HelpMe.md about aliases --- HelpMe.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/HelpMe.md b/HelpMe.md index cb8d297..95a29f7 100644 --- a/HelpMe.md +++ b/HelpMe.md @@ -42,13 +42,13 @@ Please, remember it is important to prefix all you command by `!`. This will all | platform | descriptions | |---|---| | Rolisteam | no support for comments yet. Rolisteam is a big software. You may not have all the most recent feature from diceparser. | -| Discord | no support for p operator. Color are badly managed by discord so we can't waste time about it. If the command takes too much time. It is cancel | -| Twitter | Result such be short | -| IrcBot | | -| webserver| | -| dice | | - +| Discord | no support for p operator. Color are badly managed by discord so we can't waste time about it. If the command takes too much time. It is canceled. There is really few aliases. You may ask for new aliases| +| Twitter | Result such be short. No aliases | +| IrcBot | No aliases | +| webserver| No aliases | +| dice | No aliases | +We can't set some aliases for any platform but It has to be labelled with game's name. ## How to roll a die -- cgit v1.2.3-70-g09d2 From be75cdb7fdb3748def522ebd49ed8bb0363955cf Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 26 Oct 2017 13:23:11 +0200 Subject: Update HelpMe.md Adding best practices chapter --- HelpMe.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/HelpMe.md b/HelpMe.md index 95a29f7..6b2dde0 100644 --- a/HelpMe.md +++ b/HelpMe.md @@ -411,5 +411,17 @@ Old World in darkness system. Exalted 2nd edition system. +# Best Practices +As DiceParser provides more and more features, you may find several ways to do the same thing. We want here to explain the difference between those several approaches. Then you will be able to use the right one. + +## Roll several kind of dice and sum them + +```Bad``` +> 2d8;2d10m + +```Good``` +> 2d8+2d10 + +The merge operator is useful when you want to use dice operator on all rolled dice. -- cgit v1.2.3-70-g09d2 From 368a1c476928d1c8f106822e9535b30687171a40 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sat, 28 Oct 2017 02:18:52 +0200 Subject: Update README.md add stuff --- README.md | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0e32f80..36c7a41 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,13 @@ -[![Build Status](http://www.rolisteam.org/sites/default/files/pixture_reloaded_logo.png)](http://www.rolisteam.org) +[![Build Status](https://raw.githubusercontent.com/Rolisteam/rolisteam/master/resources/logo/1000-rolisteam.png)](http://www.rolisteam.org) # DiceParser -Rolisteam Dice Parser +Dice Parser merges several tool to roll any kind of dice to play at role playing games. +It can be use as command line application on GNU/Linux +It also provides IRC bot, discord bot, twitter bot and webservice. + +[More informations](http://www.rolisteam.org/) ## Grammar The grammar is something like this: @@ -35,6 +39,20 @@ parenthese =: (expression) count =: c Validator ``` +## Build + +``` +git clone git@github.com:Rolisteam/DiceParser.git +cd DiceParser +mkdir build +cd build +cmake ../ +make +make install +``` +# Downloads + +-DiceParser is part of rolisteam : http://www.rolisteam.org/download but it can be use as standalone tool. ## Example: @@ -63,8 +81,6 @@ roll 1 die with 25 faces ### 8+8+8 compute: 24 - - ### 100/28*3 compute: 100/28 = 3 3*3 = 9 -- cgit v1.2.3-70-g09d2 From d421174d765c472bc74c75c6942e6d4329b45bb3 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sat, 28 Oct 2017 02:30:07 +0200 Subject: Update HelpMe.md Add group operator. --- HelpMe.md | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/HelpMe.md b/HelpMe.md index 6b2dde0..c2832a0 100644 --- a/HelpMe.md +++ b/HelpMe.md @@ -1,18 +1,6 @@ [![Logo](https://raw.githubusercontent.com/Rolisteam/rolisteam/master/resources/logo/1000-rolisteam.png)](http://www.rolisteam.org) # Documentation: -## Build - -``` -git clone git@github.com:Rolisteam/DiceParser.git -cd DiceParser -mkdir build -cd build -cmake ../ -make -make install -``` - ## DiceParser : What is it ? DiceParser is a software component dedicated to roll dice through simple commands. This software component is available on different platform. @@ -89,6 +77,7 @@ Thanks of several operations and options, you can tune a bit your rolling comman * p : Paint dice * m : Merge * i : if +* g : Group ### Keep @@ -222,7 +211,11 @@ To switch the operator to act in **On Scalar** method you must add ```:``` chara If you plan to use if operator to display text message. You must surround text with ```"```. Example available below. +# Group + +> 5d10g10 +Roll 5 dice and then try to group them to make group of 10 [7th sea system]. ## example: @@ -321,7 +314,7 @@ There are three kind of Validator: -Range -Boolean expression -Any operator which requires validator (such as `a,r,e,c') can use those three kind. +Any operator which requires validator (such as `a,r,e,c`) can use those three kind. ### Scalar -- cgit v1.2.3-70-g09d2 From a543a6ca8ddc2826a4433044ed1a040acbbf36a3 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sun, 29 Oct 2017 03:30:04 +0100 Subject: Update HelpMe.md add pow --- HelpMe.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/HelpMe.md b/HelpMe.md index c2832a0..d2570e0 100644 --- a/HelpMe.md +++ b/HelpMe.md @@ -297,6 +297,11 @@ Substract 4 to 6 and then roll two dice. Divide by 2 the result of 1 die. +> (2+2)^2 +Result: 16 + +> 1d10^2 + ## Roll two (or more) kinds of dice at once. To make it, you have to separate all dice commands by `;` -- cgit v1.2.3-70-g09d2 From f053853e87624a045438bacd4dd1494e91ae381f Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 27 Oct 2017 22:19:20 +0200 Subject: -c++11 update about for and nullptr. --- booleancondition.cpp | 2 +- cli/main.cpp | 2 +- compositevalidator.cpp | 6 +- diceparser.cpp | 75 ++++++++++++---------- irc/botircdiceparser.cpp | 3 +- node/countexecutenode.cpp | 24 ++++--- node/dicerollernode.cpp | 12 ++-- node/executionnode.cpp | 20 +++--- node/executionnode.h | 2 +- node/explosedicenode.cpp | 24 ++++--- node/explosedicenode.h | 2 +- node/filternode.cpp | 18 +++--- node/helpnode.cpp | 8 +-- node/ifnode.cpp | 51 ++++++++------- node/ifnode.h | 2 +- node/jumpbackwardnode.cpp | 32 +++++----- node/jumpbackwardnode.h | 2 +- node/keepdiceexecnode.cpp | 16 ++--- node/listaliasnode.cpp | 12 ++-- node/listaliasnode.h | 2 +- node/listsetrollnode.cpp | 16 ++--- node/listsetrollnode.h | 2 +- node/mergenode.cpp | 4 +- node/numbernode.cpp | 8 +-- node/paintnode.cpp | 16 ++--- node/paintnode.h | 2 +- node/parenthesesnode.cpp | 20 +++--- node/parenthesesnode.h | 2 +- node/rerolldicenode.cpp | 20 +++--- node/scalaroperatornode.cpp | 152 ++++++++++++++++++++++---------------------- node/scalaroperatornode.h | 5 ++ node/sortresult.cpp | 17 ++--- node/splitnode.cpp | 8 +-- node/startingnode.cpp | 9 ++- node/stringnode.cpp | 8 +-- operationcondition.cpp | 2 +- range.cpp | 2 +- result/diceresult.cpp | 2 +- result/result.cpp | 6 +- 39 files changed, 308 insertions(+), 308 deletions(-) diff --git a/booleancondition.cpp b/booleancondition.cpp index 7be9836..907746c 100644 --- a/booleancondition.cpp +++ b/booleancondition.cpp @@ -39,7 +39,7 @@ qint64 BooleanCondition::hasValid(Die* b,bool recursive,bool unhighlight) const } qint64 sum= 0; - foreach(qint64 value, listValues) + for(qint64 value : listValues) { switch(m_operator) { diff --git a/cli/main.cpp b/cli/main.cpp index be02507..6ed6036 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -151,7 +151,7 @@ QString diceToText(QList& diceList,bool highlight,bool homog for(auto dice : diceList) { QStringList resultGlobal; - foreach(int face, dice.keys()) + for(int face : dice.keys()) { QStringList result; ListDiceResult diceResult = dice.value(face); diff --git a/compositevalidator.cpp b/compositevalidator.cpp index 109ec26..9023460 100644 --- a/compositevalidator.cpp +++ b/compositevalidator.cpp @@ -22,14 +22,14 @@ #include "compositevalidator.h" CompositeValidator::CompositeValidator() - : m_operators(NULL),m_validatorList(NULL) + : m_operators(nullptr),m_validatorList(nullptr) { } CompositeValidator::~CompositeValidator() { qDeleteAll(*m_validatorList); - if(NULL!=m_operators) + if(nullptr!=m_operators) { delete m_operators; } @@ -40,7 +40,7 @@ qint64 CompositeValidator::hasValid(Die* b,bool recursive,bool unhighlight) cons int i = 0; qint64 sum = 0; bool highLight = false; - foreach(const Validator* validator, *m_validatorList) + for(const Validator* validator: *m_validatorList) { qint64 val = validator->hasValid(b,recursive,unhighlight); if(i==0) diff --git a/diceparser.cpp b/diceparser.cpp index 42f46ac..8838171 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -50,7 +50,7 @@ #define DEFAULT_FACES_NUMBER 10 DiceParser::DiceParser() - : m_current(nullptr)//m_start(NULL), + : m_current(nullptr)//m_start(nullptr), { m_currentTreeHasSeparator =false; m_parsingToolbox = new ParsingToolBox(); @@ -152,7 +152,6 @@ void DiceParser::insertAlias(DiceAlias* dice, int i) { m_aliasList->insert(i, dice); } - } bool DiceParser::parseLine(QString str) @@ -190,21 +189,22 @@ bool DiceParser::parseLine(QString str) { return true; } - else if(!m_errorMap.isEmpty()) + else { - m_errorMap.insert(ExecutionNode::NOTHING_UNDERSTOOD,QObject::tr("Nothing was understood")); + m_errorMap.insert(ExecutionNode::NOTHING_UNDERSTOOD,QObject::tr("Nothing was understood. To roll dice: !1d6 - full documation:" + "https://github.com/Rolisteam/DiceParser/blob/master/HelpMe.md")); } return false; } bool DiceParser::readExpression(QString& str,ExecutionNode* & node) { - ExecutionNode* operandNode=NULL; + ExecutionNode* operandNode=nullptr; QString result; QString comment; if(m_parsingToolbox->readOpenParentheses(str)) { - ExecutionNode* internalNode=NULL; + ExecutionNode* internalNode=nullptr; if(readExpression(str,internalNode)) { ParenthesesNode* parentheseNode = new ParenthesesNode(); @@ -213,7 +213,7 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) if(m_parsingToolbox->readCloseParentheses(str)) { - ExecutionNode* diceNode=NULL; + ExecutionNode* diceNode=nullptr; if(readDice(str,diceNode)) { parentheseNode->setNextNode(diceNode); @@ -224,7 +224,7 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) } else if(readOperand(str,operandNode)) { - ExecutionNode* diceNode=NULL; + ExecutionNode* diceNode=nullptr; if(readDice(str,diceNode)) { operandNode->setNextNode(diceNode); @@ -249,7 +249,7 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) } else { - ExecutionNode* diceNode=NULL; + ExecutionNode* diceNode=nullptr; if(readDice(str,diceNode)) { NumberNode* numberNode=new NumberNode(); @@ -330,12 +330,12 @@ QString DiceParser::displayResult() { DiceResult* myDiceResult = dynamic_cast(result); - if(NULL!=myDiceResult) + if(nullptr!=myDiceResult) { QString resulStr; quint64 face=0; - foreach(Die* die, myDiceResult->getResultList()) + for(Die* die : myDiceResult->getResultList()) { if(!die->hasBeenDisplayed()) { @@ -347,7 +347,7 @@ QString DiceParser::displayResult() if(die->hasChildrenValue()) { resulStr+=QStringLiteral(" ["); - foreach(qint64 i, die->getListValue()) + for(qint64 i : die->getListValue()) { resulStr+=QStringLiteral("%1 ").arg(i); } @@ -392,7 +392,7 @@ QList DiceParser::getLastIntegerResults() ExecutionNode* next = getLeafNode(node); Result* result=next->getResult(); bool scalarDone = false; - while((result!=NULL)&&(!scalarDone)) + while((result!=nullptr)&&(!scalarDone)) { if(result->hasResultOfType(Result::SCALAR)) { @@ -465,7 +465,7 @@ QStringList DiceParser::getAllDiceResult(bool& hasAlias) if(result->hasResultOfType(Result::DICE_LIST)) { DiceResult* stringResult = dynamic_cast(result); - if(NULL!=stringResult) + if(nullptr!=stringResult) { for(auto die : stringResult->getResultList()) { @@ -484,7 +484,7 @@ QStringList DiceParser::getAllDiceResult(bool& hasAlias) { if(die->isHighlighted()) { - foreach (qint64 value, die->getListValue()) + for(qint64 value : die->getListValue()) { stringListResult << QString::number(value); @@ -503,12 +503,12 @@ void DiceParser::getLastDiceResult(QList& diceValuesList,boo ExecutionNode* next = getLeafNode(start); Result* result=next->getResult(); - while(NULL!=result) + while(nullptr!=result) { if(result->hasResultOfType(Result::DICE_LIST)) { DiceResult* diceResult = dynamic_cast(result); - if(NULL!=diceResult) + if(nullptr!=diceResult) { if(homogeneous) { @@ -517,7 +517,7 @@ void DiceParser::getLastDiceResult(QList& diceValuesList,boo } quint64 face=0; ListDiceResult listpair; - foreach(Die* die, diceResult->getResultList()) + for(Die* die : diceResult->getResultList()) { if(!die->hasBeenDisplayed()) { @@ -527,7 +527,7 @@ void DiceParser::getLastDiceResult(QList& diceValuesList,boo face = die->getFaces(); if(die->hasChildrenValue()) { - foreach(qint64 i, die->getListValue()) + for(qint64 i : die->getListValue()) { valuesResult.append(i); } @@ -633,6 +633,7 @@ QList DiceParser::getSumOfDiceResult() } resultValues << resultValue; } + return resultValues; } int DiceParser::getStartNodeCount() const { @@ -732,7 +733,7 @@ bool DiceParser::readDice(QString& str,ExecutionNode* & node) bool DiceParser::readDiceOperator(QString& str,DiceOperator& op) { QStringList listKey = m_mapDiceOp->keys(); - foreach(QString key, listKey) + for(const QString& key : listKey) { if(str.startsWith(key,Qt::CaseInsensitive)) { @@ -770,13 +771,13 @@ bool DiceParser::readDiceExpression(QString& str,ExecutionNode* & node) { bool returnVal=false; - ExecutionNode* next = NULL; + ExecutionNode* next = nullptr; if(readDice(str,next)) { ExecutionNode* latest = next; while(readOption(str,latest)) { - while(NULL!=latest->getNextNode()) + while(nullptr!=latest->getNextNode()) { latest = latest->getNextNode(); } @@ -828,8 +829,8 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous) { parent = nodeExecOrChild; nodeExecOrChild = nodeExecOrChild->getNextNode(); + //qDebug() << node->getPriority() << nodeExecOrChild->getPriority() << "###########"; } - // management of operator priority if((nullptr != nodeExecOrChild)&&(nodeExec != nodeExecOrChild)) { @@ -920,17 +921,23 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, { str=str.remove(0,tmp.size()); - // option = m_OptionOp->value(tmp); switch(m_OptionOp->value(tmp)) { case Keep: { + qDebug() << "keep " << previous->toString(true) << str; + if(str == "4+7") + { + qDebug() << "nauteanuit"; + } qint64 myNumber=0; bool ascending = m_parsingToolbox->readAscending(str); + if(m_parsingToolbox->readNumber(str,myNumber)) { node = m_parsingToolbox->addSort(previous,ascending); KeepDiceExecNode* nodeK = new KeepDiceExecNode(); + qDebug() << "nodeK " << previous->toString(true) << str; nodeK->setDiceKeepNumber(myNumber); node->setNextNode(nodeK); node = nodeK; @@ -949,7 +956,7 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, previous = addRollDiceNode(DEFAULT_FACES_NUMBER,previous); }*/ DiceRollerNode* nodeTmp = dynamic_cast(previous); - if(NULL!=nodeTmp) + if(nullptr!=nodeTmp) { previous = addExploseDiceNode(nodeTmp->getFaces(),previous); @@ -969,7 +976,7 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, case Filter: { Validator* validator = m_parsingToolbox->readCompositeValidator(str); - if(NULL!=validator) + if(nullptr!=validator) { m_parsingToolbox->isValidValidator(previous,validator); @@ -996,7 +1003,7 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, case Count: { Validator* validator = m_parsingToolbox->readCompositeValidator(str); - if(NULL!=validator) + if(nullptr!=validator) { m_parsingToolbox->isValidValidator(previous,validator); @@ -1017,7 +1024,7 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, case RerollAndAdd: { Validator* validator = m_parsingToolbox->readCompositeValidator(str); - if(NULL!=validator) + if(nullptr!=validator) { m_parsingToolbox->isValidValidator(previous,validator); RerollDiceNode* rerollNode = new RerollDiceNode(); @@ -1040,7 +1047,7 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, case Explosing: { Validator* validator = m_parsingToolbox->readCompositeValidator(str); - if(NULL!=validator) + if(nullptr!=validator) { if(!m_parsingToolbox->isValidValidator(previous,validator)) { @@ -1083,10 +1090,10 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, IfNode* nodeif = new IfNode(); nodeif->setConditionType(m_parsingToolbox->readConditionType(str)); Validator* validator = m_parsingToolbox->readCompositeValidator(str); - if(NULL!=validator) + if(nullptr!=validator) { - ExecutionNode* trueNode = NULL; - ExecutionNode* falseNode = NULL; + ExecutionNode* trueNode = nullptr; + ExecutionNode* falseNode = nullptr; if(readIfInstruction(str,trueNode,falseNode)) { nodeif->setInstructionTrue(trueNode); @@ -1153,7 +1160,7 @@ bool DiceParser::readBlocInstruction(QString& str,ExecutionNode*& resultnode) str=str.remove(0,1); ExecutionNode* node; Die::ArithmeticOperator op; - ScalarOperatorNode* scalarNode = NULL; + ScalarOperatorNode* scalarNode = nullptr; if(m_parsingToolbox->readArithmeticOperator(str,op)) { scalarNode = new ScalarOperatorNode(); @@ -1163,7 +1170,7 @@ bool DiceParser::readBlocInstruction(QString& str,ExecutionNode*& resultnode) { if(str.startsWith('}')) { - if(NULL==scalarNode) + if(nullptr==scalarNode) { resultnode = node; } diff --git a/irc/botircdiceparser.cpp b/irc/botircdiceparser.cpp index 44a3224..ce9bf3a 100644 --- a/irc/botircdiceparser.cpp +++ b/irc/botircdiceparser.cpp @@ -164,8 +164,7 @@ QString BotIrcDiceParser::diceToText(QList& diceList,bool hi { QStringList result; ListDiceResult diceResult = dice.value(face); - //patternColor = patternColorarg(); - foreach (HighLightDice tmp, diceResult) + for (const auto& tmp : diceResult) { QStringList diceListStr; QStringList diceListChildren; diff --git a/node/countexecutenode.cpp b/node/countexecutenode.cpp index 1f78fd2..de5e457 100644 --- a/node/countexecutenode.cpp +++ b/node/countexecutenode.cpp @@ -4,7 +4,7 @@ CountExecuteNode::CountExecuteNode() - : m_scalarResult(new ScalarResult()),m_validator(NULL) + : m_scalarResult(new ScalarResult()),m_validator(nullptr) { m_result = m_scalarResult; } @@ -14,7 +14,7 @@ void CountExecuteNode::setValidator(Validator* validator) } CountExecuteNode::~CountExecuteNode() { - if(NULL!=m_validator) + if(nullptr!=m_validator) { delete m_validator; } @@ -23,19 +23,19 @@ CountExecuteNode::~CountExecuteNode() void CountExecuteNode::run(ExecutionNode *previous) { m_previousNode = previous; - if(NULL==previous) + if(nullptr==previous) { return; } DiceResult* previousResult = dynamic_cast(previous->getResult()); - if(NULL!=previousResult) + if(nullptr!=previousResult) { m_result->setPrevious(previousResult); QList diceList=previousResult->getResultList(); qint64 sum = 0; - foreach(Die* dice,diceList) + for(Die* dice : diceList) { - if(NULL!=m_validator) + if(nullptr!=m_validator) { sum+=m_validator->hasValid(dice,true,true); } @@ -43,7 +43,7 @@ void CountExecuteNode::run(ExecutionNode *previous) m_scalarResult->setValue(sum); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -63,23 +63,21 @@ QString CountExecuteNode::toString(bool withlabel) const qint64 CountExecuteNode::getPriority() const { qint64 priority=0; - if(NULL!=m_nextNode) + if(nullptr!=m_previousNode) { - priority = m_nextNode->getPriority(); + priority = m_previousNode->getPriority(); } - - return priority; } ExecutionNode* CountExecuteNode::getCopy() const { CountExecuteNode* node = new CountExecuteNode(); - if(NULL!=m_validator) + if(nullptr!=m_validator) { node->setValidator(m_validator->getCopy()); } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/dicerollernode.cpp b/node/dicerollernode.cpp index 89ba24d..25b9d5a 100644 --- a/node/dicerollernode.cpp +++ b/node/dicerollernode.cpp @@ -17,10 +17,10 @@ DiceRollerNode::DiceRollerNode(qint64 max,qint64 min) void DiceRollerNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(NULL!=previous) + if(nullptr!=previous) { Result* result=previous->getResult(); - if(NULL!=result) + if(nullptr!=result) { m_diceCount = result->getResult(Result::SCALAR).toReal(); m_result->setPrevious(result); @@ -40,7 +40,7 @@ void DiceRollerNode::run(ExecutionNode* previous) //qDebug() << die->getValue() << "value"; m_diceResult->insertResult(die); } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -66,18 +66,16 @@ QString DiceRollerNode::toString(bool wl) const qint64 DiceRollerNode::getPriority() const { qint64 priority=4; -// if(NULL!=m_nextNode) +// if(nullptr!=m_nextNode) // { // priority = m_nextNode->getPriority(); // } - - return priority; } ExecutionNode* DiceRollerNode::getCopy() const { DiceRollerNode* node = new DiceRollerNode(m_max,m_min); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/executionnode.cpp b/node/executionnode.cpp index c8c62f2..94d0d46 100644 --- a/node/executionnode.cpp +++ b/node/executionnode.cpp @@ -3,21 +3,21 @@ #include ExecutionNode::ExecutionNode() - : m_previousNode(NULL),m_result(NULL),m_nextNode(NULL),m_errors(QMap()),m_id(QString("\"%1\"").arg(QUuid::createUuid().toString())) + : m_previousNode(nullptr),m_result(nullptr),m_nextNode(nullptr),m_errors(QMap()),m_id(QString("\"%1\"").arg(QUuid::createUuid().toString())) { } ExecutionNode::~ExecutionNode() { - if(NULL!=m_result) + if(nullptr!=m_result) { delete m_result; - m_result = NULL; + m_result = nullptr; } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { delete m_nextNode; - m_nextNode = NULL; + m_nextNode = nullptr; } } @@ -39,9 +39,9 @@ ExecutionNode* ExecutionNode::getNextNode() } QMap ExecutionNode::getExecutionErrorMap() { - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { - foreach (ExecutionNode::DICE_ERROR_CODE key, m_nextNode->getExecutionErrorMap().keys()) + for (const auto& key : m_nextNode->getExecutionErrorMap().keys()) { m_errors.insert(key,m_nextNode->getExecutionErrorMap().value(key)); } @@ -61,7 +61,7 @@ void ExecutionNode::generateDotTree(QString& s) s.append(toString(true)); s.append(";\n"); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { s.append(toString(false)); s.append(" -> "); @@ -74,8 +74,8 @@ void ExecutionNode::generateDotTree(QString& s) { s.append(toString(false)); s.append(" -> "); - s.append("NULL;\n"); - if(NULL!=m_result) + s.append("nullptr;\n"); + if(nullptr!=m_result) { s.append(toString(false)); diff --git a/node/executionnode.h b/node/executionnode.h index c57b8b1..4913b68 100644 --- a/node/executionnode.h +++ b/node/executionnode.h @@ -23,7 +23,7 @@ public: * @brief run * @param previous */ - virtual void run(ExecutionNode* previous = NULL)=0; + virtual void run(ExecutionNode* previous = nullptr)=0; /** * @brief getResult * @return diff --git a/node/explosedicenode.cpp b/node/explosedicenode.cpp index 51fc37e..bdde83b 100644 --- a/node/explosedicenode.cpp +++ b/node/explosedicenode.cpp @@ -1,20 +1,20 @@ #include "explosedicenode.h" ExploseDiceNode::ExploseDiceNode() - : m_diceResult(new DiceResult()),m_validator(NULL) + : m_diceResult(new DiceResult()),m_validator(nullptr) { m_result = m_diceResult; } void ExploseDiceNode::run(ExecutionNode* previous) { m_previousNode = previous; - if((NULL!=previous)&&(NULL!=previous->getResult())) + if((nullptr!=previous)&&(nullptr!=previous->getResult())) { DiceResult* previous_result = static_cast(previous->getResult()); m_result->setPrevious(previous_result); - if(NULL!=previous_result) + if(nullptr!=previous_result) { - foreach(Die* die,previous_result->getResultList()) + for(Die* die : previous_result->getResultList()) { Die* tmpdie = new Die(); *tmpdie=*die; @@ -25,7 +25,7 @@ void ExploseDiceNode::run(ExecutionNode* previous) QList list = m_diceResult->getResultList(); - foreach(Die* die, list) + for(Die* die : list) { while(m_validator->hasValid(die,false)) { @@ -34,7 +34,7 @@ void ExploseDiceNode::run(ExecutionNode* previous) } // m_diceResult->setResultList(list); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -43,7 +43,7 @@ void ExploseDiceNode::run(ExecutionNode* previous) } ExploseDiceNode::~ExploseDiceNode() { - if(NULL!=m_validator) + if(nullptr!=m_validator) { delete m_validator; } @@ -66,23 +66,21 @@ QString ExploseDiceNode::toString(bool withlabel) const qint64 ExploseDiceNode::getPriority() const { qint64 priority=0; - if(NULL!=m_nextNode) + if(nullptr!=m_previousNode) { - priority = m_nextNode->getPriority(); + priority = m_previousNode->getPriority(); } - - return priority; } ExecutionNode* ExploseDiceNode::getCopy() const { ExploseDiceNode* node = new ExploseDiceNode(); - if(NULL!=m_validator) + if(nullptr!=m_validator) { node->setValidator(m_validator->getCopy()); } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/explosedicenode.h b/node/explosedicenode.h index ceb35b8..6b582a3 100644 --- a/node/explosedicenode.h +++ b/node/explosedicenode.h @@ -14,7 +14,7 @@ class ExploseDiceNode : public ExecutionNode public: ExploseDiceNode(); virtual ~ExploseDiceNode(); - virtual void run(ExecutionNode* previous = NULL); + virtual void run(ExecutionNode* previous = nullptr); virtual void setValidator(Validator* ); virtual QString toString(bool )const; virtual qint64 getPriority() const; diff --git a/node/filternode.cpp b/node/filternode.cpp index 5cee9df..0be2e62 100644 --- a/node/filternode.cpp +++ b/node/filternode.cpp @@ -8,7 +8,7 @@ FilterNode::FilterNode() FilterNode::~FilterNode() { - if(NULL!=m_validator) + if(nullptr!=m_validator) { delete m_validator; } @@ -20,13 +20,13 @@ void FilterNode::setValidator(Validator* validator) void FilterNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(NULL==previous) + if(nullptr==previous) { return; } DiceResult* previousDiceResult = static_cast(previous->getResult()); m_result->setPrevious(previousDiceResult); - if(NULL!=previousDiceResult) + if(nullptr!=previousDiceResult) { QList diceList=previousDiceResult->getResultList(); QList diceList2; @@ -48,7 +48,7 @@ void FilterNode::run(ExecutionNode* previous) } m_diceResult->setResultList(diceList2); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -69,22 +69,20 @@ QString FilterNode::toString(bool wl) const qint64 FilterNode::getPriority() const { qint64 priority=0; - if(NULL!=m_nextNode) + if(nullptr!=m_previousNode) { - priority = m_nextNode->getPriority(); + priority = m_previousNode->getPriority(); } - - return priority; } ExecutionNode* FilterNode::getCopy() const { FilterNode* node = new FilterNode(); - if(NULL!=m_validator) + if(nullptr!=m_validator) { node->setValidator(m_validator->getCopy()); } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/helpnode.cpp b/node/helpnode.cpp index 4425969..bcd7aaf 100644 --- a/node/helpnode.cpp +++ b/node/helpnode.cpp @@ -30,9 +30,9 @@ void HelpNode::run(ExecutionNode* previous) StringResult* txtResult = dynamic_cast(m_result); txtResult->setHighLight(false); - if(NULL != previous) + if(nullptr != previous) { - if(previous->getResult() == NULL) + if(previous->getResult() == nullptr) { txtResult->setText(QObject::tr("Rolisteam Dice Parser:\nFull documentation at: %1").arg(m_path)); } @@ -43,7 +43,7 @@ void HelpNode::run(ExecutionNode* previous) m_result->setPrevious(previous->getResult()); } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -72,7 +72,7 @@ void HelpNode::setHelpPath(QString path) ExecutionNode* HelpNode::getCopy() const { HelpNode* node = new HelpNode(); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/ifnode.cpp b/node/ifnode.cpp index c32a6a9..b15e203 100644 --- a/node/ifnode.cpp +++ b/node/ifnode.cpp @@ -21,14 +21,14 @@ #include "result/diceresult.h" IfNode::IfNode() - : m_validator(NULL),m_true(NULL),m_false(NULL),m_conditionType(AllOfThem) + : m_validator(nullptr),m_true(nullptr),m_false(nullptr),m_conditionType(AllOfThem) { //m_result = new DiceResult(); } IfNode::~IfNode() { - m_result=NULL; + m_result=nullptr; } void IfNode::run(ExecutionNode *previous) @@ -60,7 +60,7 @@ void IfNode::run(ExecutionNode *previous) for(Die* dice : diceList) { if(m_validator->hasValid(dice,true,true)) - { + { nextNode = (nullptr==m_true) ? nullptr: m_true->getCopy(); } else @@ -104,29 +104,29 @@ void IfNode::run(ExecutionNode *previous) { if(oneIsTrue) { - nextNode = (NULL==m_true) ? NULL: m_true->getCopy(); + nextNode = (nullptr==m_true) ? nullptr: m_true->getCopy(); } else if(oneIsFalse) { - nextNode = (NULL==m_false) ? NULL: m_false->getCopy(); + nextNode = (nullptr==m_false) ? nullptr: m_false->getCopy(); } } else if(m_conditionType==AllOfThem) { if(trueForAll) { - nextNode = (NULL==m_true) ? NULL: m_true->getCopy(); + nextNode = (nullptr==m_true) ? nullptr: m_true->getCopy(); } else if(falseForAll) { - nextNode = (NULL==m_false) ? NULL: m_false->getCopy(); + nextNode = (nullptr==m_false) ? nullptr: m_false->getCopy(); } } - if(NULL!=nextNode) + if(nullptr!=nextNode) { - if(NULL==m_nextNode) + if(nullptr==m_nextNode) { m_nextNode = nextNode; } @@ -151,9 +151,9 @@ void IfNode::run(ExecutionNode *previous) { nextNode=m_false; } - if(NULL!=nextNode) + if(nullptr!=nextNode) { - if(NULL==m_nextNode) + if(nullptr==m_nextNode) { m_nextNode = nextNode; } @@ -163,7 +163,7 @@ void IfNode::run(ExecutionNode *previous) } } - if((NULL!=m_nextNode)&&(runNext)) + if((nullptr!=m_nextNode)&&(runNext)) { m_nextNode->run(previousLoop); } @@ -187,7 +187,7 @@ void IfNode::generateDotTree(QString& s) s.append(toString(true)); s.append(";\n"); - if((NULL!=m_true)&&(m_true != m_nextNode)) + if((nullptr!=m_true)&&(m_true != m_nextNode)) { s.append(toString(false)); s.append(" -> "); @@ -196,7 +196,7 @@ void IfNode::generateDotTree(QString& s) m_true->generateDotTree(s); } - if((NULL!=m_false)&&(m_false != m_nextNode)) + if((nullptr!=m_false)&&(m_false != m_nextNode)) { s.append(toString(false)); s.append(" -> "); @@ -205,7 +205,7 @@ void IfNode::generateDotTree(QString& s) m_false->generateDotTree(s); } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { s.append(toString(false)); s.append(" -> "); @@ -217,9 +217,9 @@ void IfNode::generateDotTree(QString& s) { s.append(toString(false)); s.append(" -> "); - s.append("NULL;\n"); + s.append("nullptr;\n"); - if(NULL!=m_result) + if(nullptr!=m_result) { s.append(toString(false)); @@ -245,13 +245,18 @@ QString IfNode::toString(bool wl) const qint64 IfNode::getPriority() const { - return 4; + qint64 priority=0; + if(nullptr != getPreviousNode()) + { + priority=getPreviousNode()->getPriority(); + } + return priority; } ExecutionNode* IfNode::getLeafNode(ExecutionNode* node) { ExecutionNode* next = node; - while(NULL != next->getNextNode() ) + while(nullptr != next->getNextNode() ) { next = next->getNextNode(); } @@ -270,19 +275,19 @@ void IfNode::setConditionType(const IfNode::ConditionType &conditionType) ExecutionNode* IfNode::getCopy() const { IfNode* node = new IfNode(); - if(NULL!=m_validator) + if(nullptr!=m_validator) { node->setValidator(m_validator->getCopy()); } - if(NULL!=m_false) + if(nullptr!=m_false) { node->setInstructionFalse(m_false->getCopy()); } - if(NULL!=m_true) + if(nullptr!=m_true) { node->setInstructionTrue(m_true->getCopy()); } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/ifnode.h b/node/ifnode.h index 7376101..9205000 100644 --- a/node/ifnode.h +++ b/node/ifnode.h @@ -47,7 +47,7 @@ public: * @brief run * @param previous */ - virtual void run(ExecutionNode* previous = NULL); + virtual void run(ExecutionNode* previous = nullptr); /** * @brief setValidator */ diff --git a/node/jumpbackwardnode.cpp b/node/jumpbackwardnode.cpp index b7af106..e860f99 100644 --- a/node/jumpbackwardnode.cpp +++ b/node/jumpbackwardnode.cpp @@ -23,8 +23,8 @@ JumpBackwardNode::JumpBackwardNode() { - m_previousNode=NULL; - m_backwardNode = NULL; + m_previousNode=nullptr; + m_backwardNode = nullptr; m_diceResult =new DiceResult(); m_result = m_diceResult; } @@ -51,7 +51,7 @@ void JumpBackwardNode::generateDotTree(QString& s) s.append(toString(true)); s.append(";\n"); - if(NULL!=m_backwardNode) + if(nullptr!=m_backwardNode) { s.append(toString(false)); s.append(" -> "); @@ -60,7 +60,7 @@ void JumpBackwardNode::generateDotTree(QString& s) //m_backwardNode->generateDotTree(s); } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { s.append(toString(false)); s.append(" -> "); @@ -72,9 +72,9 @@ void JumpBackwardNode::generateDotTree(QString& s) { s.append(toString(false)); s.append(" -> "); - s.append("NULL;\n"); + s.append("nullptr;\n"); - if(NULL!=m_result) + if(nullptr!=m_result) { s.append(toString(false)); s.append(" ->"); @@ -92,12 +92,12 @@ void JumpBackwardNode::run(ExecutionNode* previous) ExecutionNode* parent = previous; bool found=false; //int i = 3; - Result* result=NULL; - while((NULL!=parent)&&(!found)) + Result* result=nullptr; + while((nullptr!=parent)&&(!found)) { result = parent->getResult(); - if(NULL!=result) + if(nullptr!=result) { //--i; if(/*(i==0)&&*/(result->hasResultOfType(Result::DICE_LIST))) @@ -108,7 +108,7 @@ void JumpBackwardNode::run(ExecutionNode* previous) else { JumpBackwardNode* jpNode = dynamic_cast(parent); - if(NULL!=jpNode) + if(nullptr!=jpNode) { found = true; m_backwardNode = parent; @@ -121,16 +121,16 @@ void JumpBackwardNode::run(ExecutionNode* previous) } } - if(NULL==result) + if(nullptr==result) { m_errors.insert(DIE_RESULT_EXPECTED,QObject::tr(" The @ operator expects dice result. Please check the documentation to fix your command.")); } else { DiceResult* diceResult = dynamic_cast(result); - if(NULL!=diceResult) + if(nullptr!=diceResult) { - foreach(Die* die,diceResult->getResultList()) + for(Die* die : diceResult->getResultList()) { Die* tmpdie = new Die(); *tmpdie=*die; @@ -141,11 +141,11 @@ void JumpBackwardNode::run(ExecutionNode* previous) m_result->setPrevious(previous->getResult()); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } - if(NULL!=diceResult) + if(nullptr!=diceResult) { for(int i =0;igetResultList().size();++i) { @@ -163,7 +163,7 @@ void JumpBackwardNode::run(ExecutionNode* previous) ExecutionNode* JumpBackwardNode::getCopy() const { JumpBackwardNode* node = new JumpBackwardNode(); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/jumpbackwardnode.h b/node/jumpbackwardnode.h index cb87181..eda71f1 100644 --- a/node/jumpbackwardnode.h +++ b/node/jumpbackwardnode.h @@ -37,7 +37,7 @@ public: * @brief run - performs the actions * @param previous */ - virtual void run(ExecutionNode* previous = NULL); + virtual void run(ExecutionNode* previous = nullptr); /** * @brief toString diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp index d36abec..355a63a 100644 --- a/node/keepdiceexecnode.cpp +++ b/node/keepdiceexecnode.cpp @@ -36,20 +36,20 @@ KeepDiceExecNode::~KeepDiceExecNode() void KeepDiceExecNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(NULL==previous) + if(nullptr==previous) { return; } DiceResult* previousDiceResult = static_cast(previous->getResult()); m_result->setPrevious(previousDiceResult); - if(NULL!=previousDiceResult) + if(nullptr!=previousDiceResult) { QList diceList=previousDiceResult->getResultList(); QList diceList3= diceList.mid(0,m_numberOfDice); QList diceList2; - foreach(Die* die,diceList3) + for(Die* die:diceList3) { Die* tmpdie = new Die(); *tmpdie=*die; @@ -70,7 +70,7 @@ void KeepDiceExecNode::run(ExecutionNode* previous) } m_diceResult->setResultList(diceList2); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -94,12 +94,10 @@ QString KeepDiceExecNode::toString(bool wl) const qint64 KeepDiceExecNode::getPriority() const { qint64 priority=0; - if(NULL!=m_nextNode) + if(nullptr!=m_previousNode) { - priority = m_nextNode->getPriority(); + priority = m_previousNode->getPriority(); } - - return priority; } @@ -107,7 +105,7 @@ ExecutionNode* KeepDiceExecNode::getCopy() const { KeepDiceExecNode* node = new KeepDiceExecNode(); node->setDiceKeepNumber(m_numberOfDice); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/listaliasnode.cpp b/node/listaliasnode.cpp index 91644d4..4c9f9f2 100644 --- a/node/listaliasnode.cpp +++ b/node/listaliasnode.cpp @@ -31,9 +31,9 @@ void ListAliasNode::run(ExecutionNode* previous ) StringResult* txtResult = dynamic_cast(m_result); txtResult->setHighLight(false); - if(NULL != previous) + if(nullptr != previous) { - if(previous->getResult() == NULL) + if(previous->getResult() == nullptr) { txtResult->setText(buildList()); @@ -45,7 +45,7 @@ void ListAliasNode::run(ExecutionNode* previous ) m_result->setPrevious(previous->getResult()); } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -53,7 +53,7 @@ void ListAliasNode::run(ExecutionNode* previous ) QString ListAliasNode::buildList() const { QString result(QObject::tr("List of Alias:\n")); - foreach(DiceAlias* key, *m_aliasList) + for(DiceAlias* key : *m_aliasList) { result+=QString("%1 : %2\n").arg(key->getCommand()).arg(key->getValue()); } @@ -62,7 +62,7 @@ QString ListAliasNode::buildList() const QString ListAliasNode::toString(bool wl) const { QStringList resultList; - foreach(DiceAlias* key, *m_aliasList) + for(DiceAlias* key : *m_aliasList) { resultList << "{" <getCommand() << key->getValue()<< "}"; } @@ -84,7 +84,7 @@ qint64 ListAliasNode::getPriority() const ExecutionNode* ListAliasNode::getCopy() const { ListAliasNode* node = new ListAliasNode(m_aliasList); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/listaliasnode.h b/node/listaliasnode.h index 19212cd..493aa1e 100644 --- a/node/listaliasnode.h +++ b/node/listaliasnode.h @@ -36,7 +36,7 @@ public: * @brief run * @param previous */ - virtual void run(ExecutionNode* previous = NULL); + virtual void run(ExecutionNode* previous = nullptr); /** * @brief toString diff --git a/node/listsetrollnode.cpp b/node/listsetrollnode.cpp index 488721a..8f86332 100644 --- a/node/listsetrollnode.cpp +++ b/node/listsetrollnode.cpp @@ -28,10 +28,10 @@ ListSetRollNode::ListSetRollNode() } ListSetRollNode::~ListSetRollNode() { - if(NULL!=m_diceResult) + if(nullptr!=m_diceResult) { delete m_diceResult; - m_diceResult =NULL; + m_diceResult =nullptr; } } @@ -59,10 +59,10 @@ qint64 ListSetRollNode::getPriority() const void ListSetRollNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(NULL!=previous) + if(nullptr!=previous) { Result* result=previous->getResult(); - if(NULL!=result) + if(nullptr!=result) { quint64 diceCount = result->getResult(Result::SCALAR).toReal(); m_result->setPrevious(result); @@ -76,7 +76,7 @@ void ListSetRollNode::run(ExecutionNode* previous) getValueFromDie(die,rollResult); } m_stringResult->setText(rollResult.join(",")); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -106,7 +106,7 @@ void ListSetRollNode::computeFacesNumber(Die* die) Q_ASSERT(m_values.size() == m_rangeList.size()); qint64 max; int i=0; - foreach(Range range, m_rangeList) + for(Range range: m_rangeList) { if(((i==0)||(maxsetRangeList(dataList); node->setUnique(m_unique); node->setListValue(m_values); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/listsetrollnode.h b/node/listsetrollnode.h index c140d8d..2cc36f0 100644 --- a/node/listsetrollnode.h +++ b/node/listsetrollnode.h @@ -36,7 +36,7 @@ class ListSetRollNode : public ExecutionNode public: ListSetRollNode(); virtual ~ListSetRollNode(); - virtual void run(ExecutionNode* previous = NULL); + virtual void run(ExecutionNode* previous = nullptr); virtual QString toString(bool)const; virtual qint64 getPriority() const; QStringList getList() const; diff --git a/node/mergenode.cpp b/node/mergenode.cpp index 1cf6062..f2323df 100644 --- a/node/mergenode.cpp +++ b/node/mergenode.cpp @@ -99,7 +99,7 @@ QString MergeNode::toString(bool withLabel) const qint64 MergeNode::getPriority() const { qint64 priority=0; - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { priority = m_nextNode->getPriority(); } @@ -108,7 +108,7 @@ qint64 MergeNode::getPriority() const ExecutionNode* MergeNode::getCopy() const { MergeNode* node = new MergeNode(); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/numbernode.cpp b/node/numbernode.cpp index 5815ad6..26141c5 100644 --- a/node/numbernode.cpp +++ b/node/numbernode.cpp @@ -39,11 +39,11 @@ NumberNode::~NumberNode() void NumberNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(NULL!=previous) + if(nullptr!=previous) { m_result->setPrevious(previous->getResult()); } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -68,7 +68,7 @@ QString NumberNode::toString(bool withLabel) const qint64 NumberNode::getPriority() const { qint64 priority=0; - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { priority = m_nextNode->getPriority(); } @@ -80,7 +80,7 @@ ExecutionNode* NumberNode::getCopy() const { NumberNode* node = new NumberNode(); node->setNumber(m_number); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/paintnode.cpp b/node/paintnode.cpp index 5a85590..035334e 100644 --- a/node/paintnode.cpp +++ b/node/paintnode.cpp @@ -53,32 +53,32 @@ void ColorItem::setColor(const QString &color) PainterNode::PainterNode() : ExecutionNode() { - m_result = NULL; - m_nextNode = NULL; + m_result = nullptr; + m_nextNode = nullptr; } PainterNode::~PainterNode() { - m_result = NULL; + m_result = nullptr; } void PainterNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(NULL==previous) + if(nullptr==previous) { return; } Result* previousResult = previous->getResult(); //m_result = previousResult; DiceResult* previousDiceResult = dynamic_cast(previousResult); - if(NULL!=previousDiceResult) + if(nullptr!=previousDiceResult) { QList diceList=previousDiceResult->getResultList(); int pastDice=0; - foreach(ColorItem item, m_colors) + for(ColorItem item: m_colors) { int current=item.colorNumber(); QList::iterator it; @@ -90,7 +90,7 @@ void PainterNode::run(ExecutionNode* previous) } } } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(previous); } @@ -127,7 +127,7 @@ void PainterNode::insertColorItem(QString color, int value) ExecutionNode* PainterNode::getCopy() const { PainterNode* node = new PainterNode(); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/paintnode.h b/node/paintnode.h index ffd8ae1..3d45b9a 100644 --- a/node/paintnode.h +++ b/node/paintnode.h @@ -48,7 +48,7 @@ class PainterNode : public ExecutionNode public: PainterNode(); virtual ~PainterNode(); - virtual void run(ExecutionNode* previous = NULL); + virtual void run(ExecutionNode* previous = nullptr); Result* getResult(); virtual QString toString(bool )const; virtual qint64 getPriority() const; diff --git a/node/parenthesesnode.cpp b/node/parenthesesnode.cpp index 96c0bb7..5c0379f 100644 --- a/node/parenthesesnode.cpp +++ b/node/parenthesesnode.cpp @@ -22,7 +22,7 @@ #include "parenthesesnode.h" ParenthesesNode::ParenthesesNode() - : m_internalNode(NULL) + : m_internalNode(nullptr) { } @@ -32,12 +32,12 @@ void ParenthesesNode::setInternelNode(ExecutionNode* node) } void ParenthesesNode::run(ExecutionNode* /*previous*/) { - m_previousNode = NULL; - if(NULL!=m_internalNode) + m_previousNode = nullptr; + if(nullptr!=m_internalNode) { m_internalNode->run(this); ExecutionNode* temp=m_internalNode; - while(NULL!=temp->getNextNode()) + while(nullptr!=temp->getNextNode()) { temp=temp->getNextNode(); } @@ -45,7 +45,7 @@ void ParenthesesNode::run(ExecutionNode* /*previous*/) } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -69,11 +69,11 @@ qint64 ParenthesesNode::getPriority() const ExecutionNode* ParenthesesNode::getCopy() const { ParenthesesNode* node = new ParenthesesNode(); - if(NULL!=m_internalNode) + if(nullptr!=m_internalNode) { node->setInternelNode(m_internalNode->getCopy()); } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } @@ -96,7 +96,7 @@ void ParenthesesNode::generateDotTree(QString & s) } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { s.append(toString(false)); s.append(" -> "); @@ -109,8 +109,8 @@ void ParenthesesNode::generateDotTree(QString & s) { s.append(toString(false)); s.append(" -> "); - s.append("NULL;\n"); - if(NULL!=m_result) + s.append("nullptr;\n"); + if(nullptr!=m_result) { s.append(toString(false)); diff --git a/node/parenthesesnode.h b/node/parenthesesnode.h index 388f6db..5f841ab 100644 --- a/node/parenthesesnode.h +++ b/node/parenthesesnode.h @@ -31,7 +31,7 @@ class ParenthesesNode : public ExecutionNode { public: ParenthesesNode(); - virtual void run(ExecutionNode* previous = NULL); + virtual void run(ExecutionNode* previous = nullptr); void setInternelNode(ExecutionNode* node); virtual QString toString(bool)const; diff --git a/node/rerolldicenode.cpp b/node/rerolldicenode.cpp index dcce4aa..8e8be2c 100644 --- a/node/rerolldicenode.cpp +++ b/node/rerolldicenode.cpp @@ -2,28 +2,28 @@ RerollDiceNode::RerollDiceNode() - : m_diceResult(new DiceResult()),m_adding(false),m_validator(NULL) + : m_diceResult(new DiceResult()),m_adding(false),m_validator(nullptr) { m_result=m_diceResult; } RerollDiceNode::~RerollDiceNode() { - if(NULL!=m_validator) + if(nullptr!=m_validator) { delete m_validator; - m_validator = NULL; + m_validator = nullptr; } } void RerollDiceNode::run(ExecutionNode* previous) { m_previousNode = previous; - if((NULL!=previous)&&(NULL!=previous->getResult())) + if((nullptr!=previous)&&(nullptr!=previous->getResult())) { DiceResult* previous_result = static_cast(previous->getResult()); m_result->setPrevious(previous_result); - if(NULL!=previous_result) + if(nullptr!=previous_result) { - foreach(Die* die,previous_result->getResultList()) + for(Die* die : previous_result->getResultList()) { Die* tmpdie = new Die(); *tmpdie=*die; @@ -34,7 +34,7 @@ void RerollDiceNode::run(ExecutionNode* previous) QList list = m_diceResult->getResultList(); - foreach(Die* die, list) + for(Die* die: list) { if(m_validator->hasValid(die,false)) { @@ -42,7 +42,7 @@ void RerollDiceNode::run(ExecutionNode* previous) } } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -72,7 +72,7 @@ void RerollDiceNode::setAddingMode(bool b) qint64 RerollDiceNode::getPriority() const { qint64 priority=0; - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { priority = m_nextNode->getPriority(); } @@ -85,7 +85,7 @@ ExecutionNode* RerollDiceNode::getCopy() const RerollDiceNode* node = new RerollDiceNode(); node->setValidator(m_validator); node->setAddingMode(m_adding); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp index 9c86917..b85f23c 100644 --- a/node/scalaroperatornode.cpp +++ b/node/scalaroperatornode.cpp @@ -26,56 +26,49 @@ ScalarOperatorNode::ScalarOperatorNode() - : m_internalNode(NULL),m_scalarResult(new ScalarResult()),m_arithmeticOperator(Die::PLUS) + : m_internalNode(nullptr),m_scalarResult(new ScalarResult()),m_arithmeticOperator(Die::PLUS) { - /*m_scalarOperationList.insert('+',PLUS); - m_scalarOperationList.insert('-',MINUS); - m_scalarOperationList.insert('x',MULTIPLICATION); - m_scalarOperationList.insert('*',MULTIPLICATION); - m_scalarOperationList.insert('/',DIVIDE);*/ - m_result = m_scalarResult; } ScalarOperatorNode::~ScalarOperatorNode() { - if(NULL!=m_internalNode) - { - delete m_internalNode; - m_internalNode = NULL; - } + if(nullptr!=m_internalNode) + { + delete m_internalNode; + m_internalNode = nullptr; + } } void ScalarOperatorNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(NULL!=m_internalNode) + if(nullptr!=m_internalNode) { - m_internalNode->run(this); + m_internalNode->run(this); } - if(NULL!=previous) + if(nullptr!=previous) { DiceResult* previousResult = static_cast(previous->getResult()); - if(NULL!=previousResult) + if(nullptr!=previousResult) { ExecutionNode* internal = m_internalNode; - if(NULL != internal) + if(nullptr != internal) { - while(NULL != internal->getNextNode() ) - { + while(nullptr != internal->getNextNode() ) + { internal = internal->getNextNode(); - } - + } - Result* internalResult = internal->getResult(); - m_result->setPrevious(internalResult); - if(NULL!=m_internalNode->getResult()) - { - m_internalNode->getResult()->setPrevious(previousResult); - } + Result* internalResult = internal->getResult(); + m_result->setPrevious(internalResult); + if(nullptr!=m_internalNode->getResult()) + { + m_internalNode->getResult()->setPrevious(previousResult); + } - switch(m_arithmeticOperator) - { + switch(m_arithmeticOperator) + { case Die::PLUS: m_scalarResult->setValue(add(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); break; @@ -88,13 +81,16 @@ void ScalarOperatorNode::run(ExecutionNode* previous) case Die::DIVIDE: m_scalarResult->setValue(divide(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); break; + case Die::POWER: + m_scalarResult->setValue(power(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); + break; default: break; - } + } } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -102,15 +98,6 @@ void ScalarOperatorNode::run(ExecutionNode* previous) } } -/*bool ScalarOperatorNode::setOperatorChar(QChar c) -{ - if(m_scalarOperationList.contains(c)) - { - m_operator = m_scalarOperationList.value(c); - return true; - } - return false; -}*/ void ScalarOperatorNode::setInternalNode(ExecutionNode* node) { @@ -133,10 +120,14 @@ qreal ScalarOperatorNode::divide(qint64 a,qint64 b) } return (qreal)a/b; } -qint64 ScalarOperatorNode::multiple(qint64 a,qint64 b) +qint64 ScalarOperatorNode::multiple(qint64 a, qint64 b) { return a*b; } +qint64 ScalarOperatorNode::power(qint64 a, qint64 b) +{ + return std::pow(a,b); +} Die::ArithmeticOperator ScalarOperatorNode::getArithmeticOperator() const { return m_arithmeticOperator; @@ -157,64 +148,71 @@ QString ScalarOperatorNode::toString(bool wl) const break; case Die::MINUS: op="-"; - break; - case Die::MULTIPLICATION: - op="*"; - break; - case Die::DIVIDE: - op="/"; - break; - default: - break; + break; + case Die::MULTIPLICATION: + op="*"; + break; + case Die::DIVIDE: + op="/"; + break; + case Die::POWER: + op="^"; + break; + default: + break; } - if(wl) - { - return QString("%1 [label=\"ScalarOperatorNode %2\"]").arg(m_id).arg(op); - } - else - { - return m_id; - } + if(wl) + { + return QString("%1 [label=\"ScalarOperatorNode %2\"]").arg(m_id).arg(op); + } + else + { + return m_id; + } } qint64 ScalarOperatorNode::getPriority() const { if((m_arithmeticOperator==Die::PLUS)||(m_arithmeticOperator==Die::MINUS)) - { + { return 1; - } - else - { + } + else if((m_arithmeticOperator==Die::MULTIPLICATION)||(m_arithmeticOperator==Die::DIVIDE)) + { return 2; - } + } + else + { + return 3; + } } void ScalarOperatorNode::generateDotTree(QString& s) { - s.append(toString(true)); - s.append(";\n"); + s.append(toString(true)); + s.append(";\n"); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { - s.append(toString(false)); + s.append(toString(false)); s.append(" -> "); - s.append(m_nextNode->toString(false)); + s.append(m_nextNode->toString(false)); s.append("[label=\"nextNode\"];\n"); m_nextNode->generateDotTree(s); } else { - s.append(toString(false)); + s.append(toString(false)); s.append(" -> "); - s.append("NULL"); - s.append(" [label=\"nextNode\"];\n"); + s.append("nullptr"); + s.append(" [label=\"nextNode\"];\n"); } QString str; str.append("\n"); - if(NULL!=m_internalNode) + if(nullptr!=m_internalNode) { - str.append(toString(false)); + str.append(toString(false)); str.append(" -> "); - str.append(m_internalNode->toString(false)); + str.append(m_internalNode->toString(false)); str.append(" [label=\"internalNode\"];\n"); m_internalNode->generateDotTree(str); } @@ -222,14 +220,14 @@ void ScalarOperatorNode::generateDotTree(QString& s) } QMap ScalarOperatorNode::getExecutionErrorMap() { - if(NULL!=m_internalNode) + if(nullptr!=m_internalNode) { for (ExecutionNode::DICE_ERROR_CODE key: m_internalNode->getExecutionErrorMap().keys()) { m_errors.insert(key,m_internalNode->getExecutionErrorMap().value(key)); } } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { for (ExecutionNode::DICE_ERROR_CODE key: m_nextNode->getExecutionErrorMap().keys()) { @@ -243,7 +241,7 @@ ExecutionNode* ScalarOperatorNode::getCopy() const ScalarOperatorNode* node = new ScalarOperatorNode(); node->setInternalNode(m_internalNode->getCopy()); node->setArithmeticOperator(m_arithmeticOperator); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/scalaroperatornode.h b/node/scalaroperatornode.h index 0855a4c..7753a6f 100644 --- a/node/scalaroperatornode.h +++ b/node/scalaroperatornode.h @@ -115,6 +115,11 @@ private: * @return */ static qint64 multiple(qint64,qint64); + /** + * @brief power + * @return + */ + static qint64 power(qint64,qint64); private: ExecutionNode* m_internalNode; diff --git a/node/sortresult.cpp b/node/sortresult.cpp index d864aa2..e3d8d1e 100644 --- a/node/sortresult.cpp +++ b/node/sortresult.cpp @@ -34,13 +34,13 @@ SortResultNode::SortResultNode() void SortResultNode::run(ExecutionNode* node) { m_previousNode = node; - if(NULL==node) + if(nullptr==node) { return; } DiceResult* previousDiceResult = dynamic_cast(node->getResult()); m_diceResult->setPrevious(previousDiceResult); - if(NULL!=previousDiceResult) + if(nullptr!=previousDiceResult) { QList diceList=previousDiceResult->getResultList(); QList diceList2=m_diceResult->getResultList(); @@ -57,7 +57,7 @@ void SortResultNode::run(ExecutionNode* node) bool found = false; int start = 0; int end = diceList2.size(); - Die* tmp2 = NULL; + Die* tmp2 = nullptr; while(!found) { int distance = end-start; @@ -92,7 +92,7 @@ void SortResultNode::run(ExecutionNode* node) } m_diceResult->setResultList(diceList2); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -123,22 +123,19 @@ QString SortResultNode::toString(bool wl) const qint64 SortResultNode::getPriority() const { qint64 priority=0; - if(NULL!=m_nextNode) + if(nullptr != m_previousNode) { - priority = m_nextNode->getPriority(); + priority = m_previousNode->getPriority(); } - - return priority; } ExecutionNode* SortResultNode::getCopy() const { SortResultNode* node = new SortResultNode(); node->setSortAscending(m_ascending); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; - } diff --git a/node/splitnode.cpp b/node/splitnode.cpp index a074248..ed32fdd 100644 --- a/node/splitnode.cpp +++ b/node/splitnode.cpp @@ -29,7 +29,7 @@ SplitNode::SplitNode() void SplitNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(NULL!=previous) + if(nullptr!=previous) { m_result->setPrevious(previous->getResult()); @@ -56,7 +56,7 @@ void SplitNode::run(ExecutionNode* previous) } } } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -76,7 +76,7 @@ QString SplitNode::toString(bool withLabel) const qint64 SplitNode::getPriority() const { qint64 priority=0; - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { priority = m_nextNode->getPriority(); } @@ -85,7 +85,7 @@ qint64 SplitNode::getPriority() const ExecutionNode* SplitNode::getCopy() const { SplitNode* node = new SplitNode(); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/startingnode.cpp b/node/startingnode.cpp index 3cd3352..3b0d660 100644 --- a/node/startingnode.cpp +++ b/node/startingnode.cpp @@ -22,12 +22,11 @@ StartingNode::StartingNode() { - + m_previousNode = nullptr; } void StartingNode::run(ExecutionNode*) { - m_previousNode = NULL; - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -48,7 +47,7 @@ QString StartingNode::toString(bool withlabel) const qint64 StartingNode::getPriority() const { qint64 priority=0; - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { priority = m_nextNode->getPriority(); } @@ -57,7 +56,7 @@ qint64 StartingNode::getPriority() const ExecutionNode* StartingNode::getCopy() const { StartingNode* node = new StartingNode(); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/stringnode.cpp b/node/stringnode.cpp index d427cd6..af2fcda 100644 --- a/node/stringnode.cpp +++ b/node/stringnode.cpp @@ -9,11 +9,11 @@ StringNode::StringNode() void StringNode::run(ExecutionNode *previous) { m_previousNode = previous; - if(NULL!=previous) + if(nullptr!=previous) { m_result->setPrevious(previous->getResult()); } - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { m_nextNode->run(this); } @@ -111,7 +111,7 @@ QString StringNode::toString(bool withLabel) const qint64 StringNode::getPriority() const { qint64 priority=0; - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { priority = m_nextNode->getPriority(); } @@ -121,7 +121,7 @@ ExecutionNode* StringNode::getCopy() const { StringNode* node = new StringNode(); node->setString(m_data); - if(NULL!=m_nextNode) + if(nullptr!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/operationcondition.cpp b/operationcondition.cpp index 6664c83..220e810 100644 --- a/operationcondition.cpp +++ b/operationcondition.cpp @@ -21,7 +21,7 @@ #include "operationcondition.h" OperationCondition::OperationCondition() - : m_operator(Modulo),m_boolean(NULL),m_value(0) + : m_operator(Modulo),m_boolean(nullptr),m_value(0) { } diff --git a/range.cpp b/range.cpp index 39a46ce..081e253 100644 --- a/range.cpp +++ b/range.cpp @@ -41,7 +41,7 @@ qint64 Range::hasValid(Die* m,bool recursive, bool unhighlight) const qint64 result = 0; if(recursive) { - foreach(qint64 value, m->getListValue()) + for(qint64 value: m->getListValue()) { if((value>=m_start)&&(value<=m_end)) { diff --git a/result/diceresult.cpp b/result/diceresult.cpp index ddedd1c..dd624e9 100644 --- a/result/diceresult.cpp +++ b/result/diceresult.cpp @@ -143,7 +143,7 @@ void DiceResult::setOperator(const Die::ArithmeticOperator& dieOperator) QString DiceResult::toString(bool wl) { QStringList scalarSum; - foreach(Die* die,m_diceValues) + for(Die* die:m_diceValues) { scalarSum << QString::number(die->getValue()); } diff --git a/result/result.cpp b/result/result.cpp index 6e1ea7a..f79e004 100644 --- a/result/result.cpp +++ b/result/result.cpp @@ -23,7 +23,7 @@ #include Result::Result() - : m_resultTypes(NONE),m_id(QString("\"%1\"").arg(QUuid::createUuid().toString())),m_previous(NULL) + : m_resultTypes(NONE),m_id(QString("\"%1\"").arg(QUuid::createUuid().toString())),m_previous(nullptr) { } Result::~Result() @@ -55,7 +55,7 @@ void Result::generateDotTree(QString& s) s.append(toString(true)); s.append(";\n"); - if(NULL!=m_previous) + if(nullptr!=m_previous) { s.append(toString(false)); s.append(" -> "); @@ -67,7 +67,7 @@ void Result::generateDotTree(QString& s) { s.append(toString(false)); s.append(" -> "); - s.append("NULL"); + s.append("nullptr"); s.append(" [label=\"previousResult\"];\n"); } -- cgit v1.2.3-70-g09d2 From 7fef6c54191ba5a57f896e8d019edb5f4898694a Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sun, 29 Oct 2017 03:30:34 +0100 Subject: -add pow --- die.h | 4 ++-- parsingtoolbox.cpp | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/die.h b/die.h index 7f5cf44..c048ee6 100644 --- a/die.h +++ b/die.h @@ -34,7 +34,7 @@ public: /** * @brief The ArithmeticOperator enum */ - enum ArithmeticOperator {PLUS,MINUS,DIVIDE,MULTIPLICATION}; + enum ArithmeticOperator {PLUS,MINUS,DIVIDE,MULTIPLICATION,POWER}; /** * @brief Die */ @@ -154,6 +154,6 @@ private: std::mt19937 m_rng; }; - +Q_DECLARE_TYPEINFO(Die,Q_MOVABLE_TYPE); #endif // DIE_H diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index eba0807..a5a9920 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -25,7 +25,7 @@ #include "node/sortresult.h" -QHash* ParsingToolBox::m_variableHash = NULL; +QHash* ParsingToolBox::m_variableHash = nullptr; ParsingToolBox::ParsingToolBox() : m_logicOp(new QMap()), @@ -58,6 +58,7 @@ ParsingToolBox::ParsingToolBox() m_arithmeticOperation->insert(QStringLiteral("x"),Die::MULTIPLICATION); m_arithmeticOperation->insert(QStringLiteral("/"),Die::DIVIDE); m_arithmeticOperation->insert(QStringLiteral("÷"),Die::DIVIDE); + m_arithmeticOperation->insert(QStringLiteral("^"),Die::POWER); } @@ -67,10 +68,10 @@ ParsingToolBox::ParsingToolBox(const ParsingToolBox& data) } ParsingToolBox::~ParsingToolBox() { - if(NULL!=m_logicOp) + if(nullptr!=m_logicOp) { delete m_logicOp; - m_logicOp = NULL; + m_logicOp = nullptr; } if(nullptr != m_logicOperation) { @@ -98,7 +99,7 @@ ExecutionNode* ParsingToolBox::addSort(ExecutionNode* e,bool b) bool ParsingToolBox::readDiceLogicOperator(QString& str,OperationCondition::ConditionOperator& op) { QString longKey; - foreach(QString tmp, m_conditionOperation->keys()) + for(const QString& tmp: m_conditionOperation->keys()) { if(str.startsWith(tmp)) { @@ -138,7 +139,7 @@ bool ParsingToolBox::readArithmeticOperator(QString &str, Die::ArithmeticOperato bool ParsingToolBox::readLogicOperator(QString& str,BooleanCondition::LogicOperator& op) { QString longKey; - foreach(QString tmp, m_logicOp->keys()) + for(const QString& tmp: m_logicOp->keys()) { if(str.startsWith(tmp)) { @@ -159,7 +160,7 @@ bool ParsingToolBox::readLogicOperator(QString& str,BooleanCondition::LogicOpera } Validator* ParsingToolBox::readValidator(QString& str) { - Validator* returnVal=NULL; + Validator* returnVal=nullptr; BooleanCondition::LogicOperator myLogicOp = BooleanCondition::Equal; readLogicOperator(str,myLogicOp); @@ -176,7 +177,7 @@ Validator* ParsingToolBox::readValidator(QString& str) condition->setValue(value); Validator* valid = readValidator(str); BooleanCondition* boolC = dynamic_cast(valid); - if(NULL!=boolC) + if(nullptr!=boolC) { condition->setBoolean(boolC); } @@ -295,7 +296,7 @@ Validator* ParsingToolBox::readCompositeValidator(QString& str) bool ParsingToolBox::readLogicOperation(QString& str,CompositeValidator::LogicOperation& op) { QString longKey; - foreach(QString tmp, m_logicOperation->keys()) + for(const QString& tmp: m_logicOperation->keys()) { if(str.startsWith(tmp)) { @@ -569,7 +570,7 @@ void ParsingToolBox::readPainterParameter(PainterNode* painter,QString& str) QString data = str.left(pos); str=str.remove(0,pos+1); QStringList duos = data.split(','); - foreach(QString duoStr,duos) + for(const QString& duoStr : duos) { QStringList keyValu = duoStr.split(':'); if(keyValu.size()==2) -- cgit v1.2.3-70-g09d2 From bbc6f032bf8f182e6e4e97c7afddf47a3fb8a911 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 3 Nov 2017 01:24:40 +0100 Subject: add separator node --- node/separatornode.cpp | 0 node/separatornode.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 node/separatornode.cpp create mode 100644 node/separatornode.h diff --git a/node/separatornode.cpp b/node/separatornode.cpp new file mode 100644 index 0000000..e69de29 diff --git a/node/separatornode.h b/node/separatornode.h new file mode 100644 index 0000000..0820429 --- /dev/null +++ b/node/separatornode.h @@ -0,0 +1,44 @@ +/*************************************************************************** +* Copyright (C) 2017 by Renaud Guezennec * +* http://www.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 SEPARATORNODE_H +#define SEPARATORNODE_H + +#include "node/executionnode.h" +#include "result/diceresult.h" + +/** + * @brief The MergeNode class is an ExecutionNode. It is dedicated to merge result of several commands. + */ +class SeparatorNode : public ExecutionNode +{ +public: + SeparatorNode(); + void run(ExecutionNode* previous); + virtual QString toString(bool withLabel)const; + virtual qint64 getPriority() const; + virtual ExecutionNode *getCopy() const; +private: + DiceResult* m_diceResult; + ExecutionNode* m_; +}; + +#endif // SEPARATORNODE_H -- cgit v1.2.3-70-g09d2