diff options
| -rw-r--r-- | diceparser.cpp | 8 | ||||
| -rw-r--r-- | diceresult.cpp | 33 | ||||
| -rw-r--r-- | diceresult.h | 25 | ||||
| -rw-r--r-- | result.cpp | 8 | ||||
| -rw-r--r-- | result.h | 18 | ||||
| -rw-r--r-- | scalarresult.cpp | 7 | ||||
| -rw-r--r-- | scalarresult.h | 3 | ||||
| -rw-r--r-- | stringresult.cpp | 24 | ||||
| -rw-r--r-- | stringresult.h | 25 |
9 files changed, 117 insertions, 34 deletions
diff --git a/diceparser.cpp b/diceparser.cpp index 5d4a610..9f745f1 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -34,6 +34,7 @@ #include "node/rerolldicenode.h" #include "node/explosedicenode.h" #include "node/parenthesesnode.h" +#include "node/helpnode.h" #define DEFAULT_FACES_NUMBER 10 @@ -64,6 +65,7 @@ DiceParser::DiceParser() m_commandList = new QList<QString>(); m_commandList->append("help"); + } ExecutionNode* DiceParser::getLatestNode(ExecutionNode* node) @@ -202,9 +204,9 @@ QString DiceParser::displayResult() while(NULL!=myResult) { ++resulCount; - if((myResult->isScalar())&&(!scalarDone)) + if((myResult->hasResultOfType(Result::SCALAR))&&(!scalarDone)) { - stream << totalValue.arg(myResult->getScalar()) << endl; //.arg(m_command) + stream << totalValue.arg(myResult->getResult(Result::SCALAR).toReal()) << endl; //.arg(m_command) scalarDone=true; } @@ -306,7 +308,7 @@ bool DiceParser::readCommand(QString& str,ExecutionNode* & node) { if(m_commandList->contains(str)) { - // node = new HelpNode(); + node = new HelpNode(); } } diff --git a/diceresult.cpp b/diceresult.cpp index f111ad4..7b73825 100644 --- a/diceresult.cpp +++ b/diceresult.cpp @@ -23,7 +23,7 @@ DiceResult::DiceResult() { - + m_resultTypes= (DICE_LIST | SCALAR); } void DiceResult::insertResult(Die* die) { @@ -38,17 +38,36 @@ void DiceResult::setResultList(QList<Die*> list) m_diceValues.clear(); m_diceValues << list; } -bool DiceResult::isScalar() const +//bool DiceResult::isScalar() const +//{ +// if(m_diceValues.size()==1) +// { +// return true; +// } +// return false; +//} +QVariant DiceResult::getResult(RESULT_TYPE type) { - if(m_diceValues.size()==1) + + switch (type) + { + case SCALAR: + return getScalarResult(); + break; + case DICE_LIST: { - return true; + + return QVariant(); + break; + } + default: + break; } - return false; + return QVariant(); + } -qreal DiceResult::getScalar() +qreal DiceResult::getScalarResult() { - if(m_diceValues.size()==1) { return m_diceValues[0]->getValue(); diff --git a/diceresult.h b/diceresult.h index ff3edc3..838a83d 100644 --- a/diceresult.h +++ b/diceresult.h @@ -31,16 +31,35 @@ class DiceResult : public Result { public: + /** + * @brief DiceResult + */ DiceResult(); - qint64 getSum(); + /** + * @brief getResultList + * @return + */ QList<Die*>& getResultList(); + /** + * @brief insertResult + */ void insertResult(Die*); + /** + * @brief setResultList + * @param list + */ void setResultList(QList<Die*> list); - bool isScalar() const; - virtual qreal getScalar(); + /** + * @brief getScalar + * @return + */ + virtual QVariant getResult(RESULT_TYPE); + +private: + qreal getScalarResult(); private: QList<Die*> m_diceValues; }; @@ -36,12 +36,8 @@ void Result::setPrevious(Result* p) m_previous = p; } -bool Result::isStringResult() -{ - return false; -} -QString Result::getStringResult() +bool Result::hasResultOfType(RESULT_TYPE type) const { - return QString(); + return (m_resultTypes & type); } @@ -22,9 +22,9 @@ #ifndef RESULT_H #define RESULT_H -#include <Qt> +//#include <Qt> #include <QString> - +#include <QVariant> /** * @brief The Result class */ @@ -32,6 +32,10 @@ class Result { public: /** + * @brief The RESULT_TYPE enum or combinaison + */ + enum RESULT_TYPE {SCALAR=1,STRING=2,DICE_LIST=4}; + /** * @brief Result */ Result(); @@ -39,12 +43,12 @@ public: * @brief isScalar * @return */ - virtual bool isScalar() const = 0; + virtual bool hasResultOfType(RESULT_TYPE) const; /** * @brief getScalar * @return */ - virtual qreal getScalar() = 0; + virtual QVariant getResult(RESULT_TYPE) = 0; /** * @brief getPrevious * @return @@ -55,11 +59,11 @@ public: */ virtual void setPrevious(Result*); - virtual bool isStringResult(); - virtual QString getStringResult(); - +protected: + int m_resultTypes;/// @brief private: Result* m_previous;/// @brief + }; #endif // RESULT_H diff --git a/scalarresult.cpp b/scalarresult.cpp index 3500675..8c924fe 100644 --- a/scalarresult.cpp +++ b/scalarresult.cpp @@ -23,6 +23,7 @@ ScalarResult::ScalarResult() { + m_resultTypes = Result::SCALAR; } @@ -30,12 +31,8 @@ void ScalarResult::setValue(qreal i) { m_value=i; } -qreal ScalarResult::getScalar() +QVariant ScalarResult::getResult(Result::RESULT_TYPE type) { return m_value; } -bool ScalarResult::isScalar() const -{ - return true; -} diff --git a/scalarresult.h b/scalarresult.h index cbcbf66..35982be 100644 --- a/scalarresult.h +++ b/scalarresult.h @@ -31,8 +31,7 @@ class ScalarResult : public Result public: ScalarResult(); - virtual bool isScalar() const; - virtual qreal getScalar(); + virtual QVariant getResult(Result::RESULT_TYPE); void setValue(qreal i); diff --git a/stringresult.cpp b/stringresult.cpp index 7f7b822..4831a76 100644 --- a/stringresult.cpp +++ b/stringresult.cpp @@ -2,4 +2,28 @@ 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/stringresult.h b/stringresult.h index 7db55a1..caa7e06 100644 --- a/stringresult.h +++ b/stringresult.h @@ -1,13 +1,36 @@ #ifndef STRINGRESULT_H #define STRINGRESULT_H +#include <QString> +#include "result.h" /** * @brief The StringResult class */ -class StringResult +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 |