File indexing completed on 2024-05-12 05:39:29

0001 /***************************************************************************
0002  * Copyright (C) 2014 by Renaud Guezennec                                   *
0003  * https://rolisteam.org/contact                      *
0004  *                                                                          *
0005  *  This file is part of DiceParser                                         *
0006  *                                                                          *
0007  * DiceParser is free software; you can redistribute it and/or modify       *
0008  * it under the terms of the GNU General Public License as published by     *
0009  * the Free Software Foundation; either version 2 of the License, or        *
0010  * (at your option) any later version.                                      *
0011  *                                                                          *
0012  * This program is distributed in the hope that it will be useful,          *
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of           *
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             *
0015  * GNU General Public License for more details.                             *
0016  *                                                                          *
0017  * You should have received a copy of the GNU General Public License        *
0018  * along with this program; if not, write to the                            *
0019  * Free Software Foundation, Inc.,                                          *
0020  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.                 *
0021  ***************************************************************************/
0022 #ifndef DICERESULT_H
0023 #define DICERESULT_H
0024 #include <QList>
0025 #include <functional>
0026 
0027 #include "diceparser/diceparserhelper.h"
0028 #include "die.h"
0029 #include "result.h"
0030 /**
0031  * @brief The DiceResult class
0032  */
0033 class DiceResult : public Result
0034 {
0035 public:
0036     /**
0037      * @brief DiceResult
0038      */
0039     DiceResult();
0040     /**
0041      * @brief ~DiceResult
0042      */
0043     virtual ~DiceResult() override;
0044 
0045     /**
0046      * @brief getResultList
0047      * @return
0048      */
0049     virtual QList<Die*>& getResultList();
0050     /**
0051      * @brief insertResult
0052      */
0053     virtual void insertResult(Die*);
0054 
0055     /**
0056      * @brief setResultList
0057      * @param list
0058      */
0059     virtual void setResultList(QList<Die*> list);
0060 
0061     /**
0062      * @brief getScalar
0063      * @return
0064      */
0065     virtual QVariant getResult(Dice::RESULT_TYPE) override;
0066     /**
0067      * @brief toString
0068      * @return
0069      */
0070     virtual QString toString(bool wl) override;
0071     /**
0072      * @brief isHomogeneous
0073      */
0074     virtual bool isHomogeneous() const;
0075     /**
0076      * @brief setHomogeneous
0077      */
0078     virtual void setHomogeneous(bool);
0079 
0080     Dice::ArithmeticOperator getOperator() const;
0081     void setOperator(const Dice::ArithmeticOperator& dieOperator);
0082     bool contains(Die* die, const std::function<bool(const Die*, const Die*)> equal);
0083 
0084     void clear() override;
0085 
0086     virtual Result* getCopy() const override;
0087 
0088 protected:
0089     qreal getScalarResult();
0090 
0091 protected:
0092     QList<Die*> m_diceValues;
0093     bool m_homogeneous;
0094     Dice::ArithmeticOperator m_operator{Dice::ArithmeticOperator::PLUS};
0095 };
0096 Q_DECLARE_METATYPE(QList<Die*>)
0097 #endif // DICERESULT_H