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. --- validator.cpp | 131 ---------------------------------------------------------- 1 file changed, 131 deletions(-) delete mode 100644 validator.cpp (limited to 'validator.cpp') diff --git a/validator.cpp b/validator.cpp deleted file mode 100644 index 201574b..0000000 --- a/validator.cpp +++ /dev/null @@ -1,131 +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 "validator.h" - -Validator::Validator() {} -Validator::~Validator() {} - -template -qint64 Validator::onEach(const std::vector& b, bool recursive, bool unlight, Functor functor) const -{ - qint64 result= 0; - std::for_each(b.begin(), b.end(), [this, recursive, unlight, functor, &result](Die* die) { - if(hasValid(die, recursive, unlight)) - { - ++result; - functor(die, recursive, unlight); - } - }); - return result; -} - -template -qint64 Validator::onEachValue(const std::vector& b, bool recursive, bool unlight, Functor functor) const -{ - qint64 result= 0; - std::for_each(b.begin(), b.end(), [this, recursive, unlight, functor, &result](Die* die) { - if(hasValid(die, recursive, unlight)) - { - ++result; - functor(die, recursive, unlight); - } - }); - return result; -} - -template -qint64 Validator::oneOfThem(const std::vector& b, bool recursive, bool unlight, Functor functor) const -{ - auto oneOfThem= std::any_of(b.begin(), b.end(), - [this, recursive, unlight](Die* die) { return hasValid(die, recursive, unlight); }); - if(oneOfThem) - functor(recursive, unlight); - return oneOfThem ? 1 : 0; -} - -template -qint64 Validator::allOfThem(const std::vector& b, bool recursive, bool unlight, Functor functor) const -{ - auto all= std::all_of(b.begin(), b.end(), - [this, recursive, unlight](Die* die) { return hasValid(die, recursive, unlight); }); - if(all) - functor(recursive, unlight); - return all ? 1 : 0; -} - -template -qint64 Validator::onScalar(const std::vector& b, bool recursive, bool unlight, Functor functor) const -{ - qint64 result= 0; - for(const auto& die : b) - { - result+= die->getValue(); - } - Die die; - die.setValue(result); - if(hasValid(&die, recursive, unlight)) - { - functor(recursive, unlight); - return 1; - } - return 0; -} - -const std::set& Validator::getPossibleValues(const std::pair&) -{ - return m_values; -} - -template -qint64 Validator::validResult(const std::vector& b, bool recursive, bool unlight, Functor functor) const -{ - qint64 result; - switch(m_conditionType) - { - case Dice::OnEach: - result= onEach(b, recursive, unlight, functor); - break; - case Dice::OnEachValue: - result= onEachValue(b, recursive, unlight, functor); - break; - case Dice::OneOfThem: - result= oneOfThem(b, recursive, unlight, functor); - break; - case Dice::AllOfThem: - result= allOfThem(b, recursive, unlight, functor); - break; - case Dice::OnScalar: - result= onScalar(b, recursive, unlight, functor); - break; - } - return result; -} - -Dice::ConditionType Validator::getConditionType() const -{ - return m_conditionType; -} - -void Validator::setConditionType(const Dice::ConditionType& conditionType) -{ - m_conditionType= conditionType; -} -- cgit v1.2.3-70-g09d2