From 07c5f6ec23fcf9237a24e71adcfacabce677f818 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 29 Apr 2022 10:48:09 +0200 Subject: Change file organization. --- result/diceresult.cpp | 193 ------------------------------------------------ result/diceresult.h | 97 ------------------------ result/result.cpp | 86 --------------------- result/result.h | 96 ------------------------ result/scalarresult.cpp | 58 --------------- result/scalarresult.h | 59 --------------- result/stringresult.cpp | 117 ----------------------------- result/stringresult.h | 45 ----------- 8 files changed, 751 deletions(-) delete mode 100644 result/diceresult.cpp delete mode 100644 result/diceresult.h delete mode 100644 result/result.cpp delete mode 100644 result/result.h delete mode 100644 result/scalarresult.cpp delete mode 100644 result/scalarresult.h delete mode 100644 result/stringresult.cpp delete mode 100644 result/stringresult.h (limited to 'result') diff --git a/result/diceresult.cpp b/result/diceresult.cpp deleted file mode 100644 index 31e316b..0000000 --- a/result/diceresult.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2014 by Renaud Guezennec * - * https://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 "diceresult.h" -#include - -DiceResult::DiceResult() -{ - m_resultTypes= (static_cast(Dice::RESULT_TYPE::DICE_LIST) | static_cast(Dice::RESULT_TYPE::SCALAR)); - m_homogeneous= true; -} -void DiceResult::insertResult(Die* die) -{ - m_diceValues.append(die); -} -QList& DiceResult::getResultList() -{ - return m_diceValues; -} -bool DiceResult::isHomogeneous() const -{ - return m_homogeneous; -} -void DiceResult::setHomogeneous(bool b) -{ - m_homogeneous= b; -} - -void DiceResult::setResultList(QList list) -{ - m_diceValues.erase( - std::remove_if(m_diceValues.begin(), m_diceValues.end(), [list](Die* die) { return list.contains(die); }), - m_diceValues.end()); - - qDeleteAll(m_diceValues.begin(), m_diceValues.end()); - m_diceValues.clear(); - m_diceValues << list; -} -DiceResult::~DiceResult() -{ - if(!m_diceValues.isEmpty()) - { - qDeleteAll(m_diceValues.begin(), m_diceValues.end()); - m_diceValues.clear(); - } -} -QVariant DiceResult::getResult(Dice::RESULT_TYPE type) -{ - switch(type) - { - case Dice::RESULT_TYPE::SCALAR: - { - return getScalarResult(); - } - case Dice::RESULT_TYPE::DICE_LIST: - { - return QVariant::fromValue(m_diceValues); - } - default: - break; - } - return QVariant(); -} -bool DiceResult::contains(Die* die, const std::function equal) -{ - for(auto& value : m_diceValues) - { - if(equal(value, die)) - { - return true; - } - } - return false; -} -qreal DiceResult::getScalarResult() -{ - if(m_diceValues.size() == 1) - { - return m_diceValues[0]->getValue(); - } - else - { - qint64 scalar= 0; - int i= 0; - for(auto& tmp : m_diceValues) - { - if(i > 0) - { - switch(m_operator) - { - case Dice::ArithmeticOperator::PLUS: - scalar+= tmp->getValue(); - break; - case Dice::ArithmeticOperator::MULTIPLICATION: - scalar*= tmp->getValue(); - break; - case Dice::ArithmeticOperator::MINUS: - scalar-= tmp->getValue(); - break; - case Dice::ArithmeticOperator::POW: - scalar= static_cast(pow(static_cast(scalar), static_cast(tmp->getValue()))); - break; - case Dice::ArithmeticOperator::DIVIDE: - case Dice::ArithmeticOperator::INTEGER_DIVIDE: - if(tmp->getValue() != 0) - { - scalar/= tmp->getValue(); - } - else - { - /// @todo Error cant divide by 0. Must be displayed. - } - break; - } - } - else - { - scalar= tmp->getValue(); - } - ++i; - } - return scalar; - } -} - -Dice::ArithmeticOperator DiceResult::getOperator() const -{ - return m_operator; -} - -void DiceResult::clear() -{ - m_diceValues.clear(); -} - -void DiceResult::setOperator(const Dice::ArithmeticOperator& dieOperator) -{ - m_operator= dieOperator; -} -QString DiceResult::toString(bool wl) -{ - QStringList scalarSum; - for(auto& die : m_diceValues) - { - scalarSum << QString::number(die->getValue()); - } - if(wl) - { - return QStringLiteral("%3 [label=\"DiceResult Value %1 dice %2\"]") - .arg(QString::number(getScalarResult()), scalarSum.join('_'), m_id); - } - else - { - return m_id; - } -} -Result* DiceResult::getCopy() const -{ - auto copy= new DiceResult(); - copy->setHomogeneous(m_homogeneous); - copy->setOperator(m_operator); - copy->m_id= m_id; - QList list; - for(auto die : m_diceValues) - { - auto newdie= new Die(*die); - newdie->setDisplayed(false); - // die->displayed(); - list.append(newdie); - } - copy->setResultList(list); - copy->setPrevious(getPrevious()); - return copy; -} diff --git a/result/diceresult.h b/result/diceresult.h deleted file mode 100644 index 1b35b7e..0000000 --- a/result/diceresult.h +++ /dev/null @@ -1,97 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2014 by Renaud Guezennec * - * https://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 -#include - -#include "diceparser/diceparserhelper.h" -#include "die.h" -#include "result.h" -/** - * @brief The DiceResult class - */ -class DiceResult : public Result -{ -public: - /** - * @brief DiceResult - */ - DiceResult(); - /** - * @brief ~DiceResult - */ - virtual ~DiceResult() override; - - /** - * @brief getResultList - * @return - */ - virtual QList& getResultList(); - /** - * @brief insertResult - */ - virtual void insertResult(Die*); - - /** - * @brief setResultList - * @param list - */ - virtual void setResultList(QList list); - - /** - * @brief getScalar - * @return - */ - virtual QVariant getResult(Dice::RESULT_TYPE) override; - /** - * @brief toString - * @return - */ - virtual QString toString(bool wl) override; - /** - * @brief isHomogeneous - */ - virtual bool isHomogeneous() const; - /** - * @brief setHomogeneous - */ - virtual void setHomogeneous(bool); - - Dice::ArithmeticOperator getOperator() const; - void setOperator(const Dice::ArithmeticOperator& dieOperator); - bool contains(Die* die, const std::function equal); - - void clear() override; - - virtual Result* getCopy() const override; - -protected: - qreal getScalarResult(); - -protected: - QList m_diceValues; - bool m_homogeneous; - Dice::ArithmeticOperator m_operator{Dice::ArithmeticOperator::PLUS}; -}; -Q_DECLARE_METATYPE(QList) -#endif // DICERESULT_H diff --git a/result/result.cpp b/result/result.cpp deleted file mode 100644 index ca410b3..0000000 --- a/result/result.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2014 by Renaud Guezennec * - * https://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 - -Result::Result() - : m_resultTypes(static_cast(Dice::RESULT_TYPE::NONE)) - , m_id(QString("\"%1\"").arg(QUuid::createUuid().toString())) - , m_previous(nullptr) -{ -} -Result::~Result() {} - -Result* Result::getPrevious() const -{ - return m_previous; -} - -void Result::setPrevious(Result* p) -{ - Q_ASSERT(p != this); - m_previous= p; -} - -bool Result::isStringResult() const -{ - return false; -} -void Result::clear() {} -bool Result::hasResultOfType(Dice::RESULT_TYPE type) const -{ - return (m_resultTypes & static_cast(type)); -} -void Result::generateDotTree(QString& s) -{ - auto str= toString(true); - if(s.contains(str)) - return; - s.append(str); - s.append(";\n"); - - if(nullptr != m_previous) - { - s.append(toString(false)); - s.append(" -> "); - s.append(m_previous->toString(false)); - s.append("[label=\"previousResult\"]\n"); - m_previous->generateDotTree(s); - } - else - { - s.append(toString(false)); - s.append(" -> "); - s.append("nullptr"); - s.append(" [label=\"previousResult\", shape=\"box\"];\n"); - } -} - -QString Result::getId() const -{ - return m_id; -} - -QString Result::getStringResult() const -{ - return {}; -} diff --git a/result/result.h b/result/result.h deleted file mode 100644 index 4432682..0000000 --- a/result/result.h +++ /dev/null @@ -1,96 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2014 by Renaud Guezennec * - * https://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 - -#include -#include -#include -/** - * @brief The Result class - */ -class Result -{ -public: - /** - * @brief Result - */ - Result(); - /** - * @brief ~Result - */ - virtual ~Result(); - - /** - * @brief isScalar - * @return - */ - virtual bool hasResultOfType(Dice::RESULT_TYPE) const; - /** - * @brief getScalar - * @return - */ - virtual QVariant getResult(Dice::RESULT_TYPE)= 0; - /** - * @brief getPrevious - * @return - */ - virtual Result* getPrevious() const; - /** - * @brief setPrevious - */ - virtual void setPrevious(Result*); - /** - * @brief isStringResult - * @return - */ - virtual bool isStringResult() const; - - virtual void clear(); - - /** - * @brief getStringResult - * @return - */ - virtual QString getStringResult() const; - /** - * @brief generateDotTree - */ - void generateDotTree(QString&); - /** - * @brief toString - * @return - */ - virtual QString toString(bool wl)= 0; - virtual Result* getCopy() const= 0; - - QString getId() const; - -protected: - int m_resultTypes; /// @brief - QString m_id; - -private: - Result* m_previous= nullptr; /// @brief -}; - -#endif // RESULT_H diff --git a/result/scalarresult.cpp b/result/scalarresult.cpp deleted file mode 100644 index dcbaa61..0000000 --- a/result/scalarresult.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2014 by Renaud Guezennec * - * https://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= static_cast(Dice::RESULT_TYPE::SCALAR); -} - -void ScalarResult::setValue(qreal i) -{ - m_value= i; -} -QVariant ScalarResult::getResult(Dice::RESULT_TYPE type) -{ - if(Dice::RESULT_TYPE::SCALAR == type) - { - return m_value; - } - else - return {}; -} -Result* ScalarResult::getCopy() const -{ - 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; - } -} diff --git a/result/scalarresult.h b/result/scalarresult.h deleted file mode 100644 index 73fe73b..0000000 --- a/result/scalarresult.h +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2014 by Renaud Guezennec * - * https://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 - -#include "result.h" -#include - -/** - * @brief The ScalarResult class is used to store scalar result by many ExecutionNode. - */ -class ScalarResult : public Result -{ -public: - /** - * @brief ScalarResult - */ - ScalarResult(); - /** - * @brief getResult - * @return - */ - virtual QVariant getResult(Dice::RESULT_TYPE); - /** - * @brief setValue - * @param i - */ - void setValue(qreal i); - /** - * @brief toString - * @return - */ - virtual QString toString(bool); - virtual Result* getCopy() const; - -private: - qreal m_value= 0; -}; - -#endif // SCALARRESULT_H diff --git a/result/stringresult.cpp b/result/stringresult.cpp deleted file mode 100644 index 113c22c..0000000 --- a/result/stringresult.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include "stringresult.h" -#include - -StringResult::StringResult() -{ - m_highlight= true; - m_resultTypes= static_cast(Dice::RESULT_TYPE::STRING); -} -void StringResult::addText(QString text) -{ - m_value.append(text); -} -StringResult::~StringResult() {} -bool StringResult::hasResultOfType(Dice::RESULT_TYPE resultType) const -{ - bool val= false; - - switch(resultType) - { - case Dice::RESULT_TYPE::STRING: - val= !isDigitOnly(); - break; - case Dice::RESULT_TYPE::SCALAR: - val= isDigitOnly(); - break; - case Dice::RESULT_TYPE::DICE_LIST: - val= (isDigitOnly() && m_value.size() > 1); - break; - default: - break; - } - return val; -} - -void StringResult::setNoComma(bool b) -{ - m_commaSeparator= !b; -} - -QString StringResult::getText() const -{ - return m_commaSeparator ? m_value.join(",") : m_value.join(QString()); -} - -QVariant StringResult::getResult(Dice::RESULT_TYPE type) -{ - switch(type) - { - case Dice::RESULT_TYPE::STRING: - return getText(); - case Dice::RESULT_TYPE::SCALAR: - return getScalarResult(); - default: - return QVariant(); - } -} -QString StringResult::toString(bool wl) -{ - 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; -} - -bool StringResult::hasHighLight() const -{ - return m_highlight; -} - -void StringResult::finished() -{ - if(isDigitOnly()) - { - std::for_each(m_value.begin(), m_value.end(), [this](const QString& str) { - auto die= new Die(); - die->setMaxValue(m_stringCount); - die->setValue(str.toInt()); - insertResult(die); - }); - } -} - -void StringResult::setStringCount(int count) -{ - m_stringCount= count; -} - -bool StringResult::isDigitOnly() const -{ - return std::all_of(m_value.begin(), m_value.end(), [](const QString& str) { - bool ok= false; - str.toInt(&ok); - return ok; - }); -} - -Result* StringResult::getCopy() const -{ - auto copy= new StringResult(); - copy->setPrevious(getPrevious()); - copy->setHighLight(m_highlight); - std::for_each(m_value.begin(), m_value.end(), [copy](const QString& str) { copy->addText(str); }); - return copy; -} - -QString StringResult::getStringResult() const -{ - return getText(); -} diff --git a/result/stringresult.h b/result/stringresult.h deleted file mode 100644 index b0ca539..0000000 --- a/result/stringresult.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef STRINGRESULT_H -#define STRINGRESULT_H - -#include "diceresult.h" -#include -/** - * @brief The StringResult class stores command result for String. - */ - -class StringResult : public DiceResult -{ -public: - /** - * @brief StringResult - */ - StringResult(); - /** - * @brief StringResult - */ - virtual ~StringResult() override; - void addText(QString text); - void finished(); - QString getText() const; - virtual QVariant getResult(Dice::RESULT_TYPE) override; - virtual QString toString(bool) override; - - virtual void setHighLight(bool); - virtual bool hasHighLight() const; - virtual bool hasResultOfType(Dice::RESULT_TYPE resultType) const override; - virtual Result* getCopy() const override; - - bool isDigitOnly() const; - - void setStringCount(int count); - QString getStringResult() const override; - void setNoComma(bool b); - -private: - QStringList m_value; - bool m_highlight= true; - int m_stringCount= 0; - bool m_commaSeparator= true; -}; - -#endif // STRINGRESULT_H -- cgit v1.2.3-70-g09d2