diff options
Diffstat (limited to 'result')
| -rw-r--r-- | result/diceresult.cpp | 28 | ||||
| -rw-r--r-- | result/diceresult.h | 56 | ||||
| -rw-r--r-- | result/result.cpp | 61 | ||||
| -rw-r--r-- | result/result.h | 65 | ||||
| -rw-r--r-- | result/scalarresult.cpp | 63 | ||||
| -rw-r--r-- | result/scalarresult.h | 45 | ||||
| -rw-r--r-- | result/stringresult.cpp | 35 | ||||
| -rw-r--r-- | result/stringresult.h | 13 |
8 files changed, 181 insertions, 185 deletions
diff --git a/result/diceresult.cpp b/result/diceresult.cpp index b66c010..76e473b 100644 --- a/result/diceresult.cpp +++ b/result/diceresult.cpp @@ -25,8 +25,8 @@ DiceResult::DiceResult() : m_operator(Die::PLUS) { - m_resultTypes = (DICE_LIST | SCALAR); - m_homogeneous = true; + m_resultTypes= (DICE_LIST | SCALAR); + m_homogeneous= true; } void DiceResult::insertResult(Die* die) { @@ -42,7 +42,7 @@ bool DiceResult::isHomogeneous() const } void DiceResult::setHomogeneous(bool b) { - m_homogeneous = b; + m_homogeneous= b; } void DiceResult::setResultList(QList<Die*> list) @@ -99,8 +99,8 @@ qreal DiceResult::getScalarResult() } else { - qint64 scalar = 0; - int i = 0; + qint64 scalar= 0; + int i= 0; for(auto& tmp : m_diceValues) { if(i > 0) @@ -108,22 +108,22 @@ qreal DiceResult::getScalarResult() switch(m_operator) { case Die::PLUS: - scalar += tmp->getValue(); + scalar+= tmp->getValue(); break; case Die::MULTIPLICATION: - scalar *= tmp->getValue(); + scalar*= tmp->getValue(); break; case Die::MINUS: - scalar -= tmp->getValue(); + scalar-= tmp->getValue(); break; case Die::POW: - scalar = static_cast<int>(pow(static_cast<double>(scalar), static_cast<double>(tmp->getValue()))); + scalar= static_cast<int>(pow(static_cast<double>(scalar), static_cast<double>(tmp->getValue()))); break; case Die::DIVIDE: case Die::INTEGER_DIVIDE: if(tmp->getValue() != 0) { - scalar /= tmp->getValue(); + scalar/= tmp->getValue(); } else { @@ -134,7 +134,7 @@ qreal DiceResult::getScalarResult() } else { - scalar = tmp->getValue(); + scalar= tmp->getValue(); } ++i; } @@ -154,7 +154,7 @@ void DiceResult::clear() void DiceResult::setOperator(const Die::ArithmeticOperator& dieOperator) { - m_operator = dieOperator; + m_operator= dieOperator; } QString DiceResult::toString(bool wl) { @@ -175,13 +175,13 @@ QString DiceResult::toString(bool wl) } Result* DiceResult::getCopy() const { - auto copy = new DiceResult(); + auto copy= new DiceResult(); copy->setHomogeneous(m_homogeneous); copy->setOperator(m_operator); QList<Die*> list; for(auto die : m_diceValues) { - auto newdie = new Die(*die); + auto newdie= new Die(*die); die->displayed(); list.append(newdie); } diff --git a/result/diceresult.h b/result/diceresult.h index 8ea807a..54e0b57 100644 --- a/result/diceresult.h +++ b/result/diceresult.h @@ -1,24 +1,24 @@ /*************************************************************************** -* Copyright (C) 2014 by Renaud Guezennec * -* http://www.rolisteam.org/contact * -* * -* 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. * -***************************************************************************/ + * Copyright (C) 2014 by Renaud Guezennec * + * http://www.rolisteam.org/contact * + * * + * 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> @@ -36,10 +36,10 @@ public: * @brief DiceResult */ DiceResult(); - /** - * @brief ~DiceResult - */ - virtual ~DiceResult(); + /** + * @brief ~DiceResult + */ + virtual ~DiceResult(); /** * @brief getResultList @@ -66,7 +66,7 @@ public: * @brief toString * @return */ - virtual QString toString(bool wl); + virtual QString toString(bool wl); /** * @brief isHomogeneous */ @@ -77,14 +77,16 @@ public: void setHomogeneous(bool); Die::ArithmeticOperator getOperator() const; - void setOperator(const Die::ArithmeticOperator & dieOperator); - bool contains(Die *die, const std::function<bool (const Die *, const Die *)> equal); + void setOperator(const Die::ArithmeticOperator& dieOperator); + bool contains(Die* die, const std::function<bool(const Die*, const Die*)> equal); void clear(); virtual Result* getCopy() const; + private: qreal getScalarResult(); + private: QList<Die*> m_diceValues; bool m_homogeneous; diff --git a/result/result.cpp b/result/result.cpp index 4c7275e..0cedc52 100644 --- a/result/result.cpp +++ b/result/result.cpp @@ -1,35 +1,31 @@ /*************************************************************************** -* Copyright (C) 2014 by Renaud Guezennec * -* http://www.rolisteam.org/contact * -* * -* 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. * -***************************************************************************/ + * Copyright (C) 2014 by Renaud Guezennec * + * http://www.rolisteam.org/contact * + * * + * 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" #include <QUuid> -Result::Result() - : m_resultTypes(NONE),m_id(QString("\"%1\"").arg(QUuid::createUuid().toString())),m_previous(nullptr) +Result::Result() : m_resultTypes(NONE), m_id(QString("\"%1\"").arg(QUuid::createUuid().toString())), m_previous(nullptr) { } -Result::~Result() -{ - -} +Result::~Result() {} Result* Result::getPrevious() { @@ -39,30 +35,27 @@ Result* Result::getPrevious() void Result::setPrevious(Result* p) { Q_ASSERT(p != this); - m_previous = p; + m_previous= p; } bool Result::isStringResult() const { return false; } -void Result::clear() -{ - -} +void Result::clear() {} bool Result::hasResultOfType(RESULT_TYPE type) const { return (m_resultTypes & type); } void Result::generateDotTree(QString& s) { - auto str = toString(true); + auto str= toString(true); if(s.contains(str)) return; s.append(str); s.append(";\n"); - if(nullptr!=m_previous) + if(nullptr != m_previous) { s.append(toString(false)); s.append(" -> "); @@ -77,6 +70,4 @@ void Result::generateDotTree(QString& s) s.append("nullptr"); s.append(" [label=\"previousResult\", shape=\"box\"];\n"); } - } - diff --git a/result/result.h b/result/result.h index 5fc4408..59c3cb9 100644 --- a/result/result.h +++ b/result/result.h @@ -1,24 +1,24 @@ /*************************************************************************** -* Copyright (C) 2014 by Renaud Guezennec * -* http://www.rolisteam.org/contact * -* * -* 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. * -***************************************************************************/ + * Copyright (C) 2014 by Renaud Guezennec * + * http://www.rolisteam.org/contact * + * * + * 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 @@ -34,7 +34,13 @@ public: /** * @brief The RESULT_TYPE enum or combinaison */ - enum RESULT_TYPE {NONE=0,SCALAR=1,STRING=2,DICE_LIST=4}; + enum RESULT_TYPE + { + NONE= 0, + SCALAR= 1, + STRING= 2, + DICE_LIST= 4 + }; /** * @brief Result */ @@ -53,7 +59,7 @@ public: * @brief getScalar * @return */ - virtual QVariant getResult(RESULT_TYPE) = 0; + virtual QVariant getResult(RESULT_TYPE)= 0; /** * @brief getPrevious * @return @@ -75,7 +81,7 @@ public: * @brief getStringResult * @return */ - QString getStringResult(); + QString getStringResult(); /** * @brief generateDotTree */ @@ -84,14 +90,15 @@ public: * @brief toString * @return */ - virtual QString toString(bool wl) = 0; - virtual Result* getCopy() const = 0; + virtual QString toString(bool wl)= 0; + virtual Result* getCopy() const= 0; + protected: - int m_resultTypes;/// @brief - QString m_id; -private: - Result* m_previous;/// @brief + int m_resultTypes; /// @brief + QString m_id; +private: + Result* m_previous; /// @brief }; #endif // RESULT_H diff --git a/result/scalarresult.cpp b/result/scalarresult.cpp index 138caf5..089c4b8 100644 --- a/result/scalarresult.cpp +++ b/result/scalarresult.cpp @@ -1,35 +1,34 @@ /*************************************************************************** -* Copyright (C) 2014 by Renaud Guezennec * -* http://www.rolisteam.org/contact * -* * -* 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. * -***************************************************************************/ + * Copyright (C) 2014 by Renaud Guezennec * + * http://www.rolisteam.org/contact * + * * + * 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; + m_resultTypes= Result::SCALAR; } - void ScalarResult::setValue(qreal i) { - m_value=i; + m_value= i; } QVariant ScalarResult::getResult(Result::RESULT_TYPE type) { @@ -42,18 +41,18 @@ QVariant ScalarResult::getResult(Result::RESULT_TYPE type) } Result* ScalarResult::getCopy() const { - auto copy = new ScalarResult(); + auto copy= new ScalarResult(); copy->setValue(m_value); return copy; } QString ScalarResult::toString(bool wl) { - if(wl) - { - return QString("%2 [label=\"ScalarResult %1\"]").arg(m_value).arg(m_id); - } - else - { - return m_id; - } + if(wl) + { + return QString("%2 [label=\"ScalarResult %1\"]").arg(m_value).arg(m_id); + } + else + { + return m_id; + } } diff --git a/result/scalarresult.h b/result/scalarresult.h index 0d40209..c20de0f 100644 --- a/result/scalarresult.h +++ b/result/scalarresult.h @@ -1,24 +1,24 @@ /*************************************************************************** -* Copyright (C) 2014 by Renaud Guezennec * -* http://www.rolisteam.org/contact * -* * -* 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. * -***************************************************************************/ + * Copyright (C) 2014 by Renaud Guezennec * + * http://www.rolisteam.org/contact * + * * + * 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 @@ -49,10 +49,11 @@ public: * @brief toString * @return */ - virtual QString toString(bool); + virtual QString toString(bool); virtual Result* getCopy() const; + private: - qreal m_value = 0; + qreal m_value= 0; }; #endif // SCALARRESULT_H diff --git a/result/stringresult.cpp b/result/stringresult.cpp index 2858155..9685bd8 100644 --- a/result/stringresult.cpp +++ b/result/stringresult.cpp @@ -2,27 +2,23 @@ StringResult::StringResult() { - m_highlight = true; - m_resultTypes = Result::STRING; + m_highlight= true; + m_resultTypes= Result::STRING; } void StringResult::setText(QString text) { - m_value=text; -} -StringResult::~StringResult() -{ - + m_value= text; } +StringResult::~StringResult() {} bool StringResult::hasResultOfType(RESULT_TYPE resultType) const { - if(resultType & Result::STRING) { return true; } else if(resultType & Result::SCALAR) { - bool ok=false; + bool ok= false; getText().toInt(&ok); return ok; } @@ -34,7 +30,6 @@ QString StringResult::getText() const } QVariant StringResult::getResult(RESULT_TYPE type) { - switch(type) { case STRING: @@ -49,18 +44,18 @@ QVariant StringResult::getResult(RESULT_TYPE type) } QString StringResult::toString(bool wl) { - if(wl) - { - return QString("%2 [label=\"StringResult_value_%1\"]").arg(getText().replace("%","_"), m_id); - } - else - { - return m_id; - } + if(wl) + { + return QString("%2 [label=\"StringResult_value_%1\"]").arg(getText().replace("%", "_"), m_id); + } + else + { + return m_id; + } } void StringResult::setHighLight(bool b) { - m_highlight = b; + m_highlight= b; } bool StringResult::hasHighLight() const @@ -69,7 +64,7 @@ bool StringResult::hasHighLight() const } Result* StringResult::getCopy() const { - auto copy = new StringResult(); + auto copy= new StringResult(); copy->setHighLight(m_highlight); copy->setText(m_value); return copy; diff --git a/result/stringresult.h b/result/stringresult.h index a8b859a..ec6c3ce 100644 --- a/result/stringresult.h +++ b/result/stringresult.h @@ -1,8 +1,8 @@ #ifndef STRINGRESULT_H #define STRINGRESULT_H -#include <QString> #include "result.h" +#include <QString> /** * @brief The StringResult class stores command result for String. */ @@ -13,10 +13,10 @@ public: * @brief StringResult */ StringResult(); - /** - * @brief StringResult - */ - virtual ~StringResult(); + /** + * @brief StringResult + */ + virtual ~StringResult(); /** * @brief setText * @param text @@ -38,10 +38,11 @@ public: */ virtual QString toString(bool); - virtual void setHighLight(bool ); + virtual void setHighLight(bool); virtual bool hasHighLight() const; virtual bool hasResultOfType(RESULT_TYPE resultType) const; virtual Result* getCopy() const; + private: QString m_value; bool m_highlight; |