aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--HelpMe.md88
-rw-r--r--README.md24
-rw-r--r--booleancondition.cpp2
-rw-r--r--cli/main.cpp2
-rw-r--r--compositevalidator.cpp2
-rw-r--r--diceparser.cpp29
-rw-r--r--die.h4
-rw-r--r--irc/botircdiceparser.cpp3
-rw-r--r--node/countexecutenode.cpp18
-rw-r--r--node/dicerollernode.cpp2
-rw-r--r--node/executionnode.cpp2
-rw-r--r--node/explosedicenode.cpp16
-rw-r--r--node/filternode.cpp14
-rw-r--r--node/ifnode.cpp9
-rw-r--r--node/jumpbackwardnode.cpp2
-rw-r--r--node/keepdiceexecnode.cpp10
-rw-r--r--node/listaliasnode.cpp4
-rw-r--r--node/listsetrollnode.cpp4
-rw-r--r--node/paintnode.cpp2
-rw-r--r--node/rerolldicenode.cpp4
-rw-r--r--node/scalaroperatornode.cpp49
-rw-r--r--node/scalaroperatornode.h5
-rw-r--r--node/separatornode.cpp0
-rw-r--r--node/separatornode.h44
-rw-r--r--node/sortresult.cpp8
-rw-r--r--node/startingnode.cpp5
-rw-r--r--parsingtoolbox.cpp9
-rw-r--r--range.cpp2
-rw-r--r--result/diceresult.cpp2
29 files changed, 243 insertions, 122 deletions
diff --git a/HelpMe.md b/HelpMe.md
index 4db864e..d2570e0 100644
--- a/HelpMe.md
+++ b/HelpMe.md
@@ -1,22 +1,43 @@
[![Logo](https://raw.githubusercontent.com/Rolisteam/rolisteam/master/resources/logo/1000-rolisteam.png)](http://www.rolisteam.org)
# Documentation:
-## Build
+## DiceParser : What is it ?
-```
-git clone git@github.com:Rolisteam/DiceParser.git
-cd DiceParser
-mkdir build
-cd build
-cmake ../
-make
-make install
-```
+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
-## Irc and Chat
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 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
It is real simple. you have to call:
@@ -56,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
@@ -183,10 +205,17 @@ 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.
+
+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:
@@ -206,11 +235,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"}
-> 2d10i:[>15]{"Success"}
+if the sum of two dice is greater than 15, It displays "Success", override it displays "Fail".
-if the sum of two dice is greater than 15, It displays "Success".
+> 2d10i:[>15]{"Success %1 "}{"Fail %1"}
+Same as above, but the final result is displayed beside Success or Fail.
+
+> 2d10i:[>15]{"Success %1 [%2]"}{"Fail %1 [%2]"}
+
+Same as above, but the result of each die is displayed inside square brackets.
## Arithmetic
@@ -262,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 `;`
@@ -279,7 +319,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
@@ -369,3 +409,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.
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
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<ExportedDiceResult>& 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 4689678..9023460 100644
--- a/compositevalidator.cpp
+++ b/compositevalidator.cpp
@@ -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 e57a93c..8838171 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -152,7 +152,6 @@ void DiceParser::insertAlias(DiceAlias* dice, int i)
{
m_aliasList->insert(i, dice);
}
-
}
bool DiceParser::parseLine(QString str)
@@ -190,9 +189,10 @@ 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;
}
@@ -335,7 +335,7 @@ QString DiceParser::displayResult()
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);
}
@@ -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);
@@ -517,7 +517,7 @@ void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& 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<ExportedDiceResult>& 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<qreal> 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))
{
@@ -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;
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/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<ExportedDiceResult>& 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 84946df..ca2c599 100644
--- a/node/countexecutenode.cpp
+++ b/node/countexecutenode.cpp
@@ -4,7 +4,7 @@
CountExecuteNode::CountExecuteNode()
- : m_scalarResult(new ScalarResult()),m_validator(nullptr)
+ : m_scalarResult(new ScalarResult()),m_validator(nullptr)
{
m_result = m_scalarResult;
}
@@ -14,7 +14,7 @@ void CountExecuteNode::setValidator(Validator* validator)
}
CountExecuteNode::~CountExecuteNode()
{
- if(nullptr!=m_validator)
+ if(nullptr!=m_validator)
{
delete m_validator;
}
@@ -23,19 +23,19 @@ CountExecuteNode::~CountExecuteNode()
void CountExecuteNode::run(ExecutionNode *previous)
{
m_previousNode = previous;
- if(nullptr==previous)
+ if(nullptr==previous)
{
return;
}
DiceResult* previousResult = dynamic_cast<DiceResult*>(previous->getResult());
- if(nullptr!=previousResult)
+ if(NULL!=previousResult)
{
m_result->setPrevious(previousResult);
QList<Die*> diceList=previousResult->getResultList();
qint64 sum = 0;
foreach(Die* dice,diceList)
{
- if(nullptr!=m_validator)
+ if(NULL!=m_validator)
{
sum+=m_validator->hasValid(dice,true,true);
}
@@ -43,7 +43,7 @@ void CountExecuteNode::run(ExecutionNode *previous)
m_scalarResult->setValue(sum);
- if(nullptr!=m_nextNode)
+ if(nullptr!=m_nextNode)
{
m_nextNode->run(this);
}
@@ -63,7 +63,7 @@ QString CountExecuteNode::toString(bool withlabel) const
qint64 CountExecuteNode::getPriority() const
{
qint64 priority=0;
- if(nullptr!=m_nextNode)
+ if(nullptr!=m_previousNode)
{
priority = m_nextNode->getPriority();
}
@@ -75,11 +75,11 @@ qint64 CountExecuteNode::getPriority() const
ExecutionNode* CountExecuteNode::getCopy() const
{
CountExecuteNode* node = new CountExecuteNode();
- if(nullptr!=m_validator)
+ if(NULL!=m_validator)
{
node->setValidator(m_validator->getCopy());
}
- if(nullptr!=m_nextNode)
+ if(NULL!=m_nextNode)
{
node->setNextNode(m_nextNode->getCopy());
}
diff --git a/node/dicerollernode.cpp b/node/dicerollernode.cpp
index b6db419..25b9d5a 100644
--- a/node/dicerollernode.cpp
+++ b/node/dicerollernode.cpp
@@ -70,8 +70,6 @@ qint64 DiceRollerNode::getPriority() const
// {
// priority = m_nextNode->getPriority();
// }
-
-
return priority;
}
ExecutionNode* DiceRollerNode::getCopy() const
diff --git a/node/executionnode.cpp b/node/executionnode.cpp
index 84aa17c..94d0d46 100644
--- a/node/executionnode.cpp
+++ b/node/executionnode.cpp
@@ -41,7 +41,7 @@ QMap<ExecutionNode::DICE_ERROR_CODE,QString> ExecutionNode::getExecutionErrorMap
{
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));
}
diff --git a/node/explosedicenode.cpp b/node/explosedicenode.cpp
index 96caaeb..81e80ee 100644
--- a/node/explosedicenode.cpp
+++ b/node/explosedicenode.cpp
@@ -1,18 +1,18 @@
#include "explosedicenode.h"
ExploseDiceNode::ExploseDiceNode()
- : m_diceResult(new DiceResult()),m_validator(nullptr)
+ : m_diceResult(new DiceResult()),m_validator(nullptr)
{
m_result = m_diceResult;
}
void ExploseDiceNode::run(ExecutionNode* previous)
{
m_previousNode = previous;
- if((nullptr!=previous)&&(nullptr!=previous->getResult()))
+ if((NULL!=previous)&&(NULL!=previous->getResult()))
{
DiceResult* previous_result = static_cast<DiceResult*>(previous->getResult());
m_result->setPrevious(previous_result);
- if(nullptr!=previous_result)
+ if(NULL!=previous_result)
{
foreach(Die* die,previous_result->getResultList())
{
@@ -34,7 +34,7 @@ void ExploseDiceNode::run(ExecutionNode* previous)
}
// m_diceResult->setResultList(list);
- if(nullptr!=m_nextNode)
+ if(NULL!=m_nextNode)
{
m_nextNode->run(this);
}
@@ -43,7 +43,7 @@ void ExploseDiceNode::run(ExecutionNode* previous)
}
ExploseDiceNode::~ExploseDiceNode()
{
- if(nullptr!=m_validator)
+ if(nullptr!=m_validator)
{
delete m_validator;
}
@@ -66,7 +66,7 @@ QString ExploseDiceNode::toString(bool withlabel) const
qint64 ExploseDiceNode::getPriority() const
{
qint64 priority=0;
- if(nullptr!=m_nextNode)
+ if(nullptr!=m_previousNode)
{
priority = m_nextNode->getPriority();
}
@@ -78,11 +78,11 @@ qint64 ExploseDiceNode::getPriority() const
ExecutionNode* ExploseDiceNode::getCopy() const
{
ExploseDiceNode* node = new ExploseDiceNode();
- if(nullptr!=m_validator)
+ if(NULL!=m_validator)
{
node->setValidator(m_validator->getCopy());
}
- if(nullptr!=m_nextNode)
+ if(NULL!=m_nextNode)
{
node->setNextNode(m_nextNode->getCopy());
}
diff --git a/node/filternode.cpp b/node/filternode.cpp
index 462774b..5153c79 100644
--- a/node/filternode.cpp
+++ b/node/filternode.cpp
@@ -8,7 +8,7 @@ FilterNode::FilterNode()
FilterNode::~FilterNode()
{
- if(nullptr!=m_validator)
+ if(NULL!=m_validator)
{
delete m_validator;
}
@@ -20,13 +20,13 @@ void FilterNode::setValidator(Validator* validator)
void FilterNode::run(ExecutionNode* previous)
{
m_previousNode = previous;
- if(nullptr==previous)
+ if(NULL==previous)
{
return;
}
DiceResult* previousDiceResult = static_cast<DiceResult*>(previous->getResult());
m_result->setPrevious(previousDiceResult);
- if(nullptr!=previousDiceResult)
+ if(NULL!=previousDiceResult)
{
QList<Die*> diceList=previousDiceResult->getResultList();
QList<Die*> diceList2;
@@ -48,7 +48,7 @@ void FilterNode::run(ExecutionNode* previous)
}
m_diceResult->setResultList(diceList2);
- if(nullptr!=m_nextNode)
+ if(NULL!=m_nextNode)
{
m_nextNode->run(this);
}
@@ -69,7 +69,7 @@ QString FilterNode::toString(bool wl) const
qint64 FilterNode::getPriority() const
{
qint64 priority=0;
- if(nullptr!=m_nextNode)
+ if(nullptr!=m_previousNode)
{
priority = m_nextNode->getPriority();
}
@@ -80,11 +80,11 @@ qint64 FilterNode::getPriority() const
ExecutionNode* FilterNode::getCopy() const
{
FilterNode* node = new FilterNode();
- if(nullptr!=m_validator)
+ if(NULL!=m_validator)
{
node->setValidator(m_validator->getCopy());
}
- if(nullptr!=m_nextNode)
+ if(NULL!=m_nextNode)
{
node->setNextNode(m_nextNode->getCopy());
}
diff --git a/node/ifnode.cpp b/node/ifnode.cpp
index b40ed82..b15e203 100644
--- a/node/ifnode.cpp
+++ b/node/ifnode.cpp
@@ -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
@@ -245,7 +245,12 @@ 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)
diff --git a/node/jumpbackwardnode.cpp b/node/jumpbackwardnode.cpp
index 1309b3b..e860f99 100644
--- a/node/jumpbackwardnode.cpp
+++ b/node/jumpbackwardnode.cpp
@@ -130,7 +130,7 @@ void JumpBackwardNode::run(ExecutionNode* previous)
DiceResult* diceResult = dynamic_cast<DiceResult*>(result);
if(nullptr!=diceResult)
{
- foreach(Die* die,diceResult->getResultList())
+ for(Die* die : diceResult->getResultList())
{
Die* tmpdie = new Die();
*tmpdie=*die;
diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp
index a93cc11..6167632 100644
--- a/node/keepdiceexecnode.cpp
+++ b/node/keepdiceexecnode.cpp
@@ -36,13 +36,13 @@ KeepDiceExecNode::~KeepDiceExecNode()
void KeepDiceExecNode::run(ExecutionNode* previous)
{
m_previousNode = previous;
- if(nullptr==previous)
+ if(NULL==previous)
{
return;
}
DiceResult* previousDiceResult = static_cast<DiceResult*>(previous->getResult());
m_result->setPrevious(previousDiceResult);
- if(nullptr!=previousDiceResult)
+ if(NULL!=previousDiceResult)
{
QList<Die*> diceList=previousDiceResult->getResultList();
@@ -70,7 +70,7 @@ void KeepDiceExecNode::run(ExecutionNode* previous)
}
m_diceResult->setResultList(diceList2);
- if(nullptr!=m_nextNode)
+ if(NULL!=m_nextNode)
{
m_nextNode->run(this);
}
@@ -94,7 +94,7 @@ QString KeepDiceExecNode::toString(bool wl) const
qint64 KeepDiceExecNode::getPriority() const
{
qint64 priority=0;
- if(nullptr!=m_nextNode)
+ if(nullptr!=m_previousNode)
{
priority = m_nextNode->getPriority();
}
@@ -107,7 +107,7 @@ ExecutionNode* KeepDiceExecNode::getCopy() const
{
KeepDiceExecNode* node = new KeepDiceExecNode();
node->setDiceKeepNumber(m_numberOfDice);
- if(nullptr!=m_nextNode)
+ if(NULL!=m_nextNode)
{
node->setNextNode(m_nextNode->getCopy());
}
diff --git a/node/listaliasnode.cpp b/node/listaliasnode.cpp
index 642f601..4c9f9f2 100644
--- a/node/listaliasnode.cpp
+++ b/node/listaliasnode.cpp
@@ -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 << "{" <<key->getCommand() << key->getValue()<< "}";
}
diff --git a/node/listsetrollnode.cpp b/node/listsetrollnode.cpp
index 21d5403..8f86332 100644
--- a/node/listsetrollnode.cpp
+++ b/node/listsetrollnode.cpp
@@ -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)||(max<range.getEnd()))&&(range.isFullyDefined()))
{
@@ -133,7 +133,7 @@ void ListSetRollNode::getValueFromDie(Die* die,QStringList& rollResult)
{
Q_ASSERT(m_values.size() == m_rangeList.size());
int i=0;
- foreach (Range range, m_rangeList)
+ for (Range range: m_rangeList)
{
if(range.hasValid(die,false))
{
diff --git a/node/paintnode.cpp b/node/paintnode.cpp
index 2770891..035334e 100644
--- a/node/paintnode.cpp
+++ b/node/paintnode.cpp
@@ -78,7 +78,7 @@ void PainterNode::run(ExecutionNode* previous)
{
QList<Die*> diceList=previousDiceResult->getResultList();
int pastDice=0;
- foreach(ColorItem item, m_colors)
+ for(ColorItem item: m_colors)
{
int current=item.colorNumber();
QList<Die*>::iterator it;
diff --git a/node/rerolldicenode.cpp b/node/rerolldicenode.cpp
index 1f8cd7e..8e8be2c 100644
--- a/node/rerolldicenode.cpp
+++ b/node/rerolldicenode.cpp
@@ -23,7 +23,7 @@ void RerollDiceNode::run(ExecutionNode* previous)
m_result->setPrevious(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<Die*> list = m_diceResult->getResultList();
- foreach(Die* die, list)
+ for(Die* die: list)
{
if(m_validator->hasValid(die,false))
{
diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp
index a9a19e3..f4884c8 100644
--- a/node/scalaroperatornode.cpp
+++ b/node/scalaroperatornode.cpp
@@ -38,44 +38,37 @@ ScalarOperatorNode::ScalarOperatorNode()
}
ScalarOperatorNode::~ScalarOperatorNode()
{
- if(nullptr!=m_internalNode)
- {
- delete m_internalNode;
- m_internalNode = nullptr;
- }
+ if(nullptr!=m_internalNode)
+ {
+ delete m_internalNode;
+ m_internalNode = nullptr;
+ }
}
void ScalarOperatorNode::run(ExecutionNode* previous)
{
m_previousNode = previous;
- if(nullptr!=m_internalNode)
+ if(NULL!=m_internalNode)
{
m_internalNode->run(this);
}
- if(nullptr!=previous)
+ if(NULL!=previous)
{
DiceResult* previousResult = static_cast<DiceResult*>(previous->getResult());
- if(nullptr!=previousResult)
+ if(NULL!=previousResult)
{
ExecutionNode* internal = m_internalNode;
- if(nullptr != internal)
+ if(NULL != internal)
{
- while(nullptr != internal->getNextNode() )
- {
+ while(nullptr != internal->getNextNode() )
+ {
internal = internal->getNextNode();
}
- 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;
@@ -94,7 +87,7 @@ void ScalarOperatorNode::run(ExecutionNode* previous)
}
}
- if(nullptr!=m_nextNode)
+ if(NULL!=m_nextNode)
{
m_nextNode->run(this);
}
@@ -193,7 +186,7 @@ void ScalarOperatorNode::generateDotTree(QString& s)
s.append(toString(true));
s.append(";\n");
- if(nullptr!=m_nextNode)
+ if(NULL!=m_nextNode)
{
s.append(toString(false));
s.append(" -> ");
@@ -205,12 +198,12 @@ void ScalarOperatorNode::generateDotTree(QString& s)
{
s.append(toString(false));
s.append(" -> ");
- s.append("nullptr");
- s.append(" [label=\"nextNode\"];\n");
+ s.append("nullptr");
+ s.append(" [label=\"nextNode\"];\n");
}
QString str;
str.append("\n");
- if(nullptr!=m_internalNode)
+ if(NULL!=m_internalNode)
{
str.append(toString(false));
str.append(" -> ");
@@ -222,14 +215,14 @@ void ScalarOperatorNode::generateDotTree(QString& s)
}
QMap<ExecutionNode::DICE_ERROR_CODE,QString> ScalarOperatorNode::getExecutionErrorMap()
{
- if(nullptr!=m_internalNode)
+ if(NULL!=m_internalNode)
{
for (ExecutionNode::DICE_ERROR_CODE key: m_internalNode->getExecutionErrorMap().keys())
{
m_errors.insert(key,m_internalNode->getExecutionErrorMap().value(key));
}
}
- if(nullptr!=m_nextNode)
+ if(NULL!=m_nextNode)
{
for (ExecutionNode::DICE_ERROR_CODE key: m_nextNode->getExecutionErrorMap().keys())
{
@@ -243,7 +236,7 @@ ExecutionNode* ScalarOperatorNode::getCopy() const
ScalarOperatorNode* node = new ScalarOperatorNode();
node->setInternalNode(m_internalNode->getCopy());
node->setArithmeticOperator(m_arithmeticOperator);
- if(nullptr!=m_nextNode)
+ if(NULL!=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/separatornode.cpp b/node/separatornode.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/node/separatornode.cpp
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
diff --git a/node/sortresult.cpp b/node/sortresult.cpp
index 5406eb6..062e1d2 100644
--- a/node/sortresult.cpp
+++ b/node/sortresult.cpp
@@ -57,7 +57,7 @@ void SortResultNode::run(ExecutionNode* node)
bool found = false;
int start = 0;
int end = diceList2.size();
- Die* tmp2 = nullptr;
+ Die* tmp2 = NULL;
while(!found)
{
int distance = end-start;
@@ -92,7 +92,7 @@ void SortResultNode::run(ExecutionNode* node)
}
m_diceResult->setResultList(diceList2);
- if(nullptr!=m_nextNode)
+ if(NULL!=m_nextNode)
{
m_nextNode->run(this);
}
@@ -123,7 +123,7 @@ QString SortResultNode::toString(bool wl) const
qint64 SortResultNode::getPriority() const
{
qint64 priority=0;
- if(nullptr!=m_nextNode)
+ if(nullptr != m_previousNode)
{
priority = m_nextNode->getPriority();
}
@@ -135,7 +135,7 @@ ExecutionNode* SortResultNode::getCopy() const
{
SortResultNode* node = new SortResultNode();
node->setSortAscending(m_ascending);
- if(nullptr!=m_nextNode)
+ if(NULL!=m_nextNode)
{
node->setNextNode(m_nextNode->getCopy());
}
diff --git a/node/startingnode.cpp b/node/startingnode.cpp
index 670dc7d..43a0dd7 100644
--- a/node/startingnode.cpp
+++ b/node/startingnode.cpp
@@ -26,7 +26,6 @@ StartingNode::StartingNode()
}
void StartingNode::run(ExecutionNode*)
{
- m_previousNode = nullptr;
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(nullptr!=m_nextNode)
+ if(NULL!=m_nextNode)
{
priority = m_nextNode->getPriority();
}
@@ -57,7 +56,7 @@ qint64 StartingNode::getPriority() const
ExecutionNode* StartingNode::getCopy() const
{
StartingNode* node = new StartingNode();
- if(nullptr!=m_nextNode)
+ if(NULL!=m_nextNode)
{
node->setNextNode(m_nextNode->getCopy());
}
diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp
index 02cdd13..a5a9920 100644
--- a/parsingtoolbox.cpp
+++ b/parsingtoolbox.cpp
@@ -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);
}
@@ -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))
{
@@ -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)
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());
}