aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2015-09-01 16:34:56 +0200
committerRenaud G <renaud@rolisteam.org>2015-09-01 16:34:56 +0200
commit7ce5a4af6fb836432eb6ce7637ea09d6a5b4e0bd (patch)
tree8762ae09c3b68a03d33895badd6e9bea8c1006ac
parent28867d0554db6cc68d295e41927e31f7e27fe135 (diff)
downloadOneRoll-7ce5a4af6fb836432eb6ce7637ea09d6a5b4e0bd.tar.gz
OneRoll-7ce5a4af6fb836432eb6ce7637ea09d6a5b4e0bd.zip
add getAllDiceResult function and hasSeparator
-rw-r--r--diceparser.cpp45
-rw-r--r--diceparser.h9
2 files changed, 48 insertions, 6 deletions
diff --git a/diceparser.cpp b/diceparser.cpp
index dcb5030..802b5f2 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -44,6 +44,7 @@
DiceParser::DiceParser()
: m_start(NULL),m_current(NULL)
{
+ m_currentTreeHasSeparator =false;
m_parsingToolbox = new ParsingToolBox();
m_mapDiceOp = new QMap<QString,DiceOperator>();
@@ -145,6 +146,7 @@ void DiceParser::insertAlias(DiceAlias* dice, int i)
bool DiceParser::parseLine(QString str)
{
+ m_currentTreeHasSeparator = false;
m_errorMap.clear();
if(NULL!=m_start)
{
@@ -412,7 +414,36 @@ QStringList DiceParser::getAllStringResult(bool& hasAlias)
return stringListResult;
}
+QStringList DiceParser::getAllDiceResult(bool& hasAlias)
+{
+ ExecutionNode* next = getLeafNode();
+ Result* result=next->getResult();
+ QList<Die*> dieListResult;
+ QStringList stringListResult;
+ while(NULL!=result)
+ {
+ if(result->hasResultOfType(Result::DICE_LIST))
+ {
+ DiceResult* stringResult = dynamic_cast<DiceResult*>(result);
+ if(NULL!=stringResult)
+ {
+ dieListResult << stringResult->getResultList();
+ hasAlias = true;
+ }
+ }
+ result = result->getPrevious();
+ }
+ foreach(Die* die, dieListResult)
+ {
+ foreach (qint64 value, die->getListValue())
+ {
+ stringListResult << QString::number(value);
+ }
+ }
+
+ return stringListResult;
+}
void DiceParser::getLastDiceResult(ExportedDiceResult& diceValues)
{
ExecutionNode* next = getLeafNode();
@@ -701,21 +732,19 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous)
}
else if(readInstructionOperator(str[0]))
{
- str=str.remove(0,1);
- delete node;
+ str=str.remove(0,1);
+ delete node;
ExecutionNode* nodeExec = NULL;
if(readExpression(str,nodeExec))
{
-
- // nodeExec = getLatestNode(nodeExec);
-
if(NULL==nodeExec)
{
return false;
}
previous->setNextNode(nodeExec);
-
+ m_currentTreeHasSeparator = true;
return true;
+
}
}
else
@@ -728,6 +757,10 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous)
}
return false;
}
+bool DiceParser::hasSeparator()const
+{
+ return m_currentTreeHasSeparator;
+}
DiceRollerNode* DiceParser::addRollDiceNode(qint64 faces,ExecutionNode* previous)
{
DiceRollerNode* mydiceRoller= new DiceRollerNode(faces);
diff --git a/diceparser.h b/diceparser.h
index 6cc6d47..3fc2cb7 100644
--- a/diceparser.h
+++ b/diceparser.h
@@ -196,6 +196,14 @@ public:
* @return
*/
QStringList getAllStringResult(bool& hasAlias);
+ /**
+ * @brief getAllDiceResult
+ * @param hasAlias
+ * @return
+ */
+ QStringList getAllDiceResult(bool& hasAlias);
+
+ bool hasSeparator()const;
private:
/**
@@ -301,6 +309,7 @@ private:
QString m_command;
ParsingToolBox* m_parsingToolbox;
QString m_helpPath;
+ bool m_currentTreeHasSeparator;
};
#endif // DICEPARSER_H