From 7ed106bc79c222586279d4351db1c5f005b0b1f3 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Tue, 24 Mar 2015 21:53:40 +0100 Subject: -Add listaliasnode to list all alias. --- diceparser.cpp | 25 +++++++++++-------------- diceparser.h | 2 +- main.cpp | 12 ++++++++---- node/helpnode.cpp | 1 - node/listaliasnode.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ node/listaliasnode.h | 33 +++++++++++++++++++++++++++++++++ node/node.pri | 6 ++++-- 7 files changed, 103 insertions(+), 22 deletions(-) create mode 100644 node/listaliasnode.cpp create mode 100644 node/listaliasnode.h diff --git a/diceparser.cpp b/diceparser.cpp index ea6dcc9..56fa72e 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -37,6 +37,7 @@ #include "node/helpnode.h" #include "node/jumpbackwardnode.h" #include "node/listsetrollnode.h" +#include "node/listaliasnode.h" #define DEFAULT_FACES_NUMBER 10 @@ -70,8 +71,9 @@ DiceParser::DiceParser() m_nodeActionMap->insert("@",JumpBackward); - m_commandList = new QList(); + m_commandList = new QStringList(); m_commandList->append("help"); + m_commandList->append("la"); } @@ -126,8 +128,6 @@ bool DiceParser::parseLine(QString str) bool DiceParser::readExpression(QString& str,ExecutionNode* & node) { - // int myNumber = 1; - // bool hasReadNumber=false; ExecutionNode* operandNode=NULL; if(m_parsingToolbox->readOpenParentheses(str)) { @@ -196,13 +196,6 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) } bool DiceParser::readNode(QString& str,ExecutionNode* & node) { - /*k case JumpBackward: - { - JumpBackwardNode* jumpNode = new JumpBackwardNode(); - previous->setNextNode(jumpNode); - node = jumpNode; - isFine=true; - }*/ QString key= str.left(1); if(m_nodeActionMap->contains(key)) { @@ -231,7 +224,6 @@ QString DiceParser::displayResult() next = next->getNextNode(); ++nodeCount; } -// qDebug() << "node count"<< nodeCount; ////////////////////////////////// // // Display @@ -277,7 +269,6 @@ QString DiceParser::displayResult() resulStr+=" ["; foreach(qint64 i, die->getListValue()) { - resulStr+=QString("%1 ").arg(i); } resulStr.remove(resulStr.size()-1,1); @@ -345,7 +336,6 @@ bool DiceParser::readDice(QString& str,ExecutionNode* & node) QStringList list; if(m_parsingToolbox->readList(str,list)) { - qDebug() << list; ListSetRollNode* lsrNode = new ListSetRollNode(); lsrNode->setListValue(list); node = lsrNode; @@ -376,7 +366,14 @@ bool DiceParser::readCommand(QString& str,ExecutionNode* & node) { if(m_commandList->contains(str)) { - node = new HelpNode(); + if(str=="help") + { + node = new HelpNode(); + } + else if(str=="la") + { + node = new ListAliasNode(m_aliasMap); + } return true; } return false; diff --git a/diceparser.h b/diceparser.h index 22dead1..c4f9f6b 100644 --- a/diceparser.h +++ b/diceparser.h @@ -177,7 +177,7 @@ private: QMap* m_OptionOp; QMap* m_nodeActionMap; QMap* m_aliasMap; - QList* m_commandList; + QStringList* m_commandList; ExecutionNode* m_start; diff --git a/main.cpp b/main.cpp index 986bc2c..0dac21c 100644 --- a/main.cpp +++ b/main.cpp @@ -39,8 +39,8 @@ int main(int argc, char *argv[]) QStringList commands; - commands << "1L[cheminée,chocolat,épée,arc,chute de pierre]" ; - /*<< "10d10c[>=6]-@c[=1]" + commands << "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" @@ -59,9 +59,11 @@ int main(int argc, char *argv[]) << "10D10e10s" << "10D10s" << "15D10e10c[8-10]" - << "x" + << "10d10e11" << "1D8+2D6+7" << "D25" + << "D25+D10" + << "D25;D10" << "8+8+8" << "1D20-88" << "100*1D20*2D6" @@ -69,7 +71,9 @@ int main(int argc, char *argv[]) << "100/8" << "100*3*8" << "help" - << "100*3*8";*/ + << "la" + << "400000D20/400000" + << "100*3*8"; if(argc>1) { diff --git a/node/helpnode.cpp b/node/helpnode.cpp index bae4b21..82f44f8 100644 --- a/node/helpnode.cpp +++ b/node/helpnode.cpp @@ -9,7 +9,6 @@ void HelpNode::run(ExecutionNode* previous) m_previousNode = previous; StringResult* txtResult = dynamic_cast(m_result); - qDebug() << m_result->hasResultOfType(Result::SCALAR) << m_result->hasResultOfType(Result::STRING); if(NULL != previous) { if(previous->getResult() == NULL) diff --git a/node/listaliasnode.cpp b/node/listaliasnode.cpp new file mode 100644 index 0000000..1d50c80 --- /dev/null +++ b/node/listaliasnode.cpp @@ -0,0 +1,46 @@ +#include "listaliasnode.h" + +ListAliasNode::ListAliasNode(QMap* apAlias) + : m_mapAlias(apAlias) +{ + m_result = new StringResult(); +} +void ListAliasNode::run(ExecutionNode* previous ) +{ + m_previousNode = previous; + StringResult* txtResult = dynamic_cast(m_result); + + if(NULL != previous) + { + if(previous->getResult() == NULL) + { + txtResult->setText(toString()); + + } + else + { + txtResult->setText(previous->getHelp()); + } + m_result->setPrevious(previous->getResult()); + } + + if(NULL!=m_nextNode) + { + m_nextNode->run(this); + } +} +QString ListAliasNode::toString()const +{ + QString result(QObject::tr("List of Alias:\n")); + foreach(QString key, m_mapAlias->keys()) + { + result+=QString("%1 : %2\n").arg(key).arg(m_mapAlias->value(key)); + } + + return result; +} + +qint64 ListAliasNode::getPriority() const +{ + return 0; +} diff --git a/node/listaliasnode.h b/node/listaliasnode.h new file mode 100644 index 0000000..d01d17a --- /dev/null +++ b/node/listaliasnode.h @@ -0,0 +1,33 @@ +#ifndef LISTALIASNODE_H +#define LISTALIASNODE_H + +#include "executionnode.h" +#include "result/stringresult.h" + + +class ListAliasNode : public ExecutionNode +{ +public: + ListAliasNode(QMap* mapAlias); + /** + * @brief run + * @param previous + */ + virtual void run(ExecutionNode* previous = NULL); + + /** + * @brief toString + * @return + */ + virtual QString toString()const; + /** + * @brief getPriority + * @return + */ + virtual qint64 getPriority() const; + +private: + QMap* m_mapAlias; +}; + +#endif // LISTALIASNODE_H diff --git a/node/node.pri b/node/node.pri index 7ed357c..7424c0b 100644 --- a/node/node.pri +++ b/node/node.pri @@ -12,7 +12,8 @@ HEADERS += \ node/parenthesesnode.h \ node/helpnode.h \ $$PWD/jumpbackwardnode.h \ - node/listsetrollnode.h + node/listsetrollnode.h \ + $$PWD/listaliasnode.h SOURCES += \ node/dicerollernode.cpp \ @@ -28,4 +29,5 @@ SOURCES += \ node/parenthesesnode.cpp \ node/helpnode.cpp \ $$PWD/jumpbackwardnode.cpp \ - node/listsetrollnode.cpp + node/listsetrollnode.cpp \ + $$PWD/listaliasnode.cpp -- cgit v1.2.3-70-g09d2