From 006fa720065dba20d7d7244da69c3c0c96213319 Mon Sep 17 00:00:00 2001 From: "Renaud G." Date: Sat, 4 Apr 2015 09:02:37 +0200 Subject: Update HelpMe.md Remove space --- HelpMe.md | 1 - 1 file changed, 1 deletion(-) diff --git a/HelpMe.md b/HelpMe.md index b3c1a4d..be2dd7a 100644 --- a/HelpMe.md +++ b/HelpMe.md @@ -164,7 +164,6 @@ 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. ### Scalar -- cgit v1.2.3-70-g09d2 From 3ac6eea8269ee5b28c88fd0736c8963c0b8c2906 Mon Sep 17 00:00:00 2001 From: "Renaud G." Date: Sun, 5 Apr 2015 17:29:54 +0200 Subject: Update HelpMe.md Add sort lower --- HelpMe.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/HelpMe.md b/HelpMe.md index be2dd7a..42260b7 100644 --- a/HelpMe.md +++ b/HelpMe.md @@ -71,6 +71,8 @@ Dice explose if their value are at the die maximum, the option sorts the resulti The dice list is sorted in descending order. +> 10d6sl +Roll 6 dice at 6 faces and then sort them ascendingly ### Counter > 3D10c[Validator] -- cgit v1.2.3-70-g09d2 From 379ffeb21fd4f067ea542e6b45967bab1ca004d5 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Mon, 6 Apr 2015 14:26:23 +0200 Subject: -Creation of dedicated class for alias management --- dicealias.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ dicealias.h | 29 ++++++++++++++++++++++ diceparser.cpp | 24 +++++++++--------- diceparser.h | 4 ++- diceparser.pri | 6 +++-- node/listaliasnode.cpp | 11 ++++----- node/listaliasnode.h | 6 ++--- 7 files changed, 123 insertions(+), 24 deletions(-) create mode 100644 dicealias.cpp create mode 100644 dicealias.h diff --git a/dicealias.cpp b/dicealias.cpp new file mode 100644 index 0000000..2a09206 --- /dev/null +++ b/dicealias.cpp @@ -0,0 +1,67 @@ +#include "dicealias.h" +#include + +DiceAlias::DiceAlias(QString cmd, QString key, bool isReplace) + : m_command(cmd),m_value(key) +{ + if(isReplace) + { + m_type = REPLACE; + } + else + { + m_type = REGEXP; + } +} + +DiceAlias::~DiceAlias() +{ + +} + +bool DiceAlias::resolved(QString & str) +{ + if((m_type == REPLACE)&&(str.contains(m_command))) + { + str.replace(m_command,m_value); + return true; + } + else if(m_type == REGEXP) + { + QRegularExpression exp(m_command); + str.replace(exp,m_value); + return true; + } + return false; +} + +void DiceAlias::setCommand(QString key) +{ + m_command = key; +} + +void DiceAlias::setValue(QString value) +{ + m_value = value; +} + +void DiceAlias::setType(RESOLUTION_TYPE type) +{ + m_type = type; +} +QString DiceAlias::getCommand() +{ + return m_command; +} + +QString DiceAlias::getValue() +{ + return m_value; +} + +bool DiceAlias::isReplace() +{ + return (m_type == REPLACE) ? true : false; +} + + diff --git a/dicealias.h b/dicealias.h new file mode 100644 index 0000000..565b903 --- /dev/null +++ b/dicealias.h @@ -0,0 +1,29 @@ +#ifndef DICEALIAS_H +#define DICEALIAS_H + +#include + +class DiceAlias +{ +public: + enum RESOLUTION_TYPE { REPLACE,REGEXP}; + DiceAlias(QString cmd, QString key, bool isReplace = true); + ~DiceAlias(); + + bool resolved(QString & str); + + void setCommand(QString key); + void setValue(QString value); + void setType(RESOLUTION_TYPE ); + + QString getCommand(); + QString getValue(); + bool isReplace(); +private: + QString m_command; + QString m_value; + RESOLUTION_TYPE m_type; + +}; + +#endif // DICEALIAS_H diff --git a/diceparser.cpp b/diceparser.cpp index 2c533dc..08decde 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -60,12 +60,11 @@ DiceParser::DiceParser() //m_OptionOp->insert(QObject::tr("@"),JumpBackward); - - m_aliasMap = new QMap; - m_aliasMap->insert("l5r","D10k"); - m_aliasMap->insert("l5R","D10K"); - m_aliasMap->insert("nwod","D10e10c[>7]"); - m_aliasMap->insert("nwod","D10e10c[>7]"); + m_aliasList = new QList(); + m_aliasList->append(new DiceAlias("l5r","D10k")); + m_aliasList->append(new DiceAlias("l5R","D10K")); + m_aliasList->append(new DiceAlias("nwod","D10e10c[>7]")); + m_aliasList->append(new DiceAlias("(.*)wod(.*)","\\1d10e[=10]c[>=\\2]-@c[=1]",false)); m_nodeActionMap = new QMap(); m_nodeActionMap->insert("@",JumpBackward); @@ -88,15 +87,16 @@ ExecutionNode* DiceParser::getLatestNode(ExecutionNode* node) } QString DiceParser::convertAlias(QString str) { - foreach(QString cmd, m_aliasMap->keys()) + foreach(DiceAlias* cmd, *m_aliasList) { - if(str.contains(cmd)) - { - str.replace(cmd,m_aliasMap->value(cmd)); - } + cmd->resolved(str); } return str; } +QList* DiceParser::getAliases() +{ + return m_aliasList; +} bool DiceParser::parseLine(QString str) { @@ -539,7 +539,7 @@ bool DiceParser::readCommand(QString& str,ExecutionNode* & node) } else if(str=="la") { - node = new ListAliasNode(m_aliasMap); + node = new ListAliasNode(m_aliasList); } return true; } diff --git a/diceparser.h b/diceparser.h index 683be88..f9db840 100644 --- a/diceparser.h +++ b/diceparser.h @@ -32,6 +32,7 @@ #include "range.h" #include "booleancondition.h" #include "parsingtoolbox.h" +#include "dicealias.h" class ExploseDiceNode; /** @@ -157,6 +158,7 @@ public: * @return */ QString humanReadableError(); + QList* getAliases(); private: /** @@ -253,7 +255,7 @@ private: QMap* m_mapDiceOp; QMap* m_OptionOp; QMap* m_nodeActionMap; - QMap* m_aliasMap; + QList* m_aliasList; QStringList* m_commandList; QMap m_errorMap; diff --git a/diceparser.pri b/diceparser.pri index b9af1d7..cacca31 100644 --- a/diceparser.pri +++ b/diceparser.pri @@ -12,7 +12,8 @@ SOURCES += $$PWD/diceparser.cpp \ $$PWD/result/result.cpp \ $$PWD/result/scalarresult.cpp \ $$PWD/parsingtoolbox.cpp \ - $$PWD/result/stringresult.cpp + $$PWD/result/stringresult.cpp \ + $$PWD/dicealias.cpp HEADERS += \ @@ -25,7 +26,8 @@ HEADERS += \ $$PWD/result/result.h \ $$PWD/result/scalarresult.h \ $$PWD/result/parsingtoolbox.h \ - $$PWD/result/stringresult.h + $$PWD/result/stringresult.h \ + $$PWD/dicealias.h HEADERS += \ diff --git a/node/listaliasnode.cpp b/node/listaliasnode.cpp index 1d50c80..b85d4c9 100644 --- a/node/listaliasnode.cpp +++ b/node/listaliasnode.cpp @@ -1,7 +1,7 @@ #include "listaliasnode.h" -ListAliasNode::ListAliasNode(QMap* apAlias) - : m_mapAlias(apAlias) +ListAliasNode::ListAliasNode(QList* apAlias) + : m_aliasList(apAlias) { m_result = new StringResult(); } @@ -29,14 +29,13 @@ void ListAliasNode::run(ExecutionNode* previous ) m_nextNode->run(this); } } -QString ListAliasNode::toString()const +QString ListAliasNode::toString() const { QString result(QObject::tr("List of Alias:\n")); - foreach(QString key, m_mapAlias->keys()) + foreach(DiceAlias* key, *m_aliasList) { - result+=QString("%1 : %2\n").arg(key).arg(m_mapAlias->value(key)); + result+=QString("%1 : %2\n").arg(key->getCommand()).arg(key->getValue()); } - return result; } diff --git a/node/listaliasnode.h b/node/listaliasnode.h index d01d17a..ea70fe7 100644 --- a/node/listaliasnode.h +++ b/node/listaliasnode.h @@ -3,12 +3,12 @@ #include "executionnode.h" #include "result/stringresult.h" - +#include "dicealias.h" class ListAliasNode : public ExecutionNode { public: - ListAliasNode(QMap* mapAlias); + ListAliasNode(QList* mapAlias); /** * @brief run * @param previous @@ -27,7 +27,7 @@ public: virtual qint64 getPriority() const; private: - QMap* m_mapAlias; + QList* m_aliasList; }; #endif // LISTALIASNODE_H -- cgit v1.2.3-70-g09d2 From 77ce7ecc41f1f5b6a4f74187451a948ad4ad7721 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Tue, 7 Apr 2015 08:35:40 +0200 Subject: remove default diceAlias. It must be managed by the end-user application. --- diceparser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diceparser.cpp b/diceparser.cpp index 08decde..09172a0 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -61,10 +61,10 @@ DiceParser::DiceParser() m_aliasList = new QList(); - m_aliasList->append(new DiceAlias("l5r","D10k")); + /*m_aliasList->append(new DiceAlias("l5r","D10k")); m_aliasList->append(new DiceAlias("l5R","D10K")); m_aliasList->append(new DiceAlias("nwod","D10e10c[>7]")); - m_aliasList->append(new DiceAlias("(.*)wod(.*)","\\1d10e[=10]c[>=\\2]-@c[=1]",false)); + m_aliasList->append(new DiceAlias("(.*)wod(.*)","\\1d10e[=10]c[>=\\2]-@c[=1]",false));*/ m_nodeActionMap = new QMap(); m_nodeActionMap->insert("@",JumpBackward); -- cgit v1.2.3-70-g09d2 From 9192ba51a362715061cce1104b5543f7e93bf70f Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 8 Apr 2015 08:47:35 +0200 Subject: Add comments --- diceparser.h | 27 ++++++++++++++++++++------- node/jumpbackwardnode.h | 8 +++++++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/diceparser.h b/diceparser.h index f9db840..7ec09ee 100644 --- a/diceparser.h +++ b/diceparser.h @@ -158,7 +158,17 @@ public: * @return */ QString humanReadableError(); + /** + * @brief getAliases + * @return + */ QList* getAliases(); + /** + * @brief DiceParser::convertAlias + * @param str + * @return + */ + QString convertAlias(QString str); private: /** @@ -220,12 +230,6 @@ private: * @return */ bool readOperand(QString&,ExecutionNode* & node); - /** - * @brief DiceParser::convertAlias - * @param str - * @return - */ - QString convertAlias(QString str); /** * @brief getErrorList @@ -246,8 +250,17 @@ private: */ bool readNode(QString& str,ExecutionNode* & node); - + /** + * @brief getLeafNode + * @return + */ ExecutionNode* getLeafNode(); + + /** + * @brief hasResultOfType + * @param notthelast + * @return + */ bool hasResultOfType(Result::RESULT_TYPE,bool notthelast = false); diff --git a/node/jumpbackwardnode.h b/node/jumpbackwardnode.h index 4ea3d11..c6c1e4d 100644 --- a/node/jumpbackwardnode.h +++ b/node/jumpbackwardnode.h @@ -6,8 +6,14 @@ class JumpBackwardNode : public ExecutionNode { public: + /** + * @brief JumpBackwardNode allows to get result from remote node in the execution tree. + */ JumpBackwardNode(); - + /** + * @brief run - performs the actions + * @param previous + */ virtual void run(ExecutionNode* previous = NULL); /** -- cgit v1.2.3-70-g09d2 From 5cfe48265ebad0ffa0a980dbc2d131fceeecdf3b Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 8 Apr 2015 21:34:02 +0200 Subject: -remove memory leaks -delete created objects --- diceParser.pro | 6 +++-- diceparser.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++--- diceparser.h | 4 ++++ main.cpp | 8 +++++-- node/countexecutenode.cpp | 9 +++++++- node/countexecutenode.h | 1 + node/dicerollernode.cpp | 8 +++---- node/dicerollernode.h | 3 +-- node/executionnode.cpp | 10 +++++++++ node/explosedicenode.cpp | 9 +++++++- node/explosedicenode.h | 1 + node/listsetrollnode.cpp | 8 +++++++ node/listsetrollnode.h | 1 + node/rerolldicenode.cpp | 10 ++++++++- node/rerolldicenode.h | 28 +++++++++++++++++++++++ node/scalaroperatornode.cpp | 18 ++++++++++++--- node/scalaroperatornode.h | 3 ++- parsingtoolbox.cpp | 9 ++++++++ parsingtoolbox.h | 7 ++++++ result/diceresult.cpp | 14 +++++------- result/diceresult.h | 4 ++++ result/stringresult.cpp | 4 ++++ result/stringresult.h | 4 ++++ 23 files changed, 195 insertions(+), 29 deletions(-) diff --git a/diceParser.pro b/diceParser.pro index 2d72fcb..c339933 100644 --- a/diceParser.pro +++ b/diceParser.pro @@ -43,7 +43,8 @@ SOURCES += main.cpp \ result/result.cpp \ result/scalarresult.cpp \ parsingtoolbox.cpp \ - result/stringresult.cpp + result/stringresult.cpp \ + dicealias.cpp HEADERS += \ @@ -56,7 +57,8 @@ HEADERS += \ result/result.h \ result/scalarresult.h \ result/parsingtoolbox.h \ - result/stringresult.h + result/stringresult.h \ + dicealias.h OTHER_FILES += README.md \ HelpMe.md diff --git a/diceparser.cpp b/diceparser.cpp index 09172a0..5e6d06f 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -42,6 +42,7 @@ #define DEFAULT_FACES_NUMBER 10 DiceParser::DiceParser() + : m_start(NULL) { m_parsingToolbox = new ParsingToolBox(); @@ -75,6 +76,44 @@ DiceParser::DiceParser() m_commandList->append(QObject::tr("la")); } +DiceParser::~DiceParser() +{ + if(NULL!=m_commandList) + { + delete m_commandList; + m_commandList = NULL; + } + if(NULL!=m_nodeActionMap) + { + delete m_nodeActionMap; + m_nodeActionMap = NULL; + } + if(NULL!=m_OptionOp) + { + delete m_OptionOp; + m_OptionOp = NULL; + } + if(NULL!=m_mapDiceOp) + { + delete m_mapDiceOp; + m_mapDiceOp = NULL; + } + if(NULL!=m_parsingToolbox) + { + delete m_parsingToolbox; + m_parsingToolbox = NULL; + } + if(NULL!=m_aliasList) + { + delete m_aliasList; + m_aliasList = NULL; + } + if(NULL!=m_start) + { + delete m_start; + m_start = NULL; + } +} ExecutionNode* DiceParser::getLatestNode(ExecutionNode* node) { @@ -101,6 +140,11 @@ QList* DiceParser::getAliases() bool DiceParser::parseLine(QString str) { m_errorMap.clear(); + if(NULL!=m_start) + { + delete m_start; + m_start = NULL; + } m_command = str; m_start = new StartingNode(); ExecutionNode* newNode = NULL; @@ -599,6 +643,7 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous) node->setInternalNode(nodeExec); if(NULL==nodeExec) { + delete node; return false; } if(node->getPriority()>=nodeExec->getPriority()) @@ -610,6 +655,10 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous) return true; } + else + { + delete node; + } } else if(readInstructionOperator(str[0])) { @@ -851,10 +900,10 @@ bool DiceParser::readOperand(QString& str,ExecutionNode* & node) if(m_parsingToolbox->readNumber(str,myNumber)) { - NumberNode* myNumberNode = new NumberNode(); - myNumberNode->setNumber(myNumber); + NumberNode* numberNode = new NumberNode(); + numberNode->setNumber(myNumber); - node = myNumberNode; + node = numberNode; return true; } return false; diff --git a/diceparser.h b/diceparser.h index 7ec09ee..1636fc9 100644 --- a/diceparser.h +++ b/diceparser.h @@ -83,6 +83,10 @@ public: * @brief DiceParser default constructor */ DiceParser(); + /** + * @brief ~DiceParser + */ + virtual ~DiceParser(); /** * @brief parseLine, method to call for starting the dice roll. It will parse the command and run the execution tree. diff --git a/main.cpp b/main.cpp index 926e3d4..7b70e23 100644 --- a/main.cpp +++ b/main.cpp @@ -39,7 +39,8 @@ int main(int argc, char *argv[]) QStringList commands; - commands << "1L[cheminée,chocolat,épée,arc,chute de pierre]" + commands<< "10d10c[>6]+@c[=10]" + << "1L[cheminée,chocolat,épée,arc,chute de pierre]" << "10d10c[>=6]-@c[=1]" << "10d10c[>=6]-@c[=1]-@c[=1]" << "10d10c[>6]+@c[=10]" @@ -61,6 +62,7 @@ int main(int argc, char *argv[]) << "15D10e10c[8-10]" << "10d10e11" << "1D8+2D6+7" + << "100190D6666666s" << "D25" << "D25+D10" << "D25;D10" @@ -73,7 +75,7 @@ int main(int argc, char *argv[]) << "help" << "la" << "400000D20/400000" - << "100*3*8"; + << "100*3*8";// if(argc>1) { @@ -100,4 +102,6 @@ int main(int argc, char *argv[]) main.show(); return a.exec(); #endif + delete myParser; + return 0; } diff --git a/node/countexecutenode.cpp b/node/countexecutenode.cpp index 281fc80..1050efc 100644 --- a/node/countexecutenode.cpp +++ b/node/countexecutenode.cpp @@ -4,7 +4,7 @@ CountExecuteNode::CountExecuteNode() - : m_scalarResult(new ScalarResult()) + : m_scalarResult(new ScalarResult()),m_validator(NULL) { m_result = m_scalarResult; } @@ -12,6 +12,13 @@ void CountExecuteNode::setValidator(Validator* validator) { m_validator = validator; } +CountExecuteNode::~CountExecuteNode() +{ + if(NULL!=m_validator) + { + delete m_validator; + } +} void CountExecuteNode::run(ExecutionNode *previous) { diff --git a/node/countexecutenode.h b/node/countexecutenode.h index c7ecdfd..519403b 100644 --- a/node/countexecutenode.h +++ b/node/countexecutenode.h @@ -16,6 +16,7 @@ public: * @brief CountExecuteNode */ CountExecuteNode(); + virtual ~CountExecuteNode(); /** * @brief run * @param previous diff --git a/node/dicerollernode.cpp b/node/dicerollernode.cpp index 1fd1a2f..f32a033 100644 --- a/node/dicerollernode.cpp +++ b/node/dicerollernode.cpp @@ -33,11 +33,9 @@ /// \brief DiceRollerNode::DiceRollerNode ////////////////////////////////////////////////// DiceRollerNode::DiceRollerNode(quint64 faces) - : m_faces(faces),m_myDiceResult(new DiceResult()) + : m_faces(faces),m_diceResult(new DiceResult()) { - m_mutex=new QMutex(); - m_result=m_myDiceResult; - + m_result=m_diceResult; } void DiceRollerNode::run(ExecutionNode* previous) { @@ -55,7 +53,7 @@ void DiceRollerNode::run(ExecutionNode* previous) Die* die = new Die(); die->setFaces(m_faces); die->roll(); - m_myDiceResult->insertResult(die); + m_diceResult->insertResult(die); } if(NULL!=m_nextNode) { diff --git a/node/dicerollernode.h b/node/dicerollernode.h index d50fe95..744a4b5 100644 --- a/node/dicerollernode.h +++ b/node/dicerollernode.h @@ -36,8 +36,7 @@ public: private: quint64 m_diceCount; quint64 m_faces; /// faces - DiceResult* m_myDiceResult; - QMutex* m_mutex; + DiceResult* m_diceResult; }; #endif // DICEROLLERNODE_H diff --git a/node/executionnode.cpp b/node/executionnode.cpp index 8bcd6e4..343e8d9 100644 --- a/node/executionnode.cpp +++ b/node/executionnode.cpp @@ -8,6 +8,16 @@ ExecutionNode::ExecutionNode() ExecutionNode::~ExecutionNode() { + if(NULL!=m_result) + { + delete m_result; + m_result = NULL; + } + if(NULL!=m_nextNode) + { + delete m_nextNode; + m_nextNode = NULL; + } } Result* ExecutionNode::getResult() diff --git a/node/explosedicenode.cpp b/node/explosedicenode.cpp index 42b3c2d..4eae270 100644 --- a/node/explosedicenode.cpp +++ b/node/explosedicenode.cpp @@ -1,7 +1,7 @@ #include "explosedicenode.h" ExploseDiceNode::ExploseDiceNode() - : m_diceResult(new DiceResult()) + : m_diceResult(new DiceResult()),m_validator(NULL) { m_result = m_diceResult; } @@ -33,6 +33,13 @@ void ExploseDiceNode::run(ExecutionNode* previous) } } } +ExploseDiceNode::~ExploseDiceNode() +{ + if(NULL!=m_validator) + { + delete m_validator; + } +} void ExploseDiceNode::setValidator(Validator* val) { m_validator = val; diff --git a/node/explosedicenode.h b/node/explosedicenode.h index b00af1a..f5d0f6e 100644 --- a/node/explosedicenode.h +++ b/node/explosedicenode.h @@ -13,6 +13,7 @@ class ExploseDiceNode : public ExecutionNode { public: ExploseDiceNode(); + virtual ~ExploseDiceNode(); virtual void run(ExecutionNode* previous = NULL); virtual void setValidator(Validator* ); virtual QString toString()const; diff --git a/node/listsetrollnode.cpp b/node/listsetrollnode.cpp index 3ab9a69..777f7b0 100644 --- a/node/listsetrollnode.cpp +++ b/node/listsetrollnode.cpp @@ -6,6 +6,14 @@ ListSetRollNode::ListSetRollNode() { m_result = m_stringResult; } +ListSetRollNode::~ListSetRollNode() +{ + if(NULL!=m_diceResult) + { + delete m_diceResult; + m_diceResult =NULL; + } +} QStringList ListSetRollNode::getList() { diff --git a/node/listsetrollnode.h b/node/listsetrollnode.h index 26fb378..c7925b8 100644 --- a/node/listsetrollnode.h +++ b/node/listsetrollnode.h @@ -12,6 +12,7 @@ class ListSetRollNode : public ExecutionNode { public: ListSetRollNode(); + virtual ~ListSetRollNode(); virtual void run(ExecutionNode* previous = NULL); virtual QString toString()const; virtual qint64 getPriority() const; diff --git a/node/rerolldicenode.cpp b/node/rerolldicenode.cpp index 81b5e01..a7cc8c4 100644 --- a/node/rerolldicenode.cpp +++ b/node/rerolldicenode.cpp @@ -2,10 +2,18 @@ RerollDiceNode::RerollDiceNode() - : m_myDiceResult(new DiceResult()),m_adding(false) + : m_myDiceResult(new DiceResult()),m_adding(false),m_validator(NULL) { m_result=m_myDiceResult; } +RerollDiceNode::~RerollDiceNode() +{ + if(NULL!=m_validator) + { + delete m_validator; + m_validator = NULL; + } +} void RerollDiceNode::run(ExecutionNode* previous) { m_previousNode = previous; diff --git a/node/rerolldicenode.h b/node/rerolldicenode.h index 4674a3e..a97e448 100644 --- a/node/rerolldicenode.h +++ b/node/rerolldicenode.h @@ -12,16 +12,44 @@ class RerollDiceNode : public ExecutionNode { public: + /** + * @brief The ReRollMode enum + */ enum ReRollMode {EQUAL,LESSER,GREATER}; + /** + * @brief RerollDiceNode + */ RerollDiceNode(); + /** + * @brief ~RerollDiceNode + */ + virtual ~RerollDiceNode(); + /** + * @brief run + * @param previous + */ virtual void run(ExecutionNode* previous); + /** + * @brief setValidator + */ virtual void setValidator(Validator* ); + /** + * @brief toString + * @return + */ virtual QString toString()const; + /** + * @brief setAddingMode + */ virtual void setAddingMode(bool); + /** + * @brief getPriority + * @return + */ virtual qint64 getPriority() const; private: diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp index 95fd077..34eb6b8 100644 --- a/node/scalaroperatornode.cpp +++ b/node/scalaroperatornode.cpp @@ -15,6 +15,14 @@ ScalarOperatorNode::ScalarOperatorNode() m_result = m_scalarResult; } +ScalarOperatorNode::~ScalarOperatorNode() +{ + if(NULL!=m_internalNode) + { + delete m_internalNode; + m_internalNode = NULL; + } +} void ScalarOperatorNode::run(ExecutionNode* previous) { @@ -43,7 +51,7 @@ void ScalarOperatorNode::run(ExecutionNode* previous) m_internalNode->getResult()->setPrevious(previousResult); } - switch(m_myOperator) + switch(m_operator) { case PLUS: m_scalarResult->setValue(add(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); @@ -74,7 +82,7 @@ bool ScalarOperatorNode::setOperatorChar(QChar c) { if(m_scalarOperationList.contains(c)) { - m_myOperator = m_scalarOperationList.value(c); + m_operator = m_scalarOperationList.value(c); return true; } return false; @@ -110,10 +118,14 @@ QString ScalarOperatorNode::toString() const } qint64 ScalarOperatorNode::getPriority() const { - if((m_myOperator==PLUS)||(m_myOperator==MINUS)) + if((m_operator==PLUS)||(m_operator==MINUS)) + { return 1; + } else + { return 2; + } } void ScalarOperatorNode::generateDotTree(QString& s) { diff --git a/node/scalaroperatornode.h b/node/scalaroperatornode.h index a67e296..7193118 100644 --- a/node/scalaroperatornode.h +++ b/node/scalaroperatornode.h @@ -12,6 +12,7 @@ class ScalarOperatorNode : public ExecutionNode public: enum ScalarOperator {PLUS,MINUS,DIVIDE,MULTIPLICATION}; ScalarOperatorNode(); + virtual ~ScalarOperatorNode(); virtual void run(ExecutionNode*); bool setOperatorChar(QChar c); void setInternalNode(ExecutionNode* node); @@ -28,7 +29,7 @@ private: qint64 multiple(qint64,qint64); private: - ScalarOperator m_myOperator; + ScalarOperator m_operator; ExecutionNode* m_internalNode; QMap m_scalarOperationList; ScalarResult* m_scalarResult; diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index e03690e..3e09bac 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -63,6 +63,14 @@ bool ParsingToolBox::readLogicOperator(QString& str,BooleanCondition::LogicOpera return false; } +ParsingToolBox::~ParsingToolBox() +{ + if(NULL!=m_logicOp) + { + delete m_logicOp; + m_logicOp = NULL; + } +} Validator* ParsingToolBox::readValidator(QString& str) { Validator* returnVal=NULL; @@ -181,6 +189,7 @@ bool ParsingToolBox::readList(QString& str,QStringList& list) { QString liststr = str.left(pos); list = liststr.split(","); + str=str.remove(0,pos+1); return true; } } diff --git a/parsingtoolbox.h b/parsingtoolbox.h index 43dca4e..d7fdc31 100644 --- a/parsingtoolbox.h +++ b/parsingtoolbox.h @@ -35,7 +35,14 @@ class ParsingToolBox { public: + /** + * @brief ParsingToolBox + */ ParsingToolBox(); + /** + * @brief ~ParsingToolBox + */ + virtual ~ParsingToolBox(); /** * @brief addSort * @param e diff --git a/result/diceresult.cpp b/result/diceresult.cpp index 0cabb11..f87079a 100644 --- a/result/diceresult.cpp +++ b/result/diceresult.cpp @@ -35,17 +35,15 @@ QList& DiceResult::getResultList() } void DiceResult::setResultList(QList list) { + qDeleteAll(m_diceValues.begin(), m_diceValues.end()); m_diceValues.clear(); m_diceValues << list; } -//bool DiceResult::isScalar() const -//{ -// if(m_diceValues.size()==1) -// { -// return true; -// } -// return false; -//} +DiceResult::~DiceResult() +{ + qDeleteAll(m_diceValues.begin(), m_diceValues.end()); + m_diceValues.clear(); +} QVariant DiceResult::getResult(RESULT_TYPE type) { diff --git a/result/diceresult.h b/result/diceresult.h index 838a83d..b805e73 100644 --- a/result/diceresult.h +++ b/result/diceresult.h @@ -35,6 +35,10 @@ public: * @brief DiceResult */ DiceResult(); + /** + * @brief ~DiceResult + */ + virtual ~DiceResult(); /** * @brief getResultList diff --git a/result/stringresult.cpp b/result/stringresult.cpp index 4831a76..9f7d2e1 100644 --- a/result/stringresult.cpp +++ b/result/stringresult.cpp @@ -8,6 +8,10 @@ void StringResult::setText(QString text) { m_value=text; } +StringResult::~StringResult() +{ + +} QString StringResult::getText() const { diff --git a/result/stringresult.h b/result/stringresult.h index caa7e06..17c43cd 100644 --- a/result/stringresult.h +++ b/result/stringresult.h @@ -13,6 +13,10 @@ public: * @brief StringResult */ StringResult(); + /** + * @brief StringResult + */ + virtual ~StringResult(); /** * @brief setText * @param text -- cgit v1.2.3-70-g09d2 From 64048b3fd2dba4220cb19946caf588f9a6f26093 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 15 Apr 2015 01:07:36 +0200 Subject: add API to make easier the use of DiceParser. --- dicealias.cpp | 32 ++++++++++++++++++++++++++ dicealias.h | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- diceparser.cpp | 7 ++++++ diceparser.h | 4 ++++ 4 files changed, 110 insertions(+), 4 deletions(-) diff --git a/dicealias.cpp b/dicealias.cpp index 2a09206..f9c366c 100644 --- a/dicealias.cpp +++ b/dicealias.cpp @@ -1,3 +1,24 @@ +/*************************************************************************** +* Copyright (C) 2014 by Renaud Guezennec * +* http://renaudguezennec.homelinux.org/accueil,3.html * +* * +* 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. * +***************************************************************************/ #include "dicealias.h" #include @@ -65,3 +86,14 @@ bool DiceAlias::isReplace() } +void DiceAlias::setReplace(bool b) +{ + if(b) + { + m_type= REPLACE; + } + else + { + m_type = REGEXP; + } +} diff --git a/dicealias.h b/dicealias.h index 565b903..ebf7a02 100644 --- a/dicealias.h +++ b/dicealias.h @@ -1,24 +1,87 @@ +/*************************************************************************** +* Copyright (C) 2014 by Renaud Guezennec * +* http://renaudguezennec.homelinux.org/accueil,3.html * +* * +* This file is part of DiceParser * +* * +* DiceParser is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ #ifndef DICEALIAS_H #define DICEALIAS_H #include - +/** + * @brief The DiceAlias class + */ class DiceAlias { public: + enum RESOLUTION_TYPE { REPLACE,REGEXP}; + /** + * @brief DiceAlias + * @param cmd + * @param key + * @param isReplace + */ DiceAlias(QString cmd, QString key, bool isReplace = true); - ~DiceAlias(); - + /** + * @brief ~DiceAlias + */ + virtual ~DiceAlias(); + /** + * @brief resolved + * @param str + * @return + */ bool resolved(QString & str); - + /** + * @brief setCommand + * @param key + */ void setCommand(QString key); + /** + * @brief setValue + * @param value + */ void setValue(QString value); + /** + * @brief setType + */ void setType(RESOLUTION_TYPE ); + /** + * @brief getCommand + * @return + */ QString getCommand(); + /** + * @brief getValue + * @return + */ QString getValue(); + /** + * @brief isReplace + * @return + */ bool isReplace(); + /** + * @brief setReplace + */ + void setReplace(bool); private: QString m_command; QString m_value; diff --git a/diceparser.cpp b/diceparser.cpp index 5e6d06f..6933071 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -136,6 +136,13 @@ QList* DiceParser::getAliases() { return m_aliasList; } +void DiceParser::insertAlias(DiceAlias* dice, int i) +{ + if(i>m_aliasList->size()) + { + m_aliasList->insert(i, dice); + } +} bool DiceParser::parseLine(QString str) { diff --git a/diceparser.h b/diceparser.h index 1636fc9..b4fd429 100644 --- a/diceparser.h +++ b/diceparser.h @@ -167,6 +167,10 @@ public: * @return */ QList* getAliases(); + /** + * @brief insertAlias + */ + void insertAlias(DiceAlias*, int); /** * @brief DiceParser::convertAlias * @param str -- cgit v1.2.3-70-g09d2 From 186af57e85671f0c9c4b2b1faf0d2065f4b0f222 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Tue, 21 Apr 2015 10:43:08 +0200 Subject: prepare much better way to give the result --- diceparser.cpp | 32 ++++++++++++++++++++++---------- die.cpp | 9 +++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/diceparser.cpp b/diceparser.cpp index 6933071..a2fa137 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -400,10 +400,12 @@ QString DiceParser::getStringResult() QString DiceParser::getLastDiceResult() { ExecutionNode* next = getLeafNode(); - QString str; - QTextStream stream(&str); + // QString str; + // QTextStream stream(&str); Result* result=next->getResult(); - QString dieValue("D%1 : {%2} "); + QMap diceValues; + //QString dieValue("%2 (D%1)"); + bool first=true; while(NULL!=result) { if(result->hasResultOfType(Result::DICE_LIST)) @@ -423,17 +425,16 @@ QString DiceParser::getLastDiceResult() die->displayed(); face = die->getFaces(); - if(die->hasChildrenValue()) { - resulStr+=" ["; + QString childDice(""); foreach(qint64 i, die->getListValue()) { - resulStr+=QString("%1,").arg(i); + childDice+=QString("%1,").arg(i); } - resulStr.remove(resulStr.size()-1,1); - resulStr+="]"; + childDice.remove(childDice.size()-1,1); + resulStr+=QString("[%1]").arg(childDice); } resulStr+=", "; } @@ -442,7 +443,17 @@ QString DiceParser::getLastDiceResult() if(!resulStr.isEmpty()) { - stream << dieValue.arg(face).arg(resulStr); + if(!diceValues.contains(face)) + { + diceValues.insert(face,resulStr); + } + else + { + QString tmp = diceValues.value(face); + tmp+=resulStr; + diceValues.insert(face,tmp); + } + //stream << dieValue.arg(face).arg(resulStr); } } } @@ -450,7 +461,8 @@ QString DiceParser::getLastDiceResult() result = result->getPrevious(); } - return str.simplified(); + //return str.simplified(); + return diceValues; } QString DiceParser::getDiceCommand() { diff --git a/die.cpp b/die.cpp index dc6576e..d8be064 100644 --- a/die.cpp +++ b/die.cpp @@ -132,3 +132,12 @@ void Die::displayed() { m_displayStatus = true; } +void Die::setHighlighted(bool a) +{ + m_highlighted = a; +} + +bool Die::isHighlighted() +{ + return m_highlighted; +} -- cgit v1.2.3-70-g09d2 From 5938230cc183b562ab076dd46dabcaf325a21157 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 22 Apr 2015 10:57:20 +0200 Subject: add bool value to know if the validator should remove the highlight of some dice --- booleancondition.cpp | 10 +++++----- booleancondition.h | 2 +- range.cpp | 15 +++++++++------ range.h | 2 +- validator.h | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/booleancondition.cpp b/booleancondition.cpp index 267d7e9..de619e7 100644 --- a/booleancondition.cpp +++ b/booleancondition.cpp @@ -25,7 +25,7 @@ BooleanCondition::BooleanCondition() { } -qint64 BooleanCondition::hasValid(Die* b,bool recursive) const +qint64 BooleanCondition::hasValid(Die* b,bool recursive,bool unhighlight) const { QList listValues; if(recursive) @@ -40,7 +40,6 @@ qint64 BooleanCondition::hasValid(Die* b,bool recursive) const qint64 sum= 0; foreach(qint64 value, listValues) { - switch(m_operator) { case Equal: @@ -58,11 +57,12 @@ qint64 BooleanCondition::hasValid(Die* b,bool recursive) const case LesserOrEqual: sum+= (value<=m_value)?1:0; break; - - } } - + if((unhighlight)&&(sum==0)) + { + b->setHighlighted(false); + } return sum; } diff --git a/booleancondition.h b/booleancondition.h index 02fadf9..8de8854 100644 --- a/booleancondition.h +++ b/booleancondition.h @@ -31,7 +31,7 @@ public: enum LogicOperator { Equal, GreaterThan, LesserThan, GreaterOrEqual, LesserOrEqual}; BooleanCondition(); - virtual qint64 hasValid(Die* b,bool recursive) const; + virtual qint64 hasValid(Die* b,bool recursive, bool unhighlight = false) const; void setOperator(LogicOperator m); void setValue(qint64); diff --git a/range.cpp b/range.cpp index 1f47c50..909c96c 100644 --- a/range.cpp +++ b/range.cpp @@ -32,25 +32,28 @@ void Range::setValue(qint64 s,qint64 e) m_end=e; } -qint64 Range::hasValid(Die* m,bool recursive) const +qint64 Range::hasValid(Die* m,bool recursive, bool unhighlight) const { + qint64 result = 0; if(recursive) { - qint64 i = 0; foreach(qint64 value, m->getListValue()) { if((value>=m_start)&&(value<=m_end)) { - ++i; + ++result; } } - return i; } else if((m->getLastRolledValue()>=m_start)&&(m->getLastRolledValue()<=m_end)) { - return 1; + ++result; } - return 0; + if((unhighlight)&&(result==0)) + { + m->setHighlighted(false); + } + return result; } QString Range::toString() { diff --git a/range.h b/range.h index 629d0c3..3573174 100644 --- a/range.h +++ b/range.h @@ -31,7 +31,7 @@ public: Range(); void setValue(qint64,qint64); - virtual qint64 hasValid(Die* b,bool recursive) const; + virtual qint64 hasValid(Die* b,bool recursive,bool unlight = false) const; virtual QString toString(); virtual quint8 getValidRangeSize(quint64 faces) const; diff --git a/validator.h b/validator.h index c9bb78e..d18a691 100644 --- a/validator.h +++ b/validator.h @@ -30,7 +30,7 @@ class Validator { public: Validator(); - virtual qint64 hasValid(Die* b,bool recursive) const = 0 ; + virtual qint64 hasValid(Die* b,bool recursive,bool unlight = false) const = 0 ; virtual QString toString()=0; virtual quint8 getValidRangeSize(quint64 faces) const = 0 ; -- cgit v1.2.3-70-g09d2 From d4c03f1eb5627294df3675de2e8e55fd721e37d8 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 22 Apr 2015 10:57:53 +0200 Subject: management of highligth dice --- node/countexecutenode.cpp | 2 +- node/keepdiceexecnode.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/node/countexecutenode.cpp b/node/countexecutenode.cpp index 1050efc..ff3d67b 100644 --- a/node/countexecutenode.cpp +++ b/node/countexecutenode.cpp @@ -35,7 +35,7 @@ void CountExecuteNode::run(ExecutionNode *previous) qint64 sum = 0; foreach(Die* dice,diceList) { - sum+=m_validator->hasValid(dice,true); + sum+=m_validator->hasValid(dice,true,true); } m_scalarResult->setValue(sum); diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp index 62b4c8f..e8cfac8 100644 --- a/node/keepdiceexecnode.cpp +++ b/node/keepdiceexecnode.cpp @@ -26,6 +26,11 @@ m_previousNode = previous; diceList2 = diceList.mid(0,m_numberOfDice); + foreach(Die* tmp,diceList.mid(m_numberOfDice,-1)) + { + tmp->setHighlighted(false); + } + m_diceResult->setResultList(diceList2); if(NULL!=m_nextNode) { -- cgit v1.2.3-70-g09d2 From b36a3b448603514c392a8db8160af72788731c44 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 22 Apr 2015 14:40:21 +0200 Subject: change the way die result are transmitted to client application --- diceparser.cpp | 48 ++++++++++++++++++------------------------------ diceparser.h | 7 ++++++- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/diceparser.cpp b/diceparser.cpp index a2fa137..f2a7ea5 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -392,77 +392,65 @@ QString DiceParser::getStringResult() str = result->getResult(Result::STRING).toString(); found = true; } - result = result->getPrevious(); } return str; } -QString DiceParser::getLastDiceResult() +void DiceParser::getLastDiceResult(ExportedDiceResult& diceValues) { ExecutionNode* next = getLeafNode(); - // QString str; - // QTextStream stream(&str); Result* result=next->getResult(); - QMap diceValues; - //QString dieValue("%2 (D%1)"); - bool first=true; + while(NULL!=result) { if(result->hasResultOfType(Result::DICE_LIST)) { - DiceResult* myDiceResult = dynamic_cast(result); - if(NULL!=myDiceResult) + DiceResult* diceResult = dynamic_cast(result); + if(NULL!=diceResult) { - - QString resulStr; + bool hasResult = false; quint64 face=0; - foreach(Die* die, myDiceResult->getResultList()) + ListDiceResult listpair; + foreach(Die* die, diceResult->getResultList()) { if(!die->hasBeenDisplayed()) { - resulStr+=QString("%1").arg(die->getValue()); + QList valuesResult; + hasResult=true; + valuesResult.append(die->getValue()); die->displayed(); face = die->getFaces(); - if(die->hasChildrenValue()) { - QString childDice(""); foreach(qint64 i, die->getListValue()) { - - childDice+=QString("%1,").arg(i); + valuesResult.append(i); } - childDice.remove(childDice.size()-1,1); - resulStr+=QString("[%1]").arg(childDice); } - resulStr+=", "; + QPair,bool> pair(valuesResult,die->isHighlighted()); + listpair.append(pair); } } - resulStr.remove(resulStr.size()-2,2); - - if(!resulStr.isEmpty()) + if(!listpair.isEmpty()) { if(!diceValues.contains(face)) { - diceValues.insert(face,resulStr); + diceValues.insert(face,listpair); } else { - QString tmp = diceValues.value(face); - tmp+=resulStr; + ListDiceResult tmp = diceValues.value(face); + tmp.append(listpair); diceValues.insert(face,tmp); } - //stream << dieValue.arg(face).arg(resulStr); + } } } result = result->getPrevious(); } - - //return str.simplified(); - return diceValues; } QString DiceParser::getDiceCommand() { diff --git a/diceparser.h b/diceparser.h index b4fd429..3f80acb 100644 --- a/diceparser.h +++ b/diceparser.h @@ -34,6 +34,11 @@ #include "parsingtoolbox.h" #include "dicealias.h" + +typedef QPair,bool> DiceAndHighlight; +typedef QList ListDiceResult; +typedef QMap ExportedDiceResult; + class ExploseDiceNode; /** * @mainpage DiceParser @@ -131,7 +136,7 @@ public: * @brief getLastDiceResult * @return */ - QString getLastDiceResult(); + void getLastDiceResult(ExportedDiceResult& diceValues); /** * @brief hasIntegerResultNotInFirst * @return -- cgit v1.2.3-70-g09d2 From bb60ef6acfe0cde680f16cb00188fa2f97e7c6ec Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 22 Apr 2015 18:38:32 +0200 Subject: add dice api to manage highlight --- die.cpp | 2 +- die.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/die.cpp b/die.cpp index d8be064..2a70bc0 100644 --- a/die.cpp +++ b/die.cpp @@ -26,7 +26,7 @@ #include Die::Die() - : m_hasValue(false),m_displayStatus(false) + : m_hasValue(false),m_displayStatus(false),m_highlighted(true) { uint seed = quintptr(this) + QDateTime::currentDateTime().toMSecsSinceEpoch(); qsrand(seed); diff --git a/die.h b/die.h index 5ef2bc2..c9ed28a 100644 --- a/die.h +++ b/die.h @@ -109,6 +109,15 @@ public: * @brief displayed */ void displayed(); + /** + * @brief setHighlighted + */ + void setHighlighted(bool); + /** + * @brief isHighlighted + * @return + */ + bool isHighlighted(); private: qint64 m_value; @@ -116,6 +125,7 @@ private: bool m_selected; bool m_hasValue; bool m_displayStatus; + bool m_highlighted; quint64 m_faces; }; -- cgit v1.2.3-70-g09d2 From 888c6cbf5a204712b591ce96148ea016eea0ba5d Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 23 Apr 2015 10:50:33 +0200 Subject: add file for cli main application --- cli/cli.pri | 2 ++ cli/main.cpp | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.cpp | 107 ----------------------------------------------------------- 3 files changed, 109 insertions(+), 107 deletions(-) create mode 100644 cli/cli.pri create mode 100644 cli/main.cpp delete mode 100644 main.cpp diff --git a/cli/cli.pri b/cli/cli.pri new file mode 100644 index 0000000..69aa44f --- /dev/null +++ b/cli/cli.pri @@ -0,0 +1,2 @@ +SOURCES += \ + $$PWD/main.cpp diff --git a/cli/main.cpp b/cli/main.cpp new file mode 100644 index 0000000..7b70e23 --- /dev/null +++ b/cli/main.cpp @@ -0,0 +1,107 @@ +/*************************************************************************** +* Copyright (C) 2014 by Renaud Guezennec * +* http://renaudguezennec.homelinux.org/accueil,3.html * +* * +* 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. * +***************************************************************************/ +#ifdef HAVE_IRC +#include +#include "irc/mainwindow.h" +#endif + +#include +#include "diceparser.h" + +int main(int argc, char *argv[]) +{ + #ifdef HAVE_IRC + QApplication a(argc, argv); + + + MainWindow main; +#endif + DiceParser* myParser = new DiceParser(); + + QStringList commands; + + commands<< "10d10c[>6]+@c[=10]" + << "1L[cheminée,chocolat,épée,arc,chute de pierre]" + << "10d10c[>=6]-@c[=1]" + << "10d10c[>=6]-@c[=1]-@c[=1]" + << "10d10c[>6]+@c[=10]" + << "1+1D10" + << "3d10c[>=5]" + << "3nwod" + << "1+(4*3)D10" + << "2+4/4" + << "2D10*2D20*8" + <<"1+(4*3)D10" + <<"(4D6)D10" + << "1D100a[>=95]a[>=96]a[>=97]a[>=98]a[>=99]e[>=100]" + << "3D100" + << "4k3" + << "10D10e[>=6]sc[>=6]" + << "100190D6666666s" + << "10D10e10s" + << "10D10s" + << "15D10e10c[8-10]" + << "10d10e11" + << "1D8+2D6+7" + << "100190D6666666s" + << "D25" + << "D25+D10" + << "D25;D10" + << "8+8+8" + << "1D20-88" + << "100*1D20*2D6" + << "100/28*3" + << "100/8" + << "100*3*8" + << "help" + << "la" + << "400000D20/400000" + << "100*3*8";// + + if(argc>1) + { + for(int i=1;iparseLine(cmd)) + { + myParser->Start(); + // myParser->displayDotTree(); + myParser->displayResult(); + } + else + { + qDebug() << "echec"; + } + } + #ifdef HAVE_IRC + main.show(); + return a.exec(); +#endif + delete myParser; + return 0; +} diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 7b70e23..0000000 --- a/main.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2014 by Renaud Guezennec * -* http://renaudguezennec.homelinux.org/accueil,3.html * -* * -* 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. * -***************************************************************************/ -#ifdef HAVE_IRC -#include -#include "irc/mainwindow.h" -#endif - -#include -#include "diceparser.h" - -int main(int argc, char *argv[]) -{ - #ifdef HAVE_IRC - QApplication a(argc, argv); - - - MainWindow main; -#endif - DiceParser* myParser = new DiceParser(); - - QStringList commands; - - commands<< "10d10c[>6]+@c[=10]" - << "1L[cheminée,chocolat,épée,arc,chute de pierre]" - << "10d10c[>=6]-@c[=1]" - << "10d10c[>=6]-@c[=1]-@c[=1]" - << "10d10c[>6]+@c[=10]" - << "1+1D10" - << "3d10c[>=5]" - << "3nwod" - << "1+(4*3)D10" - << "2+4/4" - << "2D10*2D20*8" - <<"1+(4*3)D10" - <<"(4D6)D10" - << "1D100a[>=95]a[>=96]a[>=97]a[>=98]a[>=99]e[>=100]" - << "3D100" - << "4k3" - << "10D10e[>=6]sc[>=6]" - << "100190D6666666s" - << "10D10e10s" - << "10D10s" - << "15D10e10c[8-10]" - << "10d10e11" - << "1D8+2D6+7" - << "100190D6666666s" - << "D25" - << "D25+D10" - << "D25;D10" - << "8+8+8" - << "1D20-88" - << "100*1D20*2D6" - << "100/28*3" - << "100/8" - << "100*3*8" - << "help" - << "la" - << "400000D20/400000" - << "100*3*8";// - - if(argc>1) - { - for(int i=1;iparseLine(cmd)) - { - myParser->Start(); - // myParser->displayDotTree(); - myParser->displayResult(); - } - else - { - qDebug() << "echec"; - } - } - #ifdef HAVE_IRC - main.show(); - return a.exec(); -#endif - delete myParser; - return 0; -} -- cgit v1.2.3-70-g09d2 From cd21a9b1252f4d000b18ccecacc9c4e92d59f67b Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 23 Apr 2015 10:51:01 +0200 Subject: amend files for cli main application --- cli/main.cpp | 122 ++++++++++++++++++++++++++++++++++++++++----------------- diceParser.pro | 7 +++- 2 files changed, 91 insertions(+), 38 deletions(-) diff --git a/cli/main.cpp b/cli/main.cpp index 7b70e23..8f1ec67 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -19,27 +19,100 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifdef HAVE_IRC -#include -#include "irc/mainwindow.h" -#endif #include #include "diceparser.h" +#include +#include -int main(int argc, char *argv[]) +void startDiceParsing(QString& cmd,QString& treeFile,bool highlight) { - #ifdef HAVE_IRC - QApplication a(argc, argv); + DiceParser* parser = new DiceParser(); + if(parser->parseLine(cmd)) + { + parser->Start(); + // + if(treeFile.isEmpty()) + { + parser->displayResult(); + } + else + { + parser->writeDownDotTree(); + } + } +} + + - MainWindow main; -#endif - DiceParser* myParser = new DiceParser(); +int main(int argc, char *argv[]) +{ QStringList commands; + QString cmd; + QString dotFile; + + bool color=true; + + QCommandLineParser optionParser; + QCommandLineOption color(QStringList() << "co"<< "color-off", tr("Disable color to highlight result")); + QCommandLineOption version(QStringList() << "v"<< "version", tr("Show the version and quit.")); + QCommandLineOption reset(QStringList() << "reset-settings", tr("Erase the settings and use the default parameters")); + QCommandLineOption dotFile(QStringList() << "d"<<"dot-file", tr("Instead of rolling dice, generate the execution tree and write it in "),"dotfile"); + QCommandLineOption translation(QStringList() << "t"<<"translation", QObject::tr("path to the translation file: "),"translationfile"); + QCommandLineOption help(QStringList() << "h"<<"help", QObject::tr("Display this help")); + + optionParser.addOption(color); + optionParser.addOption(version); + optionParser.addOption(reset); + optionParser.addOption(dotFile); + optionParser.addOption(translation); + optionParser.addOption(help); + + for(int i=1;i6]+@c[=10]" + cmd = commands.first(); + + + startDiceParsing(cmd,dotFile,color); + + /*commands<< "10d10c[>6]+@c[=10]" << "1L[cheminée,chocolat,épée,arc,chute de pierre]" << "10d10c[>=6]-@c[=1]" << "10d10c[>=6]-@c[=1]-@c[=1]" @@ -76,32 +149,9 @@ int main(int argc, char *argv[]) << "la" << "400000D20/400000" << "100*3*8";// +*/ + - if(argc>1) - { - for(int i=1;iparseLine(cmd)) - { - myParser->Start(); - // myParser->displayDotTree(); - myParser->displayResult(); - } - else - { - qDebug() << "echec"; - } - } - #ifdef HAVE_IRC - main.show(); - return a.exec(); -#endif - delete myParser; return 0; } diff --git a/diceParser.pro b/diceParser.pro index c339933..8af57a4 100644 --- a/diceParser.pro +++ b/diceParser.pro @@ -18,8 +18,11 @@ TEMPLATE = app #CONFIG+= IRC #CONFIG+= GUI - - +CONFIG+= CLI +CLI { +DEFINES += CLI +include(cli/cli.pri)cd +} IRC { include(irc/irc.pri) QT += gui widgets -- cgit v1.2.3-70-g09d2 From f9d748791c1d7e3d2dc4f51bec4f86a6732083e4 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 23 Apr 2015 10:52:16 +0200 Subject: improvement of the lib --- diceparser.cpp | 12 ++++++++++-- diceparser.h | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/diceparser.cpp b/diceparser.cpp index f2a7ea5..a2015d8 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -915,12 +915,20 @@ bool DiceParser::readOperand(QString& str,ExecutionNode* & node) } return false; } -void DiceParser::displayDotTree() +void DiceParser::writeDownDotTree(QString filepath) { QString str("digraph ExecutionTree {\n"); m_start->generateDotTree(str); str.append("}"); - qDebug()<< str; + + /*QFile file(filepath); + if(file.open(QIODevice::WriteOnly)) + { + QTextStream in(&file); + in << str; + }*/ + + //qDebug()<< str; } diff --git a/diceparser.h b/diceparser.h index 3f80acb..249a630 100644 --- a/diceparser.h +++ b/diceparser.h @@ -121,7 +121,7 @@ public: /** * @brief displayDotTree */ - void displayDotTree(); + void writeDownDotTree(QString filepath); /** * @brief getLastIntegerResult * @return -- cgit v1.2.3-70-g09d2 From c356c8bf53f46efb2ba0aaa6d91ef4c4ade320b6 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 24 Apr 2015 11:08:32 +0200 Subject: add commandLine parser(not working yet) --- cli/main.cpp | 129 ++++++++++++++++++++++++++++++++++++++++++++++++--------- diceParser.pro | 3 +- 2 files changed, 110 insertions(+), 22 deletions(-) diff --git a/cli/main.cpp b/cli/main.cpp index 8f1ec67..7476eb4 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -24,21 +24,101 @@ #include "diceparser.h" #include #include +#include + +QString diceToText(ExportedDiceResult& dice) +{ + QStringList resultGlobal; + foreach(int face, dice.keys()) + { + QStringList result; + ListDiceResult diceResult = dice.value(face); + bool previousHighlight=false; + QString patternColor("\e[0;31m"); + //patternColor = patternColorarg(); + foreach (DiceAndHighlight tmp, diceResult) + { + QStringList diceListStr; + QStringList diceListChildren; + if((previousHighlight)&&(!tmp.second)) + { + result << patternColor << result.join(',') <<"\e[0m"; + } + previousHighlight = tmp.second; + for(int i =0; i < tmp.first.size(); ++i) + { + quint64 dievalue = tmp.first[i]; + if(i==0) + { + diceListStr << QString::number(dievalue); + } + else + { + diceListChildren << QString::number(dievalue); + } + } + if(!diceListChildren.isEmpty()) + { + diceListStr << QString("[%1]").arg(diceListChildren.join(',')); + } + + result << diceListStr.join(' '); + } + if(previousHighlight) + { + QStringList list; + list << patternColor << result.join(',') << "\e[0m"; + result = list; + } + if(dice.keys().size()>1) + { + resultGlobal << QString(" d%2:(%1)").arg(result.join(' ')).arg(face); + } + else + { + resultGlobal << result; + } + } + return resultGlobal.join(' '); +} void startDiceParsing(QString& cmd,QString& treeFile,bool highlight) { DiceParser* parser = new DiceParser(); + if(parser->parseLine(cmd)) { parser->Start(); // if(treeFile.isEmpty()) { - parser->displayResult(); + ExportedDiceResult list; + parser->getLastDiceResult(list); + QString diceText = diceToText(list); + QString scalarText; + QString str; + + if(parser->hasIntegerResultNotInFirst()) + { + scalarText = QString("%1").arg(parser->getLastIntegerResult()); + } + else if(!list.isEmpty()) + { + scalarText = QString("%1").arg(parser->getSumOfDiceResult()); + } + + str = QString("Result: \e[0;31m%1\e[0m, details:[%3 (%2)]").arg(scalarText).arg(diceText).arg(parser->getDiceCommand()); + + if(parser->hasStringResult()) + { + str = parser->getStringResult().replace("\n","
"); + } + qDebug() << str; + } else { - parser->writeDownDotTree(); + parser->writeDownDotTree(treeFile); } } } @@ -51,19 +131,23 @@ int main(int argc, char *argv[]) QStringList commands; QString cmd; - QString dotFile; + QString dotFileStr; - bool color=true; + bool colorb=false; QCommandLineParser optionParser; - QCommandLineOption color(QStringList() << "co"<< "color-off", tr("Disable color to highlight result")); - QCommandLineOption version(QStringList() << "v"<< "version", tr("Show the version and quit.")); - QCommandLineOption reset(QStringList() << "reset-settings", tr("Erase the settings and use the default parameters")); - QCommandLineOption dotFile(QStringList() << "d"<<"dot-file", tr("Instead of rolling dice, generate the execution tree and write it in "),"dotfile"); - QCommandLineOption translation(QStringList() << "t"<<"translation", QObject::tr("path to the translation file: "),"translationfile"); - QCommandLineOption help(QStringList() << "h"<<"help", QObject::tr("Display this help")); - - optionParser.addOption(color); + QCommandLineOption color(QStringList() << "co"<< "color-off", "Disable color to highlight result"); + QCommandLineOption version(QStringList() << "v"<< "version", "Show the version and quit."); + QCommandLineOption reset(QStringList() << "reset-settings", "Erase the settings and use the default parameters"); + QCommandLineOption dotFile(QStringList() << "d"<<"dot-file", "Instead of rolling dice, generate the execution tree and write it in ","dotfile"); + QCommandLineOption translation(QStringList() << "t"<<"translation", "path to the translation file: ","translationfile"); + QCommandLineOption help(QStringList() << "h"<<"help", "Display this help"); + + if(!optionParser.addOption(color)) + { + qDebug()<< optionParser.errorText(); + } + optionParser.addOption(version); optionParser.addOption(reset); optionParser.addOption(dotFile); @@ -76,12 +160,20 @@ int main(int argc, char *argv[]) commands << QString::fromLatin1(argv[i]); } - optionParser.parse(commands); + if(!optionParser.parse(commands)) + { + qDebug()<< optionParser.errorText(); + } + else + { + qDebug() << "no error"; + } if(optionParser.isSet(color)) { - return 0; + qDebug() << "color"; + colorb = false; } else if(optionParser.isSet(version)) { @@ -93,7 +185,7 @@ int main(int argc, char *argv[]) } else if(optionParser.isSet(dotFile)) { - dotFile = optionParser.value(dotFile); + dotFileStr = optionParser.value(dotFile); } else if(optionParser.isSet(translation)) { @@ -101,16 +193,13 @@ int main(int argc, char *argv[]) } else if(optionParser.isSet(help)) { - cmd = "help"; } - - cmd = commands.first(); - - startDiceParsing(cmd,dotFile,color); + qDebug() << "super 5" << cmd << dotFileStr << colorb; + startDiceParsing(cmd,dotFileStr,colorb); /*commands<< "10d10c[>6]+@c[=10]" << "1L[cheminée,chocolat,épée,arc,chute de pierre]" diff --git a/diceParser.pro b/diceParser.pro index 8af57a4..3a95496 100644 --- a/diceParser.pro +++ b/diceParser.pro @@ -36,8 +36,7 @@ DEFINES+= HAVE_GUI } -SOURCES += main.cpp \ - diceparser.cpp \ +SOURCES += diceparser.cpp \ result/diceresult.cpp \ range.cpp \ booleancondition.cpp \ -- cgit v1.2.3-70-g09d2 From 7ec87c14e11b84dcf0af0b0176da15225362ada6 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 24 Apr 2015 21:05:23 +0200 Subject: file output for dot --- diceparser.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/diceparser.cpp b/diceparser.cpp index a2015d8..c710f55 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -23,7 +23,7 @@ #include #include #include - +#include #include "node/startingnode.h" #include "node/scalaroperatornode.h" @@ -922,12 +922,12 @@ void DiceParser::writeDownDotTree(QString filepath) str.append("}"); - /*QFile file(filepath); + QFile file(filepath); if(file.open(QIODevice::WriteOnly)) { QTextStream in(&file); in << str; - }*/ + } //qDebug()<< str; -- cgit v1.2.3-70-g09d2 From edfcca8d1a630ca7ca79133bd0b03af14fef6363 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 24 Apr 2015 21:05:54 +0200 Subject: use cmake for diceparser --- CMakeLists.txt | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..577e112 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,71 @@ +cmake_minimum_required(VERSION 2.8) + + +project(dice) + +#/net/rnd/src/qt/qt-everywhere-enterprise-src-5.3.0/linux-x86_64-gcc-4.7.2/lib/cmake +set(CMAKE_PREFIX_PATH "/net/rnd/src/qt/qt-everywhere-enterprise-src-5.3.0/linux-x86_64-gcc-4.7.2/lib/cmake") + +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} +#${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") + + +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) + +# Find the QtWidgets library +find_package(Qt5Core) + +set(EXECUTABLE_OUTPUT_PATH bin/) + +include_directories(${Qt5Core_INCLUDES}) +add_definitions(${Qt5Core_DEFINITIONS}) + +set(MODE "cli") +#file ( +# GLOB_RECURSE +# source_files +# *.cpp +# result/* +# node/* +#) +add_executable( + dice + diceparser.cpp + range.cpp + booleancondition.cpp + validator.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/jumpbackwardnode.cpp +node/keepdiceexecnode.cpp +node/listaliasnode.cpp +node/listsetrollnode.cpp +node/numbernode.cpp +node/parenthesesnode.cpp +node/rerolldicenode.cpp +node/scalaroperatornode.cpp +node/sortresult.cpp +node/startingnode.cpp +cli/main.cpp + ) + +#add_executable(dice cli/main.cpp) + + +target_link_libraries(dice ${Qt5Core_LIBRARIES}) + +#qt5_use_modules() + -- cgit v1.2.3-70-g09d2