File indexing completed on 2024-04-28 05:37:01
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 VALIDATOR_H 0023 #define VALIDATOR_H 0024 0025 #include <diceparser/diceparserhelper.h> 0026 0027 #include "die.h" 0028 #include <QString> 0029 #include <Qt> 0030 #include <set> 0031 /** 0032 * @brief The Validator class is an abstract class for checking the validity of dice for some 0033 * operator. 0034 */ 0035 // template <Dice::ConditionType C> 0036 class Validator 0037 { 0038 public: 0039 /** 0040 * @brief Validator 0041 */ 0042 Validator(); 0043 /** 0044 * @brief ~Validator 0045 */ 0046 virtual ~Validator(); 0047 /** 0048 * @brief hasValid 0049 * @param b 0050 * @param recursive 0051 * @param unlight 0052 * @return 0053 */ 0054 virtual qint64 hasValid(Die* b, bool recursive, bool unlight= false) const= 0; 0055 /** 0056 * @brief toString 0057 * @return 0058 */ 0059 virtual QString toString()= 0; 0060 /** 0061 * @brief getValidRangeSize 0062 * @param faces 0063 * @return 0064 */ 0065 virtual Dice::CONDITION_STATE isValidRangeSize(const std::pair<qint64, qint64>& range) const= 0; 0066 /** 0067 * @brief getCopy 0068 * @return return a copy of this validator 0069 */ 0070 virtual Validator* getCopy() const= 0; 0071 /** 0072 * @brief getPossibleValues 0073 * @param range 0074 * @return 0075 */ 0076 virtual const std::set<qint64>& getPossibleValues(const std::pair<qint64, qint64>& range); 0077 /** 0078 * @brief validResult 0079 * @param b 0080 * @param recursive 0081 * @param unlight 0082 * @return 0083 */ 0084 template <typename Functor> 0085 qint64 validResult(const std::vector<Die*>& b, bool recursive, bool unlight, Functor functor) const; 0086 0087 Dice::ConditionType getConditionType() const; 0088 void setConditionType(const Dice::ConditionType& conditionType); 0089 0090 protected: 0091 template <typename Functor> 0092 qint64 onEach(const std::vector<Die*>& b, bool recursive, bool unlight, Functor functor) const; 0093 template <typename Functor> 0094 qint64 onEachValue(const std::vector<Die*>& b, bool recursive, bool unlight, Functor functor) const; 0095 template <typename Functor> 0096 qint64 oneOfThem(const std::vector<Die*>& b, bool recursive, bool unlight, Functor functor) const; 0097 template <typename Functor> 0098 qint64 allOfThem(const std::vector<Die*>& b, bool recursive, bool unlight, Functor functor) const; 0099 template <typename Functor> 0100 qint64 onScalar(const std::vector<Die*>& b, bool recursive, bool unlight, Functor functor) const; 0101 0102 protected: 0103 std::set<qint64> m_values; 0104 Dice::ConditionType m_conditionType= Dice::OnEach; 0105 }; 0106 0107 #endif // VALIDATOR_H