File indexing completed on 2024-04-28 05:37:02

0001 /***************************************************************************
0002  * Copyright (C) 2014 by Renaud Guezennec                                   *
0003  * http://www.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 VALIDATORLIST_H
0023 #define VALIDATORLIST_H
0024 
0025 #include <QList>
0026 #include <QString>
0027 #include <QVector>
0028 #include <Qt>
0029 
0030 #include <diceparser/diceparserhelper.h>
0031 #include <functional>
0032 
0033 class Validator;
0034 class Die;
0035 class Result;
0036 
0037 class ValidatorResult
0038 {
0039 
0040 public:
0041     ValidatorResult();
0042 
0043     const std::vector<std::pair<Die*, qint64>>& validDice() const;
0044     std::vector<std::pair<Die*, qint64>>& validDiceRef();
0045     void setValidDice(const std::vector<std::pair<Die*, qint64>>& pairs);
0046     void appendValidDice(Die* die, qint64 sum);
0047 
0048     void setAllTrue(bool allTrue);
0049     bool allTrue() const;
0050 
0051     bool contains(Die* die);
0052 
0053 private:
0054     std::vector<std::pair<Die*, qint64>> m_validDice;
0055     bool m_allTrue= false;
0056 
0057     /*friend bool operator>(const ValidatorResult& a, const ValidatorResult& b)
0058     {
0059         if(a.m_validDice.size() > b.m_validDice.size())
0060             return true;
0061         if(a.m_validDice.size() == b.m_validDice.size())
0062         {
0063             if(!a.m_allTrue && b.m_allTrue)
0064                 return true;
0065             else
0066                 return false;
0067         }
0068         return false;
0069     }*/
0070 };
0071 /**
0072  * @brief The BooleanCondition class is a Validator class checking validity from logic expression.
0073  * It manages many operators (see : @ref LogicOperator).
0074  */
0075 class ValidatorList
0076 {
0077 public:
0078     ValidatorList();
0079     virtual ~ValidatorList();
0080 
0081     virtual qint64 hasValid(Die* b, bool recursive, bool unhighlight= false) const;
0082 
0083     void setOperationList(const QVector<Dice::LogicOperation>& m);
0084     void setValidators(const QList<Validator*>& valids);
0085 
0086     QString toString();
0087 
0088     virtual Dice::CONDITION_STATE isValidRangeSize(const std::pair<qint64, qint64>& range) const;
0089 
0090     virtual ValidatorList* getCopy() const;
0091 
0092     void validResult(Result* result, bool recursive, bool unlight, std::function<void(Die*, qint64)> functor) const;
0093 
0094 private:
0095     QVector<Dice::LogicOperation> m_operators;
0096     QList<Validator*> m_validatorList;
0097 };
0098 
0099 #endif // VALIDATORLIST_H