From 8122ac01552c631b14ea096117c775ff6509ea24 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sun, 3 Apr 2016 14:29:21 +0200 Subject: change contact link. --- diceparser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'diceparser.h') diff --git a/diceparser.h b/diceparser.h index 0df633b..871a0d3 100644 --- a/diceparser.h +++ b/diceparser.h @@ -1,6 +1,6 @@ /*************************************************************************** * Copyright (C) 2014 by Renaud Guezennec * -* http://renaudguezennec.homelinux.org/accueil,3.html * +* http://www.rolisteam.org/contact * * * * This file is part of DiceParser * * * -- cgit v1.2.3-70-g09d2 From 9311cabe959739e74b62e46563bace3ebc63e15d Mon Sep 17 00:00:00 2001 From: Renaud Guezennec Date: Wed, 13 Apr 2016 16:23:48 +0200 Subject: Add management for variable in DiceParser. --- diceparser.cpp | 4 ++++ diceparser.h | 5 +++++ parsingtoolbox.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- parsingtoolbox.h | 20 +++++++++++++++++--- 4 files changed, 75 insertions(+), 4 deletions(-) (limited to 'diceparser.h') diff --git a/diceparser.cpp b/diceparser.cpp index 90d52e3..af87199 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -1086,3 +1086,7 @@ void DiceParser::setPathToHelp(QString l) { m_helpPath = l; } +void DiceParser::setVariableDictionary(QHash* variables) +{ + ParsingToolBox::setVariableHash(variables); +} diff --git a/diceparser.h b/diceparser.h index 0df633b..0757f99 100644 --- a/diceparser.h +++ b/diceparser.h @@ -204,6 +204,11 @@ public: bool hasSeparator()const; bool readIfInstruction(QString &str, ExecutionNode* &trueNode, ExecutionNode* &falseNode); + /** + * @brief setVariableDictionary + * @param variables + */ + void setVariableDictionary(QHash* variables); private: /** diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index 00dfe81..5014b31 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -24,6 +24,7 @@ #include "parsingtoolbox.h" #include "node/sortresult.h" +QHash* ParsingToolBox::m_variableHash = NULL; ParsingToolBox::ParsingToolBox() { @@ -279,7 +280,9 @@ bool ParsingToolBox::readNumber(QString& str, qint64& myNumber) } if(number.isEmpty()) - return false; + { + return readVariable(str,myNumber); + } bool ok; myNumber = number.toLongLong(&ok); @@ -288,8 +291,43 @@ bool ParsingToolBox::readNumber(QString& str, qint64& myNumber) str=str.remove(0,number.size()); return true; } + return false; } + +bool ParsingToolBox::readVariable(QString &str, qint64 &myNumber) +{ + if(str.isEmpty()) + return false; + if(str.startsWith("${")) + { + str=str.remove(0,2); + } + QString key; + int post = str.indexOf('}'); + key = str.left(post); + + if(NULL!=m_variableHash) + { + if(m_variableHash->contains(key)) + { + QString value = m_variableHash->value(key); + bool ok; + int valueInt = value.toInt(&ok); + if(ok) + { + myNumber = valueInt; + str=str.remove(0,post+1); + return true; + } + + } + } + + + return false; + +} bool ParsingToolBox::readOpenParentheses(QString& str) { if(str.startsWith("(")) @@ -436,6 +474,16 @@ void ParsingToolBox::readPainterParameter(PainterNode* painter,QString& str) } } +QHash *ParsingToolBox::getVariableHash() +{ + return m_variableHash; +} + +void ParsingToolBox::setVariableHash(QHash *variableHash) +{ + m_variableHash = variableHash; +} + void ParsingToolBox::readProbability(QStringList& str,QList& ranges) { quint64 totalDistance=0; diff --git a/parsingtoolbox.h b/parsingtoolbox.h index 4aeb16e..efe7acd 100644 --- a/parsingtoolbox.h +++ b/parsingtoolbox.h @@ -95,7 +95,13 @@ public: */ static bool readNumber(QString& str, qint64& myNumber); - + /** + * @brief readVariable + * @param str + * @param myNumber + * @return + */ + static bool readVariable(QString& str,qint64& myNumber); /** * @brief readOpenParentheses * @param str @@ -154,11 +160,19 @@ public: bool readArithmeticOperator(QString& str, ScalarOperatorNode::ArithmeticOperator& op); static void readPainterParameter(PainterNode *painter, QString &str); + + static QHash *getVariableHash(); + static void setVariableHash(QHash *variableHash); + private: - QMap* m_logicOp; - QMap* m_logicOperation; + + QMap* m_logicOp; + QMap* m_logicOperation; QMap* m_conditionOperation; QHash* m_arithmeticOperation; + + + static QHash* m_variableHash; }; #endif // PARSINGTOOLBOX_H -- cgit v1.2.3-70-g09d2