From 53d4f802d3e9327c45c5e437bcfea474e6ad943a Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 18 Oct 2017 18:15:32 +0200 Subject: add group --- cli/CMakeLists.txt | 65 ++++++++++++++++++++++++------------------------ cli/main.cpp | 1 + diceparser.cpp | 15 +++++++++++ diceparser.h | 2 +- irc/CMakeLists.txt | 1 + mobile/CMakeLists.txt | 1 + node/ifnode.cpp | 4 +-- node/numbernode.cpp | 10 ++++++++ node/numbernode.h | 1 + node/parenthesesnode.cpp | 43 ++++++++++++++++++++++++++++++++ node/parenthesesnode.h | 1 + parsingtoolbox.cpp | 15 +++++++++++ result/result.cpp | 1 + 13 files changed, 125 insertions(+), 35 deletions(-) diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 150e90e..58c28cf 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -59,40 +59,41 @@ if(Qt5Core_FOUND) endif() SET( dice_sources - ../diceparser.cpp - ../range.cpp - ../booleancondition.cpp - ../validator.cpp - ../compositevalidator.cpp - ../operationcondition.cpp - ../die.cpp - ../parsingtoolbox.cpp - ../dicealias.cpp - ../result/result.cpp - ../result/scalarresult.cpp - ../result/stringresult.cpp - ../result/diceresult.cpp - ../node/countexecutenode.cpp - ../node/dicerollernode.cpp - ../node/executionnode.cpp - ../node/explosedicenode.cpp - ../node/helpnode.cpp - ../node/mergenode.cpp - ../node/jumpbackwardnode.cpp - ../node/keepdiceexecnode.cpp - ../node/listaliasnode.cpp - ../node/listsetrollnode.cpp - ../node/numbernode.cpp - ../node/parenthesesnode.cpp - ../node/paintnode.cpp - ../node/rerolldicenode.cpp - ../node/scalaroperatornode.cpp - ../node/sortresult.cpp - ../node/startingnode.cpp - ../node/filternode.cpp - ../node/stringnode.cpp + ../diceparser.cpp + ../range.cpp + ../booleancondition.cpp + ../validator.cpp + ../compositevalidator.cpp + ../operationcondition.cpp + ../die.cpp + ../parsingtoolbox.cpp + ../dicealias.cpp + ../result/result.cpp + ../result/scalarresult.cpp + ../result/stringresult.cpp + ../result/diceresult.cpp + ../node/countexecutenode.cpp + ../node/dicerollernode.cpp + ../node/executionnode.cpp + ../node/explosedicenode.cpp + ../node/helpnode.cpp + ../node/mergenode.cpp + ../node/jumpbackwardnode.cpp + ../node/keepdiceexecnode.cpp + ../node/listaliasnode.cpp + ../node/listsetrollnode.cpp + ../node/numbernode.cpp + ../node/parenthesesnode.cpp + ../node/paintnode.cpp + ../node/rerolldicenode.cpp + ../node/scalaroperatornode.cpp + ../node/sortresult.cpp + ../node/startingnode.cpp + ../node/filternode.cpp + ../node/stringnode.cpp ../node/ifnode.cpp ../node/splitnode.cpp + ../node/groupnode.cpp main.cpp ../highlightdice.cpp ) diff --git a/cli/main.cpp b/cli/main.cpp index b871df8..bb5d104 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -325,6 +325,7 @@ void startDiceParsing(QStringList& cmds,QString& treeFile,bool highlight) out << parser->humanReadableError()<< "\n";; } } + delete parser; } void usage() diff --git a/diceparser.cpp b/diceparser.cpp index 796850f..f58faf0 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -44,6 +44,7 @@ #include "node/paintnode.h" #include "node/stringnode.h" #include "node/splitnode.h" +#include "node/groupnode.h" #define DEFAULT_FACES_NUMBER 10 @@ -71,6 +72,7 @@ DiceParser::DiceParser() m_OptionOp->insert(QStringLiteral("p"),Painter); m_OptionOp->insert(QStringLiteral("f"),Filter); m_OptionOp->insert(QStringLiteral("u"),Split); + m_OptionOp->insert(QStringLiteral("g"),Group); m_aliasList = new QList(); @@ -1070,6 +1072,19 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, found = true; } break; + case Group: + { + qint64 groupNumber=0; + if(m_parsingToolbox->readNumber(str,groupNumber)) + { + GroupNode* groupNode = new GroupNode(); + groupNode->setGroupValue(groupNumber); + previous->setNextNode(groupNode); + node = groupNode; + found = true; + } + } + break; } } diff --git a/diceparser.h b/diceparser.h index 2ff1e56..5073142 100644 --- a/diceparser.h +++ b/diceparser.h @@ -81,7 +81,7 @@ public: /** * @brief The OptionOperator enum gathering all options availables for result. */ - enum OptionOperator {KeepAndExplose,Keep,Reroll,Explosing,Sort,Count,RerollAndAdd,Merge,ifOperator,Painter,Filter,Split}; + enum OptionOperator {KeepAndExplose,Keep,Reroll,Explosing,Sort,Count,RerollAndAdd,Merge,ifOperator,Painter,Filter,Split,Group}; /** * @brief The CommandOperator enum */ diff --git a/irc/CMakeLists.txt b/irc/CMakeLists.txt index 73d7e5a..6f06695 100644 --- a/irc/CMakeLists.txt +++ b/irc/CMakeLists.txt @@ -71,6 +71,7 @@ add_executable( ../node/stringnode.cpp ../node/filternode.cpp ../node/splitnode.cpp + ../node/groupnode.cpp botircdiceparser.cpp main.cpp) diff --git a/mobile/CMakeLists.txt b/mobile/CMakeLists.txt index 89232c8..9515006 100644 --- a/mobile/CMakeLists.txt +++ b/mobile/CMakeLists.txt @@ -91,6 +91,7 @@ SET( diceGui_sources ../node/filternode.cpp ../node/stringnode.cpp ../node/splitnode.cpp + ../node/groupnode.cpp main.cpp maincontroler.cpp commandmodel.cpp diff --git a/node/ifnode.cpp b/node/ifnode.cpp index 3df60de..c32a6a9 100644 --- a/node/ifnode.cpp +++ b/node/ifnode.cpp @@ -192,8 +192,8 @@ void IfNode::generateDotTree(QString& s) s.append(toString(false)); s.append(" -> "); s.append(m_true->toString(false)); - s.append("[label=\"true\"];\n"); -// s.append(" [label=\"nextNode\"];\n"); + s.append("[label=\"true"+m_validator->toString()+"\"];\n"); + m_true->generateDotTree(s); } if((NULL!=m_false)&&(m_false != m_nextNode)) diff --git a/node/numbernode.cpp b/node/numbernode.cpp index 7a2dcff..5815ad6 100644 --- a/node/numbernode.cpp +++ b/node/numbernode.cpp @@ -26,6 +26,16 @@ NumberNode::NumberNode() { m_result = m_scalarResult; } +NumberNode::~NumberNode() +{ + /// @todo make sure there is no copy of the internal result. + /*if( nullptr != m_scalarResult) + { + delete m_scalarResult; + m_scalarResult = nullptr; + }*/ +} + void NumberNode::run(ExecutionNode* previous) { m_previousNode = previous; diff --git a/node/numbernode.h b/node/numbernode.h index 9f1b751..80cbace 100644 --- a/node/numbernode.h +++ b/node/numbernode.h @@ -32,6 +32,7 @@ class NumberNode : public ExecutionNode { public: NumberNode(); + virtual ~NumberNode(); void run(ExecutionNode* previous); void setNumber(qint64); virtual QString toString(bool withLabel)const; diff --git a/node/parenthesesnode.cpp b/node/parenthesesnode.cpp index 2383226..96c0bb7 100644 --- a/node/parenthesesnode.cpp +++ b/node/parenthesesnode.cpp @@ -80,3 +80,46 @@ ExecutionNode* ParenthesesNode::getCopy() const return node; } + +void ParenthesesNode::generateDotTree(QString & s) +{ + s.append(toString(true)); + s.append(";\n"); + + if(nullptr != m_internalNode) + { + s.append(toString(false)); + s.append(" -> "); + s.append(m_internalNode->toString(false)); + s.append("[label=\"internal\"];\n"); + m_internalNode->generateDotTree(s); + + } + + if(NULL!=m_nextNode) + { + s.append(toString(false)); + s.append(" -> "); + s.append(m_nextNode->toString(false)); + s.append("[label=\"next\"];\n"); +// s.append(" [label=\"nextNode\"];\n"); + m_nextNode->generateDotTree(s); + } + else + { + s.append(toString(false)); + s.append(" -> "); + s.append("NULL;\n"); + if(NULL!=m_result) + { + + s.append(toString(false)); + s.append(" ->"); + s.append(m_result->toString(false)); + s.append(" [label=\"Result\"];\n"); + + + m_result->generateDotTree(s); + } + } +} diff --git a/node/parenthesesnode.h b/node/parenthesesnode.h index df3c32a..388f6db 100644 --- a/node/parenthesesnode.h +++ b/node/parenthesesnode.h @@ -37,6 +37,7 @@ public: virtual QString toString(bool)const; virtual qint64 getPriority() const; virtual ExecutionNode *getCopy() const; + virtual void generateDotTree(QString&); private: ExecutionNode* m_internalNode; }; diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index 3ff7e21..2a237a5 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -72,6 +72,21 @@ ParsingToolBox::~ParsingToolBox() delete m_logicOp; m_logicOp = NULL; } + if(nullptr != m_logicOperation) + { + delete m_logicOperation; + m_logicOperation= nullptr; + } + if(nullptr != m_conditionOperation) + { + delete m_conditionOperation; + m_conditionOperation= nullptr; + } + if(nullptr != m_arithmeticOperation) + { + delete m_arithmeticOperation; + m_arithmeticOperation= nullptr; + } } ExecutionNode* ParsingToolBox::addSort(ExecutionNode* e,bool b) { diff --git a/result/result.cpp b/result/result.cpp index 71c0445..6e1ea7a 100644 --- a/result/result.cpp +++ b/result/result.cpp @@ -63,6 +63,7 @@ void Result::generateDotTree(QString& s) s.append("\n"); m_previous->generateDotTree(s); } + else { s.append(toString(false)); s.append(" -> "); -- cgit v1.2.3-70-g09d2