From 7d9f1e52c18b8f63e7b511bcd28e4fd4e9f0c5a7 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 24 Mar 2016 22:21:57 +0100 Subject: fix c++11 code --- parsingtoolbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'parsingtoolbox.cpp') diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index 1c9dc90..00dfe81 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -100,8 +100,8 @@ bool ParsingToolBox::readArithmeticOperator(QString &str, ScalarOperatorNode::Ar { bool found = false; //QHash::Iterator - auto i = m_arithmeticOperation->begin(); - for(; i !=m_arithmeticOperation->end() && !found; ++i) + + for(auto i = m_arithmeticOperation->begin() ; i !=m_arithmeticOperation->end() && !found; ++i) { if(str.startsWith(i.key())) { -- 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 'parsingtoolbox.cpp') 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