aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/result
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2015-03-06 00:25:25 +0100
committerRenaud G <renaud@rolisteam.org>2015-03-06 00:25:25 +0100
commit7d0c1d999344ea625670bf3d90d7c900cadb4854 (patch)
treef48b806051e125bf984fbdf07d5a8a436c3b0452 /result
parent606001e99593372d0a71c566a5efdefd48175305 (diff)
downloadOneRoll-7d0c1d999344ea625670bf3d90d7c900cadb4854.tar.gz
OneRoll-7d0c1d999344ea625670bf3d90d7c900cadb4854.zip
Reorganize files.
Creation of subdir result.
Diffstat (limited to 'result')
-rw-r--r--result/diceresult.cpp86
-rw-r--r--result/diceresult.h67
-rw-r--r--result/result.cpp56
-rw-r--r--result/result.h88
-rw-r--r--result/scalarresult.cpp38
-rw-r--r--result/scalarresult.h42
-rw-r--r--result/stringresult.cpp29
-rw-r--r--result/stringresult.h36
8 files changed, 442 insertions, 0 deletions
diff --git a/result/diceresult.cpp b/result/diceresult.cpp
new file mode 100644
index 0000000..0cabb11
--- /dev/null
+++ b/result/diceresult.cpp
@@ -0,0 +1,86 @@
+/***************************************************************************
+* Copyright (C) 2014 by Renaud Guezennec *
+* http://renaudguezennec.homelinux.org/accueil,3.html *
+* *
+* This file is part of DiceParser *
+* *
+* DiceParser is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the *
+* Free Software Foundation, Inc., *
+* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+***************************************************************************/
+#include "diceresult.h"
+
+DiceResult::DiceResult()
+{
+ m_resultTypes= (DICE_LIST);
+}
+void DiceResult::insertResult(Die* die)
+{
+ m_diceValues.append(die);
+}
+QList<Die*>& DiceResult::getResultList()
+{
+ return m_diceValues;
+}
+void DiceResult::setResultList(QList<Die*> list)
+{
+ m_diceValues.clear();
+ m_diceValues << list;
+}
+//bool DiceResult::isScalar() const
+//{
+// if(m_diceValues.size()==1)
+// {
+// return true;
+// }
+// return false;
+//}
+QVariant DiceResult::getResult(RESULT_TYPE type)
+{
+
+ switch (type)
+ {
+ case SCALAR:
+ return getScalarResult();
+ break;
+ case DICE_LIST:
+ {
+
+ return QVariant();
+ break;
+ }
+ default:
+ break;
+ }
+ return QVariant();
+
+}
+qreal DiceResult::getScalarResult()
+{
+ if(m_diceValues.size()==1)
+ {
+ return m_diceValues[0]->getValue();
+ }
+ else
+ {
+ qint64 scalarSum = 0;
+ foreach(Die* die,m_diceValues)
+ {
+ scalarSum+=die->getValue();
+ }
+ return scalarSum;
+ }
+
+ return 0;
+}
diff --git a/result/diceresult.h b/result/diceresult.h
new file mode 100644
index 0000000..838a83d
--- /dev/null
+++ b/result/diceresult.h
@@ -0,0 +1,67 @@
+/***************************************************************************
+* Copyright (C) 2014 by Renaud Guezennec *
+* http://renaudguezennec.homelinux.org/accueil,3.html *
+* *
+* This file is part of DiceParser *
+* *
+* DiceParser is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the *
+* Free Software Foundation, Inc., *
+* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+***************************************************************************/
+#ifndef DICERESULT_H
+#define DICERESULT_H
+#include <QList>
+
+#include "die.h"
+#include "result.h"
+/**
+ * @brief The DiceResult class
+ */
+class DiceResult : public Result
+{
+public:
+ /**
+ * @brief DiceResult
+ */
+ DiceResult();
+
+ /**
+ * @brief getResultList
+ * @return
+ */
+ QList<Die*>& getResultList();
+ /**
+ * @brief insertResult
+ */
+ void insertResult(Die*);
+
+ /**
+ * @brief setResultList
+ * @param list
+ */
+ void setResultList(QList<Die*> list);
+
+ /**
+ * @brief getScalar
+ * @return
+ */
+ virtual QVariant getResult(RESULT_TYPE);
+
+private:
+ qreal getScalarResult();
+private:
+ QList<Die*> m_diceValues;
+};
+
+#endif // DICERESULT_H
diff --git a/result/result.cpp b/result/result.cpp
new file mode 100644
index 0000000..740bf85
--- /dev/null
+++ b/result/result.cpp
@@ -0,0 +1,56 @@
+/***************************************************************************
+* Copyright (C) 2014 by Renaud Guezennec *
+* http://renaudguezennec.homelinux.org/accueil,3.html *
+* *
+* This file is part of DiceParser *
+* *
+* DiceParser is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the *
+* Free Software Foundation, Inc., *
+* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+***************************************************************************/
+#include "result.h"
+
+Result::Result()
+ : m_previous(NULL)
+{
+}
+
+Result* Result::getPrevious()
+{
+ return m_previous;
+}
+
+void Result::setPrevious(Result* p)
+{
+ m_previous = p;
+}
+
+bool Result::isStringResult()
+{
+ return false;
+}
+
+bool Result::hasResultOfType(RESULT_TYPE type) const
+{
+ return (m_resultTypes & type);
+}
+void Result::generateDotTree(QString& s)
+{
+ s.append(toString());
+
+}
+QString Result::toString()
+{
+ QString();
+}
diff --git a/result/result.h b/result/result.h
new file mode 100644
index 0000000..dcd0b8d
--- /dev/null
+++ b/result/result.h
@@ -0,0 +1,88 @@
+/***************************************************************************
+* Copyright (C) 2014 by Renaud Guezennec *
+* http://renaudguezennec.homelinux.org/accueil,3.html *
+* *
+* This file is part of DiceParser *
+* *
+* DiceParser is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the *
+* Free Software Foundation, Inc., *
+* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+***************************************************************************/
+#ifndef RESULT_H
+#define RESULT_H
+
+//#include <Qt>
+#include <QString>
+#include <QVariant>
+/**
+ * @brief The Result class
+ */
+class Result
+{
+public:
+ /**
+ * @brief The RESULT_TYPE enum or combinaison
+ */
+ enum RESULT_TYPE {SCALAR=1,STRING=2,DICE_LIST=4};
+ /**
+ * @brief Result
+ */
+ Result();
+ /**
+ * @brief isScalar
+ * @return
+ */
+ virtual bool hasResultOfType(RESULT_TYPE) const;
+ /**
+ * @brief getScalar
+ * @return
+ */
+ virtual QVariant getResult(RESULT_TYPE) = 0;
+ /**
+ * @brief getPrevious
+ * @return
+ */
+ virtual Result* getPrevious();
+ /**
+ * @brief setPrevious
+ */
+ virtual void setPrevious(Result*);
+ /**
+ * @brief isStringResult
+ * @return
+ */
+ bool isStringResult();
+
+ /**
+ * @brief getStringResult
+ * @return
+ */
+ QString getStringResult();
+ /**
+ * @brief generateDotTree
+ */
+ void generateDotTree(QString&);
+ /**
+ * @brief toString
+ * @return
+ */
+ QString toString();
+protected:
+ int m_resultTypes;/// @brief
+private:
+ Result* m_previous;/// @brief
+
+};
+
+#endif // RESULT_H
diff --git a/result/scalarresult.cpp b/result/scalarresult.cpp
new file mode 100644
index 0000000..8c924fe
--- /dev/null
+++ b/result/scalarresult.cpp
@@ -0,0 +1,38 @@
+/***************************************************************************
+* Copyright (C) 2014 by Renaud Guezennec *
+* http://renaudguezennec.homelinux.org/accueil,3.html *
+* *
+* This file is part of DiceParser *
+* *
+* DiceParser is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the *
+* Free Software Foundation, Inc., *
+* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+***************************************************************************/
+#include "scalarresult.h"
+
+ScalarResult::ScalarResult()
+{
+ m_resultTypes = Result::SCALAR;
+}
+
+
+void ScalarResult::setValue(qreal i)
+{
+ m_value=i;
+}
+QVariant ScalarResult::getResult(Result::RESULT_TYPE type)
+{
+ return m_value;
+}
+
diff --git a/result/scalarresult.h b/result/scalarresult.h
new file mode 100644
index 0000000..35982be
--- /dev/null
+++ b/result/scalarresult.h
@@ -0,0 +1,42 @@
+/***************************************************************************
+* Copyright (C) 2014 by Renaud Guezennec *
+* http://renaudguezennec.homelinux.org/accueil,3.html *
+* *
+* This file is part of DiceParser *
+* *
+* DiceParser is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the *
+* Free Software Foundation, Inc., *
+* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+***************************************************************************/
+#ifndef SCALARRESULT_H
+#define SCALARRESULT_H
+
+#include "result.h"
+#include <Qt>
+
+
+class ScalarResult : public Result
+{
+public:
+ ScalarResult();
+
+ virtual QVariant getResult(Result::RESULT_TYPE);
+
+ void setValue(qreal i);
+
+private:
+ qreal m_value;
+};
+
+#endif // SCALARRESULT_H
diff --git a/result/stringresult.cpp b/result/stringresult.cpp
new file mode 100644
index 0000000..4831a76
--- /dev/null
+++ b/result/stringresult.cpp
@@ -0,0 +1,29 @@
+#include "stringresult.h"
+
+StringResult::StringResult()
+{
+ m_resultTypes = Result::STRING;
+}
+void StringResult::setText(QString text)
+{
+ m_value=text;
+}
+
+QString StringResult::getText() const
+{
+ return m_value;
+}
+QVariant StringResult::getResult(RESULT_TYPE type)
+{
+
+ switch(type)
+ {
+ case STRING:
+ return getText();
+ break;
+
+ }
+
+
+ return QVariant();
+}
diff --git a/result/stringresult.h b/result/stringresult.h
new file mode 100644
index 0000000..caa7e06
--- /dev/null
+++ b/result/stringresult.h
@@ -0,0 +1,36 @@
+#ifndef STRINGRESULT_H
+#define STRINGRESULT_H
+
+#include <QString>
+#include "result.h"
+/**
+ * @brief The StringResult class
+ */
+class StringResult : public Result
+{
+public:
+ /**
+ * @brief StringResult
+ */
+ StringResult();
+ /**
+ * @brief setText
+ * @param text
+ */
+ void setText(QString text);
+ /**
+ * @brief getText
+ * @return
+ */
+ QString getText() const;
+ /**
+ * @brief getScalar
+ * @return
+ */
+ virtual QVariant getResult(RESULT_TYPE);
+
+private:
+ QString m_value;
+};
+
+#endif // STRINGRESULT_H