aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRenaud Guezennec <renaud.guezennec@ext.mpsa.com>2016-01-26 15:35:18 +0100
committerRenaud Guezennec <renaud.guezennec@ext.mpsa.com>2016-01-26 15:35:18 +0100
commit19bfac5d61c7e30a1e5bbe115d56908474546052 (patch)
tree861b2810c38bdfb28140c621a68aa3ddeb0a4564
parent821b47e5b13167bc89841762311296e1ed0bedba (diff)
downloadOneRoll-19bfac5d61c7e30a1e5bbe115d56908474546052.tar.gz
OneRoll-19bfac5d61c7e30a1e5bbe115d56908474546052.zip
Implementation of the if node. Work with one if.
-rw-r--r--diceparser.cpp37
-rw-r--r--diceparser.h1
-rw-r--r--node/ifnode.cpp39
-rw-r--r--node/ifnode.h3
-rw-r--r--parsingtoolbox.cpp6
-rw-r--r--parsingtoolbox.h2
6 files changed, 76 insertions, 12 deletions
diff --git a/diceparser.cpp b/diceparser.cpp
index 6e63eec..92cd2e1 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -954,7 +954,15 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)/
Validator* validator = m_parsingToolbox->readCompositeValidator(str);
if(NULL!=validator)
{
-
+ ExecutionNode* trueNode;
+ ExecutionNode* falseNode;
+ if(readIfInstruction(str,trueNode,falseNode))
+ {
+ nodeif->setInstructionTrue(trueNode);
+ nodeif->setInstructionFalse(falseNode);
+ nodeif->setValidator(validator);
+ previous->setNextNode(nodeif);
+ }
}
}
@@ -963,6 +971,33 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)/
}
return isFine;
}
+bool DiceParser::readIfInstruction(QString& str,ExecutionNode*& trueNode,ExecutionNode*& falseNode)
+{
+ if(str.startsWith('{'))
+ {
+ str=str.remove(0,1);
+ ExecutionNode* node;
+ readExpression(str,node);
+ if(str.startsWith('}'))
+ {
+ trueNode = node;
+ str=str.remove(0,1);
+ if(str.startsWith('{'))
+ {
+ str=str.remove(0,1);
+ ExecutionNode* node2;
+ readExpression(str,node2);
+ if(str.startsWith('}'))
+ {
+ falseNode=node2;
+ return true;
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+}
QMap<ExecutionNode::ERROR_CODE,QString> DiceParser::getErrorMap()
{
diff --git a/diceparser.h b/diceparser.h
index ae21ebc..a1fc8b8 100644
--- a/diceparser.h
+++ b/diceparser.h
@@ -204,6 +204,7 @@ public:
QStringList getAllDiceResult(bool& hasAlias);
bool hasSeparator()const;
+ bool readIfInstruction(QString &str, ExecutionNode* &trueNode, ExecutionNode* &falseNode);
private:
/**
diff --git a/node/ifnode.cpp b/node/ifnode.cpp
index 80e5264..5543a93 100644
--- a/node/ifnode.cpp
+++ b/node/ifnode.cpp
@@ -22,7 +22,7 @@
IfNode::IfNode()
{
- m_result = new DiceResult();
+ //m_result = new DiceResult();
}
IfNode::~IfNode()
@@ -37,20 +37,42 @@ void IfNode::run(ExecutionNode *previous)
{
return;
}
+ ExecutionNode* previousLoop = previous;
+ ExecutionNode* nextNode = NULL;
Result* previousResult = previous->getResult();
+ m_result = previousResult;
DiceResult* previousDiceResult = dynamic_cast<DiceResult*>(previousResult);
if(NULL!=previousDiceResult)
{
qreal value = previousResult->getResult(Result::SCALAR).toReal();
+
QList<Die*> diceList=previousDiceResult->getResultList();
+
+
if(NULL!=m_validator)
{
if(!diceList.isEmpty())
{
foreach(Die* dice,diceList)
{
- m_validator->hasValid(dice,true,true);
+ if(m_validator->hasValid(dice,true,true))
+ {
+ nextNode=m_true;
+ }
+ else
+ {
+ nextNode=m_false;
+ }
+ if(NULL!=nextNode)
+ {
+ if(NULL==m_nextNode)
+ {
+ m_nextNode = nextNode;
+ }
+ nextNode->run(previousLoop);
+ previousLoop = getLeafNode(nextNode);
+ }
}
}
else
@@ -63,10 +85,10 @@ void IfNode::run(ExecutionNode *previous)
}
}
- if(NULL!=m_nextNode)
+ /* if(NULL!=m_nextNode)
{
m_nextNode->run(this);
- }
+ }*/
}
void IfNode::setValidator(Validator* val)
@@ -93,3 +115,12 @@ qint64 IfNode::getPriority() const
return 4;
}
+ExecutionNode* IfNode::getLeafNode(ExecutionNode* node)
+{
+ ExecutionNode* next = node;
+ while(NULL != next->getNextNode() )
+ {
+ next = next->getNextNode();
+ }
+ return next;
+}
diff --git a/node/ifnode.h b/node/ifnode.h
index ec962a2..56b23fa 100644
--- a/node/ifnode.h
+++ b/node/ifnode.h
@@ -41,6 +41,9 @@ public:
virtual qint64 getPriority() const;
protected:
+ ExecutionNode *getLeafNode(ExecutionNode *node);
+
+protected:
DiceResult* m_diceResult;
Validator* m_validator;
diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp
index a7220a0..23e35ba 100644
--- a/parsingtoolbox.cpp
+++ b/parsingtoolbox.cpp
@@ -378,13 +378,7 @@ ParsingToolBox::LIST_OPERATOR ParsingToolBox::readListOperator(QString& str)
}
return NONE;
}
-bool ParsingToolBox::readIfInstruction(QString& str,ExecutionNode* trueNode,ExecutionNode* falseNode)
-{
- if(str.startsWith('{'))
- {
- }
-}
void ParsingToolBox::readProbability(QStringList& str,QList<Range>& ranges)
{
diff --git a/parsingtoolbox.h b/parsingtoolbox.h
index 04a46c4..94ef624 100644
--- a/parsingtoolbox.h
+++ b/parsingtoolbox.h
@@ -145,7 +145,7 @@ public:
bool readDiceLogicOperator(QString &str, OperationCondition::ConditionOperator &op);
- bool readIfInstruction(QString& str,ExecutionNode* trueNode,ExecutionNode* falseNode);
+
private:
QMap<QString,BooleanCondition::LogicOperator>* m_logicOp;
QMap<QString,CompositeValidator::LogicOperation>* m_logicOperation;