From 2d9fe10724dc1d5de86e63670536b9a1b6599ba1 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Tue, 9 Jun 2015 08:44:49 +0200 Subject: -add method to read list with probability value. It sets range for all values in List node. --- parsingtoolbox.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 2 deletions(-) (limited to 'parsingtoolbox.cpp') diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index f6b1f12..696d330 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -179,17 +179,20 @@ bool ParsingToolBox::readCloseParentheses(QString& str) else return false; } -bool ParsingToolBox::readList(QString& str,QStringList& list) +bool ParsingToolBox::readList(QString& str,QStringList& list,QList& ranges) { if(str.startsWith("[")) { str=str.remove(0,1); - int pos = str.indexOf("]"); + int pos = str.lastIndexOf("]"); if(-1!=pos) { QString liststr = str.left(pos); list = liststr.split(","); str=str.remove(0,pos+1); + readProbability(list,ranges); + + return true; } } @@ -270,4 +273,91 @@ bool ParsingToolBox::readDiceRange(QString& str,int& start, int& end) } } +} +ParsingToolBox::LIST_OPERATOR ParsingToolBox::readListOperator(QString& str) +{ + + if(str.startsWith('u')) + { + return UNIQUE; + } + return NONE; +} +void ParsingToolBox::readProbability(QStringList& str,QList& ranges) +{ + quint64 totalDistance=0; + quint64 undefDistance = 0; + int undefCount=0; + int maxValue = 0; + int i=0; + int j=0; + //range + foreach(QString line,str) + { + int pos = line.indexOf('['); + if(-1!=pos) + { + QString range = line.right(line.length()-pos); + line = line.left(pos); + str[j]=line; + int start; + int end; + if(readDiceRange(range,start,end)) + { + Range range; + range.setValue(start,end); + ranges.append(range); + totalDistance += end-start+1; + ++i; + } + else + { + Range range; + range.setStart(start); + ranges.append(range); + ++undefCount; + undefDistance +=start; + } + if((end>maxValue)||(i==1)) + { + maxValue = end; + } + } + ++j; + + } + + + + + ///Normalize list +// qDebug() << 100 - undefDistance; +// qDebug() << totalDistance; + + qint64 totalDistPourcent = totalDistance * undefDistance / (100-undefDistance); + + if(totalDistPourcent Date: Thu, 11 Jun 2015 11:16:04 +0200 Subject: remove debug message --- parsingtoolbox.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'parsingtoolbox.cpp') diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index 696d330..e7c603c 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -327,13 +327,6 @@ void ParsingToolBox::readProbability(QStringList& str,QList& ranges) } - - - - ///Normalize list -// qDebug() << 100 - undefDistance; -// qDebug() << totalDistance; - qint64 totalDistPourcent = totalDistance * undefDistance / (100-undefDistance); if(totalDistPourcent& ranges) tmp.setEnd(maxValue+(truc*totalDistPourcent)); maxValue = maxValue+(truc*totalDistPourcent); - qDebug() << truc << totalDistPourcent << undefDistance << totalDistance << maxValue << dist << totalDistPourcent << tmp.toString(); ranges[i]=tmp; } } -- cgit v1.2.3-70-g09d2 From f3ed92235184ec754bbf96eadf0693ae67e5de1b Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 20 Aug 2015 00:30:15 +0200 Subject: Add compositevalidator to explose operator. --- parsingtoolbox.cpp | 114 +++++++++++++++++++++++++++++++++++++++++++---------- parsingtoolbox.h | 14 +++++-- 2 files changed, 104 insertions(+), 24 deletions(-) (limited to 'parsingtoolbox.cpp') diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index e7c603c..50b166a 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -33,6 +33,12 @@ ParsingToolBox::ParsingToolBox() m_logicOp->insert("<",BooleanCondition::LesserThan); m_logicOp->insert("=",BooleanCondition::Equal); m_logicOp->insert(">",BooleanCondition::GreaterThan); + + + m_logicOperation = new QMap(); + m_logicOperation->insert("|",CompositeValidator::OR); + m_logicOperation->insert("^",CompositeValidator::EXCLUSIVE_OR); + m_logicOperation->insert("&",CompositeValidator::AND); } ExecutionNode* ParsingToolBox::addSort(ExecutionNode* e,bool b) { @@ -74,27 +80,23 @@ ParsingToolBox::~ParsingToolBox() Validator* ParsingToolBox::readValidator(QString& str) { Validator* returnVal=NULL; - bool expectSquareBrasket=false; + bool isOk = true; - if((str.startsWith("["))) - { - str=str.remove(0,1); - expectSquareBrasket = true; - } + BooleanCondition::LogicOperator myLogicOp = BooleanCondition::Equal; bool hasReadLogicOperator = readLogicOperator(str,myLogicOp); - int value=0; + qint64 value=0; if(readNumber(str,value)) { if(str.startsWith("-")) { str=str.remove(0,1); - int end=0; + qint64 end=0; if(readNumber(str,end)) { - if(expectSquareBrasket) + /* if(expectSquareBrasket) { if(str.startsWith("]")) { @@ -105,7 +107,7 @@ Validator* ParsingToolBox::readValidator(QString& str) { isOk=false; } - } + }*/ if(isOk) { str=str.remove(0,1); @@ -117,12 +119,12 @@ Validator* ParsingToolBox::readValidator(QString& str) } else { - if((expectSquareBrasket)&&(str.startsWith("]"))) + /* if((expectSquareBrasket)&&(str.startsWith("]"))) { str=str.remove(0,1); isOk=true; - } - if(isOk) + }*/ + //if(isOk) { BooleanCondition* condition = new BooleanCondition(); condition->setValue(value); @@ -133,14 +135,86 @@ Validator* ParsingToolBox::readValidator(QString& str) } return returnVal; } -bool ParsingToolBox::readNumber(QString& str, int& myNumber) +Validator* ParsingToolBox::readCompositeValidator(QString& str) +{ + bool expectSquareBrasket=false; + if((str.startsWith("["))) + { + str=str.remove(0,1); + expectSquareBrasket = true; + } + + Validator* tmp = readValidator(str); + CompositeValidator::LogicOperation opLogic; + + QVector* operators = new QVector(); + QList* validatorList = new QList(); + + while(NULL!=tmp) + { + bool hasOperator = readLogicOperation(str,opLogic); + if( hasOperator ) + { + operators->append(opLogic); + validatorList->append(tmp); + tmp = readValidator(str); + } + else + { + if((expectSquareBrasket)&&(str.startsWith("]"))) + { + str=str.remove(0,1); + //isOk=true; + } + + if(!validatorList->isEmpty()) + { + validatorList->append(tmp); + } + else + { + return tmp; + } + tmp = NULL; + } + + } + CompositeValidator* validator = new CompositeValidator(); + validator->setOperationList(operators); + validator->setValidatorList(validatorList); + + return validator; +} +bool ParsingToolBox::readLogicOperation(QString& str,CompositeValidator::LogicOperation& op) +{ + QString longKey; + foreach(QString tmp, m_logicOperation->keys()) + { + if(str.startsWith(tmp)) + { + if(longKey.size()0) + { + str=str.remove(0,longKey.size()); + op = m_logicOperation->value(longKey); + return true; + } + + return false; +} + +bool ParsingToolBox::readNumber(QString& str, qint64& myNumber) { if(str.isEmpty()) return false; QString number; int i=0; - while(igetPreviousNode(); } } -bool ParsingToolBox::readDiceRange(QString& str,int& start, int& end) +bool ParsingToolBox::readDiceRange(QString& str,qint64& start, qint64& end) { bool expectSquareBrasket=false; @@ -300,8 +372,8 @@ void ParsingToolBox::readProbability(QStringList& str,QList& ranges) QString range = line.right(line.length()-pos); line = line.left(pos); str[j]=line; - int start; - int end; + qint64 start; + qint64 end; if(readDiceRange(range,start,end)) { Range range; diff --git a/parsingtoolbox.h b/parsingtoolbox.h index cb97708..3d37f7b 100644 --- a/parsingtoolbox.h +++ b/parsingtoolbox.h @@ -27,6 +27,7 @@ #include "node/executionnode.h" #include "node/dicerollernode.h" #include "booleancondition.h" +#include "compositevalidator.h" #include "range.h" /** @@ -71,7 +72,12 @@ public: * @return */ Validator* readValidator(QString& str); - + /** + * @brief readCompositeValidator + * @param str + * @return + */ + Validator* readCompositeValidator(QString& str); /** * @brief readNumber read number in the given str and remove from the string the read character. @@ -79,7 +85,7 @@ public: * @param myNumber reference to the found number * @return true, succeed to read number, false otherwise. */ - bool readNumber(QString& str, int& myNumber); + bool readNumber(QString& str, qint64& myNumber); /** @@ -123,7 +129,7 @@ public: * @param end * @return */ - bool readDiceRange(QString& str,int& start, int& end); + bool readDiceRange(QString& str,qint64& start, qint64& end); /** * @brief readListOperator * @param str @@ -133,9 +139,11 @@ public: void readProbability(QStringList& str,QList& ranges); + bool readLogicOperation(QString& str,CompositeValidator::LogicOperation& op); private: QMap* m_logicOp; + QMap* m_logicOperation; }; #endif // PARSINGTOOLBOX_H -- cgit v1.2.3-70-g09d2