diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-05-02 08:42:08 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-05-02 08:42:08 +0000 |
| commit | 822b5fcaa34b78b9668a58680f9e0d89aa3fd7bd (patch) | |
| tree | 40dc605213eff20f62b16e5f54e5e5e03d744d63 | |
| parent | 696414f1dc8bc419427efb6c1abe1bbae0a68a56 (diff) | |
[FIX] Exceptions no longer used in pokemod
[DEL] Exception and BugCatcher are no longer needed
[ADD] Object.cpp added
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@119 6ecfd1a5-f3ed-3746-8530-beee90d26b22
79 files changed, 2877 insertions, 3372 deletions
@@ -1,4 +1,13 @@ ----------------- +Rev: 119 +Date: 2 May 2008 +User: MathStuf +----------------- +[FIX] Exceptions no longer used in pokemod +[DEL] Exception and BugCatcher are no longer needed +[ADD] Object.cpp added + +----------------- Rev: 118 Date: 30 April 2008 User: MathStuf diff --git a/general/Audio.cpp b/general/Audio.cpp index 966cdd15..c5ce73e2 100644 --- a/general/Audio.cpp +++ b/general/Audio.cpp @@ -18,18 +18,18 @@ // Header include #include "Audio.h" -void Audio::playSFX(const QString& url) throw(OpenException) +void Audio::playSFX(const QString& url) { Phonon::MediaObject* sfx = new Phonon::MediaObject(); - Q_CHECK_PTR(sfx); sfx->setCurrentSource(url); - if (sfx->state() == Phonon::ErrorState) - throw(OpenException("Audio", url)); - sfx->play(); - m_curPlay.append(sfx); + if (sfx->state() != Phonon::ErrorState) + { + sfx->play(); + m_curPlay.append(sfx); + } } -void Audio::playMusic(const QString& url) throw(OpenException) +void Audio::playMusic(const QString& url) { if (!m_started) start(); @@ -39,9 +39,8 @@ void Audio::playMusic(const QString& url) throw(OpenException) else { m_music.setCurrentSource(url); - if (m_music.state() == Phonon::ErrorState) - throw(OpenException("Audio", url)); - m_music.play(); + if (m_music.state() != Phonon::ErrorState) + m_music.play(); } } diff --git a/general/Audio.h b/general/Audio.h index d06f7492..5f6b2fe7 100644 --- a/general/Audio.h +++ b/general/Audio.h @@ -18,9 +18,6 @@ #ifndef __AUDIO__ #define __AUDIO__ -// General includes -#include "Exception.h" - // Qt includes // #include <Phonon/AudioOutput> // #include <Phonon/MediaObject> @@ -46,8 +43,8 @@ class Audio : public QObject clear(); } - void playSFX(const QString& url) throw(OpenException); - void playMusic(const QString& url) throw(OpenException); + void playSFX(const QString& url); + void playMusic(const QString& url); void prune(); void clear(); diff --git a/general/BugCatcher.cpp b/general/BugCatcher.cpp deleted file mode 100644 index e83dc87c..00000000 --- a/general/BugCatcher.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> - * - * This program 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 3 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, see <http://www.gnu.org/licenses/>. - */ - -// Header include -#include "BugCatcher.h" - -KAboutData* BugCatcher::m_aboutData = NULL; diff --git a/general/BugCatcher.h b/general/BugCatcher.h deleted file mode 100644 index 8e607c95..00000000 --- a/general/BugCatcher.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> - * - * This program 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 3 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, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __BUGCATCHER__ -#define __BUGCATCHER__ - -// General includes -#include "Exception.h" - -// KDE includes -#include <kbugreport.h> -#include <kmessagebox.h> - -// Forward declarations -class KAboutData; - -class BugCatcher -{ - public: - static void setAbout(KAboutData* aboutData) - { - m_aboutData = aboutData; - } - static void deleteAbout() - { - m_aboutData = NULL; - } - static void report(const Exception& exception) - { - if (!m_aboutData) - return; - KBugReport bug(NULL, true, m_aboutData); - if (KMessageBox::questionYesNo(&bug, "Missed an error catching spot. Please email me (MathStuf@gmail.com) with the error and \"PokeModr - error\" as the subject.", exception.message()) == KMessageBox::Yes) - bug.exec(); - } - private: - static KAboutData* m_aboutData; -}; - -#endif diff --git a/general/Exception.h b/general/Exception.h deleted file mode 100644 index b52fc4b6..00000000 --- a/general/Exception.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> - * - * This program 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 3 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, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __EXCEPTIONS__ -#define __EXCEPTIONS__ - -// Qt includes -#include <QString> - -class Exception -{ - public: - Exception(const QString& className, const QString error) : - m_className(className), - m_error(error) - { - } - - QString message() const - { - return QString("%1: %2").arg(m_className).arg(m_error); - } - private: - const QString m_className; - const QString m_error; -}; - -class UnusedException : public Exception -{ - public: - UnusedException(const QString& className, const QString& variable) : - Exception(className, QString("setting unused %1").arg(variable)) - { - } -}; - -class BoundsException : public Exception -{ - public: - BoundsException(const QString& className, const QString& variable) : - Exception(className, QString("%1 out-of-bounds").arg(variable)) - { - } -}; - -class IndexException : public BoundsException -{ - public: - IndexException(const QString& className, const QString& variable) : - BoundsException(className, QString("%1 index").arg(variable)) - { - } -}; - -class ReplaceException : public Exception -{ - public: - ReplaceException(const QString& className, const QString& fileName) : - Exception(className, QString("unable to replace %1").arg(fileName)) - { - } -}; - -class SaveException : public Exception -{ - public: - SaveException(const QString& className, const QString& fileName) : - Exception(className, QString("unable to save %1").arg(fileName)) - { - } -}; - -class OpenException : public Exception -{ - public: - OpenException(const QString& className, const QString& fileName) : - Exception(className, QString("unable to open %1").arg(fileName)) - { - } -}; - -class DirException : public Exception -{ - public: - DirException(const QString& className, const QString& path) : - Exception(className, QString("unable to create path %1").arg(path)) - { - } -}; - -class InvalidException : public Exception -{ - public: - InvalidException(const QString& className, const QString& fileName) : - Exception(className, QString("%1 is invalid").arg(fileName)) - { - } -}; - -class RemoveException : public Exception -{ - public: - RemoveException(const QString& className, const QString& fileName) : - Exception(className, QString("unable to remove %1").arg(fileName)) - { - } -}; - -class SizeException : public Exception -{ - public: - SizeException(const QString& className, const QString& variable) : - Exception(className, QString("wrong size for %1").arg(variable)) - { - } -}; - -#endif diff --git a/general/Flag.cpp b/general/Flag.cpp index cc8918b4..e08ba9f0 100644 --- a/general/Flag.cpp +++ b/general/Flag.cpp @@ -19,3 +19,40 @@ #include "Flag.h" const QStringList Flag::ValueStr = QStringList() << "Off" << "On" << "Ignore"; + +Flag::Flag(const int flag, const int status) : + m_flag(flag) +{ + setStatus(status); +} + +void Flag::set(const int flag, const int status) +{ + setFlag(flag); + setStatus(status); +} + +void Flag::setFlag(const int flag) +{ + m_flag = flag; +} + +void Flag::setStatus(const int status) +{ + if (End <= status) + { + m_status = Ignore; + return; + } + m_status = status; +} + +int Flag::flag() const +{ + return m_flag; +} + +int Flag::status() const +{ + return m_status; +} diff --git a/general/Flag.h b/general/Flag.h index ca86082d..bb9548f3 100644 --- a/general/Flag.h +++ b/general/Flag.h @@ -18,9 +18,6 @@ #ifndef __FLAG__ #define __FLAG__ -// General includes -#include "Exception.h" - // Qt includes #include <QStringList> @@ -36,36 +33,14 @@ class Flag }; static const QStringList ValueStr; - inline Flag(const int flag = 0, const int status = 0) : - m_flag(flag) - { - setStatus(status); - } + Flag(const int flag = 0, const int status = Off); - inline void set(const int flag, const int status) - { - setFlag(flag); - setStatus(status); - } - inline void setFlag(const int flag) - { - m_flag = flag; - } - void setStatus(const int status) throw(BoundsException) - { - if (End <= status) - throw(BoundsException("Flag", "status")); - m_status = status; - } + void set(const int flag, const int status); + void setFlag(const int flag); + void setStatus(const int status); - inline int flag() const - { - return m_flag; - } - inline int status() const - { - return m_status; - } + int flag() const; + int status() const; private: int m_flag; int m_status; diff --git a/general/Matrix.h b/general/Matrix.h index d32f387b..5ba0d4e8 100644 --- a/general/Matrix.h +++ b/general/Matrix.h @@ -18,9 +18,6 @@ #ifndef __MATRIX__ #define __MATRIX__ -// General includes -#include "Exception.h" - // Qt includes #include <QVector> @@ -58,18 +55,18 @@ template<class T> class Matrix row.append(value); ++m_width; } - void insertRow(const int row, const T& value = T()) throw(BoundsException) + void insertRow(const int row, const T& value = T()) { if (m_height < row) - throw(BoundsException("Matrix", "dimension")); + return; m_width += !m_width; m_matrix.insert(row, QVector<T>(m_width, value)); ++m_height; } - void insertColumn(const int column, const T& value = T()) throw(BoundsException) + void insertColumn(const int column, const T& value = T()) { if (m_width < column) - throw(BoundsException("Matrix", "dimension")); + return; if (!m_height) { m_matrix.append(QVector<T>(1)); @@ -79,18 +76,18 @@ template<class T> class Matrix row.insert(column, value); ++m_width; } - void deleteRow(const int row) throw(BoundsException) + void deleteRow(const int row) { if (m_height <= row) - throw(BoundsException("Matrix", "dimension")); + return; m_matrix.remove(row); if (!(--m_height)) m_width = 0; } - void deleteColumn(const int column) throw(BoundsException) + void deleteColumn(const int column) { if (m_width <= column) - throw(BoundsException("Matrix", "dimension")); + return; foreach (QVector<T> row, m_matrix) row.remove(column); if (!(--m_width)) @@ -103,10 +100,10 @@ template<class T> class Matrix m_matrix.clear(); } - void set(const int row, const int column, const T& value) throw(BoundsException) + void set(const int row, const int column, const T& value) { if ((m_height <= row) || (m_width <= column)) - throw(BoundsException("Matrix", "dimension")); + return; (m_matrix[row])[column] = value; } void resize(const int height, const int width, const T& value = T()) @@ -124,22 +121,22 @@ template<class T> class Matrix m_matrix = QVector< QVector<T> >(m_height, QVector<T>(m_width, value)); } - const T& at(const int row, const int column) const throw(BoundsException) + T at(const int row, const int column) const { if ((m_height <= row) || (m_width <= column)) - throw(BoundsException("Matrix", "dimension")); + return T(); return m_matrix.at(row).at(column); } - const QVector<T> row(const int row) const throw(BoundsException) + QVector<T> row(const int row) const { if (height <= row) - throw(BoundsException("Matrix", "dimension")); + return QVector<T>(); return m_matrix.at(row); } - const QVector<T> column(const int column) const throw(BoundsException) + QVector<T> column(const int column) const { if (m_width <= column) - throw(BoundsException("Matrix", "dimension")); + return QVector<T>(); QVector<T> c; foreach (QVector<T> row, m_matrix) c.append(row.at(column)); @@ -154,13 +151,14 @@ template<class T> class Matrix return m_width; } - T& operator()(const int row, const int column) throw(BoundsException) + T& operator()(const int row, const int column) { + // FIXME: compile error if used :( if ((m_height <= row) || (m_width <= column)) - throw(BoundsException("Matrix", "dimension")); + return T(); return (m_matrix[row])[column]; } - const T& operator()(const int row, const int column) const + T operator()(const int row, const int column) const { return at(row, column); } diff --git a/general/general.pro b/general/general.pro index 5810ce03..4dd1df7f 100644 --- a/general/general.pro +++ b/general/general.pro @@ -9,9 +9,8 @@ LIBS += -lphonon \ CONFIG += qt \ warn_on \ - dll \ - exceptions -!win32:CONFIG += debug + dll +!win32 : CONFIG += debug # Following is reformatted from the KTIGCC .pro file win32 { @@ -54,13 +53,10 @@ win32 { } SOURCES += Audio.cpp \ - BugCatcher.cpp \ Flag.cpp \ Fraction.cpp HEADERS += Audio.h \ - BugCatcher.h \ - Exception.h \ Flag.h \ Fraction.h \ Hat.h \ @@ -68,10 +64,10 @@ HEADERS += Audio.h \ Point.h INSTALLS += target -isEmpty(PREFIX) { +isEmpty(PREFIX){ PREFIX = $$(PREFIX)/lib } -isEmpty(PREFIX) { +isEmpty(PREFIX){ PREFIX = /usr/lib`kde4-config --libsuffix` } target.path = $$PREFIX diff --git a/pokemod/Ability.cpp b/pokemod/Ability.cpp index 3b69d831..5c3a72ad 100644 --- a/pokemod/Ability.cpp +++ b/pokemod/Ability.cpp @@ -22,6 +22,9 @@ #include "AbilityEffect.h" #include "Pokemod.h" +// Qt includes +#include <QSet> + Ability::Ability(const Ability& ability) : Object("Ability", ability.parent(), ability.id()) { @@ -51,34 +54,21 @@ Ability::~Ability() clear(); } -bool Ability::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Ability \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("No Name"); -// valid = false; -// } -// if (effectCount()) -// { -// QMap<int, bool> idChecker; -// foreach (AbilityEffect* effect, m_effects) -// { -// if (!effect->isValid()) -// valid = false; -// if (idChecker[effect->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); -// idChecker[effect->id()] = true; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("No effects")); -// valid = false; -// } -// return valid; +void Ability::validate(QTextStream& stream) +{ + if (m_name.isEmpty()) + error(stream, "Name is empty"); + if (!effectCount()) + error(stream, "No effects"); + QSet<int> idChecker; + foreach (AbilityEffect* effect, m_effects) + { + if (!effect->isValid(stream)) + setValid(false); + if (idChecker.contains(effect->id())) + subclassError(stream, "effect", effect->id()); + idChecker.insert(effect->id()); + } } void Ability::load(const QDomElement& xml, int id) @@ -106,26 +96,26 @@ QString Ability::name() const return m_name; } -const AbilityEffect* Ability::effect(const int index) const throw(IndexException) +const AbilityEffect* Ability::effect(const int index) const { if (effectCount() <= index) - warning<IndexException>("effect"); + return NULL; return m_effects.at(index); } -AbilityEffect* Ability::effect(const int index) throw(IndexException) +AbilityEffect* Ability::effect(const int index) { if (effectCount() <= index) - error<IndexException>("effect"); + return NULL; return m_effects[index]; } -const AbilityEffect* Ability::effectById(const int id) const throw(IndexException) +const AbilityEffect* Ability::effectById(const int id) const { return effect(effectIndex(id)); } -AbilityEffect* Ability::effectById(const int id) throw(IndexException) +AbilityEffect* Ability::effectById(const int id) { return effect(effectIndex(id)); } @@ -166,15 +156,15 @@ AbilityEffect* Ability::newEffect(AbilityEffect* effect) return effect; } -void Ability::deleteEffect(const int index) throw(IndexException) +void Ability::deleteEffect(const int index) { if (effectCount() <= index) - error<IndexException>("effect"); + return; delete m_effects[index]; m_effects.removeAt(index); } -void Ability::deleteEffectById(const int id) throw(IndexException) +void Ability::deleteEffectById(const int id) { deleteEffect(effectIndex(id)); } diff --git a/pokemod/Ability.h b/pokemod/Ability.h index 827befc3..d5931605 100644 --- a/pokemod/Ability.h +++ b/pokemod/Ability.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - // Qt includes #include <QList> @@ -46,21 +43,21 @@ class Ability : public Object QString name() const; - const AbilityEffect* effect(const int index) const throw(IndexException); - AbilityEffect* effect(const int index) throw(IndexException); - const AbilityEffect* effectById(const int id) const throw(IndexException); - AbilityEffect* effectById(const int id) throw(IndexException); + const AbilityEffect* effect(const int index) const; + AbilityEffect* effect(const int index); + const AbilityEffect* effectById(const int id) const; + AbilityEffect* effectById(const int id); int effectIndex(const int id) const; int effectCount() const; AbilityEffect* newEffect(); AbilityEffect* newEffect(const QDomElement& xml); AbilityEffect* newEffect(const AbilityEffect& effect); - void deleteEffect(const int index) throw(IndexException); - void deleteEffectById(const int id) throw(IndexException); + void deleteEffect(const int index); + void deleteEffectById(const int id); Ability& operator=(const Ability& rhs); private: - bool validate() const; + void validate(QTextStream& stream); int effectId() const; AbilityEffect* newEffect(AbilityEffect* effect); diff --git a/pokemod/AbilityEffect.cpp b/pokemod/AbilityEffect.cpp index dba7a5e2..427fdb44 100644 --- a/pokemod/AbilityEffect.cpp +++ b/pokemod/AbilityEffect.cpp @@ -64,145 +64,17 @@ AbilityEffect::AbilityEffect(const QDomElement& xml, const Object* parent, const load(xml, id); } -bool AbilityEffect::validate() const +void AbilityEffect::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Effect with id %1---").arg(id()), Pokemod::V_Msg); -// if (m_effect < E_End) -// { -// bool ok = true; -// switch (m_effect) -// { -// case E_Stats: -// if ((Pokemod::ST_HP == m_value1) || (Pokemod::ST_End_Battle <= m_value1) || ((Pokemod::ST_SpecialDefense == m_value1) && !static_cast<const Pokemod*>(pokemod())->rules()->specialSplit())) -// ok = false; -// break; -// case E_Status: -// if (Pokemod::STS_End <= m_value1) -// ok = false; -// break; -// case E_Ability: -// if (static_cast<const Pokemod*>(pokemod())->abilityIndex(m_value1) == INT_MAX) -// ok = false; -// break; -// case E_AccuracyPowerTrade: -// if (PA_End <= m_value1) -// ok = false; -// break; -// case E_ItemEffect: -// if (IT_End <= m_value1) -// ok = false; -// break; -// case E_Type: -// if (static_cast<const Pokemod*>(pokemod())->typeIndex(m_value1) == INT_MAX) -// ok = false; -// break; -// case E_Weather: -// if (Pokemod::W_End_All <= m_value1) -// ok = false; -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid value 1"); -// valid = false; -// ok = true; -// } -// switch (m_effect) -// { -// case E_Stats: -// if (Pokemod::BM_End <= m_value2) -// ok = false; -// break; -// case E_Status: -// case E_Weather: -// if (C_End <= m_value2) -// ok = false; -// break; -// case E_Ability: -// if (I_End <= m_value2) -// ok = false; -// break; -// case E_Type: -// if (B_End <= m_value2) -// ok = false; -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid value 2"); -// valid = false; -// ok = true; -// } -// switch (m_effect) -// { -// case E_DamageToHP: -// case E_PreventDamage: -// case E_AutoHeal: -// case E_DealDamage: -// case E_Wilds: -// case E_AccuracyPowerTrade: -// case E_Type: -// case E_FastHatch: -// if ((m_value3 < 0) || (100 < m_value3)) -// ok = false; -// break; -// case E_Stats: -// if ((m_value3 < -12) || (12 < m_value3)) -// ok = false; -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid value 3"); -// valid = false; -// ok = true; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid effect"); -// valid = false; -// } -// if (m_trigger < T_End) -// { -// bool ok = true; -// switch (m_trigger) -// { -// case T_Weather: -// if (Pokemod::W_End_All <= m_triggerValue1) -// ok = false; -// break; -// case T_Type: -// if (static_cast<const Pokemod*>(pokemod())->typeIndex(m_triggerValue1) == INT_MAX) -// ok = false; -// break; -// case T_HPBoundary: -// if (S_End <= m_triggerValue1) -// ok = false; -// break; -// case T_StatChange: -// if ((Pokemod::ST_HP == m_triggerValue1) || (Pokemod::ST_End_Battle <= m_triggerValue1) || ((Pokemod::ST_SpecialDefense == m_triggerValue1) && !static_cast<const Pokemod*>(pokemod())->rules()->specialSplit())) -// ok = false; -// break; -// case T_Status: -// if (Pokemod::STS_End <= m_triggerValue1) -// ok = false; -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid trigger value 1"); -// valid = false; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid trigger"); -// valid = false; -// } -// return valid; + TEST_SETUP(); + TEST(setChance, chance); + TEST(setEffect, effect); + TEST(setValue1, value1); + TEST(setValue2, value2); + TEST(setValue3, value3); + TEST(setTrigger, trigger); + TEST(setTriggerValue1, triggerValue1); + TEST(setTriggerValue2, triggerValue2); } void AbilityEffect::load(const QDomElement& xml, int id) @@ -232,91 +104,130 @@ QDomElement AbilityEffect::save() const return xml; } -void AbilityEffect::setChance(const Fraction& chance) throw(BoundsException) +void AbilityEffect::setChance(const Fraction& chance) { if (1 < chance) - error<BoundsException>("chance"); + { + boundsError("chance"); + return; + } m_chance = chance; } -void AbilityEffect::setEffect(const int effect) throw(BoundsException) +void AbilityEffect::setEffect(const int effect) { if (E_End <= effect) - error<BoundsException>("effect"); + { + boundsError("effect"); + return; + } m_effect = effect; m_value1 = INT_MAX; m_value2 = INT_MAX; m_value3 = 0; } -void AbilityEffect::setValue1(const int value1) throw(Exception) +void AbilityEffect::setValue1(const int value1) { switch (m_effect) { case E_Stats: if ((Pokemod::ST_HP == value1) || (Pokemod::ST_End_Battle <= value1) || ((Pokemod::ST_SpecialDefense == value1) && !static_cast<const Pokemod*>(pokemod())->rules()->specialSplit())) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_Status: if (Pokemod::STS_End <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_Ability: if (static_cast<const Pokemod*>(pokemod())->abilityIndex(value1) == INT_MAX) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_AccuracyPowerTrade: if (PA_End <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_ItemEffect: if (IT_End <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_Type: if (static_cast<const Pokemod*>(pokemod())->typeIndex(value1) == INT_MAX) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_Weather: if (Pokemod::W_End_All <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; default: - error<UnusedException>("value1"); - break; + unusedError("value1"); + return; } m_value1 = value1; } -void AbilityEffect::setValue2(const int value2) throw(Exception) +void AbilityEffect::setValue2(const int value2) { switch (m_effect) { case E_Stats: if (Pokemod::BM_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Status: case E_Weather: if (C_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Ability: if (I_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Type: if (B_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; default: - error<UnusedException>("value2"); - break; + unusedError("value2"); + return; } m_value2 = value2; } -void AbilityEffect::setValue3(const int value3) throw(Exception) +void AbilityEffect::setValue3(const int value3) { switch (m_effect) { @@ -329,63 +240,90 @@ void AbilityEffect::setValue3(const int value3) throw(Exception) case E_Type: case E_FastHatch: if ((value3 < 0) || (100 < value3)) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; case E_Stats: if ((value3 < -12) || (12 < value3)) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; default: - error<UnusedException>("value3"); - break; + unusedError("value3"); + return; } m_value3 = value3; } -void AbilityEffect::setTrigger(const int trigger) throw(BoundsException) +void AbilityEffect::setTrigger(const int trigger) { if (T_End <= trigger) - error<BoundsException>("trigger"); + { + boundsError("trigger"); + return; + } m_trigger = trigger; m_triggerValue1 = INT_MAX; m_triggerValue2.set(1, 1); } -void AbilityEffect::setTriggerValue1(const int triggerValue1) throw(Exception) +void AbilityEffect::setTriggerValue1(const int triggerValue1) { switch (m_trigger) { case T_Weather: if (Pokemod::W_End_All <= triggerValue1) - error<BoundsException>("triggerValue1"); + { + boundsError("triggerValue1"); + return; + } break; case T_Type: if (static_cast<const Pokemod*>(pokemod())->typeIndex(triggerValue1) == INT_MAX) - error<BoundsException>("triggerValue1"); + { + boundsError("triggerValue1"); + return; + } break; case T_HPBoundary: if (S_End <= triggerValue1) - error<BoundsException>("triggerValue1"); + { + boundsError("triggerValue1"); + return; + } break; case T_StatChange: if ((Pokemod::ST_HP == triggerValue1) || (Pokemod::ST_End_Battle <= triggerValue1) || ((Pokemod::ST_SpecialDefense == triggerValue1) && !static_cast<const Pokemod*>(pokemod())->rules()->specialSplit())) - error<BoundsException>("triggerValue1"); + { + boundsError("triggerValue1"); + return; + } break; case T_Status: if (Pokemod::STS_End <= triggerValue1) - error<BoundsException>("triggerValue1"); + { + boundsError("triggerValue1"); + return; + } break; default: - error<UnusedException>("triggerValue1"); - break; + unusedError("triggerValue1"); + return; } m_triggerValue1 = triggerValue1; } -void AbilityEffect::setTriggerValue2(const Fraction& triggerValue2) throw(UnusedException) +void AbilityEffect::setTriggerValue2(const Fraction& triggerValue2) { if (m_trigger != T_HPBoundary) - error<UnusedException>("triggerValue2"); + { + unusedError("triggerValue2"); + return; + } m_triggerValue2 = triggerValue2; } diff --git a/pokemod/AbilityEffect.h b/pokemod/AbilityEffect.h index 05773ca9..ddb9ee46 100644 --- a/pokemod/AbilityEffect.h +++ b/pokemod/AbilityEffect.h @@ -22,7 +22,6 @@ #include "Object.h" // General includes -#include "../general/Exception.h" #include "../general/Fraction.h" // Qt includes @@ -124,14 +123,14 @@ class AbilityEffect : public Object void load(const QDomElement& xml, int id = INT_MAX); QDomElement save() const; - void setChance(const Fraction& chance) throw(BoundsException); - void setEffect(const int effect) throw(BoundsException); - void setValue1(const int value1) throw(Exception); - void setValue2(const int value2) throw(Exception); - void setValue3(const int value3) throw(Exception); - void setTrigger(const int trigger) throw(BoundsException); - void setTriggerValue1(const int triggerValue1) throw(Exception); - void setTriggerValue2(const Fraction& triggerValue2) throw(UnusedException); + void setChance(const Fraction& chance); + void setEffect(const int effect); + void setValue1(const int value1); + void setValue2(const int value2); + void setValue3(const int value3); + void setTrigger(const int trigger); + void setTriggerValue1(const int triggerValue1); + void setTriggerValue2(const Fraction& triggerValue2); Fraction chance() const; int effect() const; @@ -144,7 +143,7 @@ class AbilityEffect : public Object AbilityEffect& operator=(const AbilityEffect& rhs); private: - bool validate() const; + void validate(QTextStream& stream); Fraction m_chance; int m_effect; diff --git a/pokemod/Author.cpp b/pokemod/Author.cpp index bc5fc725..dcb88e9b 100644 --- a/pokemod/Author.cpp +++ b/pokemod/Author.cpp @@ -50,29 +50,16 @@ Author::Author(const QDomElement& xml, const Object* parent, const int id) : load(xml, id); } -bool Author::validate() const +void Author::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Author \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name not defined"); -// valid = false; -// } -// if (m_email == "") -// static_cast<const Pokemod*>(pokemod())->validationMsg("Email not defined", Pokemod::V_Warn); -// else if (!QRegExp("[a-zA-Z0-9%-_\\.]+@[a-zA-Z0-9\\-]+(\\.[a-zA-Z]+)*\\.[a-zA-Z]{2,4}").exactMatch(m_email)) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid email"); -// valid = false; -// } -// if (m_role == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Role not defined"); -// valid = false; -// } -// return valid; + if (m_name.isEmpty()) + error(stream, "Name is empty"); + if (m_email.isEmpty()) + warning(stream, "Email is empty"); + else if (!QRegExp("[a-zA-Z0-9%-_\\.]+@[a-zA-Z0-9\\-]+(\\.[a-zA-Z]+)*\\.[a-zA-Z]{2,4}").exactMatch(m_email)) + error(stream, "Email is invalid"); + if (m_role.isEmpty()) + error(stream, "Role is empty"); } void Author::load(const QDomElement& xml, int id) diff --git a/pokemod/Author.h b/pokemod/Author.h index 6eceeecb..aada9ae0 100644 --- a/pokemod/Author.h +++ b/pokemod/Author.h @@ -42,7 +42,7 @@ class Author : public Object Author& operator=(const Author& rhs); private: - bool validate() const; + void validate(QTextStream& stream); QString m_name; QString m_email; diff --git a/pokemod/Badge.cpp b/pokemod/Badge.cpp index 28c5ae09..b8e3b0d0 100644 --- a/pokemod/Badge.cpp +++ b/pokemod/Badge.cpp @@ -52,22 +52,16 @@ Badge::Badge(const QDomElement& xml, const Object* parent, const int id) : load(xml, id); } -bool Badge::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Badge \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name not defined"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < m_obey) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Obey level out of range"); -// valid = false; -// } -// return valid; +void Badge::validate(QTextStream& stream) +{ + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setFace, face); + TEST(setBadge, badge); + TEST(setObey, obey); + TEST_ARRAY(setStat, stat, (static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY)); + TEST_ARRAY(setHm, hm, Pokemod::HM_End_All); } void Badge::load(const QDomElement& xml, int id) @@ -98,40 +92,52 @@ void Badge::setName(const QString& name) m_name = name; } -void Badge::setFace(const QPixmap& face) throw(SizeException) +void Badge::setFace(const QPixmap& face) { if (face.size() != QSize(64, 64)) - error<SizeException>("face"); + sizeError("face"); m_face = face; } -void Badge::setBadge(const QPixmap& badge) throw(SizeException) +void Badge::setBadge(const QPixmap& badge) { if (badge.size() != QSize(64, 64)) - error<SizeException>("badge"); + sizeError("badge"); m_badge = badge; } -void Badge::setObey(const int obey) throw(BoundsException) +void Badge::setObey(const int obey) { if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < obey) - error<BoundsException>("obey"); + { + boundsError("obey"); + return; + } m_obey = obey; } -void Badge::setStat(const int stat, const Fraction& multiplier) throw(BoundsException) +void Badge::setStat(const int stat, const Fraction& multiplier) { if (multiplier < 1) - error<BoundsException>("stat multiplier"); + { + boundsError("stat multiplier"); + return; + } if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) - error<BoundsException>("stat"); + { + boundsError("stat"); + return; + } m_stat[stat] = multiplier; } -void Badge::setHm(const int hm, const bool hmAllowed) throw(BoundsException) +void Badge::setHm(const int hm, const bool hmAllowed) { if (Pokemod::HM_End_All <= hm) - error<BoundsException>("hm"); + { + boundsError("hm"); + return; + } m_hm[hm] = hmAllowed; } @@ -155,17 +161,19 @@ int Badge::obey() const return m_obey; } -Fraction Badge::stat(const int stat) const throw(BoundsException) +Fraction Badge::stat(const int stat) const { + // TODO: Message about fetching out-of-bounds if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) - warning<BoundsException>("stat"); + return Fraction(); return m_stat[stat]; } -bool Badge::hm(const int hm) const throw(BoundsException) +bool Badge::hm(const int hm) const { + // TODO: Message about fetching out-of-bounds if (Pokemod::HM_End_All <= hm) - warning<BoundsException>("hm"); + return false; return m_hm[hm]; } diff --git a/pokemod/Badge.h b/pokemod/Badge.h index 8ce82128..cb2bd0d5 100644 --- a/pokemod/Badge.h +++ b/pokemod/Badge.h @@ -23,7 +23,6 @@ #include "Pokemod.h" // General includes -#include "../general/Exception.h" #include "../general/Fraction.h" // Qt includes @@ -41,22 +40,22 @@ class Badge : public Object QDomElement save() const; void setName(const QString& name); - void setFace(const QPixmap& face) throw(SizeException); - void setBadge(const QPixmap& badge) throw(SizeException); - void setObey(const int obey) throw(BoundsException); - void setStat(const int stat, const Fraction& multiplier) throw(BoundsException); - void setHm(const int hm, const bool hmAllowed) throw(BoundsException); + void setFace(const QPixmap& face); + void setBadge(const QPixmap& badge); + void setObey(const int obey); + void setStat(const int stat, const Fraction& multiplier); + void setHm(const int hm, const bool hmAllowed); QString name() const; QPixmap face() const; QPixmap badge() const; int obey() const; - Fraction stat(const int stat) const throw(BoundsException); - bool hm(const int hm) const throw(BoundsException); + Fraction stat(const int stat) const; + bool hm(const int hm) const; Badge& operator=(const Badge& rhs); private: - bool validate() const; + void validate(QTextStream& stream); QString m_name; QPixmap m_face; diff --git a/pokemod/CoinList.cpp b/pokemod/CoinList.cpp index 10544a69..b24d09d1 100644 --- a/pokemod/CoinList.cpp +++ b/pokemod/CoinList.cpp @@ -24,6 +24,9 @@ #include "ItemEffect.h" #include "Pokemod.h" +// Qt includes +#include <QSet> + CoinList::CoinList(const CoinList& coinList) : Object("CoinList", coinList.parent(), coinList.id()) { @@ -54,64 +57,37 @@ CoinList::~CoinList() clear(); } -bool CoinList::validate() const +void CoinList::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Coin List \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name not defined"); -// valid = false; -// } -// bool ok = false; -// for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()) && !ok; ++i) -// { -// const Item* item = static_cast<const Pokemod*>(pokemod())->item(i); -// for (int j = 0; (j < item->effectCount()) && !ok; ++j) -// { -// const ItemEffect* effect = item->effect(j); -// if (effect->effect() == ItemEffect::E_CoinCase) -// ok = (effect->value1() == m_value); -// } -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("No coin cases which hold the right kind of coin"); -// valid = false; -// } -// if (objectCount()) -// { -// QMap<int, bool> idChecker; -// QMap<int, bool> itemChecker; -// QMap<int, bool> speciesChecker; -// foreach (CoinListObject* object, m_objects) -// { -// if (!object->isValid()) -// valid = false; -// if (idChecker[object->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate object with id %1").arg(object->id())); -// idChecker[object->id()] = true; -// if (object->type() == CoinListObject::Item) -// { -// if (itemChecker[object->object()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate object with item %1").arg(object->id())); -// itemChecker[object->object()] = true; -// } -// else if (object->type() == CoinListObject::Species) -// { -// if (speciesChecker[object->object()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate object with item %1").arg(object->id())); -// speciesChecker[object->object()] = true; -// } -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no objects"); -// valid = false; -// } -// return valid; + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setValue, value); + if (!objectCount()) + error(stream, "There are no objects"); + QSet<int> idChecker; + QSet<int> itemChecker; + QSet<int> speciesChecker; + foreach (CoinListObject* object, m_objects) + { + if (!object->isValid(stream)) + setValid(false); + if (idChecker.contains(object->id())) + subclassError(stream, "object", object->id()); + idChecker.insert(object->id()); + if (object->type() == CoinListObject::Item) + { + if (itemChecker.contains(object->object())) + subclassError(stream, "object item", object->id()); + itemChecker.insert(object->object()); + } + else if (object->type() == CoinListObject::Species) + { + if (speciesChecker.contains(object->object())) + subclassError(stream, "object species", object->id()); + speciesChecker.insert(object->object()); + } + } } void CoinList::load(const QDomElement& xml, int id) @@ -136,7 +112,7 @@ void CoinList::setName(const QString& name) m_name = name; } -void CoinList::setValue(const int value) throw(Exception) +void CoinList::setValue(const int value) { for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()); ++i) { @@ -151,7 +127,7 @@ void CoinList::setValue(const int value) throw(Exception) } } } - throw(Exception(className(), "No compatable coin cases")); + boundsError("value"); } QString CoinList::name() const @@ -164,26 +140,26 @@ int CoinList::value() const return m_value; } -const CoinListObject* CoinList::object(const int index) const throw(IndexException) +const CoinListObject* CoinList::object(const int index) const { if (objectCount() <= index) - warning<IndexException>("object"); + return NULL; return m_objects.at(index); } -CoinListObject* CoinList::object(const int index) throw(IndexException) +CoinListObject* CoinList::object(const int index) { if (objectCount() <= index) - error<IndexException>("object"); + return NULL; return m_objects[index]; } -const CoinListObject* CoinList::objectById(const int id) const throw(IndexException) +const CoinListObject* CoinList::objectById(const int id) const { return object(objectIndex(id)); } -CoinListObject* CoinList::objectById(const int id) throw(IndexException) +CoinListObject* CoinList::objectById(const int id) { return object(objectIndex(id)); } @@ -224,15 +200,15 @@ CoinListObject* CoinList::newObject(CoinListObject* object) return object; } -void CoinList::deleteObject(const int index) throw(IndexException) +void CoinList::deleteObject(const int index) { if (objectCount() <= index) - error<IndexException>("object"); + return; delete m_objects[index]; m_objects.removeAt(index); } -void CoinList::deleteObjectById(const int id) throw( IndexException ) +void CoinList::deleteObjectById(const int id) { deleteObject(objectIndex(id)); } diff --git a/pokemod/CoinList.h b/pokemod/CoinList.h index cd30e41b..2749662a 100644 --- a/pokemod/CoinList.h +++ b/pokemod/CoinList.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - // Qt includes #include <QList> @@ -43,26 +40,26 @@ class CoinList : public Object QDomElement save() const; void setName(const QString& name); - void setValue(const int value) throw(Exception); + void setValue(const int value); QString name() const; int value() const; - const CoinListObject* object(const int index) const throw(IndexException); - CoinListObject* object(const int index) throw(IndexException); - const CoinListObject* objectById(const int id) const throw(IndexException); - CoinListObject* objectById(const int id) throw(IndexException); + const CoinListObject* object(const int index) const; + CoinListObject* object(const int index); + const CoinListObject* objectById(const int id) const; + CoinListObject* objectById(const int id); int objectIndex(const int id) const; int objectCount() const; CoinListObject* newObject(); CoinListObject* newObject(const QDomElement& xml); CoinListObject* newObject(const CoinListObject& object); - void deleteObject(const int index) throw(IndexException); - void deleteObjectById(const int id) throw(IndexException); + void deleteObject(const int index); + void deleteObjectById(const int id); CoinList& operator=(const CoinList& rhs); private: - bool validate() const; + void validate(QTextStream& stream); int objectId() const; CoinListObject* newObject(CoinListObject* object); diff --git a/pokemod/CoinListObject.cpp b/pokemod/CoinListObject.cpp index 499427a5..11b358f5 100644 --- a/pokemod/CoinListObject.cpp +++ b/pokemod/CoinListObject.cpp @@ -47,38 +47,12 @@ CoinListObject::CoinListObject(const QDomElement& xml, const Object* parent, con load(xml, id); } -bool CoinListObject::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Object with id %1---").arg(id()), Pokemod::V_Msg); -// if (Item == m_type) -// { -// if (static_cast<const Pokemod*>(pokemod())->itemIndex(m_object) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid item"); -// valid = false; -// } -// } -// else if (Species == m_type) -// { -// if (static_cast<const Pokemod*>(pokemod())->speciesIndex(m_object) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid Species"); -// valid = false; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid type"); -// valid = false; -// } -// if (!m_amount || ((1 < m_amount) && (Species == m_type))) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid amount"); -// valid = false; -// } -// return valid; +void CoinListObject::validate(QTextStream& stream) +{ + TEST_SETUP(); + TEST(setType, type); + TEST(setObject, object); + TEST(setAmount, amount); } void CoinListObject::load(const QDomElement& xml, int id) @@ -100,25 +74,34 @@ QDomElement CoinListObject::save() const return xml; } -void CoinListObject::setType(const int type) throw(BoundsException) +void CoinListObject::setType(const int type) { if (End <= type) - error<BoundsException>("type"); + { + boundsError("type"); + return; + } m_type = type; m_object = INT_MAX; } -void CoinListObject::setObject(const int object) throw(BoundsException) +void CoinListObject::setObject(const int object) { if (((Item == m_type) && (static_cast<const Pokemod*>(pokemod())->itemIndex(object) == INT_MAX)) || ((Species == m_type) && (static_cast<const Pokemod*>(pokemod())->speciesIndex(object) == INT_MAX))) - error<BoundsException>("object"); + { + boundsError("object"); + return; + } m_object = object; } -void CoinListObject::setAmount(const int amount) throw(BoundsException) +void CoinListObject::setAmount(const int amount) { if (!amount || ((Species == m_type) && (1 < amount))) - error<BoundsException>("amount"); + { + boundsError("amount"); + return; + } m_amount = amount; } diff --git a/pokemod/CoinListObject.h b/pokemod/CoinListObject.h index 6a0e2f41..1bf52b5e 100644 --- a/pokemod/CoinListObject.h +++ b/pokemod/CoinListObject.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - class CoinListObject : public Object { public: @@ -43,9 +40,9 @@ class CoinListObject : public Object void load(const QDomElement& xml, int id = INT_MAX); QDomElement save() const; - void setType(const int type) throw(BoundsException); - void setObject(const int object) throw(BoundsException); - void setAmount(const int amount) throw(BoundsException); + void setType(const int type); + void setObject(const int object); + void setAmount(const int amount); void setCost(const int cost); int type() const; @@ -55,7 +52,7 @@ class CoinListObject : public Object CoinListObject& operator=(const CoinListObject& rhs); private: - bool validate() const; + void validate(QTextStream& stream); int m_type; int m_object; diff --git a/pokemod/Dialog.cpp b/pokemod/Dialog.cpp index 8ec1ee1a..5c0ea887 100644 --- a/pokemod/Dialog.cpp +++ b/pokemod/Dialog.cpp @@ -57,7 +57,7 @@ Dialog::Dialog(const QDomElement& xml, const Object* parent, const int id) : load(xml, id); } -bool Dialog::validate() const +void Dialog::validate(QTextStream& stream) { // TODO: validate // bool valid = true; @@ -65,12 +65,12 @@ bool Dialog::validate() const // if (m_dialog == "") // { // static_cast<const Pokemod*>(pokemod())->validationMsg("Dialog is empty"); -// valid = false; +// setValid(false); // } // if (m_dialog.count('%') & 1) // { // static_cast<const Pokemod*>(pokemod())->validationMsg("Command delimiter mismatch"); -// valid = false; +// setValid(false); // } // else // { @@ -87,14 +87,14 @@ bool Dialog::validate() const // if (numArgs != CommandNumArgs[curCmd]) // { // static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Invalid number of arguments for \"%1\". %2 given when %3 needed").arg(CommandStr[curCmd]).arg(numArgs).arg(CommandNumArgs[curCmd])); -// valid = false; +// setValid(false); // } // break; // case Menu: // if (!(numArgs & 1)) // { // static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid number of arguments for Menu"); -// valid = false; +// setValid(false); // } // break; // case End: @@ -106,7 +106,7 @@ bool Dialog::validate() const // if (curCmdStr != "") // { // static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Invalid command \"%1\"").arg(curCmdStr)); -// valid = false; +// setValid(false); // } // curCmd = End; // } @@ -136,7 +136,7 @@ bool Dialog::validate() const // if (!ok) // { // static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Bad flag in \"%1\"").arg(CommandStr[curCmd])); -// valid = false; +// setValid(false); // } // } // break; @@ -151,7 +151,7 @@ bool Dialog::validate() const // if (!ok) // { // static_cast<const Pokemod*>(pokemod())->validationMsg("Bad flag in \"Test Flag\""); -// valid = false; +// setValid(false); // } // break; // case 3: @@ -282,7 +282,7 @@ bool Dialog::validate() const // if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < temp) // { // static_cast<const Pokemod*>(pokemod())->validationMsg("Higher level than allowed in \"Give Pokémon\""); -// valid = false; +// setValid(false); // } // } // else @@ -334,7 +334,7 @@ bool Dialog::validate() const // if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < temp) // { // static_cast<const Pokemod*>(pokemod())->validationMsg("More money given than can be held in \"Give Money\"", Pokemod::V_Warn); -// valid = false; +// setValid(false); // } // } // else @@ -354,7 +354,7 @@ bool Dialog::validate() const // if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < temp) // { // static_cast<const Pokemod*>(pokemod())->validationMsg("More money taken than can be held in \"Take Money\""); -// valid = false; +// setValid(false); // } // } // else @@ -445,7 +445,7 @@ bool Dialog::validate() const // if (((curCmd == CheckRoster) ? static_cast<const Pokemod*>(pokemod())->rules()->maxParty() : ((curCmd == CheckLevels) ? static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() : static_cast<const Pokemod*>(pokemod())->rules()->maxMoney())) < temp) // { // static_cast<const Pokemod*>(pokemod())->validationMsg(QString("More %1 than can be carried in \"%2\"").arg((curCmd == CheckRoster) ? "party members" : ((curCmd == CheckLevels) ? "level" : "money")).arg(CommandStr[curCmd])); -// valid = false; +// setValid(false); // } // } // else @@ -617,7 +617,7 @@ bool Dialog::validate() const // if (!temp) // { // static_cast<const Pokemod*>(pokemod())->validationMsg("Item in argument #1 in \"Safari\" isn\'t a PokéBall"); -// valid = false; +// setValid(false); // } // } // else @@ -656,7 +656,7 @@ bool Dialog::validate() const // if (invError) // { // static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Invalid argument #%1 in \"%2\"").arg(invError).arg(CommandStr[curCmd])); -// valid = false; +// setValid(false); // } // } // break; @@ -689,10 +689,13 @@ QString Dialog::dialog() const return m_dialog; } -void Dialog::insertCommand(const int position, const QString& command) throw(BoundsException) +void Dialog::insertCommand(const int position, const QString& command) { if (m_dialog.length() < position) - error<BoundsException>("command"); + { + boundsError("command"); + return; + } m_dialog.insert(position, command); } diff --git a/pokemod/Dialog.h b/pokemod/Dialog.h index 0146a541..aeb09cf3 100644 --- a/pokemod/Dialog.h +++ b/pokemod/Dialog.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - // Qt includes #include <QList> @@ -98,11 +95,11 @@ class Dialog : public Object QString dialog() const; - void insertCommand(const int position, const QString& command) throw(BoundsException); + void insertCommand(const int position, const QString& command); Dialog& operator=(const Dialog& rhs); private: - bool validate() const; + void validate(QTextStream& stream); QString m_dialog; }; diff --git a/pokemod/EggGroup.cpp b/pokemod/EggGroup.cpp index 8ca56d6b..8035862d 100644 --- a/pokemod/EggGroup.cpp +++ b/pokemod/EggGroup.cpp @@ -45,17 +45,10 @@ EggGroup::EggGroup(const QDomElement& xml, const Object* parent, const int id) : load(xml, id); } -bool EggGroup::validate() const +void EggGroup::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Egg Group \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is not defined"); -// valid = false; -// } -// return valid; + if (m_name.isEmpty()) + error(stream, "Name is empty"); } void EggGroup::load(const QDomElement& xml, int id) diff --git a/pokemod/EggGroup.h b/pokemod/EggGroup.h index 89a9d342..c54ed6bb 100644 --- a/pokemod/EggGroup.h +++ b/pokemod/EggGroup.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - class EggGroup : public Object { public: @@ -41,7 +38,7 @@ class EggGroup : public Object EggGroup& operator=(const EggGroup& rhs); private: - bool validate() const; + void validate(QTextStream& stream); QString m_name; }; diff --git a/pokemod/Item.cpp b/pokemod/Item.cpp index 21d3c118..80dd77f0 100644 --- a/pokemod/Item.cpp +++ b/pokemod/Item.cpp @@ -22,6 +22,9 @@ #include "ItemEffect.h" #include "Pokemod.h" +// Qt includes +#include <QSet> + Item::Item(const Item& item) : Object("Item", item.parent(), item.id()) { @@ -55,44 +58,24 @@ Item::~Item() clear(); } -bool Item::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Item \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is not defined"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->itemTypeIndex(m_type) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid item type"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < m_price) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid price"); -// valid = false; -// } -// if (effectCount()) -// { -// QMap<int, bool> idChecker; -// foreach (ItemEffect* effect, m_effects) -// { -// if (!effect->isValid()) -// valid = false; -// if (idChecker[effect->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); -// idChecker[effect->id()] = true; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no effects"); -// valid = false; -// } -// return valid; +void Item::validate(QTextStream& stream) +{ + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setType, type); + TEST(setPrice, price); + if (!effectCount()) + error(stream, "There are no effects"); + QSet<int> idChecker; + foreach (ItemEffect* effect, m_effects) + { + if (!effect->isValid(stream)) + setValid(false); + if (idChecker.contains(effect->id())) + subclassError(stream, "effect", effect->id()); + idChecker.insert(effect->id()); + } } void Item::load(const QDomElement& xml, int id) @@ -128,17 +111,23 @@ void Item::setSellable(const bool sellable) m_sellable = sellable; } -void Item::setType(const int type) throw(BoundsException) +void Item::setType(const int type) { if (static_cast<const Pokemod*>(pokemod())->itemTypeIndex(type) == INT_MAX) - error<BoundsException>("type"); + { + boundsError("type"); + return; + } m_type = type; } -void Item::setPrice(const int price) throw(BoundsException) +void Item::setPrice(const int price) { if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < price) - error<BoundsException>("price"); + { + boundsError("price"); + return; + } m_price = price; } @@ -172,26 +161,26 @@ QString Item::description() const return m_description; } -const ItemEffect* Item::effect(const int index) const throw(IndexException) +const ItemEffect* Item::effect(const int index) const { if (effectCount() <= index) - warning<IndexException>("effect"); + return NULL; return m_effects.at(index); } -ItemEffect* Item::effect(const int index) throw(IndexException) +ItemEffect* Item::effect(const int index) { if (effectCount() <= index) - error<IndexException>("effect"); + return NULL; return m_effects[index]; } -const ItemEffect* Item::effectById(const int id) const throw(IndexException) +const ItemEffect* Item::effectById(const int id) const { return effect(effectIndex(id)); } -ItemEffect* Item::effectById(const int id) throw(IndexException) +ItemEffect* Item::effectById(const int id) { return effect(effectIndex(id)); } @@ -232,15 +221,15 @@ ItemEffect* Item::newEffect(ItemEffect* effect) return effect; } -void Item::deleteEffect(const int index) throw(IndexException) +void Item::deleteEffect(const int index) { if (effectCount() <= index) - error<IndexException>("effect"); + return; delete m_effects[index]; m_effects.removeAt(index); } -void Item::deleteEffectById(const int id) throw(IndexException) +void Item::deleteEffectById(const int id) { deleteEffect(effectIndex(id)); } diff --git a/pokemod/Item.h b/pokemod/Item.h index fb0f1fae..93391cf9 100644 --- a/pokemod/Item.h +++ b/pokemod/Item.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - // Qt includes #include <QList> @@ -44,8 +41,8 @@ class Item : public Object void setName(const QString& name); void setSellable(const bool sellable); - void setType(const int type) throw(BoundsException); - void setPrice(const int price) throw(BoundsException); + void setType(const int type); + void setPrice(const int price); void setDescription(const QString& description); QString name() const; @@ -54,21 +51,21 @@ class Item : public Object int price() const; QString description() const; - const ItemEffect* effect(const int index) const throw(IndexException); - ItemEffect* effect(const int index) throw(IndexException); - const ItemEffect* effectById(const int id) const throw(IndexException); - ItemEffect* effectById(const int id) throw(IndexException); + const ItemEffect* effect(const int index) const; + ItemEffect* effect(const int index); + const ItemEffect* effectById(const int id) const; + ItemEffect* effectById(const int id); int effectIndex(const int id) const; int effectCount() const; ItemEffect* newEffect(); ItemEffect* newEffect(const QDomElement& xml); ItemEffect* newEffect(const ItemEffect& effect); - void deleteEffect(const int index) throw(IndexException); - void deleteEffectById(const int index) throw(IndexException); + void deleteEffect(const int index); + void deleteEffectById(const int index); Item& operator=(const Item& rhs); private: - bool validate() const; + void validate(QTextStream& stream); int effectId() const; ItemEffect* newEffect(ItemEffect* effect); diff --git a/pokemod/ItemEffect.cpp b/pokemod/ItemEffect.cpp index d7b98023..98ca941a 100644 --- a/pokemod/ItemEffect.cpp +++ b/pokemod/ItemEffect.cpp @@ -62,244 +62,15 @@ ItemEffect::ItemEffect(const QDomElement& xml, const Object* parent, const int i load(xml, id); } -bool ItemEffect::validate() const +void ItemEffect::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Effect with id %1---").arg(id()), Pokemod::V_Msg); -// switch (m_effect) -// { -// case E_Revive: -// case E_LevelBoost: -// case E_StatBoost: -// case E_PPBoost: -// case E_Fish: -// case E_Repel: -// case E_Escape: -// case E_TM: -// case E_HM: -// case E_Map: -// case E_Itemfinder: -// case E_Bike: -// case E_Scope: -// case E_Coin: -// case E_CoinCase: -// case E_Acorn: -// case E_Evolution: -// if (!m_overworld) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Effect only works in the overworld"); -// valid = false; -// } -// break; -// case E_Flinch: -// case E_First: -// case E_KeepAlive: -// case E_ModifyStatBattle: -// case E_ShieldBattle: -// case E_RunBattle: -// case E_TypeBoost: -// case E_ExpShare: -// case E_Ball: -// case E_Berry: -// if (m_overworld) -// { -// valid = false; -// static_cast<const Pokemod*>(pokemod())->validationMsg("Effect cannot work in the overworld"); -// } -// break; -// } -// if (m_effect < E_End) -// { -// bool ok = true; -// switch (m_effect) -// { -// case E_HPCure: -// case E_Revive: -// if ((m_value4 != R_Absolute) || !m_value1) -// ok = false; -// break; -// case E_LevelBoost: -// case E_ShieldBattle: -// case E_PPBoost: -// case E_Repel: -// if (!m_value1) -// ok = false; -// break; -// case E_StatBoost: -// case E_Acorn: -// if ((m_value1 < 0) || (65536 <= m_value1)) -// ok = false; -// break; -// case E_ModifyStatBattle: -// if ((m_value1 < -12) || (12 < m_value1)) -// ok = false; -// break; -// case E_Ball: -// switch (m_value2) -// { -// case B_Regular: -// if (256 <= m_value1) -// ok = false; -// break; -// case B_Level: -// if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < m_value1) -// ok = false; -// break; -// case B_Master: -// case B_Love: -// case B_Area: -// case B_Time: -// case B_Battle: -// case B_Friend: -// case B_Stat: -// case B_Type: -// case B_Weight: -// break; -// default: -// ok = false; -// break; -// } -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid value 1"); -// valid = false; -// ok = true; -// } -// switch (m_effect) -// { -// case E_HPCure: -// case E_Revive: -// if (R_End <= m_value2) -// ok = false; -// break; -// case E_CureStatus: -// if (Pokemod::STS_End <= m_value2) -// ok = false; -// break; -// case E_StatBoost: -// if ((m_value2 <= 0) || (65536 <= m_value2)) -// ok = false; -// break; -// case E_ModifyStatBattle: -// if (Pokemod::ST_End_Battle <= m_value2) -// ok = false; -// break; -// case E_ShieldBattle: -// if (SP_End <= m_value2) -// ok = false; -// break; -// case E_TypeBoost: -// if (static_cast<const Pokemod*>(pokemod())->typeIndex(m_value2) == INT_MAX) -// ok = false; -// break; -// case E_PPRestore: -// if (A_End <= m_value2) -// ok = false; -// break; -// case E_Repel: -// if (RP_End <= m_value2) -// ok = false; -// break; -// case E_Escape: -// if (ES_End <= m_value2) -// ok = false; -// break; -// case E_TM: -// case E_HM: -// if (static_cast<const Pokemod*>(pokemod())->moveIndex(m_value2) == INT_MAX) -// ok = false; -// break; -// case E_Ball: -// if (B_End <= m_value2) -// ok = false; -// break; -// case E_Berry: -// if (B2_End <= m_value2) -// ok = false; -// break; -// case E_Coin: -// case E_CoinCase: -// if (m_value2 <= 0) -// ok = false; -// break; -// case E_Acorn: -// if (static_cast<const Pokemod*>(pokemod())->itemIndex(m_value2) == INT_MAX) -// ok = false; -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid value 2"); -// valid = false; -// ok = true; -// } -// switch (m_effect) -// { -// case E_StatBoost: -// if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= m_value3) -// ok = false; -// break; -// case E_Ball: -// switch (m_value2) -// { -// case B_Regular: -// case B_Master: -// case B_Level: -// case B_Love: -// case B_Battle: -// case B_Friend: -// case B_Weight: -// break; -// case B_Area: -// if (MapWildList::End <= m_value3) -// ok = false; -// break; -// case B_Time: -// if (static_cast<const Pokemod*>(pokemod())->timeIndex(m_value3) == INT_MAX) -// ok = false; -// break; -// case B_Stat: -// if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= m_value3) -// ok = false; -// break; -// case B_Type: -// if (static_cast<const Pokemod*>(pokemod())->typeIndex(m_value3) == INT_MAX) -// ok = false; -// break; -// } -// break; -// case E_Berry: -// switch (m_value2) -// { -// case B2_HPCure: -// if (Pokemod::REL_End <= m_value3) -// ok = false; -// break; -// case B2_StatusCure: -// if (Pokemod::STS_End <= m_value3) -// ok = false; -// break; -// default: -// ok = false; -// break; -// } -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid value 3"); -// valid = false; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid effect"); -// valid = false; -// } -// return valid; + TEST_SETUP(); + TEST(setOverworld, overworld); + TEST(setEffect, effect); + TEST(setValue1, value1); + TEST(setValue2, value2); + TEST(setValue3, value3); + TEST(setValue4, value4); } void ItemEffect::load(const QDomElement& xml, int id) @@ -329,7 +100,7 @@ QDomElement ItemEffect::save() const return xml; } -void ItemEffect::setOverworld(const bool overworld) throw(Exception) +void ItemEffect::setOverworld(const bool overworld) { switch (m_effect) { @@ -351,7 +122,10 @@ void ItemEffect::setOverworld(const bool overworld) throw(Exception) case E_Acorn: case E_Evolution: if (!overworld) - throw(Exception(className(), "overworld mismatch")); + { + error("Overworld mismatch"); + return; + } break; case E_Flinch: case E_First: @@ -364,7 +138,10 @@ void ItemEffect::setOverworld(const bool overworld) throw(Exception) case E_Ball: case E_Berry: if (overworld) - throw(Exception(className(), "overworld mismatch")); + { + error("Overworld mismatch"); + return; + } break; } m_overworld = overworld; @@ -380,10 +157,13 @@ void ItemEffect::setHeld(const bool held) m_held = held; } -void ItemEffect::setEffect(const int effect) throw(Exception) +void ItemEffect::setEffect(const int effect) { if (E_End <= effect) - throw(BoundsException(className(), "effect out-of-bounds")); + { + boundsError("effect"); + return; + } switch (effect) { case E_Revive: @@ -425,30 +205,42 @@ void ItemEffect::setEffect(const int effect) throw(Exception) m_value4.set(1, 1); } -void ItemEffect::setValue1(const int value1) throw(Exception) +void ItemEffect::setValue1(const int value1) { switch (m_effect) { case E_HPCure: case E_Revive: if ((m_value4 != R_Absolute) || !value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_LevelBoost: case E_ShieldBattle: case E_PPBoost: case E_Repel: if (!value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_StatBoost: case E_Acorn: if ((value1 < 0) || (65536 <= value1)) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_ModifyStatBattle: if ((value1 < -12) || (12 < value1)) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_Fish: case E_Coin: @@ -459,11 +251,17 @@ void ItemEffect::setValue1(const int value1) throw(Exception) { case B_Regular: if (256 <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case B_Level: if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case B_Master: case B_Love: @@ -476,95 +274,141 @@ void ItemEffect::setValue1(const int value1) throw(Exception) case B_Weight: break; default: - error<BoundsException>("value1"); + boundsError("value1"); + return; } break; default: - error<UnusedException>("value1"); - break; + unusedError("value1"); + return; } m_value1 = value1; } -void ItemEffect::setValue2(const int value2) throw(Exception) +void ItemEffect::setValue2(const int value2) { switch (m_effect) { case E_HPCure: case E_Revive: if (R_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_CureStatus: if (Pokemod::STS_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_StatBoost: if ((value2 <= 0) || (65536 <= value2)) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_ModifyStatBattle: if (Pokemod::ST_End_Battle <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_ShieldBattle: if (SP_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_TypeBoost: if (static_cast<const Pokemod*>(pokemod())->typeIndex(value2) == INT_MAX) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_PPRestore: if (A_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Repel: if (RP_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Escape: if (ES_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_TM: case E_HM: if (static_cast<const Pokemod*>(pokemod())->moveIndex(value2) == INT_MAX) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Ball: if (B_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Scope: break; case E_Berry: if (B2_End <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Coin: case E_CoinCase: if (value2 <= 0) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; case E_Acorn: if (static_cast<const Pokemod*>(pokemod())->itemIndex(value2) == INT_MAX) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; default: - error<UnusedException>("value2"); - break; + unusedError("value2"); + return; } m_value2 = value2; } -void ItemEffect::setValue3(const int value3) throw(Exception) +void ItemEffect::setValue3(const int value3) { switch (m_effect) { case E_StatBoost: if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value3) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; case E_Ball: switch (m_value2) @@ -575,26 +419,38 @@ void ItemEffect::setValue3(const int value3) throw(Exception) break; case B_Area: if (MapWildList::End <= value3) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; case B_Time: if (static_cast<const Pokemod*>(pokemod())->timeIndex(value3) == INT_MAX) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; case B_Stat: if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value3) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; case B_Type: if (static_cast<const Pokemod*>(pokemod())->typeIndex(value3) == INT_MAX) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; case B_Regular: case B_Master: case B_Love: case B_Battle: - error<UnusedException>("value3"); - break; + unusedError("value3"); + return; } break; case E_Berry: @@ -602,33 +458,45 @@ void ItemEffect::setValue3(const int value3) throw(Exception) { case B2_HPCure: if (Pokemod::REL_End <= value3) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; case B2_StatusCure: if (Pokemod::STS_End <= value3) - error<BoundsException>("value3"); + { + boundsError("value3"); + return; + } break; default: - error<UnusedException>("value3"); - break; + unusedError("value3"); + return; } break; default: - error<UnusedException>("value3"); - break; + unusedError("value3"); + return; } m_value3 = value3; } -void ItemEffect::setValue4(const Fraction& value4) throw(Exception) +void ItemEffect::setValue4(const Fraction& value4) { if ((E_TypeBoost == m_effect) || (E_PPBoost == m_effect)) { if (value4 < 1) - error<BoundsException>("value4"); + { + boundsError("value4"); + return; + } } else if (1 < value4) - error<BoundsException>("value4"); + { + boundsError("value4"); + return; + } switch (m_effect) { case E_CureStatus: @@ -647,14 +515,23 @@ void ItemEffect::setValue4(const Fraction& value4) throw(Exception) case E_CoinCase: case E_Acorn: case E_Evolution: - error<UnusedException>("value4"); + { + unusedError("value4"); + return; + } case E_Ball: if (m_value2 == B_Master) - error<UnusedException>("value4"); + { + unusedError("value4"); + return; + } break; case E_Berry: if (m_value2 != B2_HPCure) - error<UnusedException>("value4"); + { + unusedError("value4"); + return; + } break; } m_value4 = value4; diff --git a/pokemod/ItemEffect.h b/pokemod/ItemEffect.h index 43f9fd7e..7ca903aa 100644 --- a/pokemod/ItemEffect.h +++ b/pokemod/ItemEffect.h @@ -22,7 +22,6 @@ #include "Object.h" // General includes -#include "../general/Exception.h" #include "../general/Fraction.h" // Qt includes @@ -141,14 +140,14 @@ class ItemEffect : public Object void load(const QDomElement& xml, int id = INT_MAX); QDomElement save() const; - void setOverworld(const bool overworld) throw(Exception); + void setOverworld(const bool overworld); void setBattle(const bool battle); void setHeld(const bool held); - void setEffect(const int effect) throw(Exception); - void setValue1(const int value1) throw(Exception); - void setValue2(const int value2) throw(Exception); - void setValue3(const int value3) throw(Exception); - void setValue4(const Fraction& value4) throw(Exception); + void setEffect(const int effect); + void setValue1(const int value1); + void setValue2(const int value2); + void setValue3(const int value3); + void setValue4(const Fraction& value4); bool overworld() const; bool battle() const; @@ -161,7 +160,7 @@ class ItemEffect : public Object ItemEffect& operator=(const ItemEffect& rhs); private: - bool validate() const; + void validate(QTextStream& stream); bool m_overworld; bool m_battle; diff --git a/pokemod/ItemType.cpp b/pokemod/ItemType.cpp index 09142061..b9c19fc1 100644 --- a/pokemod/ItemType.cpp +++ b/pokemod/ItemType.cpp @@ -50,27 +50,13 @@ ItemType::ItemType(const QDomElement& xml, const Object* parent, const int id) : load(xml, id); } -bool ItemType::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Item Type \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is not defined"); -// valid = false; -// } -// if (!m_player) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid storage with the player"); -// valid = false; -// } -// if (End <= m_count) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid count"); -// valid = false; -// } -// return valid; +void ItemType::validate(QTextStream& stream) +{ + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setPlayer, player); + TEST(setCount, count); } void ItemType::load(const QDomElement& xml, int id) @@ -102,17 +88,23 @@ void ItemType::setComputer(const int computer) m_computer = computer; } -void ItemType::setPlayer(const int player) throw(BoundsException) +void ItemType::setPlayer(const int player) { if (!player) - error<BoundsException>("player"); + { + boundsError("player"); + return; + } m_player = player; } -void ItemType::setCount(const int count) throw(BoundsException) +void ItemType::setCount(const int count) { if (End <= count) - error<BoundsException>("count"); + { + boundsError("count"); + return; + } m_count = count; } diff --git a/pokemod/ItemType.h b/pokemod/ItemType.h index 3437bfa8..acea02ee 100644 --- a/pokemod/ItemType.h +++ b/pokemod/ItemType.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - class ItemType : public Object { public: @@ -45,8 +42,8 @@ class ItemType : public Object void setName(const QString& name); void setComputer(const int computer); - void setPlayer(const int player) throw(BoundsException); - void setCount(const int count) throw(BoundsException); + void setPlayer(const int player); + void setCount(const int count); QString name() const; int computer() const; @@ -55,7 +52,7 @@ class ItemType : public Object ItemType& operator=(const ItemType& rhs); private: - bool validate() const; + void validate(QTextStream& stream); QString m_name; int m_computer; diff --git a/pokemod/Map.cpp b/pokemod/Map.cpp index d1aece20..429b3d0f 100644 --- a/pokemod/Map.cpp +++ b/pokemod/Map.cpp @@ -25,6 +25,9 @@ #include "MapWildList.h" #include "Pokemod.h" +// Qt includes +#include <QSet> + const QStringList Map::TypeStr = QStringList() << "Outdoor" << "Dungeon" << "Building"; Map::Map(const Map& map) : @@ -58,127 +61,71 @@ Map::~Map() clear(); } -bool Map::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Map \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("name is not defined"); -// valid = false; -// } -// if ((m_flyWarp != INT_MAX) && (warpIndex(m_flyWarp) == INT_MAX)) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid fly destination warp"); -// valid = false; -// } -// if (m_type < End) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid type"); -// valid = false; -// } -// QMap<int, bool> idChecker; -// if (effectCount()) -// { -// foreach (MapEffect* effect, m_effects) -// { -// if (!effect->isValid()) -// valid = false; -// if (idChecker[effect->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); -// idChecker[effect->id()] = true; -// if (width() <= effect->coordinate().x()) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid x coordinate"); -// valid = false; -// } -// if (height() <= effect->coordinate().y()) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid y coordinate"); -// valid = false; -// } -// } -// idChecker.clear(); -// } -// else -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no effects", Pokemod::V_Warn); -// if (trainerCount()) -// { -// foreach (MapTrainer* trainer, m_trainers) -// { -// if (!trainer->isValid()) -// valid = false; -// if (idChecker[trainer->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate trainer with id %1").arg(trainer->id())); -// idChecker[trainer->id()] = true; -// if (width() <= trainer->coordinate().x()) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid x coordinate"); -// valid = false; -// } -// if (height() <= trainer->coordinate().y()) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid y coordinate"); -// valid = false; -// } -// } -// idChecker.clear(); -// } -// else -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no trainers", Pokemod::V_Warn); -// if (warpCount()) -// { -// foreach (MapWarp* warp, m_warps) -// { -// if (!warp->isValid()) -// valid = false; -// if (idChecker[warp->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate warp with id %1").arg(warp->id())); -// idChecker[warp->id()] = true; -// if (width() <= warp->coordinate().x()) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid x coordinate"); -// valid = false; -// } -// if (height() <= warp->coordinate().y()) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid y coordinate"); -// valid = false; -// } -// } -// idChecker.clear(); -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no warps"); -// valid = false; -// } -// if (wildListCount()) -// { -// foreach (MapWildList* wildList, m_wildLists) -// { -// if (!wildList->isValid()) -// valid = false; -// if (idChecker[wildList->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate effect with id %1").arg(wildList->id())); -// idChecker[wildList->id()] = true; -// } -// } -// else -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no effects", Pokemod::V_Warn); -// for (int i = 0; i < width(); ++i) -// { -// for (int j = 0; j < height(); ++j) -// { -// if (static_cast<const Pokemod*>(pokemod())->tileIndex(m_tile(i, j)) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Invalid tile at (%1, %2)").arg(i).arg(j)); -// valid = false; -// } -// } -// } -// return valid; +void Map::validate(QTextStream& stream) +{ + // TODO: validate that every tile that can have a wild encounter has a list to go along with it + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setFlyWarp, flyWarp); + TEST(setType, type); + TEST_MATRIX(setTile, tile); + QSet<int> idChecker; + QSet<QString> nameChecker; + if (!effectCount()) + warning(stream, "There are no effects"); + foreach (MapEffect* effect, m_effects) + { + if (!effect->isValid(stream)) + setValid(false); + if (idChecker.contains(effect->id())) + subclassError(stream, "effect", effect->id()); + idChecker.insert(effect->id()); + if (nameChecker.contains(effect->name())) + subclassError(stream, "effect", effect->name()); + nameChecker.insert(effect->name()); + } + idChecker.clear(); + nameChecker.clear(); + if (!trainerCount()) + warning(stream, "There are no trainers"); + foreach (MapTrainer* trainer, m_trainers) + { + if (!trainer->isValid(stream)) + setValid(false); + if (idChecker.contains(trainer->id())) + subclassError(stream, "trainer", trainer->id()); + idChecker.insert(trainer->id()); + if (nameChecker.contains(trainer->name())) + subclassError(stream, "trainer", trainer->name()); + nameChecker.insert(trainer->name()); + } + idChecker.clear(); + nameChecker.clear(); + if (!warpCount()) + error(stream, "There are no warps"); + foreach (MapWarp* warp, m_warps) + { + if (!warp->isValid(stream)) + setValid(false); + if (idChecker.contains(warp->id())) + subclassError(stream, "warp", warp->id()); + idChecker.insert(warp->id()); + if (nameChecker.contains(warp->name())) + subclassError(stream, "warp", warp->name()); + nameChecker.insert(warp->name()); + } + idChecker.clear(); + if (!wildListCount()) + error(stream, "There are no wild lists"); + foreach (MapWildList* wildList, m_wildLists) + { + if (!wildList->isValid(stream)) + setValid(false); + if (idChecker.contains(wildList->id())) + subclassError(stream, "effect", wildList->id()); + idChecker.insert(wildList->id()); + } } void Map::load(const QDomElement& xml, int id) @@ -213,17 +160,23 @@ void Map::setName(const QString& name) m_name = name; } -void Map::setFlyWarp(const int warp) throw(BoundsException) +void Map::setFlyWarp(const int warp) { if ((warp != INT_MAX) && (warpIndex(warp) == INT_MAX)) - error<BoundsException>("warp"); + { + boundsError("warp"); + return; + } m_flyWarp = warp; } -void Map::setType(const int type) throw(BoundsException) +void Map::setType(const int type) { if (End <= type) - error<BoundsException>("type"); + { + boundsError("type"); + return; + } m_type = type; } @@ -242,21 +195,24 @@ int Map::type() const return m_type; } -void Map::setTile(int x, int y, int id) throw(BoundsException) +void Map::setTile(const int row, const int column, const int tile) { - if (static_cast<const Pokemod*>(pokemod())->tileIndex(id) == INT_MAX) - error<BoundsException>("tile"); - m_tile(x, y) = id; + if (static_cast<const Pokemod*>(pokemod())->tileIndex(tile) == INT_MAX) + { + boundsError("tile"); + return; + } + m_tile.set(row, column, tile); } -void Map::insertColumn(int x) +void Map::insertColumn(const int column) { - m_tile.insertColumn(x, 0); + m_tile.insertColumn(column, 0); } -void Map::insertRow(int y) +void Map::insertRow(const int row) { - m_tile.insertRow(y, 0); + m_tile.insertRow(row, 0); } void Map::addColumn() @@ -269,14 +225,14 @@ void Map::addRow() m_tile.addRow(0); } -void Map::deleteColumn(int x) +void Map::deleteColumn(const int column) { - m_tile.deleteColumn(x); + m_tile.deleteColumn(column); } -void Map::deleteRow(int y) +void Map::deleteRow(const int row) { - m_tile.deleteRow(y); + m_tile.deleteRow(row); } const Matrix<int>* Map::map() const @@ -289,9 +245,9 @@ Matrix<int>* Map::map() return &m_tile; } -int Map::tile(int x, int y) const +int Map::tile(const int row, const int column) const { - return m_tile(x, y); + return m_tile.at(row, column); } int Map::width() const @@ -304,26 +260,26 @@ int Map::height() const return m_tile.height(); } -const MapEffect* Map::effect(const int index) const throw(IndexException) +const MapEffect* Map::effect(const int index) const { if (effectCount() <= index) - warning<IndexException>("effect"); + return NULL; return m_effects.at(index); } -MapEffect* Map::effect(const int index) throw(IndexException) +MapEffect* Map::effect(const int index) { if (effectCount() <= index) - error<IndexException>("effect"); + return NULL; return m_effects[index]; } -const MapEffect* Map::effectById(const int index) const throw(IndexException) +const MapEffect* Map::effectById(const int index) const { return effect(effectIndex(index)); } -MapEffect* Map::effectById(const int index) throw(IndexException) +MapEffect* Map::effectById(const int index) { return effect(effectIndex(index)); } @@ -364,15 +320,15 @@ MapEffect* Map::newEffect(MapEffect* effect) return effect; } -void Map::deleteEffect(const int index) throw(IndexException) +void Map::deleteEffect(const int index) { if (effectCount() <= index) - error<IndexException>("effect"); + return; delete m_effects[index]; m_effects.removeAt(index); } -void Map::deleteEffectById(const int id) throw(IndexException) +void Map::deleteEffectById(const int id) { deleteEffect(effectIndex(id)); } @@ -385,26 +341,26 @@ int Map::newEffectId() const return i; } -const MapTrainer* Map::trainer(const int index) const throw(IndexException) +const MapTrainer* Map::trainer(const int index) const { if (trainerCount() <= index) - warning<IndexException>("trainer"); + return NULL; return m_trainers.at(index); } -MapTrainer* Map::trainer(const int index) throw(IndexException) +MapTrainer* Map::trainer(const int index) { if (trainerCount() <= index) - error<IndexException>("trainer"); + return NULL; return m_trainers[index]; } -const MapTrainer* Map::trainerById(const int id) const throw(IndexException) +const MapTrainer* Map::trainerById(const int id) const { return trainer(trainerIndex(id)); } -MapTrainer* Map::trainerById(const int id) throw(IndexException) +MapTrainer* Map::trainerById(const int id) { return trainer(trainerIndex(id)); } @@ -445,15 +401,15 @@ MapTrainer* Map::newTrainer(MapTrainer* trainer) return trainer; } -void Map::deleteTrainer(const int index) throw(IndexException) +void Map::deleteTrainer(const int index) { if (trainerCount() <= index) - error<IndexException>("trainer"); + return; delete m_trainers[index]; m_trainers.removeAt(index); } -void Map::deleteTrainerById(const int id) throw(IndexException) +void Map::deleteTrainerById(const int id) { deleteTrainer(trainerIndex(id)); } @@ -466,26 +422,26 @@ int Map::newTrainerId() const return i; } -const MapWarp* Map::warp(const int index) const throw(IndexException) +const MapWarp* Map::warp(const int index) const { if (warpCount() <= index) - warning<IndexException>("warp"); + return NULL; return m_warps.at(index); } -MapWarp* Map::warp(const int index) throw(IndexException) +MapWarp* Map::warp(const int index) { if (warpCount() <= index) - error<IndexException>("warp"); + return NULL; return m_warps[index]; } -const MapWarp* Map::warpById(const int id) const throw(IndexException) +const MapWarp* Map::warpById(const int id) const { return warp(warpIndex(id)); } -MapWarp* Map::warpById(const int id) throw(IndexException) +MapWarp* Map::warpById(const int id) { return warp(warpIndex(id)); } @@ -526,15 +482,15 @@ MapWarp* Map::newWarp(MapWarp* warp) return warp; } -void Map::deleteWarp(const int index) throw(IndexException) +void Map::deleteWarp(const int index) { if (warpCount() <= index) - error<IndexException>("warp"); + return; delete m_warps[index]; m_warps.removeAt(index); } -void Map::deleteWarpById(const int id) throw(IndexException) +void Map::deleteWarpById(const int id) { deleteWarp(warpIndex(id)); } @@ -547,26 +503,26 @@ int Map::newWarpId() const return i; } -const MapWildList* Map::wildList(const int index) const throw(IndexException) +const MapWildList* Map::wildList(const int index) const { if (wildListCount() <= index) - warning<IndexException>("wild list"); + return NULL; return m_wildLists.at(index); } -MapWildList* Map::wildList(const int index) throw(IndexException) +MapWildList* Map::wildList(const int index) { if (wildListCount() <= index) - error<IndexException>("wild list"); + return NULL; return m_wildLists[index]; } -const MapWildList* Map::wildListById(const int id) const throw(IndexException) +const MapWildList* Map::wildListById(const int id) const { return wildList(wildListIndex(id)); } -MapWildList* Map::wildListById(const int id) throw(IndexException) +MapWildList* Map::wildListById(const int id) { return wildList(wildListIndex(id)); } @@ -607,15 +563,15 @@ MapWildList* Map::newWildList(MapWildList* wildList) return wildList; } -void Map::deleteWildList(const int index) throw(IndexException) +void Map::deleteWildList(const int index) { if (wildListCount() <= index) - error<IndexException>("wild list"); + return; delete m_wildLists[index]; m_wildLists.removeAt(index); } -void Map::deleteWildListById(const int id) throw(IndexException) +void Map::deleteWildListById(const int id) { deleteWildList(wildListIndex(id)); } diff --git a/pokemod/Map.h b/pokemod/Map.h index cc18040f..8da19dc5 100644 --- a/pokemod/Map.h +++ b/pokemod/Map.h @@ -22,7 +22,6 @@ #include "Object.h" // General includes -#include "../general/Exception.h" #include "../general/Matrix.h" // Qt includes @@ -56,78 +55,78 @@ class Map : public Object QDomElement save() const; void setName(const QString& name); - void setFlyWarp(const int warp) throw(BoundsException); - void setType(const int type) throw(BoundsException); + void setFlyWarp(const int warp); + void setType(const int type); QString name() const; int flyWarp() const; int type() const; - void setTile(int x, int y, int id) throw(BoundsException); - void insertColumn(int x); - void insertRow(int y); + void setTile(const int row, const int column, const int tile); + void insertColumn(const int column); + void insertRow(const int row); void addColumn(); void addRow(); - void deleteColumn(int x); - void deleteRow(int y); + void deleteColumn(const int column); + void deleteRow(const int row); const Matrix<int>* map() const; Matrix<int>* map(); - int tile(int x, int y) const; + int tile(const int row, const int column) const; int width() const; int height() const; - const MapEffect* effect(const int index) const throw(IndexException); - MapEffect* effect(const int index) throw(IndexException); - const MapEffect* effectById(const int id) const throw(IndexException); - MapEffect* effectById(const int id) throw(IndexException); + const MapEffect* effect(const int index) const; + MapEffect* effect(const int index); + const MapEffect* effectById(const int id) const; + MapEffect* effectById(const int id); int effectIndex(const int id) const; int effectCount() const; MapEffect* newEffect(); MapEffect* newEffect(const QDomElement& xml); MapEffect* newEffect(const MapEffect& effect); - void deleteEffect(const int index) throw(IndexException); - void deleteEffectById(const int id) throw(IndexException); + void deleteEffect(const int index); + void deleteEffectById(const int id); - const MapTrainer* trainer(const int index) const throw(IndexException); - MapTrainer* trainer(const int index) throw(IndexException); - const MapTrainer* trainerById(const int id) const throw(IndexException); - MapTrainer* trainerById(const int id) throw(IndexException); + const MapTrainer* trainer(const int index) const; + MapTrainer* trainer(const int index); + const MapTrainer* trainerById(const int id) const; + MapTrainer* trainerById(const int id); int trainerIndex(const int id) const; int trainerCount() const; MapTrainer* newTrainer(); MapTrainer* newTrainer(const QDomElement& xml); MapTrainer* newTrainer(const MapTrainer& trainer); - void deleteTrainer(const int index) throw(IndexException); - void deleteTrainerById(const int id) throw(IndexException); + void deleteTrainer(const int index); + void deleteTrainerById(const int id); - const MapWarp* warp(const int index) const throw(IndexException); - MapWarp* warp(const int index) throw(IndexException); - const MapWarp* warpById(const int id) const throw(IndexException); - MapWarp* warpById(const int id) throw(IndexException); + const MapWarp* warp(const int index) const; + MapWarp* warp(const int index); + const MapWarp* warpById(const int id) const; + MapWarp* warpById(const int id); int warpIndex(const int id) const; int warpCount() const; MapWarp* newWarp(); MapWarp* newWarp(const QDomElement& xml); MapWarp* newWarp(const MapWarp& warp); - void deleteWarp(const int index) throw(IndexException); - void deleteWarpById(const int id) throw(IndexException); + void deleteWarp(const int index); + void deleteWarpById(const int id); - const MapWildList* wildList(const int index) const throw(IndexException); - MapWildList* wildList(const int index) throw(IndexException); - const MapWildList* wildListById(const int id) const throw(IndexException); - MapWildList* wildListById(const int id) throw(IndexException); + const MapWildList* wildList(const int index) const; + MapWildList* wildList(const int index); + const MapWildList* wildListById(const int id) const; + MapWildList* wildListById(const int id); int wildListIndex(const int id) const; int wildListCount() const; MapWildList* newWildList(); MapWildList* newWildList(const QDomElement& xml); MapWildList* newWildList(const MapWildList& wildList); - void deleteWildList(const int index) throw(IndexException); - void deleteWildListById(const int id) throw(IndexException); + void deleteWildList(const int index); + void deleteWildListById(const int id); Map& operator=(const Map& rhs); private: - bool validate() const; + void validate(QTextStream& stream); int newEffectId() const; MapEffect* newEffect(MapEffect* effect); diff --git a/pokemod/MapEffect.cpp b/pokemod/MapEffect.cpp index e11e5ec0..a8a6b5f1 100644 --- a/pokemod/MapEffect.cpp +++ b/pokemod/MapEffect.cpp @@ -63,62 +63,18 @@ MapEffect::MapEffect(const QDomElement& xml, const Object* parent, const int id) load(xml, id); } -bool MapEffect::validate() const +void MapEffect::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Effect \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is not defined"); -// valid = false; -// } -// if (Flag::End <= m_existFlag.status()) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid existence flag status"); -// valid = false; -// } -// if (m_effect < E_End) -// { -// bool ok = true; -// switch (m_effect) -// { -// case E_Item: -// if (static_cast<const Pokemod*>(pokemod())->itemIndex(m_value2) == INT_MAX) -// ok = false; -// break; -// case E_PC: -// if (PC_End <= m_value2) -// ok = false; -// break; -// case E_StrengthBlock: -// case E_Button: -// if (Flag::End <= m_value2) -// ok = false; -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid val2"); -// valid = false; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid effect"); -// valid = false; -// } -// if (Pokemod::D_End_None <= m_direction) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid driection"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->dialogIndex(m_dialog) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid dialog"); -// valid = false; -// } -// return valid; + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setCoordinate, coordinate); + TEST(setSkin, skin); + TEST(setEffect, effect); + TEST(setValue1, value1); + TEST(setValue2, value2); + TEST(setDirection, direction); + TEST(setDialog, dialog); } void MapEffect::load(const QDomElement& xml, int id) @@ -159,10 +115,13 @@ void MapEffect::setName(const QString& name) m_name = name; } -void MapEffect::setCoordinate(const Point& coordinate) throw(BoundsException) +void MapEffect::setCoordinate(const Point& coordinate) { if ((static_cast<const Map*>(parent())->width() <= coordinate.x()) || (static_cast<const Map*>(parent())->height() <= coordinate.y())) - error<BoundsException>("coordinate"); + { + boundsError("coordinate"); + return; + } m_coordinate = coordinate; } @@ -171,57 +130,78 @@ void MapEffect::setExistFlag(const Flag& existFlag) m_existFlag = existFlag; } -void MapEffect::setSkin(const QPixmap& skin) throw(SizeException) +void MapEffect::setSkin(const QPixmap& skin) { if (skin.size() != QSize(192, 128)) - error<SizeException>("skin"); + { + sizeError("skin"); + return; + } m_skin = skin; } -void MapEffect::setEffect(const int effect) throw(BoundsException) +void MapEffect::setEffect(const int effect) { if (E_End <= effect) - error<BoundsException>("effect"); + { + boundsError("effect"); + return; + } m_effect = effect; m_value1 = INT_MAX; m_value2 = INT_MAX; } -void MapEffect::setValue1(const int value1) throw(UnusedException) +void MapEffect::setValue1(const int value1) { if ((m_effect != E_StrengthBlock) && (m_effect != E_Button)) - error<UnusedException>("val1"); + { + unusedError("val1"); + return; + } m_value1 = value1; } -void MapEffect::setValue2(const int value2) throw(Exception) +void MapEffect::setValue2(const int value2) { switch (m_effect) { case E_Item: if (static_cast<const Pokemod*>(pokemod())->itemIndex(value2) == INT_MAX) - error<BoundsException>("val2"); + { + boundsError("val2"); + return; + } break; case E_PC: if (PC_End <= value2) - error<BoundsException>("val2"); + { + boundsError("val2"); + return; + } break; case E_StrengthBlock: case E_Button: if (Flag::End <= value2) - error<BoundsException>("val2"); + { + boundsError("val2"); + return; + } break; default: - error<UnusedException>("val2"); - break; + unusedError("val2"); + return; } m_value2 = value2; } -void MapEffect::setDirection(const int direction) throw(BoundsException) +void MapEffect::setDirection(const int direction) { if (Pokemod::D_End_None <= direction) - error<BoundsException>("direction"); + { + boundsError("direction"); + return; + } m_direction = direction; } @@ -235,10 +215,13 @@ void MapEffect::setCanMove(const bool canMove) m_canMove = canMove; } -void MapEffect::setDialog(const int dialog) throw(BoundsException) +void MapEffect::setDialog(const int dialog) { if (static_cast<const Pokemod*>(pokemod())->dialogIndex(dialog) == INT_MAX) - error<BoundsException>("dialog"); + { + boundsError("dialog"); + return; + } m_dialog = dialog; } diff --git a/pokemod/MapEffect.h b/pokemod/MapEffect.h index ca6579d9..604a7876 100644 --- a/pokemod/MapEffect.h +++ b/pokemod/MapEffect.h @@ -22,7 +22,6 @@ #include "Object.h" // General includes -#include "../general/Exception.h" #include "../general/Flag.h" #include "../general/Point.h" @@ -64,16 +63,16 @@ class MapEffect : public Object QDomElement save() const; void setName(const QString& name); - void setCoordinate(const Point& coordinate) throw(BoundsException); + void setCoordinate(const Point& coordinate); void setExistFlag(const Flag& existFlag); - void setSkin(const QPixmap& skin) throw(SizeException); - void setEffect(const int effect) throw(BoundsException); - void setValue1(const int value1) throw(UnusedException); - void setValue2(const int value2) throw(Exception); - void setDirection(const int direction) throw(BoundsException); + void setSkin(const QPixmap& skin); + void setEffect(const int effect); + void setValue1(const int value1); + void setValue2(const int value2); + void setDirection(const int direction); void setIsGhost(const bool isGhost); void setCanMove(const bool canMove); - void setDialog(const int dialog) throw(BoundsException); + void setDialog(const int dialog); QString name() const; Point coordinate() const; @@ -89,7 +88,7 @@ class MapEffect : public Object MapEffect& operator=(const MapEffect& rhs); private: - bool validate() const; + void validate(QTextStream& stream); QString m_name; Point m_coordinate; diff --git a/pokemod/MapTrainer.cpp b/pokemod/MapTrainer.cpp index 93ae61cc..e486475a 100644 --- a/pokemod/MapTrainer.cpp +++ b/pokemod/MapTrainer.cpp @@ -24,6 +24,9 @@ #include "MapTrainerTeamMember.h" #include "Pokemod.h" +// Qt includes +#include <QSet> + MapTrainer::MapTrainer(const MapTrainer& trainer) : Object("MapTrainer", trainer.parent(), trainer.id()) { @@ -61,59 +64,28 @@ MapTrainer::~MapTrainer() clear(); } -bool MapTrainer::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Trainer \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is not defined"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->trainerIndex(m_trainerClass) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid trainer class"); -// valid = false; -// } -// if (Pokemod::D_End_None <= m_direction) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid direction"); -// valid = false; -// } -// if (!m_numFight || (static_cast<const Pokemod*>(pokemod())->rules()->maxFight() < m_numFight)) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid number of Pokémon for a fight"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->dialogIndex(m_dialog) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid dialog"); -// valid = false; -// } -// if (teamMemberCount() <= m_leadTeamMember) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid lead member"); -// valid = false; -// } -// if (teamMemberCount()) -// { -// QMap<int, bool> idChecker; -// foreach (MapTrainerTeamMember* teamMember, m_teamMember) -// { -// if (!teamMember->isValid()) -// valid = false; -// if (idChecker[teamMember->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate team member with id %1").arg(teamMember->id())); -// idChecker[teamMember->id()] = true; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no team members"); -// valid = false; -// } -// return valid; +void MapTrainer::validate(QTextStream& stream) +{ + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setTrainerClass, trainerClass); + TEST(setCoordinate, coordinate); + TEST(setDirection, direction); + TEST(setNumFight, numFight); + TEST(setDialog, dialog); + TEST(setLeadTeamMember, leadTeamMember); + if (!teamMemberCount()) + error(stream, "There are no team members"); + QSet<int> idChecker; + foreach (MapTrainerTeamMember* teamMember, m_teamMember) + { + if (!teamMember->isValid(stream)) + setValid(false); + if (idChecker.contains(teamMember->id())) + subclassError(stream, "team member", teamMember->id()); + idChecker.insert(teamMember->id()); + } } void MapTrainer::load(const QDomElement& xml, int id) @@ -151,17 +123,23 @@ void MapTrainer::setName(const QString& name) m_name = name; } -void MapTrainer::setTrainerClass(const int trainerClass) throw(BoundsException) +void MapTrainer::setTrainerClass(const int trainerClass) { if (static_cast<const Pokemod*>(pokemod())->trainerIndex(trainerClass) == INT_MAX) - error<BoundsException>("trainerClass"); + { + boundsError("trainerClass"); + return; + } m_trainerClass = trainerClass; } -void MapTrainer::setCoordinate(const Point& coordinate) throw(BoundsException) +void MapTrainer::setCoordinate(const Point& coordinate) { if ((static_cast<const Map*>(parent())->width() <= coordinate.x()) || (static_cast<const Map*>(parent())->height() <= coordinate.y())) - error<BoundsException>("coordinate"); + { + boundsError("coordinate"); + return; + } m_coordinate = coordinate; } @@ -170,17 +148,23 @@ void MapTrainer::setSight(const int sight) m_sight = sight; } -void MapTrainer::setDirection(const int direction) throw(BoundsException) +void MapTrainer::setDirection(const int direction) { if (Pokemod::D_End_None <= direction) - error<BoundsException>("direction"); + { + boundsError("direction"); + return; + } m_direction = direction; } -void MapTrainer::setNumFight(const int numFight) throw(BoundsException) +void MapTrainer::setNumFight(const int numFight) { if (!numFight || (static_cast<const Pokemod*>(pokemod())->rules()->maxFight() < numFight)) - error<BoundsException>("numFight"); + { + boundsError("numFight"); + return; + } m_numFight = numFight; } @@ -189,17 +173,23 @@ void MapTrainer::setAppearFlag(const Flag& appearFlag) m_appearFlag = appearFlag; } -void MapTrainer::setDialog(const int dialog) throw(BoundsException) +void MapTrainer::setDialog(const int dialog) { if (static_cast<const Pokemod*>(pokemod())->dialogIndex(dialog) == INT_MAX) - error<BoundsException>("dialog"); + { + boundsError("dialog"); + return; + } m_dialog = dialog; } -void MapTrainer::setLeadTeamMember(const int leadMember) throw(BoundsException) +void MapTrainer::setLeadTeamMember(const int leadMember) { if (teamMemberCount() <= leadMember) - error<BoundsException>("leadTeamMember"); + { + boundsError("leadTeamMember"); + return; + } m_leadTeamMember = leadMember; } @@ -248,26 +238,26 @@ int MapTrainer::leadTeamMember() const return m_leadTeamMember; } -const MapTrainerTeamMember* MapTrainer::teamMember(const int index) const throw(IndexException) +const MapTrainerTeamMember* MapTrainer::teamMember(const int index) const { if (teamMemberCount() <= index) - warning<IndexException>("team member"); + return NULL; return m_teamMember.at(index); } -MapTrainerTeamMember* MapTrainer::teamMember(const int index) throw(IndexException) +MapTrainerTeamMember* MapTrainer::teamMember(const int index) { if (teamMemberCount() <= index) - error<IndexException>("team member"); + return NULL; return m_teamMember[index]; } -const MapTrainerTeamMember* MapTrainer::teamMemberById(const int id) const throw(IndexException) +const MapTrainerTeamMember* MapTrainer::teamMemberById(const int id) const { return teamMember(teamMemberIndex(id)); } -MapTrainerTeamMember* MapTrainer::teamMemberById(const int id) throw(IndexException) +MapTrainerTeamMember* MapTrainer::teamMemberById(const int id) { return teamMember(teamMemberIndex(id)); } @@ -308,15 +298,15 @@ MapTrainerTeamMember* MapTrainer::newTeamMember(MapTrainerTeamMember* teamMember return teamMember; } -void MapTrainer::deleteTeamMember(const int index) throw(IndexException) +void MapTrainer::deleteTeamMember(const int index) { if (teamMemberCount() <= index) - error<IndexException>("team member"); + return; delete m_teamMember[index]; m_teamMember.removeAt(index); } -void MapTrainer::deleteTeamMemberById(const int id) throw(IndexException) +void MapTrainer::deleteTeamMemberById(const int id) { deleteTeamMember(teamMemberIndex(id)); } diff --git a/pokemod/MapTrainer.h b/pokemod/MapTrainer.h index 12e2471b..aa359bcd 100644 --- a/pokemod/MapTrainer.h +++ b/pokemod/MapTrainer.h @@ -22,7 +22,6 @@ #include "Object.h" // General includes -#include "../general/Exception.h" #include "../general/Flag.h" #include "../general/Point.h" @@ -45,14 +44,14 @@ class MapTrainer : public Object QDomElement save() const; void setName(const QString& name); - void setTrainerClass(const int trainerClass) throw(BoundsException); - void setCoordinate(const Point& coordinate) throw(BoundsException); + void setTrainerClass(const int trainerClass); + void setCoordinate(const Point& coordinate); void setSight(const int sight); - void setDirection(const int direction) throw(BoundsException); - void setNumFight(const int numFight) throw(BoundsException); + void setDirection(const int direction); + void setNumFight(const int numFight); void setAppearFlag(const Flag& appearFlag); - void setDialog(const int dialog) throw(BoundsException); - void setLeadTeamMember(const int leadMember) throw(BoundsException); + void setDialog(const int dialog); + void setLeadTeamMember(const int leadMember); QString name() const; int trainerClass() const; @@ -64,21 +63,21 @@ class MapTrainer : public Object int dialog() const; int leadTeamMember() const; - const MapTrainerTeamMember* teamMember(const int index) const throw(IndexException); - MapTrainerTeamMember* teamMember(const int index) throw(IndexException); - const MapTrainerTeamMember* teamMemberById(const int id) const throw(IndexException); - MapTrainerTeamMember* teamMemberById(const int id) throw(IndexException); + const MapTrainerTeamMember* teamMember(const int index) const; + MapTrainerTeamMember* teamMember(const int index); + const MapTrainerTeamMember* teamMemberById(const int id) const; + MapTrainerTeamMember* teamMemberById(const int id); int teamMemberIndex(const int id) const; int teamMemberCount() const; MapTrainerTeamMember* newTeamMember(); MapTrainerTeamMember* newTeamMember(const QDomElement& xml); MapTrainerTeamMember* newTeamMember(const MapTrainerTeamMember& teamMember); - void deleteTeamMember(const int index) throw(IndexException); - void deleteTeamMemberById(const int id) throw(IndexException); + void deleteTeamMember(const int index); + void deleteTeamMemberById(const int id); MapTrainer& operator=(const MapTrainer& rhs); private: - bool validate() const; + void validate(QTextStream& stream); int newTeamMemberId() const; MapTrainerTeamMember* newTeamMember(MapTrainerTeamMember* teamMember); diff --git a/pokemod/MapTrainerTeamMember.cpp b/pokemod/MapTrainerTeamMember.cpp index 94e44357..1a6759ba 100644 --- a/pokemod/MapTrainerTeamMember.cpp +++ b/pokemod/MapTrainerTeamMember.cpp @@ -23,6 +23,9 @@ #include "Species.h" #include "Pokemod.h" +// Qt includes +#include <QSet> + MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainerTeamMember& teamMember) : Object("MapTrainerTeamMember", teamMember.parent(), teamMember.id()) { @@ -49,50 +52,21 @@ MapTrainerTeamMember::MapTrainerTeamMember(const QDomElement& xml, const Object* load(xml, id); } -bool MapTrainerTeamMember::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---------Team Member with id %1---").arg(id()), Pokemod::V_Msg); -// if (static_cast<const Pokemod*>(pokemod())->speciesIndex(m_species) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid species"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() <= m_level) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid level"); -// valid = false; -// } -// if (m_items.size() <= static_cast<const Pokemod*>(pokemod())->rules()->holdItems()) -// { -// QMap<int, bool> itemChecker; -// foreach (int item, m_items) -// { -// if (static_cast<const Pokemod*>(pokemod())->itemIndex(item) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid item"); -// valid = false; -// } -// if (itemChecker[item]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate of item %1").arg(item)); -// itemChecker[item] = true; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Too many held items"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->rules()->natureAllowed()) -// { -// if (static_cast<const Pokemod*>(pokemod())->natureIndex(m_nature) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid nature"); -// valid = false; -// } -// } -// return valid; +void MapTrainerTeamMember::validate(QTextStream& stream) +{ + TEST_SETUP(); + TEST(setSpecies, species); + TEST(setLevel, level); + if (m_item.size() <= static_cast<const Pokemod*>(pokemod())->rules()->holdItems()) + { + TEST_LIST(setItem, item); + } + else + error(stream, "Too many held items"); + if (static_cast<const Pokemod*>(pokemod())->rules()->natureAllowed()) + { + TEST(setNature, nature); + } } void MapTrainerTeamMember::load(const QDomElement& xml, int id) @@ -101,7 +75,7 @@ void MapTrainerTeamMember::load(const QDomElement& xml, int id) LOAD(int, species); LOAD(int, level); LOAD(int, nature); - LOAD_LIST(int, items) + LOAD_LIST(int, item) } QDomElement MapTrainerTeamMember::save() const @@ -110,41 +84,53 @@ QDomElement MapTrainerTeamMember::save() const SAVE(int, species); SAVE(int, level); SAVE(int, nature); - SAVE_LIST(int, items); + SAVE_LIST(int, item); return xml; } -void MapTrainerTeamMember::setSpecies(const int species) throw(BoundsException) +void MapTrainerTeamMember::setSpecies(const int species) { if (static_cast<const Pokemod*>(pokemod())->speciesIndex(species) == INT_MAX) - error<BoundsException>("species"); + { + boundsError("species"); + return; + } m_species = species; } -void MapTrainerTeamMember::setLevel(const int level) throw(BoundsException) +void MapTrainerTeamMember::setLevel(const int level) { if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < level) - error<BoundsException>("level"); + { + boundsError("level"); + return; + } m_level = level; } -void MapTrainerTeamMember::setItem(const int item, const bool state) throw(BoundsException) +void MapTrainerTeamMember::setItem(const int item, const bool state) { if (static_cast<const Pokemod*>(pokemod())->itemIndex(item) == INT_MAX) - error<BoundsException>("item"); + { + boundsError("item"); + return; + } if (state) { - if (!m_items.contains(item)) - m_items.append(item); + if (!m_item.contains(item)) + m_item.append(item); } else - m_items.removeAll(item); + m_item.removeAll(item); } -void MapTrainerTeamMember::setNature(const int nature) throw(BoundsException) +void MapTrainerTeamMember::setNature(const int nature) { if (!static_cast<const Pokemod*>(pokemod())->rules()->natureAllowed() || (static_cast<const Pokemod*>(pokemod())->natureIndex(nature) == INT_MAX)) - error<BoundsException>("nature"); + { + boundsError("nature"); + return; + } m_nature = nature; } @@ -165,7 +151,7 @@ int MapTrainerTeamMember::nature() const bool MapTrainerTeamMember::item(const int item) const { - return m_items.contains(item); + return m_item.contains(item); } MapTrainerTeamMember& MapTrainerTeamMember::operator=(const MapTrainerTeamMember& rhs) @@ -175,6 +161,6 @@ MapTrainerTeamMember& MapTrainerTeamMember::operator=(const MapTrainerTeamMember COPY(species); COPY(level); COPY(nature); - COPY(items); + COPY(item); return *this; } diff --git a/pokemod/MapTrainerTeamMember.h b/pokemod/MapTrainerTeamMember.h index ffcca93c..fb7a51af 100644 --- a/pokemod/MapTrainerTeamMember.h +++ b/pokemod/MapTrainerTeamMember.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - // Qt includes #include <QList> @@ -38,10 +35,10 @@ class MapTrainerTeamMember : public Object void load(const QDomElement& xml, int id = INT_MAX); QDomElement save() const; - void setSpecies(const int species) throw(BoundsException); - void setLevel(const int level) throw(BoundsException); - void setNature(const int nature) throw(BoundsException); - void setItem(const int item, const bool state) throw(BoundsException); + void setSpecies(const int species); + void setLevel(const int level); + void setNature(const int nature); + void setItem(const int item, const bool state); int species() const; int level() const; @@ -50,12 +47,12 @@ class MapTrainerTeamMember : public Object MapTrainerTeamMember& operator=(const MapTrainerTeamMember& p); private: - bool validate() const; + void validate(QTextStream& stream); int m_species; int m_level; int m_nature; - QList<int> m_items; + QList<int> m_item; }; #endif diff --git a/pokemod/MapWarp.cpp b/pokemod/MapWarp.cpp index 15e6ee38..3cf1e0b0 100644 --- a/pokemod/MapWarp.cpp +++ b/pokemod/MapWarp.cpp @@ -36,7 +36,7 @@ MapWarp::MapWarp(const Object* parent, const int id) : m_name(""), m_coordinate(0, 0), m_directionOut(INT_MAX), - m_warpType(INT_MAX), + m_type(INT_MAX), m_isBiking(Flag::Ignore), m_isFlash(Flag::Ignore), m_isFoggy(Flag::Ignore), @@ -61,50 +61,18 @@ MapWarp::MapWarp(const QDomElement& xml, const Object* parent, const int id) : load(xml, id); } -bool MapWarp::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Warp \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is not defined"); -// valid = false; -// } -// if (!m_from[Pokemod::D_Up] && !m_from[Pokemod::D_Down] && !m_from[Pokemod::D_Left] && !m_from[Pokemod::D_Right]) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("No access from any direction"); -// valid = false; -// } -// if (Pokemod::D_End_None <= m_directionOut) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid direction out"); -// valid = false; -// } -// if (End <= m_warpType) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid type"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->mapIndex(m_toMap) != INT_MAX) -// { -// if (static_cast<const Pokemod*>(pokemod())->mapById(m_toMap)->warpIndex(m_toWarp) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid destination warp"); -// valid = false; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid destination map"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->dialogIndex(m_dialog) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid dialog"); -// valid = false; -// } -// return valid; +void MapWarp::validate(QTextStream& stream) +{ + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + if (!m_from[Pokemod::D_Up] && !m_from[Pokemod::D_Down] && !m_from[Pokemod::D_Left] && !m_from[Pokemod::D_Right]) + error(stream, "No access from any direction"); + TEST(setDirectionOut, directionOut); + TEST(setType, type); + TEST(setToMap, toMap); + TEST(setToWarp, toWarp); + TEST(setDialog, dialog); } void MapWarp::load(const QDomElement& xml, int id) @@ -114,7 +82,7 @@ void MapWarp::load(const QDomElement& xml, int id) LOAD(Point, coordinate); LOAD_ARRAY(bool, from, Pokemod::D_End); LOAD(int, directionOut); - LOAD(int, warpType); + LOAD(int, type); LOAD(bool, isBiking); LOAD(bool, isFlash); LOAD(bool, isFoggy); @@ -131,7 +99,7 @@ QDomElement MapWarp::save() const SAVE(Point, coordinate); SAVE_ARRAY(bool, from, Pokemod::D_End); SAVE(int, directionOut); - SAVE(int, warpType); + SAVE(int, type); SAVE(bool, isBiking); SAVE(bool, isFlash); SAVE(bool, isFoggy); @@ -147,69 +115,99 @@ void MapWarp::setName(const QString& name) m_name = name; } -void MapWarp::setCoordinate(const Point& coordinate) throw(BoundsException) +void MapWarp::setCoordinate(const Point& coordinate) { if ((static_cast<const Map*>(parent())->width() <= coordinate.x()) || (static_cast<const Map*>(parent())->height() <= coordinate.y())) - error<BoundsException>("coordinate"); + { + boundsError("coordinate"); + return; + } m_coordinate = coordinate; } -void MapWarp::setFrom(const int direction, const bool can) throw(BoundsException) +void MapWarp::setFrom(const int direction, const bool can) { if (Pokemod::D_End <= direction) - error<BoundsException>("direction"); + { + boundsError("direction"); + return; + } m_from[direction] = can; } -void MapWarp::setDirectionOut(const int directionOut) throw(BoundsException) +void MapWarp::setDirectionOut(const int directionOut) { if (Pokemod::D_End <= directionOut) - error<BoundsException>("direction"); + { + boundsError("direction"); + return; + } m_directionOut = directionOut; } -void MapWarp::setWarpType(const int warpType) throw(BoundsException) +void MapWarp::setType(const int type) { - if (End <= warpType) - error<BoundsException>("warpType"); - m_warpType = warpType; + if (End <= type) + { + boundsError("type"); + return; + } + m_type = type; } -void MapWarp::setIsBiking(const int isBiking) throw(BoundsException) +void MapWarp::setIsBiking(const int isBiking) { if (Flag::End <= isBiking) - error<BoundsException>("isBiking"); + { + boundsError("isBiking"); + return; + } m_isBiking = isBiking; } -void MapWarp::setIsFlash(const int isFlash) throw(BoundsException) +void MapWarp::setIsFlash(const int isFlash) { if (Flag::End <= isFlash) - error<BoundsException>("isFlash"); + { + boundsError("isFlash"); + return; + } m_isFlash = isFlash; } -void MapWarp::setIsFoggy(const int isFoggy) throw(BoundsException) +void MapWarp::setIsFoggy(const int isFoggy) { if (Flag::End <= isFoggy) - error<BoundsException>("isFoggy"); + { + boundsError("isFoggy"); + return; + } m_isFoggy = isFoggy; } -void MapWarp::setToMap(const int toMap) throw(BoundsException) +void MapWarp::setToMap(const int toMap) { if (static_cast<const Pokemod*>(pokemod())->mapIndex(toMap) == INT_MAX) - error<BoundsException>("toMap"); + { + boundsError("toMap"); + return; + } m_toMap = toMap; m_toWarp = INT_MAX; } -void MapWarp::setToWarp(const int toWarp) throw(BoundsException) +void MapWarp::setToWarp(const int toWarp) { if (static_cast<const Pokemod*>(pokemod())->mapIndex(m_toMap) == INT_MAX) - error<BoundsException>("toMap"); + { + boundsError("toMap"); + return; + } if (static_cast<const Pokemod*>(pokemod())->mapById(m_toMap)->warpIndex(toWarp) == INT_MAX) - error<BoundsException>("toWarp"); + { + boundsError("toWarp"); + return; + } m_toWarp = toWarp; } @@ -218,10 +216,13 @@ void MapWarp::setWorkingFlag(const Flag& workingFlag) m_workingFlag = workingFlag; } -void MapWarp::setDialog(const int dialog) throw(BoundsException) +void MapWarp::setDialog(const int dialog) { if (static_cast<const Pokemod*>(pokemod())->dialogIndex(dialog) == INT_MAX) - error<BoundsException>("dialog"); + { + boundsError("dialog"); + return; + } m_dialog = dialog; } @@ -235,10 +236,11 @@ Point MapWarp::coordinate() const return m_coordinate; } -bool MapWarp::from(const int direction) const throw(BoundsException) +bool MapWarp::from(const int direction) const { + // TODO: Message about fetching out-of-bounds if (Pokemod::D_End <= direction) - warning<BoundsException>("direction"); + return false; return m_from[direction]; } @@ -247,9 +249,9 @@ int MapWarp::directionOut() const return m_directionOut; } -int MapWarp::warpType() const +int MapWarp::type() const { - return m_warpType; + return m_type; } int MapWarp::isBiking() const @@ -295,7 +297,7 @@ MapWarp& MapWarp::operator=(const MapWarp& rhs) COPY(coordinate); COPY_ARRAY(from, Pokemod::D_End); COPY(directionOut); - COPY(warpType); + COPY(type); COPY(isBiking); COPY(isFlash); COPY(isFoggy); diff --git a/pokemod/MapWarp.h b/pokemod/MapWarp.h index 678f4408..3cdd8de6 100644 --- a/pokemod/MapWarp.h +++ b/pokemod/MapWarp.h @@ -23,7 +23,6 @@ #include "Pokemod.h" // General includes -#include "../general/Exception.h" #include "../general/Flag.h" #include "../general/Point.h" @@ -49,23 +48,23 @@ class MapWarp : public Object QDomElement save() const; void setName(const QString& name); - void setCoordinate(const Point& coordinate) throw(BoundsException); - void setFrom(const int direction, const bool can) throw(BoundsException); - void setDirectionOut(const int directionOut) throw(BoundsException); - void setWarpType(const int warpType) throw(BoundsException); - void setIsBiking(const int isBiking) throw(BoundsException); - void setIsFlash(const int isFlash) throw(BoundsException); - void setIsFoggy(const int isFoggy) throw(BoundsException); - void setToMap(const int toMap) throw(BoundsException); - void setToWarp(const int toWarp) throw(BoundsException); + void setCoordinate(const Point& coordinate); + void setFrom(const int direction, const bool can); + void setDirectionOut(const int directionOut); + void setType(const int type); + void setIsBiking(const int isBiking); + void setIsFlash(const int isFlash); + void setIsFoggy(const int isFoggy); + void setToMap(const int toMap); + void setToWarp(const int toWarp); void setWorkingFlag(const Flag& workingFlag); - void setDialog(const int dialog) throw(BoundsException); + void setDialog(const int dialog); QString name() const; Point coordinate() const; - bool from(const int d) const throw(BoundsException); + bool from(const int d) const; int directionOut() const; - int warpType() const; + int type() const; int isBiking() const; int isFlash() const; int isFoggy() const; @@ -76,13 +75,13 @@ class MapWarp : public Object MapWarp& operator=(const MapWarp& rhs); private: - bool validate() const; + void validate(QTextStream& stream); QString m_name; Point m_coordinate; bool m_from[Pokemod::D_End]; int m_directionOut; - int m_warpType; + int m_type; int m_isBiking; int m_isFlash; int m_isFoggy; diff --git a/pokemod/MapWildList.cpp b/pokemod/MapWildList.cpp index 5c866aef..ff092db2 100644 --- a/pokemod/MapWildList.cpp +++ b/pokemod/MapWildList.cpp @@ -24,6 +24,9 @@ #include "MapWildListEncounter.h" #include "Pokemod.h" +// Qt includes +#include <QSet> + const QStringList MapWildList::ControlStr = QStringList() << "Grass" << "Surfing" << "Fishing" << "Dive" << "Headbutt" << "Rock Smash"; MapWildList::MapWildList(const MapWildList& wildList) : @@ -57,82 +60,24 @@ MapWildList::~MapWildList() clear(); } -bool MapWildList::validate() const +void MapWildList::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Wild List with id %1---").arg(id()), Pokemod::V_Msg); -// if (End <= m_control) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid control"); -// valid = false; -// } -// else if (m_control == Fishing) -// { -// bool ok = false; -// for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()) && !ok; ++i) -// { -// const Item* item = static_cast<const Pokemod*>(pokemod())->item(i); -// for (int j = 0; (j < item->effectCount()) && !ok; ++j) -// { -// const ItemEffect* effect = item->effect(j); -// ok = ((effect->effect() == ItemEffect::E_Fish) && (effect->value2() == m_value)); -// } -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid fishing value"); -// valid = false; -// } -// } -// QMap<int, bool> idChecker; -// foreach (int time, m_times) -// { -// if (static_cast<const Pokemod*>(pokemod())->timeIndex(time) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid time"); -// valid = false; -// } -// if (idChecker[time]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate of time %1").arg(time)); -// idChecker[time] = true; -// } -// idChecker.clear(); -// if (m_scope != INT_MAX) -// { -// bool ok = false; -// for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()) && !ok; ++i) -// { -// const Item* item = static_cast<const Pokemod*>(pokemod())->item(i); -// for (int j = 0; (j < item->effectCount()) && !ok; ++j) -// { -// const ItemEffect* effect = item->effect(j); -// ok = ((effect->effect() == ItemEffect::E_Scope) && (effect->value2() == m_scope)); -// } -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid scope"); -// valid = false; -// } -// } -// if (encounterCount()) -// { -// foreach (MapWildListEncounter* encounter, m_encounters) -// { -// if (!encounter->isValid()) -// valid = false; -// if (idChecker[encounter->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate encounter with id %1").arg(encounter->id())); -// idChecker[encounter->id()] = true; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("No effects")); -// valid = false; -// } -// return valid; + TEST_SETUP(); + TEST(setControl, control); + TEST(setValue, value); + TEST_LIST(setTime, time); + TEST(setScope, scope); + if (!encounterCount()) + error(stream, "There are no encounters"); + QSet<int> idChecker; + foreach (MapWildListEncounter* encounter, m_encounters) + { + if (!encounter->isValid(stream)) + setValid(false); + if (idChecker.contains(encounter->id())) + subclassError(stream, "encounter", encounter->id()); + idChecker.insert(encounter->id()); + } } void MapWildList::load(const QDomElement& xml, int id) @@ -140,7 +85,7 @@ void MapWildList::load(const QDomElement& xml, int id) LOAD_ID(); LOAD(int, control); LOAD(int, value); - LOAD_LIST(int, times); + LOAD_LIST(int, time); LOAD(int, scope); LOAD_SUB(newEncounter, MapWildListEncounter); } @@ -150,70 +95,83 @@ QDomElement MapWildList::save() const SAVE_CREATE(); SAVE(int, control); SAVE(int, value); - SAVE_LIST(int, times); + SAVE_LIST(int, time); SAVE(int, scope); SAVE_SUB(MapWildListEncounter, encounters); return xml; } -void MapWildList::setControl(const int control) throw(BoundsException) +void MapWildList::setControl(const int control) { if (End <= control) - error<BoundsException>("control"); + { + boundsError("control"); + return; + } m_control = control; m_value = INT_MAX; } -void MapWildList::setValue(const int value) throw(Exception) +void MapWildList::setValue(const int value) { if (m_control != Fishing) - error<UnusedException>("value"); - bool ok = false; - for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()) && !ok; ++i) + { + unusedError("value"); + return; + } + for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()); ++i) { const Item* item = static_cast<const Pokemod*>(pokemod())->item(i); - for (int j = 0; (j < item->effectCount()) && !ok; ++j) + for (int j = 0; (j < item->effectCount()); ++j) { const ItemEffect* effect = item->effect(j); - ok = ((effect->effect() == ItemEffect::E_Fish) && (effect->value2() == value)); + if ((effect->effect() == ItemEffect::E_Fish) && (effect->value2() == value)) + { + m_value = value; + return; + } } } - if (!ok) - error<BoundsException>("value"); - m_value = value; + boundsError("value"); } -void MapWildList::setTime(const int time, const bool state) throw(BoundsException) +void MapWildList::setTime(const int time, const bool state) { if (static_cast<const Pokemod*>(pokemod())->timeIndex(time) == INT_MAX) - error<BoundsException>("time"); + { + boundsError("time"); + return; + } if (state) { - if (!m_times.contains(time)) - m_times.append(time); + if (!m_time.contains(time)) + m_time.append(time); } else - m_times.removeAll(time); + m_time.removeAll(time); } -void MapWildList::setScope(const int scope) throw(BoundsException) +void MapWildList::setScope(const int scope) { if (scope != INT_MAX) { - bool ok = false; - for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()) && !ok; ++i) + for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemCount()); ++i) { const Item* item = static_cast<const Pokemod*>(pokemod())->item(i); - for (int j = 0; (j < item->effectCount()) && !ok; ++j) + for (int j = 0; (j < item->effectCount()); ++j) { const ItemEffect* effect = item->effect(j); - ok = ((effect->effect() == ItemEffect::E_Scope) && (effect->value2() == scope)); + if ((effect->effect() == ItemEffect::E_Scope) && (effect->value2() == scope)) + { + m_scope = scope; + return; + } } } - if (!ok) - error<BoundsException>("scope"); + boundsError("value"); } - m_scope = scope; + else + m_scope = scope; } int MapWildList::control() const @@ -228,7 +186,7 @@ int MapWildList::value() const bool MapWildList::time(const int time) const { - return m_times.contains(time); + return m_time.contains(time); } int MapWildList::scope() const @@ -236,26 +194,26 @@ int MapWildList::scope() const return m_scope; } -const MapWildListEncounter* MapWildList::encounter(const int index) const throw(IndexException) +const MapWildListEncounter* MapWildList::encounter(const int index) const { if (encounterCount() <= index) - warning<IndexException>("encounter"); + return NULL; return m_encounters.at(index); } -MapWildListEncounter* MapWildList::encounter(const int index) throw(IndexException) +MapWildListEncounter* MapWildList::encounter(const int index) { if (encounterCount() <= index) - error<IndexException>("encounter"); + return NULL; return m_encounters[index]; } -const MapWildListEncounter* MapWildList::encounterById(const int id) const throw(IndexException) +const MapWildListEncounter* MapWildList::encounterById(const int id) const { return encounter(encounterIndex(id)); } -MapWildListEncounter* MapWildList::encounterById(const int id) throw(IndexException) +MapWildListEncounter* MapWildList::encounterById(const int id) { return encounter(encounterIndex(id)); } @@ -296,15 +254,15 @@ MapWildListEncounter* MapWildList::newEncounter(MapWildListEncounter* encounter) return encounter; } -void MapWildList::deleteEncounter(const int index) throw(IndexException) +void MapWildList::deleteEncounter(const int index) { if (encounterCount() <= index) - error<IndexException>("encounter"); + return; delete m_encounters[index]; m_encounters.removeAt(index); } -void MapWildList::deleteEncounterById(const int id) throw(IndexException) +void MapWildList::deleteEncounterById(const int id) { deleteEncounter(encounterIndex(id)); } @@ -324,7 +282,7 @@ MapWildList& MapWildList::operator=(const MapWildList& rhs) clear(); COPY(control); COPY(value); - COPY(times); + COPY(time); COPY(scope); COPY_SUB(MapWildListEncounter, encounters); return *this; diff --git a/pokemod/MapWildList.h b/pokemod/MapWildList.h index 8e3e340d..79002e7c 100644 --- a/pokemod/MapWildList.h +++ b/pokemod/MapWildList.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - // Qt includes #include <QList> @@ -54,31 +51,31 @@ class MapWildList : public Object void load(const QDomElement& xml, int id = INT_MAX); QDomElement save() const; - void setControl(const int control) throw(BoundsException); - void setValue(const int value) throw(Exception); - void setTime(const int time, const bool state) throw(BoundsException); - void setScope(const int scope) throw(BoundsException); + void setControl(const int control); + void setValue(const int value); + void setTime(const int time, const bool state); + void setScope(const int scope); int control() const; int value() const; bool time(const int time) const; int scope() const; - const MapWildListEncounter* encounter(const int index) const throw(IndexException); - MapWildListEncounter* encounter(const int index) throw(IndexException); - const MapWildListEncounter* encounterById(const int id) const throw(IndexException); - MapWildListEncounter* encounterById(const int id) throw(IndexException); + const MapWildListEncounter* encounter(const int index) const; + MapWildListEncounter* encounter(const int index); + const MapWildListEncounter* encounterById(const int id) const; + MapWildListEncounter* encounterById(const int id); int encounterIndex(const int id) const; int encounterCount() const; MapWildListEncounter* newEncounter(); MapWildListEncounter* newEncounter(const QDomElement& xml); MapWildListEncounter* newEncounter(const MapWildListEncounter& encounter); - void deleteEncounter(const int index) throw(IndexException); - void deleteEncounterById(const int id) throw(IndexException); + void deleteEncounter(const int index); + void deleteEncounterById(const int id); MapWildList& operator=(const MapWildList& rhs); private: - bool validate() const; + void validate(QTextStream& stream); int newEncounterId() const; MapWildListEncounter* newEncounter(MapWildListEncounter* encounter); @@ -87,7 +84,7 @@ class MapWildList : public Object int m_control; int m_value; - QList<int> m_times; + QList<int> m_time; int m_scope; QList<MapWildListEncounter*> m_encounters; diff --git a/pokemod/MapWildListEncounter.cpp b/pokemod/MapWildListEncounter.cpp index e230747e..4e087f42 100644 --- a/pokemod/MapWildListEncounter.cpp +++ b/pokemod/MapWildListEncounter.cpp @@ -48,27 +48,12 @@ MapWildListEncounter::MapWildListEncounter(const QDomElement& xml, const Object* load(xml, id); } -bool MapWildListEncounter::validate() const +void MapWildListEncounter::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---------Encounter with id %1---").arg(id()), Pokemod::V_Msg); -// if (static_cast<const Pokemod*>(pokemod())->speciesIndex(m_species) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid species"); -// valid = false; -// } -// if (!m_level || (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() <= m_level)) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid level"); -// valid = false; -// } -// if (!m_weight) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid weighting"); -// valid = false; -// } -// return valid; + TEST_SETUP(); + TEST(setSpecies, species); + TEST(setLevel, level); + TEST(setWeight, weight); } void MapWildListEncounter::load(const QDomElement& xml, int id) @@ -88,24 +73,33 @@ QDomElement MapWildListEncounter::save() const return xml; } -void MapWildListEncounter::setSpecies(const int species) throw(BoundsException) +void MapWildListEncounter::setSpecies(const int species) { if (static_cast<const Pokemod*>(pokemod())->speciesIndex(species) == INT_MAX) - error<BoundsException>("species"); + { + boundsError("species"); + return; + } m_species = species; } -void MapWildListEncounter::setLevel(const int level) throw(BoundsException) +void MapWildListEncounter::setLevel(const int level) { if (!level || (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() <= level)) - error<BoundsException>("level"); + { + boundsError("level"); + return; + } m_level = level; } -void MapWildListEncounter::setWeight(const int weight) throw(BoundsException) +void MapWildListEncounter::setWeight(const int weight) { if (!weight) - error<BoundsException>("weight"); + { + boundsError("weight"); + return; + } m_weight = weight; } diff --git a/pokemod/MapWildListEncounter.h b/pokemod/MapWildListEncounter.h index 800b5855..7b10d696 100644 --- a/pokemod/MapWildListEncounter.h +++ b/pokemod/MapWildListEncounter.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - class MapWildListEncounter: public Object { public: @@ -35,9 +32,9 @@ class MapWildListEncounter: public Object void load(const QDomElement& xml, int id = INT_MAX); QDomElement save() const; - void setSpecies(const int species) throw(BoundsException); - void setLevel(const int level) throw(BoundsException); - void setWeight(const int weight) throw(BoundsException); + void setSpecies(const int species); + void setLevel(const int level); + void setWeight(const int weight); int species() const; int level() const; @@ -45,7 +42,7 @@ class MapWildListEncounter: public Object MapWildListEncounter& operator=(const MapWildListEncounter& rhs); private: - bool validate() const; + void validate(QTextStream& stream); int m_species; int m_level; diff --git a/pokemod/Move.cpp b/pokemod/Move.cpp index 1c676eac..2e98ad65 100644 --- a/pokemod/Move.cpp +++ b/pokemod/Move.cpp @@ -22,6 +22,9 @@ #include "MoveEffect.h" #include "Pokemod.h" +// Qt includes +#include <QSet> + const QStringList Move::TargetStr = QStringList() << "Player" << "Enemy" << "All" << "Random"; const QStringList Move::ChoiceStr = QStringList() << "Player" << "Enemy" << "Random"; @@ -68,59 +71,27 @@ Move::~Move() clear(); } -bool Move::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Move \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is not defined"); -// valid = ""; -// } -// if (static_cast<const Pokemod*>(pokemod())->typeIndex(m_type) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid type"); -// valid = false; -// } -// if (!m_powerPoints) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid number of power points"); -// valid = false; -// } -// if (T_End <= m_target) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid target"); -// valid = false; -// } -// if (!m_target || (static_cast<const Pokemod*>(pokemod())->rules()->maxFight() * ((m_target == T_All) ? static_cast<const Pokemod*>(pokemod())->rules()->maxPlayers() : 1)) < m_numTargets) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid number of targets"); -// valid = false; -// } -// if (C_End <= m_targetChoice) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid target choice"); -// valid = false; -// } -// if (effectCount()) -// { -// QMap<int, bool> idChecker; -// foreach (MoveEffect* effect, m_effects) -// { -// if (!effect->isValid()) -// valid = false; -// if (idChecker[effect->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); -// idChecker[effect->id()] = true; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no effects"); -// valid = false; -// } -// return valid; +void Move::validate(QTextStream& stream) +{ + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setType, type); + TEST(setPowerPoints, powerPoints); + TEST(setTarget, target); + TEST(setNumTargets, numTargets); + TEST(setTargetChoice, targetChoice); + if (!effectCount()) + warning(stream, "There are no effects"); + QSet<int> idChecker; + foreach (MoveEffect* effect, m_effects) + { + if (!effect->isValid(stream)) + setValid(false); + if (idChecker.contains(effect->id())) + subclassError(stream, "effect", effect->id()); + idChecker.insert(effect->id()); + } } void Move::load(const QDomElement& xml, int id) @@ -170,10 +141,13 @@ void Move::setName(const QString& name) m_name = name; } -void Move::setAccuracy(const Fraction& accuracy) throw(BoundsException) +void Move::setAccuracy(const Fraction& accuracy) { if (1 < accuracy) - error<BoundsException>("accuracy"); + { + boundsError("accuracy"); + return; + } m_accuracy = accuracy; } @@ -182,10 +156,13 @@ void Move::setPower(const int power) m_power = power; } -void Move::setType(const int type) throw(BoundsException) +void Move::setType(const int type) { if (static_cast<const Pokemod*>(pokemod())->typeIndex(type) == INT_MAX) - error<BoundsException>("type"); + { + boundsError("type"); + return; + } m_type = type; } @@ -194,31 +171,43 @@ void Move::setSpecial(const bool special) m_special = special; } -void Move::setPowerPoints(const int powerPoints) throw(BoundsException) +void Move::setPowerPoints(const int powerPoints) { if (!powerPoints) - error<BoundsException>("powerPoints"); + { + boundsError("powerPoints"); + return; + } m_powerPoints = powerPoints; } -void Move::setTarget(const int target) throw(BoundsException) +void Move::setTarget(const int target) { if (T_End <= target) - error<BoundsException>("target"); + { + boundsError("target"); + return; + } m_target = target; } -void Move::setNumTargets(const int numTargets) throw(BoundsException) +void Move::setNumTargets(const int numTargets) { if (!numTargets || ((static_cast<const Pokemod*>(pokemod())->rules()->maxFight() * ((m_target == T_All) ? static_cast<const Pokemod*>(pokemod())->rules()->maxPlayers() : 1)) < numTargets)) - error<BoundsException>("numTargets"); + { + boundsError("numTargets"); + return; + } m_numTargets = numTargets; } -void Move::setTargetChoice(const int targetChoice) throw(BoundsException) +void Move::setTargetChoice(const int targetChoice) { if (C_End <= targetChoice) - error<BoundsException>("targetChoice"); + { + boundsError("targetChoice"); + return; + } m_targetChoice = targetChoice; } @@ -327,26 +316,26 @@ QString Move::description() const return m_description; } -const MoveEffect* Move::effect(const int index) const throw(IndexException) +const MoveEffect* Move::effect(const int index) const { if (effectCount() <= index) - warning<IndexException>("effect"); + return NULL; return m_effects.at(index); } -MoveEffect* Move::effect(const int index) throw(IndexException) +MoveEffect* Move::effect(const int index) { if (effectCount() <= index) - error<IndexException>("effect"); + return NULL; return m_effects[index]; } -const MoveEffect* Move::effectById(const int id) const throw(IndexException) +const MoveEffect* Move::effectById(const int id) const { return effect(effectIndex(id)); } -MoveEffect* Move::effectById(const int id) throw(IndexException) +MoveEffect* Move::effectById(const int id) { return effect(effectIndex(id)); } @@ -387,15 +376,15 @@ MoveEffect* Move::newEffect(MoveEffect* effect) return effect; } -void Move::deleteEffect(const int index) throw(IndexException) +void Move::deleteEffect(const int index) { if (effectCount() <= index) - error<IndexException>("effect"); + return; delete m_effects[index]; m_effects.removeAt(index); } -void Move::deleteEffectById(const int id) throw(IndexException) +void Move::deleteEffectById(const int id) { deleteEffect(effectIndex(id)); } diff --git a/pokemod/Move.h b/pokemod/Move.h index 0e893726..6084b273 100644 --- a/pokemod/Move.h +++ b/pokemod/Move.h @@ -22,7 +22,6 @@ #include "Object.h" // General includes -#include "../general/Exception.h" #include "../general/Fraction.h" // Qt includes @@ -63,14 +62,14 @@ class Move : public Object QDomElement save() const; void setName(const QString& name); - void setAccuracy(const Fraction& accuracy) throw(BoundsException); + void setAccuracy(const Fraction& accuracy); void setPower(const int power); - void setType(const int type) throw(BoundsException); + void setType(const int type); void setSpecial(const bool special); - void setPowerPoints(const int powerPoints) throw(BoundsException); - void setTarget(const int target) throw(BoundsException); - void setNumTargets(const int numTargets) throw(BoundsException); - void setTargetChoice(const int targetChoice) throw(BoundsException); + void setPowerPoints(const int powerPoints); + void setTarget(const int target); + void setNumTargets(const int numTargets); + void setTargetChoice(const int targetChoice); void setIgnoreAccuracy(const bool ignoreAccuracy); void setCanFlinch(const bool canFlinch); void setCanRandom(const bool canRandom); @@ -96,21 +95,21 @@ class Move : public Object int priority() const; QString description() const; - const MoveEffect* effect(const int index) const throw(IndexException); - MoveEffect* effect(const int index) throw(IndexException); - const MoveEffect* effectById(const int id) const throw(IndexException); - MoveEffect* effectById(const int id) throw(IndexException); + const MoveEffect* effect(const int index) const; + MoveEffect* effect(const int index); + const MoveEffect* effectById(const int id) const; + MoveEffect* effectById(const int id); int effectIndex(const int id) const; int effectCount() const; MoveEffect* newEffect(); MoveEffect* newEffect(const QDomElement& xml); MoveEffect* newEffect(const MoveEffect& effect); - void deleteEffect(const int index) throw(IndexException); - void deleteEffectById(const int id) throw(IndexException); + void deleteEffect(const int index); + void deleteEffectById(const int id); Move& operator=(const Move& rhs); private: - bool validate() const; + void validate(QTextStream& stream); int newEffectId() const; MoveEffect* newEffect(MoveEffect* effect); diff --git a/pokemod/MoveEffect.cpp b/pokemod/MoveEffect.cpp index e790d672..9847ffdf 100644 --- a/pokemod/MoveEffect.cpp +++ b/pokemod/MoveEffect.cpp @@ -52,12 +52,15 @@ MoveEffect::MoveEffect(const QDomElement& xml, const Object* parent, const int i load(xml, id); } -bool MoveEffect::validate() const +void MoveEffect::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Effect with id %1---").arg(id()), Pokemod::V_Msg); -// return valid; + TEST_SETUP(); + TEST(setChance, chance); + TEST(setEffect, effect); + TEST(setValue1, value1); + TEST(setValue2, value2); + TEST(setValue3, value3); + TEST(setValue4, value4); } void MoveEffect::load(const QDomElement& xml, int id) @@ -83,17 +86,23 @@ QDomElement MoveEffect::save() const return xml; } -void MoveEffect::setChance(const Fraction& chance) throw(BoundsException) +void MoveEffect::setChance(const Fraction& chance) { if (1 < chance) - error<BoundsException>("chance"); + { + boundsError("chance"); + return; + } m_chance = chance; } -void MoveEffect::setEffect(const int effect) throw(BoundsException) +void MoveEffect::setEffect(const int effect) { if (E_End <= effect) - error<BoundsException>("effect"); + { + boundsError("effect"); + return; + } m_effect = effect; m_value1 = INT_MAX; m_value2 = INT_MAX; @@ -101,50 +110,68 @@ void MoveEffect::setEffect(const int effect) throw(BoundsException) m_value4.set(1, 1); } -void MoveEffect::setValue1(const int value1) throw(Exception) +void MoveEffect::setValue1(const int value1) { switch (m_effect) { case E_Damage: if (D_End <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_Status: case E_NeedStatus: if (Pokemod::STS_End <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } throw; case E_Stat: if (Pokemod::ST_End_Battle <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_Counter: case E_Shield: if (MT_End <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case E_Recoil: if (R_End <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; default: - error<BoundsException>("value1"); - break; + unusedError("value1"); + return; } m_value1 = value1; } -void MoveEffect::setValue2(const int value2) throw(Exception) +void MoveEffect::setValue2(const int value2) { switch (m_effect) { case E_Damage: if ((D_Level <= m_value1) || !value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; default: - error<BoundsException>("value2"); - break; + unusedError("value2"); + return; } m_value2 = value2; } @@ -160,10 +187,13 @@ void MoveEffect::setValue3(const int value3) m_value3 = value3; } -void MoveEffect::setValue4(const Fraction& value4) throw(BoundsException) +void MoveEffect::setValue4(const Fraction& value4) { if ((m_effect != E_StealHP) && (m_effect != E_Counter) && (m_effect != E_Selfdestruct) && (m_effect != E_Mirror) && (m_effect != E_GetMoney) && (m_effect != E_WaitAndReturn) && (m_effect != E_Recoil) && (1 < value4)) - error<BoundsException>("value4"); + { + boundsError("value4"); + return; + } m_value4 = value4; } diff --git a/pokemod/MoveEffect.h b/pokemod/MoveEffect.h index 7e47f5c3..b7004be5 100644 --- a/pokemod/MoveEffect.h +++ b/pokemod/MoveEffect.h @@ -22,7 +22,6 @@ #include "Object.h" // General includes -#include "../general/Exception.h" #include "../general/Fraction.h" // Qt includes @@ -116,12 +115,12 @@ class MoveEffect : public Object void load(const QDomElement& xml, int id = INT_MAX); QDomElement save() const; - void setChance(const Fraction& chance) throw(BoundsException); - void setEffect(const int effect) throw(BoundsException); - void setValue1(const int value1) throw(Exception); - void setValue2(const int value2) throw(Exception); + void setChance(const Fraction& chance); + void setEffect(const int effect); + void setValue1(const int value1); + void setValue2(const int value2); void setValue3(const int value3); - void setValue4(const Fraction& value4) throw(BoundsException); + void setValue4(const Fraction& value4); Fraction chance() const; int effect() const; @@ -132,7 +131,7 @@ class MoveEffect : public Object MoveEffect& operator=(const MoveEffect& rhs); private: - bool validate() const; + void validate(QTextStream& stream); Fraction m_chance; int m_effect; diff --git a/pokemod/Nature.cpp b/pokemod/Nature.cpp index 62e14267..4ecbd337 100644 --- a/pokemod/Nature.cpp +++ b/pokemod/Nature.cpp @@ -48,22 +48,12 @@ Nature::Nature(const QDomElement& xml, const Object* parent, const int id) : load(xml, id); } -bool Nature::validate() const +void Nature::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Nature \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is not defined"); -// valid = false; -// } -// if (!m_weight) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Weight is not valid"); -// valid = false; -// } -// return valid; + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setWeight, weight); } void Nature::load(const QDomElement& xml, int id) @@ -88,17 +78,23 @@ void Nature::setName(const QString& name) m_name = name; } -void Nature::setStat(const int stat, const Fraction& multiplier) throw(BoundsException) +void Nature::setStat(const int stat, const Fraction& multiplier) { if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) - error<BoundsException>("stat"); + { + boundsError("stat"); + return; + } m_stat[stat] = multiplier; } -void Nature::setWeight(const int weight) throw(BoundsException) +void Nature::setWeight(const int weight) { if (!weight) - error<BoundsException>("weight"); + { + boundsError("weight"); + return; + } m_weight = weight; } @@ -107,10 +103,11 @@ QString Nature::name() const return m_name; } -Fraction Nature::stat(const int stat) const throw(BoundsException) +Fraction Nature::stat(const int stat) const { + // TODO: Message about fetching out-of-bounds if (Pokemod::ST_End_GSC <= stat) - warning<BoundsException>("stat"); + return Fraction(); return m_stat[stat]; } diff --git a/pokemod/Nature.h b/pokemod/Nature.h index c6c007a1..dc19153a 100644 --- a/pokemod/Nature.h +++ b/pokemod/Nature.h @@ -23,7 +23,6 @@ #include "Pokemod.h" // General includes -#include "../general/Exception.h" #include "../general/Fraction.h" class Nature : public Object @@ -38,16 +37,16 @@ class Nature : public Object QDomElement save() const; void setName(const QString& name); - void setStat(const int stat, const Fraction& multiplier) throw(BoundsException); - void setWeight(const int weight) throw(BoundsException); + void setStat(const int stat, const Fraction& multiplier); + void setWeight(const int weight); QString name() const; - Fraction stat(const int stat) const throw(BoundsException); + Fraction stat(const int stat) const; int weight() const; Nature& operator=(const Nature& rhs); private: - bool validate() const; + void validate(QTextStream& stream); QString m_name; Fraction m_stat[Pokemod::ST_End_GSC]; diff --git a/pokemod/Object.cpp b/pokemod/Object.cpp new file mode 100644 index 00000000..7ec3b16c --- /dev/null +++ b/pokemod/Object.cpp @@ -0,0 +1,155 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Object.h" + +Object::Object(const Object& object) : + m_id(object.id()), + m_className(object.className()), + m_parent(object.parent()) +{ +} + +Object::Object(const QString& className, const Object* parent, const int id) : + m_id(id), + m_className(className), + m_parent(parent) +{ +} + +const Object* Object::parent() const +{ + return m_parent; +} + +const Object* Object::pokemod() const +{ + if (m_parent) + return m_parent->pokemod(); + return this; +} + +bool Object::isValid(QTextStream& stream) +{ + setValid(true); + if (!isGood()) + boundsError(stream, "ID"); + validate(stream); + return m_valid; +} + +bool Object::isGood() const +{ + return ((0 <= m_id) && (INT_MAX != m_id)); +} + +int Object::id() const +{ + return m_id; +} + +QString Object::className() const +{ + return m_className; +} + +bool Object::valid() const +{ + return m_valid; +} + +void Object::setId(const int id) +{ + m_id = id; +} + +void Object::setValid(const bool valid) +{ + m_valid = valid; +} + +void Object::warning(const QString& message) +{ + m_lastError = message; +} + +void Object::warning(QTextStream& stream, const QString& message) const +{ + stream << m_className << " (" << m_id << "): " << message; +} + +void Object::error(const QString& message) +{ + setValid(false); + m_lastError = message; +} + +void Object::error(QTextStream& stream, const QString& message) +{ + setValid(false); + warning(stream, message); +} + +void Object::unusedError(const QString& variable) +{ + warning(QString("Setting unused variable %1").arg(variable)); +} + +void Object::unusedError(QTextStream& stream, const QString& variable) +{ + warning(stream, QString("Setting unused variable %1").arg(variable)); +} + +void Object::boundsError(const QString& variable) +{ + error(QString("Value for %1 out-of-bounds").arg(variable)); +} + +void Object::boundsError(QTextStream& stream, const QString& variable) +{ + error(stream, QString("Value for %1 out-of-bounds").arg(variable)); +} + +void Object::sizeError(const QString& variable) +{ + error(QString("Wrong size for %1").arg(variable)); +} + +void Object::sizeError(QTextStream& stream, const QString& variable) +{ + error(stream, QString("Wrong size for %1").arg(variable)); +} + +void Object::subclassError(QTextStream& stream, const QString& subclass, const int id) +{ + error(stream, QString("Duplicate %1 with id %2").arg(subclass).arg(id)); +} + +void Object::subclassError(QTextStream& stream, const QString& subclass, const QString& name) +{ + error(stream, QString("Duplicate %1 with name %2").arg(subclass).arg(name)); +} + +void Object::lastError(QTextStream& stream) +{ + warning(stream, m_lastError); +} + +void Object::clear() +{ +} diff --git a/pokemod/Object.h b/pokemod/Object.h index 82d18800..e6f4add3 100644 --- a/pokemod/Object.h +++ b/pokemod/Object.h @@ -20,6 +20,7 @@ // Qt includes #include <QDomElement> +#include <QTextStream> // C includes #include <climits> @@ -27,78 +28,52 @@ class Object { public: - inline Object(const Object& object) : - m_id(object.id()), - m_className(object.className()), - m_parent(object.parent()) - { - } - inline Object(const QString& className, const Object* parent, const int id) : - m_id(id), - m_className(className), - m_parent(parent) - { - } + Object(const Object& object); + Object(const QString& className, const Object* parent, const int id); virtual ~Object() { } + virtual void load(const QDomElement& xml, int id = INT_MAX) = 0; virtual QDomElement save() const = 0; - inline const Object* parent() const - { - return m_parent; - } + const Object* parent() const; + const Object* pokemod() const; - inline const Object* pokemod() const - { - if (m_parent) - return m_parent->pokemod(); - return this; - } + bool isValid(QTextStream& stream); + bool isGood() const; - inline int id() const - { - return m_id; - } - inline bool isValid() const - { - if (isGood()) - return validate(); - return false; - } - inline bool isGood() const - { - return ((0 <= m_id) && (INT_MAX != m_id)); - } - - inline QString className() const - { - return m_className; - } + int id() const; + QString className() const; protected: - inline void setId(const int id) - { - m_id = id; - } - virtual bool validate() const = 0; - template<class T> inline void warning(const QString& message) const throw(T) - { - throw(T(m_className, message)); - } - template<class T> inline void error(const QString& message) throw(T) - { - m_valid = false; - warning<T>(message); - } - virtual void clear() - { - } + bool valid() const; + + void setId(const int id); + void setValid(const bool valid); + + void warning(const QString& message); + void warning(QTextStream& stream, const QString& message) const; + void error(const QString& message); + void error(QTextStream& stream, const QString& message); + void unusedError(const QString& variable); + void unusedError(QTextStream& stream, const QString& variable); + void boundsError(const QString& variable); + void boundsError(QTextStream& stream, const QString& variable); + void sizeError(const QString& variable); + void sizeError(QTextStream& stream, const QString& variable); + void subclassError(QTextStream& stream, const QString& subclass, const int id); + void subclassError(QTextStream& stream, const QString& subclass, const QString& name); + void lastError(QTextStream& stream); + + virtual void validate(QTextStream& stream) = 0; + + virtual void clear(); private: int m_id; const QString m_className; const Object* m_parent; bool m_valid; + QString m_lastError; }; #define LOAD_NODE(variable) xml.firstChildElement(variable) @@ -236,4 +211,50 @@ class Object foreach (class* subclass, rhs.m_##variable) \ m_##variable.append(new class(*subclass, this, subclass->id())) +#define TEST_SETUP() bool _valid; +#define TEST(setter, variable) \ + _valid = valid(); \ + setValid(true); \ + setter(m_##variable); \ + if (!valid()) \ + lastError(stream); \ + if (!_valid) \ + setValid(false) +#define TEST_ARRAY(setter, variable, size) \ + _valid = valid(); \ + for (int i = 0; i < size; ++i) \ + { \ + setValid(true); \ + setter(i, variable(i)); \ + if (!valid()) \ + lastError(stream); \ + } \ + if (!_valid) \ + setValid(false) +#define TEST_LIST(setter, variable) \ + _valid = valid(); \ + foreach (int variable, m_##variable) \ + { \ + setValid(true); \ + setter(variable, true); \ + if (!valid()) \ + lastError(stream); \ + } \ + if (!_valid) \ + setValid(false) +#define TEST_MATRIX(setter, variable) \ + _valid = valid(); \ + for (int i = 0; i < m_##variable.height(); ++i) \ + { \ + for (int j = 0; j < m_##variable.width(); ++j) \ + { \ + setValid(true); \ + setter(i, j, variable(i, j)); \ + if (!valid()) \ + lastError(stream); \ + } \ + } \ + if (!_valid) \ + setValid(false) + #endif diff --git a/pokemod/Pokemod.cpp b/pokemod/Pokemod.cpp index abb6f482..e70fcbe3 100644 --- a/pokemod/Pokemod.cpp +++ b/pokemod/Pokemod.cpp @@ -39,6 +39,7 @@ // Qt includes #include <QBuffer> +#include <QSet> const QStringList Pokemod::ValidationStr = QStringList() << "Message" << "Warn" << "Error"; const QStringList Pokemod::StatRBYStr = QStringList() << "HP" << "Attack" << "Defense" << "Speed" << "Special" << "Special" << "Accuracy" << "Evasion"; @@ -52,7 +53,6 @@ const QStringList Pokemod::HMStr = QStringList() << "Cut" << "Fly" << "Surf" << Pokemod::Pokemod() : Object("Pokemod", NULL, 0), - valOutput(NULL), m_title(""), m_version(""), m_description(""), @@ -80,7 +80,6 @@ Pokemod::Pokemod(const Pokemod& pokemod) : Pokemod::Pokemod(const QDomElement& xml) : Object("Pokemod", NULL, 0), - valOutput(NULL), m_rules(this) { load(xml); @@ -91,290 +90,293 @@ Pokemod::~Pokemod() clear(); } -bool Pokemod::validate() const -{ - // TODO: validate -// bool valid = true; -// validationMsg(QString("Pokemod \"%1\"").arg(m_title), V_Msg); -// if (m_title == "") -// { -// validationMsg("Title is not defined"); -// valid = false; -// } -// if (m_version == "") -// { -// validationMsg("Version is not defined"); -// valid = false; -// } -// if (m_description == "") -// validationMsg("Description is not defined", V_Warn); -// if (mapIndex(m_startMap)) -// { -// if (mapById(m_startMap)->warpIndex(m_startWarp) == INT_MAX) -// { -// validationMsg("Invalid starting warp"); -// valid = false; -// } -// } -// else -// { -// validationMsg("Invalid starting map"); -// valid = false; -// } -// if (m_superPCUname == "") -// validationMsg("Super PC username not defined", V_Warn); -// if (m_superPCPasswd == "") -// validationMsg("Super PC password not defined", V_Warn); -// if ((m_typeChart.width() != typeCount()) || (m_typeChart.height() != typeCount())) -// { -// validationMsg("TypeChart is invalid"); -// valid = false; -// } -// if (!m_rules.isValid()) -// valid = false; -// QMap<int, bool> idChecker; -// QMap<int, bool> timeChecker; -// if (m_rules.abilityAllowed()) -// { -// if (!abilityCount()) -// { -// validationMsg("There are no abilities"); -// valid = false; -// } -// foreach (Ability* ability, m_abilities) -// { -// if (!ability->isValid()) -// valid = false; -// if (idChecker[ability->id()]) -// validationMsg(QString("Duplicate ability with id %1").arg(ability->id())); -// idChecker[ability->id()] = true; -// } -// idChecker.clear(); -// } -// if (!authorCount()) -// { -// validationMsg("There are no authors"); -// valid = false; -// } -// foreach (Author* author, m_authors) -// { -// if (!author->isValid()) -// valid = false; -// if (idChecker[author->id()]) -// validationMsg(QString("Duplicate author with id %1").arg(author->id())); -// idChecker[author->id()] = true; -// } -// idChecker.clear(); -// if (!badgeCount()) -// validationMsg("There are no badges", V_Warn); -// foreach (Badge* badge, m_badges) -// { -// if (!badge->isValid()) -// valid = false; -// if (idChecker[badge->id()]) -// validationMsg(QString("Duplicate badge with id %1").arg(badge->id())); -// idChecker[badge->id()] = true; -// } -// idChecker.clear(); -// if (!coinListCount()) -// validationMsg("There are no coin lists", V_Warn); -// foreach (CoinList* coinList, m_coinLists) -// { -// if (!coinList->isValid()) -// valid = false; -// if (idChecker[coinList->id()]) -// validationMsg(QString("Duplicate coin list with id %1").arg(coinList->id())); -// idChecker[coinList->id()] = true; -// } -// idChecker.clear(); -// if (!dialogCount()) -// { -// validationMsg("There are no dialogs"); -// valid = false; -// } -// foreach (Dialog* dialog, m_dialogs) -// { -// if (!dialog->isValid()) -// valid = false; -// if (idChecker[dialog->id()]) -// validationMsg(QString("Duplicate dialog with id %1").arg(dialog->id())); -// idChecker[dialog->id()] = true; -// } -// idChecker.clear(); -// if (m_rules.breedingAllowed()) -// { -// if (!eggGroupCount()) -// { -// validationMsg("There are no egg grous"); -// valid = false; -// } -// foreach (EggGroup* eggGroup, m_eggGroups) -// { -// if (!eggGroup->isValid()) -// valid = false; -// if (idChecker[eggGroup->id()]) -// validationMsg(QString("Duplicate egg group with id %1").arg(eggGroup->id())); -// idChecker[eggGroup->id()] = true; -// } -// idChecker.clear(); -// } -// if (!itemCount()) -// validationMsg("There are no m_items", V_Warn); -// foreach (Item* item, m_items) -// { -// if (!item->isValid()) -// valid = false; -// if (idChecker[item->id()]) -// validationMsg(QString("Duplicate item with id %1").arg(item->id())); -// idChecker[item->id()] = true; -// } -// idChecker.clear(); -// if (!itemTypeCount()) -// { -// validationMsg("There are no item types", itemCount() ? V_Error : V_Warn); -// if (itemCount()) -// valid = false; -// } -// foreach (ItemType* itemType, m_itemTypes) -// { -// if (!itemType->isValid()) -// valid = false; -// if (idChecker[itemType->id()]) -// validationMsg(QString("Duplicate item type with id %1").arg(itemType->id())); -// idChecker[itemType->id()] = true; -// } -// idChecker.clear(); -// if (!mapCount()) -// { -// validationMsg("There are no m_maps"); -// valid = false; -// } -// foreach (Map* map, m_maps) -// { -// if (!map->isValid()) -// valid = false; -// if (idChecker[map->id()]) -// validationMsg(QString("Duplicate map with id %1").arg(map->id())); -// idChecker[map->id()] = true; -// } -// idChecker.clear(); -// if (!moveCount()) -// { -// validationMsg("There are no m_moves"); -// valid = false; -// } -// foreach (Move* move, m_moves) -// { -// if (!move->isValid()) -// valid = false; -// if (idChecker[move->id()]) -// validationMsg(QString("Duplicate move with id %1").arg(move->id())); -// idChecker[move->id()] = true; -// } -// idChecker.clear(); -// if (m_rules.natureAllowed()) -// { -// if (!natureCount()) -// { -// validationMsg("There are no natures"); -// valid = false; -// } -// foreach (Nature* nature, m_natures) -// { -// if (!nature->isValid()) -// valid = false; -// if (idChecker[nature->id()]) -// validationMsg(QString("Duplicate ability with id %1").arg(nature->id())); -// idChecker[nature->id()] = true; -// } -// idChecker.clear(); -// } -// if (!speciesCount()) -// { -// validationMsg("There are no m_species"); -// valid = false; -// } -// foreach (Species* m_species, m_species) -// { -// if (!m_species->isValid()) -// valid = false; -// if (idChecker[m_species->id()]) -// validationMsg(QString("Duplicate m_species with id %1").arg(m_species->id())); -// idChecker[m_species->id()] = true; -// } -// idChecker.clear(); -// if (!storeCount()) -// validationMsg("There are no m_stores", V_Warn); -// foreach (Store* store, m_stores) -// { -// if (!store->isValid()) -// valid = false; -// if (idChecker[store->id()]) -// validationMsg(QString("Duplicate store with id %1").arg(store->id())); -// idChecker[store->id()] = true; -// } -// idChecker.clear(); -// if (!tileCount()) -// { -// validationMsg("There are no m_tiles"); -// valid = false; -// } -// foreach (Tile* tile, m_tiles) -// { -// if (!tile->isValid()) -// valid = false; -// if (idChecker[tile->id()]) -// validationMsg(QString("Duplicate tile with id %1").arg(tile->id())); -// idChecker[tile->id()] = true; -// } -// idChecker.clear(); -// if (!trainerCount()) -// { -// validationMsg("There are no times", Pokemod::V_Warn); -// } -// foreach (Trainer* trainer, m_trainers) -// { -// if (!trainer->isValid()) -// valid = false; -// if (idChecker[trainer->id()]) -// validationMsg(QString("Duplicate trainer with id %1").arg(trainer->id())); -// idChecker[trainer->id()] = true; -// } -// idChecker.clear(); -// if (!timeCount()) -// { -// validationMsg("There are no times"); -// valid = false; -// } -// foreach (Time* time, m_times) -// { -// if (!time->isValid()) -// valid = false; -// if (idChecker[time->id()]) -// validationMsg(QString("Duplicate time with id %1").arg(time->id())); -// idChecker[time->id()] = true; -// if (timeChecker[(60 * time->hour()) + time->minute()]) -// validationMsg(QString("Duplicate time at %1:%2").arg(time->hour()).arg(time->minute())); -// timeChecker[(60 * time->hour()) + time->minute()] = true; -// } -// idChecker.clear(); -// if (!typeCount()) -// { -// validationMsg("There are no types"); -// valid = false; -// } -// foreach (Type* type, m_types) -// { -// if (!type->isValid()) -// valid = false; -// if (idChecker[type->id()]) -// validationMsg(QString("Duplicate type with id %1").arg(type->id())); -// idChecker[type->id()] = true; -// } -// return valid; -} - -void Pokemod::load(const QDomElement& xml, const int) throw(Exception) +void Pokemod::validate(QTextStream& stream) +{ + if (m_title.isEmpty()) + error(stream, "Title is empty"); + if (m_version.isEmpty()) + error(stream, "Version is empty"); + if (m_description.isEmpty()) + warning(stream, "Description is empty"); + if (mapIndex(m_startMap) == INT_MAX) + error(stream, "Invalid starting map"); + else + { + if (mapById(m_startMap)->warpIndex(m_startWarp) == INT_MAX) + error(stream, "Invalid starting warp"); + } + if (m_superPCUname.isEmpty()) + warning(stream, "Super PC username not defined"); + if (m_superPCPasswd.isEmpty()) + warning(stream, "Super PC password not defined"); + if ((m_typeChart.width() != typeCount()) || (m_typeChart.height() != typeCount())) + error(stream, "Type chart is invalid"); + if (!m_rules.isValid(stream)) + setValid(false); + QSet<int> idChecker; + QSet<QString> nameChecker; + QSet<int> timeChecker; + if (m_rules.abilityAllowed()) + { + if (!abilityCount()) + error(stream, "There are no abilities"); + foreach (Ability* ability, m_abilities) + { + if (!ability->isValid(stream)) + setValid(false); + if (idChecker.contains(ability->id())) + subclassError(stream, "ability", ability->id()); + idChecker.insert(ability->id()); + if (nameChecker.contains(ability->name())) + subclassError(stream, "ability", ability->name()); + nameChecker.insert(ability->name()); + } + idChecker.clear(); + nameChecker.clear(); + } + if (!authorCount()) + error(stream, "There are no authors"); + foreach (Author* author, m_authors) + { + if (!author->isValid(stream)) + setValid(false); + if (idChecker.contains(author->id())) + subclassError(stream, "author", author->id()); + idChecker.insert(author->id()); + if (nameChecker.contains(author->name())) + subclassError(stream, "author", author->name()); + nameChecker.insert(author->name()); + } + idChecker.clear(); + nameChecker.clear(); + if (!badgeCount()) + error(stream, "There are no badges"); + foreach (Badge* badge, m_badges) + { + if (!badge->isValid(stream)) + setValid(false); + if (idChecker.contains(badge->id())) + subclassError(stream, "badge", badge->id()); + idChecker.insert(badge->id()); + if (nameChecker.contains(badge->name())) + subclassError(stream, "badge", badge->name()); + nameChecker.insert(badge->name()); + } + idChecker.clear(); + nameChecker.clear(); + if (!coinListCount()) + warning(stream, "There are no coin lists"); + foreach (CoinList* coinList, m_coinLists) + { + if (!coinList->isValid(stream)) + setValid(false); + if (idChecker.contains(coinList->id())) + subclassError(stream, "coin list", coinList->id()); + idChecker.insert(coinList->id()); + if (nameChecker.contains(coinList->name())) + subclassError(stream, "coin list", coinList->name()); + nameChecker.insert(coinList->name()); + } + idChecker.clear(); + nameChecker.clear(); + if (!dialogCount()) + error(stream, "There are no dialogs"); + foreach (Dialog* dialog, m_dialogs) + { + if (!dialog->isValid(stream)) + setValid(false); + if (idChecker.contains(dialog->id())) + subclassError(stream, "dialog", dialog->id()); + idChecker.insert(dialog->id()); + } + idChecker.clear(); + if (m_rules.breedingAllowed()) + { + if (!eggGroupCount()) + error(stream, "There are no egg groups"); + foreach (EggGroup* eggGroup, m_eggGroups) + { + if (!eggGroup->isValid(stream)) + setValid(false); + if (idChecker.contains(eggGroup->id())) + subclassError(stream, "egg group", eggGroup->id()); + idChecker.insert(eggGroup->id()); + if (nameChecker.contains(eggGroup->name())) + subclassError(stream, "egg group", eggGroup->name()); + nameChecker.insert(eggGroup->name()); + } + idChecker.clear(); + nameChecker.clear(); + } + if (!itemCount()) + warning(stream, "There are no items"); + foreach (Item* item, m_items) + { + if (!item->isValid(stream)) + setValid(false); + if (idChecker.contains(item->id())) + subclassError(stream, "item", item->id()); + idChecker.insert(item->id()); + if (nameChecker.contains(item->name())) + subclassError(stream, "item", item->name()); + nameChecker.insert(item->name()); + } + idChecker.clear(); + nameChecker.clear(); + if (!itemTypeCount() && itemCount()) + error(stream, "There are no item types"); + foreach (ItemType* itemType, m_itemTypes) + { + if (!itemType->isValid(stream)) + setValid(false); + if (idChecker.contains(itemType->id())) + subclassError(stream, "item type", itemType->id()); + idChecker.insert(itemType->id()); + if (nameChecker.contains(itemType->name())) + subclassError(stream, "item type", itemType->name()); + nameChecker.insert(itemType->name()); + } + idChecker.clear(); + nameChecker.clear(); + if (!mapCount()) + error(stream, "There are no maps"); + foreach (Map* map, m_maps) + { + if (!map->isValid(stream)) + setValid(false); + if (idChecker.contains(map->id())) + subclassError(stream, "map", map->id()); + idChecker.insert(map->id()); + if (nameChecker.contains(map->name())) + subclassError(stream, "map", map->name()); + nameChecker.insert(map->name()); + } + idChecker.clear(); + nameChecker.clear(); + if (!moveCount()) + error(stream, "There are no moves"); + foreach (Move* move, m_moves) + { + if (!move->isValid(stream)) + setValid(false); + if (idChecker.contains(move->id())) + subclassError(stream, "move", move->id()); + idChecker.insert(move->id()); + if (nameChecker.contains(move->name())) + subclassError(stream, "move", move->name()); + nameChecker.insert(move->name()); + } + idChecker.clear(); + nameChecker.clear(); + if (m_rules.natureAllowed()) + { + if (!natureCount()) + error(stream, "There are no natures"); + foreach (Nature* nature, m_natures) + { + if (!nature->isValid(stream)) + setValid(false); + if (idChecker.contains(nature->id())) + subclassError(stream, "ability", nature->id()); + idChecker.insert(nature->id()); + } + idChecker.clear(); + nameChecker.clear(); + } + if (!speciesCount()) + error(stream, "There are no species"); + foreach (Species* m_species, m_species) + { + if (!m_species->isValid(stream)) + setValid(false); + if (idChecker.contains(m_species->id())) + subclassError(stream, "species", m_species->id()); + idChecker.insert(m_species->id()); + if (nameChecker.contains(m_species->name())) + subclassError(stream, "species", m_species->name()); + nameChecker.insert(m_species->name()); + } + idChecker.clear(); + nameChecker.clear(); + if (!storeCount()) + warning(stream, "There are no stores"); + foreach (Store* store, m_stores) + { + if (!store->isValid(stream)) + setValid(false); + if (idChecker.contains(store->id())) + subclassError(stream, "store", store->id()); + idChecker.insert(store->id()); + if (nameChecker.contains(store->name())) + subclassError(stream, "store", store->name()); + nameChecker.insert(store->name()); + } + idChecker.clear(); + nameChecker.clear(); + if (!tileCount()) + error(stream, "There are no tiles"); + foreach (Tile* tile, m_tiles) + { + if (!tile->isValid(stream)) + setValid(false); + if (idChecker.contains(tile->id())) + subclassError(stream, "tile", tile->id()); + idChecker.insert(tile->id()); + if (nameChecker.contains(tile->name())) + subclassError(stream, "tile", tile->name()); + nameChecker.insert(tile->name()); + } + idChecker.clear(); + nameChecker.clear(); + if (!trainerCount()) + warning(stream, "There are no trainers"); + foreach (Trainer* trainer, m_trainers) + { + if (!trainer->isValid(stream)) + setValid(false); + if (idChecker.contains(trainer->id())) + subclassError(stream, "trainer", trainer->id()); + idChecker.insert(trainer->id()); + if (nameChecker.contains(trainer->name())) + subclassError(stream, "trainer", trainer->name()); + nameChecker.insert(trainer->name()); + } + idChecker.clear(); + nameChecker.clear(); + if (!timeCount()) + error(stream, "There are no times"); + foreach (Time* time, m_times) + { + if (!time->isValid(stream)) + setValid(false); + if (idChecker.contains(time->id())) + subclassError(stream, "time", time->id()); + idChecker.insert(time->id()); + if (nameChecker.contains(time->name())) + subclassError(stream, "time", time->name()); + nameChecker.insert(time->name()); + if (timeChecker.contains((60 * time->hour()) + time->minute())) + subclassError(stream, "time", QString("%1:%2").arg(time->hour()).arg(time->minute())); + timeChecker.insert((60 * time->hour()) + time->minute()); + } + idChecker.clear(); + nameChecker.clear(); + if (!typeCount()) + error(stream, "There are no types"); + foreach (Type* type, m_types) + { + if (!type->isValid(stream)) + setValid(false); + if (idChecker.contains(type->id())) + subclassError(stream, "type", type->id()); + idChecker.insert(type->id()); + if (nameChecker.contains(type->name())) + subclassError(stream, "type", type->name()); + nameChecker.insert(type->name()); + } +} + +void Pokemod::load(const QDomElement& xml, const int) { clear(); LOAD(QString, title); @@ -454,25 +456,6 @@ int Pokemod::maxCompatability(const Pokemod& pokemod) const // TODO: MaxCompatability between two versions } -void Pokemod::validationMsg(const QString& message, const Validation level) const throw(Exception) -{ - if (!valOutput) - throw(Exception(className(), "valOutput isn\'t set")); - if (V_End < level) - warning<BoundsException>("level"); - (*valOutput) << ValidationStr[level] << ": " << message; -} - -void Pokemod::setValOutput(QStringList& s) -{ - valOutput = &s; -} - -void Pokemod::unsetValOutput() -{ - valOutput = NULL; -} - void Pokemod::setTitle(const QString& title) { m_title = title; @@ -488,61 +471,88 @@ void Pokemod::setDescription(const QString& description) m_description = description; } -void Pokemod::setStartMap(const int startMap) throw(BoundsException) +void Pokemod::setStartMap(const int startMap) { if (mapIndex(startMap) == INT_MAX) - error<BoundsException>("startMap"); + { + boundsError("startMap"); + return; + } m_startMap = startMap; } -void Pokemod::setStartWarp(const int startWarp) throw(BoundsException) +void Pokemod::setStartWarp(const int startWarp) { if (mapIndex(m_startMap) == INT_MAX) - error<BoundsException>("startMap"); + { + boundsError("startMap"); + return; + } if (mapById(m_startMap)->warpIndex(startWarp) == INT_MAX) - error<BoundsException>("startWarp"); + { + boundsError("startWarp"); + return; + } m_startWarp = startWarp; } -void Pokemod::setWalkSkin(const QPixmap& walkSkin) throw(SizeException) +void Pokemod::setWalkSkin(const QPixmap& walkSkin) { if (walkSkin.size() != QSize(192, 128)) - error<SizeException>("walkSkin"); + { + sizeError("walkSkin"); + return; + } m_walkSkin = walkSkin; } -void Pokemod::setBikeSkin(const QPixmap& bikeSkin) throw(SizeException) +void Pokemod::setBikeSkin(const QPixmap& bikeSkin) { if (bikeSkin.size() != QSize(192, 128)) - error<SizeException>("bikeSkin"); + { + sizeError("bikeSkin"); + return; + } m_bikeSkin = bikeSkin; } -void Pokemod::setSurfSkin(const QPixmap& surfSkin) throw(SizeException) +void Pokemod::setSurfSkin(const QPixmap& surfSkin) { if (surfSkin.size() != QSize(192, 128)) - error<SizeException>("surfSkin"); + { + sizeError("surfSkin"); + return; + } m_surfSkin = surfSkin; } -void Pokemod::setFlySkin(const QPixmap& flySkin) throw(SizeException) +void Pokemod::setFlySkin(const QPixmap& flySkin) { if (flySkin.size() != QSize(192, 128)) - error<SizeException>("flySkin"); + { + sizeError("flySkin"); + return; + } m_flySkin = flySkin; } -void Pokemod::setFishSkin(const QPixmap& fishSkin) throw(SizeException) +void Pokemod::setFishSkin(const QPixmap& fishSkin) { if (fishSkin.size() != QSize(192, 128)) - error<SizeException>("fishSkin"); + { + sizeError("fishSkin"); + return; + } m_fishSkin = fishSkin; } -void Pokemod::setSurfFishSkin(const QPixmap& surfFishSkin) throw(SizeException) +void Pokemod::setSurfFishSkin(const QPixmap& surfFishSkin) { if (surfFishSkin.size() != QSize(192, 128)) - error<SizeException>("surfFishSkin"); + { + sizeError("surfFishSkin"); + return; + } m_surfFishSkin = surfFishSkin; } @@ -558,7 +568,7 @@ void Pokemod::setSuperPCPasswd(const QString& password) void Pokemod::setTypeChart(const int attack, const int defense, const Fraction& multiplier) { - m_typeChart(attack, defense) = multiplier; + m_typeChart.set(attack, defense, multiplier); } void Pokemod::setRules(const Rules& rules) @@ -661,26 +671,26 @@ Rules* Pokemod::rules() return &m_rules; } -const Ability* Pokemod::ability(const int index) const throw(IndexException) +const Ability* Pokemod::ability(const int index) const { if (abilityCount() <= index) - warning<IndexException>("ability"); + return NULL; return m_abilities.at(index); } -Ability* Pokemod::ability(const int index) throw(IndexException) +Ability* Pokemod::ability(const int index) { if (abilityCount() <= index) - error<IndexException>("ability"); + return NULL; return m_abilities[index]; } -const Ability* Pokemod::abilityById(const int id) const throw(IndexException) +const Ability* Pokemod::abilityById(const int id) const { return ability(abilityIndex(id)); } -Ability* Pokemod::abilityById(const int id) throw(IndexException) +Ability* Pokemod::abilityById(const int id) { return ability(abilityIndex(id)); } @@ -721,15 +731,15 @@ Ability* Pokemod::newAbility(Ability* ability) return ability; } -void Pokemod::deleteAbility(const int index) throw(IndexException) +void Pokemod::deleteAbility(const int index) { if (abilityCount() <= index) - error<IndexException>("ability"); + return; delete m_abilities[index]; m_abilities.removeAt(index); } -void Pokemod::deleteAbilityById(const int id) throw(IndexException) +void Pokemod::deleteAbilityById(const int id) { deleteAbility(abilityIndex(id)); } @@ -742,26 +752,26 @@ int Pokemod::newAbilityId() const return i; } -const Author* Pokemod::author(const int index) const throw(IndexException) +const Author* Pokemod::author(const int index) const { if (authorCount() <= index) - warning<IndexException>("author"); + return NULL; return m_authors.at(index); } -Author* Pokemod::author(const int index) throw(IndexException) +Author* Pokemod::author(const int index) { if (authorCount() <= index) - error<IndexException>("author"); + return NULL; return m_authors[index]; } -const Author* Pokemod::authorById(const int id) const throw(IndexException) +const Author* Pokemod::authorById(const int id) const { return author(authorIndex(id)); } -Author* Pokemod::authorById(const int id) throw(IndexException) +Author* Pokemod::authorById(const int id) { return author(authorIndex(id)); } @@ -802,15 +812,15 @@ Author* Pokemod::newAuthor(Author* author) return author; } -void Pokemod::deleteAuthor(const int index) throw(IndexException) +void Pokemod::deleteAuthor(const int index) { if (authorCount() <= index) - error<IndexException>("author"); + return; delete m_authors[index]; m_authors.removeAt(index); } -void Pokemod::deleteAuthorById(const int id) throw(IndexException) +void Pokemod::deleteAuthorById(const int id) { deleteAuthor(authorIndex(id)); } @@ -823,26 +833,26 @@ int Pokemod::newAuthorId() const return i; } -const Badge* Pokemod::badge(const int index) const throw(IndexException) +const Badge* Pokemod::badge(const int index) const { if (badgeCount() <= index) - warning<IndexException>("badge"); + return NULL; return m_badges.at(index); } -Badge* Pokemod::badge(const int index) throw(IndexException) +Badge* Pokemod::badge(const int index) { if (badgeCount() <= index) - error<IndexException>("badge"); + return NULL; return m_badges[index]; } -const Badge* Pokemod::badgeById(const int id) const throw(IndexException) +const Badge* Pokemod::badgeById(const int id) const { return badge(badgeIndex(id)); } -Badge* Pokemod::badgeById(const int id) throw(IndexException) +Badge* Pokemod::badgeById(const int id) { return badge(badgeIndex(id)); } @@ -883,15 +893,15 @@ Badge* Pokemod::newBadge(Badge* badge) return badge; } -void Pokemod::deleteBadge(const int index) throw(IndexException) +void Pokemod::deleteBadge(const int index) { if (badgeCount() <= index) - error<IndexException>("badge"); + return; delete m_badges[index]; m_badges.removeAt(index); } -void Pokemod::deleteBadgeById(const int id) throw(IndexException) +void Pokemod::deleteBadgeById(const int id) { deleteBadge(badgeIndex(id)); } @@ -904,26 +914,26 @@ int Pokemod::newBadgeId() const return i; } -const CoinList* Pokemod::coinList(const int index) const throw(IndexException) +const CoinList* Pokemod::coinList(const int index) const { if (coinListCount() <= index) - warning<IndexException>("coin list"); + return NULL; return m_coinLists.at(index); } -CoinList* Pokemod::coinList(const int index) throw(IndexException) +CoinList* Pokemod::coinList(const int index) { if (coinListCount() <= index) - error<IndexException>("coin list"); + return NULL; return m_coinLists[index]; } -const CoinList* Pokemod::coinListById(const int id) const throw(IndexException) +const CoinList* Pokemod::coinListById(const int id) const { return coinList(coinListIndex(id)); } -CoinList* Pokemod::coinListById(const int id) throw(IndexException) +CoinList* Pokemod::coinListById(const int id) { return coinList(coinListIndex(id)); } @@ -964,15 +974,15 @@ CoinList* Pokemod::newCoinList(CoinList* coinList) return coinList; } -void Pokemod::deleteCoinList(const int index) throw(IndexException) +void Pokemod::deleteCoinList(const int index) { if (coinListCount() <= index) - error<IndexException>("coin list"); + return; delete m_coinLists[index]; m_coinLists.removeAt(index); } -void Pokemod::deleteCoinListById(const int id) throw(IndexException) +void Pokemod::deleteCoinListById(const int id) { deleteCoinList(coinListIndex(id)); } @@ -985,26 +995,26 @@ int Pokemod::newCoinListId() const return i; } -const Dialog* Pokemod::dialog(const int index) const throw(IndexException) +const Dialog* Pokemod::dialog(const int index) const { if (dialogCount() <= index) - warning<IndexException>("dialog"); + return NULL; return m_dialogs.at(index); } -Dialog* Pokemod::dialog(const int index) throw(IndexException) +Dialog* Pokemod::dialog(const int index) { if (dialogCount() <= index) - error<IndexException>("dialog"); + return NULL; return m_dialogs[index]; } -const Dialog* Pokemod::dialogById(const int id) const throw(IndexException) +const Dialog* Pokemod::dialogById(const int id) const { return dialog(dialogIndex(id)); } -Dialog* Pokemod::dialogById(const int id) throw(IndexException) +Dialog* Pokemod::dialogById(const int id) { return dialog(dialogIndex(id)); } @@ -1045,15 +1055,15 @@ Dialog* Pokemod::newDialog(Dialog* dialog) return dialog; } -void Pokemod::deleteDialog(const int index) throw(IndexException) +void Pokemod::deleteDialog(const int index) { if (dialogCount() <= index) - error<IndexException>("dialog"); + return; delete m_dialogs[index]; m_dialogs.removeAt(index); } -void Pokemod::deleteDialogById(const int id) throw(IndexException) +void Pokemod::deleteDialogById(const int id) { deleteDialog(dialogIndex(id)); } @@ -1066,26 +1076,26 @@ int Pokemod::newDialogId() const return i; } -const EggGroup* Pokemod::eggGroup(const int index) const throw(IndexException) +const EggGroup* Pokemod::eggGroup(const int index) const { if (eggGroupCount() <= index) - warning<IndexException>("egg group"); + return NULL; return m_eggGroups.at(index); } -EggGroup* Pokemod::eggGroup(const int index) throw(IndexException) +EggGroup* Pokemod::eggGroup(const int index) { if (eggGroupCount() <= index) - error<IndexException>("egg group"); + return NULL; return m_eggGroups[index]; } -const EggGroup* Pokemod::eggGroupById(const int id) const throw(IndexException) +const EggGroup* Pokemod::eggGroupById(const int id) const { return eggGroup(eggGroupIndex(id)); } -EggGroup* Pokemod::eggGroupById(const int id) throw(IndexException) +EggGroup* Pokemod::eggGroupById(const int id) { return eggGroup(eggGroupIndex(id)); } @@ -1126,15 +1136,15 @@ EggGroup* Pokemod::newEggGroup(EggGroup* eggGroup) return eggGroup; } -void Pokemod::deleteEggGroup(const int index) throw(IndexException) +void Pokemod::deleteEggGroup(const int index) { if (eggGroupCount() <= index) - error<IndexException>("egg group"); + return; delete m_eggGroups[index]; m_eggGroups.removeAt(index); } -void Pokemod::deleteEggGroupById(const int id) throw(IndexException) +void Pokemod::deleteEggGroupById(const int id) { deleteEggGroup(eggGroupIndex(id)); } @@ -1147,26 +1157,26 @@ int Pokemod::newEggGroupId() const return i; } -const Item* Pokemod::item(const int index) const throw(IndexException) +const Item* Pokemod::item(const int index) const { if (itemCount() <= index) - warning<IndexException>("item"); + return NULL; return m_items.at(index); } -Item* Pokemod::item(const int index) throw(IndexException) +Item* Pokemod::item(const int index) { if (itemCount() <= index) - error<IndexException>("item"); + return NULL; return m_items[index]; } -const Item* Pokemod::itemById(const int id) const throw(IndexException) +const Item* Pokemod::itemById(const int id) const { return item(itemIndex(id)); } -Item* Pokemod::itemById(const int id) throw(IndexException) +Item* Pokemod::itemById(const int id) { return item(itemIndex(id)); } @@ -1207,15 +1217,15 @@ Item* Pokemod::newItem(Item* item) return item; } -void Pokemod::deleteItem(const int index) throw(IndexException) +void Pokemod::deleteItem(const int index) { if (itemCount() <= index) - error<IndexException>("item"); + return; delete m_items[index]; m_items.removeAt(index); } -void Pokemod::deleteItemById(const int id) throw(IndexException) +void Pokemod::deleteItemById(const int id) { deleteItem(itemIndex(id)); } @@ -1228,26 +1238,26 @@ int Pokemod::newItemId() const return i; } -const ItemType* Pokemod::itemType(const int index) const throw(IndexException) +const ItemType* Pokemod::itemType(const int index) const { if (itemTypeCount() <= index) - warning<IndexException>("item type"); + return NULL; return m_itemTypes.at(index); } -ItemType* Pokemod::itemType(const int index) throw(IndexException) +ItemType* Pokemod::itemType(const int index) { if (itemTypeCount() <= index) - error<IndexException>("item type"); + return NULL; return m_itemTypes[index]; } -const ItemType* Pokemod::itemTypeById(const int id) const throw(IndexException) +const ItemType* Pokemod::itemTypeById(const int id) const { return itemType(itemTypeIndex(id)); } -ItemType* Pokemod::itemTypeById(const int id) throw(IndexException) +ItemType* Pokemod::itemTypeById(const int id) { return itemType(itemTypeIndex(id)); } @@ -1288,15 +1298,15 @@ ItemType* Pokemod::newItemType(ItemType* itemType) return itemType; } -void Pokemod::deleteItemType(const int index) throw(IndexException) +void Pokemod::deleteItemType(const int index) { if (itemTypeCount() <= index) - error<IndexException>("item type"); + return; delete m_itemTypes[index]; m_itemTypes.removeAt(index); } -void Pokemod::deleteItemTypeById(const int id) throw(IndexException) +void Pokemod::deleteItemTypeById(const int id) { deleteItemType(itemTypeIndex(id)); } @@ -1309,26 +1319,26 @@ int Pokemod::newItemTypeId() const return i; } -const Map* Pokemod::map(const int index) const throw(IndexException) +const Map* Pokemod::map(const int index) const { if (mapCount() <= index) - warning<IndexException>("map"); + return NULL; return m_maps.at(index); } -Map* Pokemod::map(const int index) throw(IndexException) +Map* Pokemod::map(const int index) { if (mapCount() <= index) - error<IndexException>("map"); + return NULL; return m_maps[index]; } -const Map* Pokemod::mapById(const int id) const throw(IndexException) +const Map* Pokemod::mapById(const int id) const { return map(mapIndex(id)); } -Map* Pokemod::mapById(const int id) throw(IndexException) +Map* Pokemod::mapById(const int id) { return map(mapIndex(id)); } @@ -1369,15 +1379,15 @@ Map* Pokemod::newMap(Map* map) return map; } -void Pokemod::deleteMap(const int index) throw(IndexException) +void Pokemod::deleteMap(const int index) { if (mapCount() <= index) - error<IndexException>("map"); + return; delete m_maps[index]; m_maps.removeAt(index); } -void Pokemod::deleteMapById(const int id) throw(IndexException) +void Pokemod::deleteMapById(const int id) { deleteMap(mapIndex(id)); } @@ -1390,26 +1400,26 @@ int Pokemod::newMapId() const return i; } -const Move* Pokemod::move(const int index) const throw(IndexException) +const Move* Pokemod::move(const int index) const { if (moveCount() <= index) - warning<IndexException>("move"); + return NULL; return m_moves.at(index); } -Move* Pokemod::move(const int index) throw(IndexException) +Move* Pokemod::move(const int index) { if (moveCount() <= index) - error<IndexException>("move"); + return NULL; return m_moves[index]; } -const Move* Pokemod::moveById(const int id) const throw(IndexException) +const Move* Pokemod::moveById(const int id) const { return move(moveIndex(id)); } -Move* Pokemod::moveById(const int id) throw(IndexException) +Move* Pokemod::moveById(const int id) { return move(moveIndex(id)); } @@ -1450,15 +1460,15 @@ Move* Pokemod::newMove(Move* move) return move; } -void Pokemod::deleteMove(const int index) throw(IndexException) +void Pokemod::deleteMove(const int index) { if (moveCount() <= index) - error<IndexException>("move"); + return; delete m_moves[index]; m_moves.removeAt(index); } -void Pokemod::deleteMoveById(const int id) throw(IndexException) +void Pokemod::deleteMoveById(const int id) { deleteMove(moveIndex(id)); } @@ -1471,26 +1481,26 @@ int Pokemod::newMoveId() const return i; } -const Nature* Pokemod::nature(const int index) const throw(IndexException) +const Nature* Pokemod::nature(const int index) const { if (natureCount() <= index) - warning<IndexException>("nature"); + return NULL; return m_natures.at(index); } -Nature* Pokemod::nature(const int index) throw(IndexException) +Nature* Pokemod::nature(const int index) { if (natureCount() <= index) - error<IndexException>("nature"); + return NULL; return m_natures[index]; } -const Nature* Pokemod::natureById(const int id) const throw(IndexException) +const Nature* Pokemod::natureById(const int id) const { return nature(natureIndex(id)); } -Nature* Pokemod::natureById(const int id) throw(IndexException) +Nature* Pokemod::natureById(const int id) { return nature(natureIndex(id)); } @@ -1531,15 +1541,15 @@ Nature* Pokemod::newNature(Nature* nature) return nature; } -void Pokemod::deleteNature(const int index) throw(IndexException) +void Pokemod::deleteNature(const int index) { if (natureCount() <= index) - error<IndexException>("nature"); + return; delete m_natures[index]; m_natures.removeAt(index); } -void Pokemod::deleteNatureById(const int id) throw(IndexException) +void Pokemod::deleteNatureById(const int id) { deleteNature(natureIndex(id)); } @@ -1552,26 +1562,26 @@ int Pokemod::newNatureId() const return i; } -const Species* Pokemod::species(const int index) const throw(IndexException) +const Species* Pokemod::species(const int index) const { if (speciesCount() <= index) - warning<IndexException>("species"); + return NULL; return m_species.at(index); } -Species* Pokemod::species(const int index) throw(IndexException) +Species* Pokemod::species(const int index) { if (speciesCount() <= index) - error<IndexException>("species"); + return NULL; return m_species[index]; } -const Species* Pokemod::speciesById(const int id) const throw(IndexException) +const Species* Pokemod::speciesById(const int id) const { return species(speciesIndex(id)); } -Species* Pokemod::speciesById(const int id) throw(IndexException) +Species* Pokemod::speciesById(const int id) { return species(speciesIndex(id)); } @@ -1612,15 +1622,15 @@ Species* Pokemod::newSpecies(Species* species) return species; } -void Pokemod::deleteSpecies(const int index) throw(IndexException) +void Pokemod::deleteSpecies(const int index) { if (speciesCount() <= index) - error<IndexException>("species"); + return; delete m_species[index]; m_species.removeAt(index); } -void Pokemod::deleteSpeciesById(const int id) throw(IndexException) +void Pokemod::deleteSpeciesById(const int id) { deleteSpecies(speciesIndex(id)); } @@ -1633,26 +1643,26 @@ int Pokemod::newSpeciesId() const return i; } -const Store* Pokemod::store(const int index) const throw(IndexException) +const Store* Pokemod::store(const int index) const { if (storeCount() <= index) - warning<IndexException>("store"); + return NULL; return m_stores.at(index); } -Store* Pokemod::store(const int index) throw(IndexException) +Store* Pokemod::store(const int index) { if (storeCount() <= index) - error<IndexException>("store"); + return NULL; return m_stores[index]; } -const Store* Pokemod::storeById(const int id) const throw(IndexException) +const Store* Pokemod::storeById(const int id) const { return store(storeIndex(id)); } -Store* Pokemod::storeById(const int id) throw(IndexException) +Store* Pokemod::storeById(const int id) { return store(storeIndex(id)); } @@ -1693,15 +1703,15 @@ Store* Pokemod::newStore(Store* store) return store; } -void Pokemod::deleteStore(const int index) throw(IndexException) +void Pokemod::deleteStore(const int index) { if (storeCount() <= index) - error<IndexException>("store"); + return; delete m_stores[index]; m_stores.removeAt(index); } -void Pokemod::deleteStoreById(const int id) throw(IndexException) +void Pokemod::deleteStoreById(const int id) { deleteStore(storeIndex(id)); } @@ -1714,26 +1724,26 @@ int Pokemod::newStoreId() const return i; } -const Tile* Pokemod::tile(const int index) const throw(IndexException) +const Tile* Pokemod::tile(const int index) const { if (tileCount() <= index) - warning<IndexException>("tile"); + return NULL; return m_tiles.at(index); } -Tile* Pokemod::tile(const int index) throw(IndexException) +Tile* Pokemod::tile(const int index) { if (tileCount() <= index) - error<IndexException>("tile"); + return NULL; return m_tiles[index]; } -const Tile* Pokemod::tileById(const int id) const throw(IndexException) +const Tile* Pokemod::tileById(const int id) const { return tile(tileIndex(id)); } -Tile* Pokemod::tileById(const int id) throw(IndexException) +Tile* Pokemod::tileById(const int id) { return tile(tileIndex(id)); } @@ -1774,15 +1784,15 @@ Tile* Pokemod::newTile(Tile* tile) return tile; } -void Pokemod::deleteTile(const int index) throw(IndexException) +void Pokemod::deleteTile(const int index) { if (tileCount() <= index) - error<IndexException>("tile"); + return; delete m_tiles[index]; m_tiles.removeAt(index); } -void Pokemod::deleteTileById(const int id) throw(IndexException) +void Pokemod::deleteTileById(const int id) { deleteTile(tileIndex(id)); } @@ -1795,26 +1805,26 @@ int Pokemod::newTileId() const return i; } -const Time* Pokemod::time(const int index) const throw(IndexException) +const Time* Pokemod::time(const int index) const { if (timeCount() <= index) - warning<IndexException>("time"); + return NULL; return m_times.at(index); } -Time* Pokemod::time(const int i) throw(IndexException) +Time* Pokemod::time(const int i) { if (timeCount() <= i) - error<IndexException>("time"); + return NULL; return m_times[i]; } -const Time* Pokemod::timeById(const int id) const throw(IndexException) +const Time* Pokemod::timeById(const int id) const { return time(timeIndex(id)); } -Time* Pokemod::timeById(const int id) throw(IndexException) +Time* Pokemod::timeById(const int id) { return time(timeIndex(id)); } @@ -1855,15 +1865,15 @@ Time* Pokemod::newTime(Time* time) return time; } -void Pokemod::deleteTime(const int index) throw(IndexException) +void Pokemod::deleteTime(const int index) { if (timeCount() <= index) - error<IndexException>("time"); + return; delete m_times[index]; m_times.removeAt(index); } -void Pokemod::deleteTimeById(const int id) throw(IndexException) +void Pokemod::deleteTimeById(const int id) { deleteTime(timeIndex(id)); } @@ -1876,26 +1886,26 @@ int Pokemod::newTimeId() const return i; } -const Trainer* Pokemod::trainer(const int index) const throw(IndexException) +const Trainer* Pokemod::trainer(const int index) const { if (trainerCount() <= index) - warning<IndexException>("trainer"); + return NULL; return m_trainers.at(index); } -Trainer* Pokemod::trainer(const int index) throw(IndexException) +Trainer* Pokemod::trainer(const int index) { if (trainerCount() <= index) - error<IndexException>("trainer"); + return NULL; return m_trainers[index]; } -const Trainer* Pokemod::trainerById(const int id) const throw(IndexException) +const Trainer* Pokemod::trainerById(const int id) const { return trainer(trainerIndex(id)); } -Trainer* Pokemod::trainerById(const int id) throw(IndexException) +Trainer* Pokemod::trainerById(const int id) { return trainer(trainerIndex(id)); } @@ -1936,15 +1946,15 @@ Trainer* Pokemod::newTrainer(Trainer* trainer) return trainer; } -void Pokemod::deleteTrainer(const int index) throw(IndexException) +void Pokemod::deleteTrainer(const int index) { if (trainerCount() <= index) - error<IndexException>("trainer"); + return; delete m_trainers[index]; m_trainers.removeAt(index); } -void Pokemod::deleteTrainerById(const int id) throw(IndexException) +void Pokemod::deleteTrainerById(const int id) { deleteTrainer(trainerIndex(id)); } @@ -1957,26 +1967,26 @@ int Pokemod::newTrainerId() const return i; } -const Type* Pokemod::type(const int index) const throw(IndexException) +const Type* Pokemod::type(const int index) const { if (typeCount() <= index) - warning<IndexException>("type"); + return NULL; return m_types.at(index); } -Type* Pokemod::type(const int index) throw(IndexException) +Type* Pokemod::type(const int index) { if (typeCount() <= index) - error<IndexException>("type"); + return NULL; return m_types[index]; } -const Type* Pokemod::typeById(const int id) const throw(IndexException) +const Type* Pokemod::typeById(const int id) const { return type(typeIndex(id)); } -Type* Pokemod::typeById(const int id) throw(IndexException) +Type* Pokemod::typeById(const int id) { return type(typeIndex(id)); } @@ -2024,10 +2034,10 @@ Type* Pokemod::newType(Type* type) return type; } -void Pokemod::deleteType(const int index) throw(IndexException) +void Pokemod::deleteType(const int index) { if (typeCount() <= index) - error<IndexException>("type"); + return; delete m_types[index]; if (typeCount() == 1) m_typeChart.deleteColumn(index); @@ -2039,7 +2049,7 @@ void Pokemod::deleteType(const int index) throw(IndexException) m_types.removeAt(index); } -void Pokemod::deleteTypeById(const int id) throw(IndexException) +void Pokemod::deleteTypeById(const int id) { deleteType(typeIndex(id)); } diff --git a/pokemod/Pokemod.h b/pokemod/Pokemod.h index 9acc1bb7..09bb2607 100644 --- a/pokemod/Pokemod.h +++ b/pokemod/Pokemod.h @@ -23,7 +23,6 @@ #include "Rules.h" // General includes -#include "../general/Exception.h" #include "../general/Fraction.h" #include "../general/Matrix.h" #include "../general/Point.h" @@ -164,26 +163,22 @@ class Pokemod : public Object Pokemod(const QDomElement& xml); ~Pokemod(); - void load(const QDomElement& xml, const int = 0) throw(Exception); + void load(const QDomElement& xml, const int = 0); QDomElement save() const; int maxCompatability(const Pokemod& rhs) const; - void validationMsg(const QString& msg, Validation val = V_Error) const throw(Exception); - void setValOutput(QStringList& s); - void unsetValOutput(); - void setTitle(const QString& title); void setVersion(const QString& version); void setDescription(const QString& description); - void setStartMap(const int startMap) throw(BoundsException); - void setStartWarp(const int startWarp) throw(BoundsException); - void setWalkSkin(const QPixmap& walkSkin) throw(SizeException); - void setBikeSkin(const QPixmap& bikeSkin) throw(SizeException); - void setSurfSkin(const QPixmap& surfSkin) throw(SizeException); - void setFlySkin(const QPixmap& slySkin) throw(SizeException); - void setFishSkin(const QPixmap& fishSkin) throw(SizeException); - void setSurfFishSkin(const QPixmap& surfFishSkin) throw(SizeException); + void setStartMap(const int startMap); + void setStartWarp(const int startWarp); + void setWalkSkin(const QPixmap& walkSkin); + void setBikeSkin(const QPixmap& bikeSkin); + void setSurfSkin(const QPixmap& surfSkin); + void setFlySkin(const QPixmap& slySkin); + void setFishSkin(const QPixmap& fishSkin); + void setSurfFishSkin(const QPixmap& surfFishSkin); void setSuperPCUname(const QString& username); void setSuperPCPasswd(const QString& password); void setTypeChart(const int attack, const int defense, const Fraction& multiplier); @@ -209,215 +204,213 @@ class Pokemod : public Object const Rules* rules() const; Rules* rules(); - const Ability* ability(const int index) const throw(IndexException); - Ability* ability(const int index) throw(IndexException); - const Ability* abilityById(const int id) const throw(IndexException); - Ability* abilityById(const int id) throw(IndexException); + const Ability* ability(const int index) const; + Ability* ability(const int index); + const Ability* abilityById(const int id) const; + Ability* abilityById(const int id); int abilityIndex(const int id) const; int abilityCount() const; Ability* newAbility(); Ability* newAbility(const QDomElement& xml); Ability* newAbility(const Ability& ability); - void deleteAbility(const int index) throw(IndexException); - void deleteAbilityById(const int id) throw(IndexException); + void deleteAbility(const int index); + void deleteAbilityById(const int id); - const Author* author(const int index) const throw(IndexException); - Author* author(const int index) throw(IndexException); - const Author* authorById(const int id) const throw(IndexException); - Author* authorById(const int id) throw(IndexException); + const Author* author(const int index) const; + Author* author(const int index); + const Author* authorById(const int id) const; + Author* authorById(const int id); int authorIndex(const int id) const; int authorCount() const; Author* newAuthor(); Author* newAuthor(const QDomElement& xml); Author* newAuthor(const Author& author); - void deleteAuthor(const int index) throw(IndexException); - void deleteAuthorById(const int id) throw(IndexException); + void deleteAuthor(const int index); + void deleteAuthorById(const int id); - const Badge* badge(const int index) const throw(IndexException); - Badge* badge(const int index) throw(IndexException); - const Badge* badgeById(const int id) const throw(IndexException); - Badge* badgeById(const int id) throw(IndexException); + const Badge* badge(const int index) const; + Badge* badge(const int index); + const Badge* badgeById(const int id) const; + Badge* badgeById(const int id); int badgeIndex(const int id) const; int badgeCount() const; Badge* newBadge(); Badge* newBadge(const QDomElement& xml); Badge* newBadge(const Badge& badge); - void deleteBadge(const int index) throw(IndexException); - void deleteBadgeById(const int id) throw(IndexException); + void deleteBadge(const int index); + void deleteBadgeById(const int id); - const CoinList* coinList(const int index) const throw(IndexException); - CoinList* coinList(const int index) throw(IndexException); - const CoinList* coinListById(const int id) const throw(IndexException); - CoinList* coinListById(const int id) throw(IndexException); + const CoinList* coinList(const int index) const; + CoinList* coinList(const int index); + const CoinList* coinListById(const int id) const; + CoinList* coinListById(const int id); int coinListIndex(const int id) const; int coinListCount() const; CoinList* newCoinList(); CoinList* newCoinList(const QDomElement& xml); CoinList* newCoinList(const CoinList& coinList); - void deleteCoinList(const int index) throw(IndexException); - void deleteCoinListById(const int id) throw(IndexException); + void deleteCoinList(const int index); + void deleteCoinListById(const int id); - const Dialog* dialog(const int index) const throw(IndexException); - Dialog* dialog(const int index) throw(IndexException); - const Dialog* dialogById(const int id) const throw(IndexException); - Dialog* dialogById(const int id) throw(IndexException); + const Dialog* dialog(const int index) const; + Dialog* dialog(const int index); + const Dialog* dialogById(const int id) const; + Dialog* dialogById(const int id); int dialogIndex(const int id) const; int dialogCount() const; Dialog* newDialog(); Dialog* newDialog(const QDomElement& xml); Dialog* newDialog(const Dialog& dialog); - void deleteDialog(const int index) throw(IndexException); - void deleteDialogById(const int id) throw(IndexException); + void deleteDialog(const int index); + void deleteDialogById(const int id); - const EggGroup* eggGroup(const int index) const throw(IndexException); - EggGroup* eggGroup(const int index) throw(IndexException); - const EggGroup* eggGroupById(const int id) const throw(IndexException); - EggGroup* eggGroupById(const int id) throw(IndexException); + const EggGroup* eggGroup(const int index) const; + EggGroup* eggGroup(const int index); + const EggGroup* eggGroupById(const int id) const; + EggGroup* eggGroupById(const int id); int eggGroupIndex(const int id) const; int eggGroupCount() const; EggGroup* newEggGroup(); EggGroup* newEggGroup(const QDomElement& xml); EggGroup* newEggGroup(const EggGroup& eggGroup); - void deleteEggGroup(const int index) throw(IndexException); - void deleteEggGroupById(const int id) throw(IndexException); + void deleteEggGroup(const int index); + void deleteEggGroupById(const int id); - const Item* item(const int index) const throw(IndexException); - Item* item(const int index) throw(IndexException); - const Item* itemById(const int id) const throw(IndexException); - Item* itemById(const int id) throw(IndexException); + const Item* item(const int index) const; + Item* item(const int index); + const Item* itemById(const int id) const; + Item* itemById(const int id); int itemIndex(const int id) const; int itemCount() const; Item* newItem(); Item* newItem(const QDomElement& xml); Item* newItem(const Item& item); - void deleteItem(const int index) throw(IndexException); - void deleteItemById(const int id) throw(IndexException); + void deleteItem(const int index); + void deleteItemById(const int id); - const ItemType* itemType(const int index) const throw(IndexException); - ItemType* itemType(const int index) throw(IndexException); - const ItemType* itemTypeById(const int id) const throw(IndexException); - ItemType* itemTypeById(const int id) throw(IndexException); + const ItemType* itemType(const int index) const; + ItemType* itemType(const int index); + const ItemType* itemTypeById(const int id) const; + ItemType* itemTypeById(const int id); int itemTypeIndex(const int id) const; int itemTypeCount() const; ItemType* newItemType(); ItemType* newItemType(const QDomElement& xml); ItemType* newItemType(const ItemType& itemType); - void deleteItemType(const int index) throw(IndexException); - void deleteItemTypeById(const int id) throw(IndexException); + void deleteItemType(const int index); + void deleteItemTypeById(const int id); - const Map* map(const int index) const throw(IndexException); - Map* map(const int index) throw(IndexException); - const Map* mapById(const int id) const throw(IndexException); - Map* mapById(const int id) throw(IndexException); + const Map* map(const int index) const; + Map* map(const int index); + const Map* mapById(const int id) const; + Map* mapById(const int id); int mapIndex(const int id) const; int mapCount() const; Map* newMap(); Map* newMap(const QDomElement& xml); Map* newMap(const Map& map); - void deleteMap(const int index) throw(IndexException); - void deleteMapById(const int id) throw(IndexException); + void deleteMap(const int index); + void deleteMapById(const int id); - const Move* move(const int index) const throw(IndexException); - Move* move(const int index) throw(IndexException); - const Move* moveById(const int id) const throw(IndexException); - Move* moveById(const int id) throw(IndexException); + const Move* move(const int index) const; + Move* move(const int index); + const Move* moveById(const int id) const; + Move* moveById(const int id); int moveIndex(const int id) const; int moveCount() const; Move* newMove(); Move* newMove(const QDomElement& xml); Move* newMove(const Move& move); - void deleteMove(const int index) throw(IndexException); - void deleteMoveById(const int id) throw(IndexException); + void deleteMove(const int index); + void deleteMoveById(const int id); - const Nature* nature(const int index) const throw(IndexException); - Nature* nature(const int index) throw(IndexException); - const Nature* natureById(const int id) const throw(IndexException); - Nature* natureById(const int id) throw(IndexException); + const Nature* nature(const int index) const; + Nature* nature(const int index); + const Nature* natureById(const int id) const; + Nature* natureById(const int id); int natureIndex(const int id) const; int natureCount() const; Nature* newNature(); Nature* newNature(const QDomElement& xml); Nature* newNature(const Nature& nature); - void deleteNature(const int index) throw(IndexException); - void deleteNatureById(const int id) throw(IndexException); + void deleteNature(const int index); + void deleteNatureById(const int id); - const Species* species(const int index) const throw(IndexException); - Species* species(const int index) throw(IndexException); - const Species* speciesById(const int id) const throw(IndexException); - Species* speciesById(const int id) throw(IndexException); + const Species* species(const int index) const; + Species* species(const int index); + const Species* speciesById(const int id) const; + Species* speciesById(const int id); int speciesIndex(const int id) const; int speciesCount() const; Species* newSpecies(); Species* newSpecies(const QDomElement& xml); Species* newSpecies(const Species& species); - void deleteSpecies(const int index) throw(IndexException); - void deleteSpeciesById(const int id) throw(IndexException); + void deleteSpecies(const int index); + void deleteSpeciesById(const int id); - const Store* store(const int index) const throw(IndexException); - Store* store(const int index) throw(IndexException); - const Store* storeById(const int id) const throw(IndexException); - Store* storeById(const int id) throw(IndexException); + const Store* store(const int index) const; + Store* store(const int index); + const Store* storeById(const int id) const; + Store* storeById(const int id); int storeIndex(const int id) const; int storeCount() const; Store* newStore(); Store* newStore(const QDomElement& xml); Store* newStore(const Store& store); - void deleteStore(const int index) throw(IndexException); - void deleteStoreById(const int id) throw(IndexException); + void deleteStore(const int index); + void deleteStoreById(const int id); - const Tile* tile(const int index) const throw(IndexException); - Tile* tile(const int index) throw(IndexException); - const Tile* tileById(const int id) const throw(IndexException); - Tile* tileById(const int id) throw(IndexException); + const Tile* tile(const int index) const; + Tile* tile(const int index); + const Tile* tileById(const int id) const; + Tile* tileById(const int id); int tileIndex(const int id) const; int tileCount() const; Tile* newTile(); Tile* newTile(const QDomElement& xml); Tile* newTile(const Tile& tile); - void deleteTile(const int index) throw(IndexException); - void deleteTileById(const int id) throw(IndexException); + void deleteTile(const int index); + void deleteTileById(const int id); - const Time* time(const int index) const throw(IndexException); - Time* time(const int index) throw(IndexException); - const Time* timeById(const int id) const throw(IndexException); - Time* timeById(const int id) throw(IndexException); + const Time* time(const int index) const; + Time* time(const int index); + const Time* timeById(const int id) const; + Time* timeById(const int id); int timeIndex(const int id) const; int timeCount() const; Time* newTime(); Time* newTime(const QDomElement& xml); Time* newTime(const Time& time); - void deleteTime(const int index) throw(IndexException); - void deleteTimeById(const int id) throw(IndexException); + void deleteTime(const int index); + void deleteTimeById(const int id); - const Trainer* trainer(const int index) const throw(IndexException); - Trainer* trainer(const int index) throw(IndexException); - const Trainer* trainerById(const int id) const throw(IndexException); - Trainer* trainerById(const int id) throw(IndexException); + const Trainer* trainer(const int index) const; + Trainer* trainer(const int index); + const Trainer* trainerById(const int id) const; + Trainer* trainerById(const int id); int trainerIndex(const int id) const; int trainerCount() const; Trainer* newTrainer(); Trainer* newTrainer(const QDomElement& xml); Trainer* newTrainer(const Trainer& trainer); - void deleteTrainer(const int index) throw(IndexException); - void deleteTrainerById(const int id) throw(IndexException); + void deleteTrainer(const int index); + void deleteTrainerById(const int id); - const Type* type(const int index) const throw(IndexException); - Type* type(const int index) throw(IndexException); - const Type* typeById(const int id) const throw(IndexException); - Type* typeById(const int id) throw(IndexException); + const Type* type(const int index) const; + Type* type(const int index); + const Type* typeById(const int id) const; + Type* typeById(const int id); int typeIndex(const int id) const; int typeCount() const; Type* newType(); Type* newType(const QDomElement& xml); Type* newType(const Type& type); - void deleteType(const int index) throw(IndexException); - void deleteTypeById(const int id) throw(IndexException); + void deleteType(const int index); + void deleteTypeById(const int id); Pokemod& operator=(const Pokemod& rhs); private: - QStringList* valOutput; - - bool validate() const; + void validate(QTextStream& stream); int newAbilityId() const; Ability* newAbility(Ability* ability); diff --git a/pokemod/Rules.cpp b/pokemod/Rules.cpp index 6c113e88..600bfdd5 100644 --- a/pokemod/Rules.cpp +++ b/pokemod/Rules.cpp @@ -72,59 +72,30 @@ Rules::Rules(const QDomElement& xml, const Object* parent) : load(xml); } -bool Rules::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg("---Rules", Pokemod::V_Msg); -// if (!m_numBoxes) -// static_cast<const Pokemod*>(pokemod())->validationMsg("No box storage", Pokemod::V_Warn); -// else if (!m_boxSize) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid box size"); -// valid = false; -// } -// if (!m_maxParty) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid party size"); -// valid = false; -// } -// if (!m_maxParty || (m_maxParty < m_maxFight)) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Larger active than party"); -// valid = false; -// } -// if (m_maxPlayers < 2) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Cannot have battles without at least two players"); -// valid = false; -// } -// if (!m_maxMoves) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("No moves can be learned"); -// valid = false; -// } -// if (!m_maxMoney) -// static_cast<const Pokemod*>(pokemod())->validationMsg("Player cannot carry any money", Pokemod::V_Warn); -// if (1 < m_maxDVValue) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid maximum DV value"); -// valid = false; -// } -// if (m_effortValuesAllowed) -// { -// if (m_maxTotalEV < m_maxEVPerStat) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("More EV points are allowed on a stat than allowed overall"); -// valid = false; -// } -// } -// if (.005 < m_pokerusChance) -// static_cast<const Pokemod*>(pokemod())->validationMsg("Pokérus chance is unusually high", Pokemod::V_Warn); -// return valid; -} - -void Rules::load(const QDomElement& xml, const int) throw(Exception) +void Rules::validate(QTextStream& stream) +{ + TEST_SETUP(); + TEST(setBreedingAllowed, breedingAllowed); + TEST(setNumBoxes, numBoxes); + TEST(setBoxSize, boxSize); + TEST(setMaxParty, maxParty); + TEST(setMaxFight, maxFight); + TEST(setMaxPlayers, maxPlayers); + TEST(setMaxMoves, maxMoves); + TEST(setMaxLevel, maxLevel); + if (!m_maxMoney) + warning(stream, "Player cannot carry any money"); + TEST(setMaxDVValue, maxDVValue); + if (m_effortValuesAllowed) + { + TEST(setMaxEVPerStat, maxEVPerStat); + } + TEST(setPokerusChance, pokerusChance); + if (.005 < m_pokerusChance) + warning(stream, "Pokerus chance is high"); +} + +void Rules::load(const QDomElement& xml, const int) { clear(); LOAD(bool, genderAllowed); @@ -194,6 +165,11 @@ void Rules::setGenderAllowed(const bool genderAllowed) void Rules::setBreedingAllowed(const bool breedingAllowed) { + if (!m_genderAllowed && breedingAllowed) + { + boundsError("breedingAllowed"); + return; + } m_breedingAllowed = breedingAllowed; } @@ -224,43 +200,61 @@ void Rules::setNumBoxes(const int numBoxes) void Rules::setBoxSize(const int boxSize) { + if (m_numBoxes && !boxSize) + { + boundsError("boxSize"); + return; + } m_boxSize = boxSize; } -void Rules::setMaxParty(const int maxParty) throw(BoundsException) +void Rules::setMaxParty(const int maxParty) { if (!maxParty) - error<BoundsException>("maxParty"); + { + boundsError("maxParty"); + return; + } m_maxParty = maxParty; - if (maxParty < m_maxFight) - setMaxFight(maxParty); } -void Rules::setMaxFight(const int maxFight) throw(BoundsException) +void Rules::setMaxFight(const int maxFight) { if (m_maxParty < maxFight) - error<BoundsException>("maxFight"); + { + boundsError("maxFight"); + return; + } m_maxFight = maxFight; } -void Rules::setMaxPlayers(const int maxPlayers) throw(BoundsException) +void Rules::setMaxPlayers(const int maxPlayers) { if (!maxPlayers) - error<BoundsException>("maxPlayers"); + { + boundsError("maxPlayers"); + return; + } m_maxPlayers = maxPlayers; } -void Rules::setMaxMoves(const int maxMoves) throw(BoundsException) +void Rules::setMaxMoves(const int maxMoves) { if (!maxMoves) - error<BoundsException>("maxMoves"); + { + boundsError("maxMoves"); + return; + } m_maxMoves = maxMoves; } -void Rules::setMaxLevel(const int maxLevel) throw(BoundsException) +void Rules::setMaxLevel(const int maxLevel) { if (!maxLevel) - error<BoundsException>("maxLevel"); + { + boundsError("maxLevel"); + return; + } m_maxLevel = maxLevel; } @@ -277,19 +271,25 @@ void Rules::setHardCash(const bool hardCash) void Rules::setSpecialSplit(const bool specialSplit) { m_specialSplit = specialSplit; - if (!specialSplit) - setSpecialDVSplit(false); } void Rules::setSpecialDVSplit(const bool specialDVSplit) { + if (specialDVSplit && m_specialSplit) + { + boundsError("specialDVSplit"); + return; + } m_specialDVSplit = specialDVSplit; } -void Rules::setMaxDVValue(const unsigned char maxDVValue) throw(BoundsException) +void Rules::setMaxDVValue(const unsigned char maxDVValue) { if (1 < maxDVValue) - error<BoundsException>("maxDVValue"); + { + boundsError("maxDVValue"); + return; + } m_maxDVValue = maxDVValue; } @@ -318,26 +318,33 @@ void Rules::setEffortValuesAllowed(const bool effortValuesAllowed) m_effortValuesAllowed = effortValuesAllowed; } -void Rules::setMaxTotalEV(const int maxTotalEV) throw(BoundsException) +void Rules::setMaxTotalEV(const int maxTotalEV) { if (!maxTotalEV) - error<BoundsException>("maxTotalEV"); + { + boundsError("maxTotalEV"); + return; + } m_maxTotalEV = maxTotalEV; - if (maxTotalEV < m_maxEVPerStat) - setMaxEVPerStat(maxTotalEV); } -void Rules::setMaxEVPerStat(const int maxEVPerStat) throw(BoundsException) +void Rules::setMaxEVPerStat(const int maxEVPerStat) { - if (!maxEVPerStat || (m_maxTotalEV < maxEVPerStat)) - error<BoundsException>("maxEVPerStat"); + if ((!maxEVPerStat && m_maxTotalEV) || (m_maxTotalEV < maxEVPerStat)) + { + boundsError("maxEVPerStat"); + return; + } m_maxEVPerStat = maxEVPerStat; } -void Rules::setPokerusChance(const Fraction& pokerusChance) throw(BoundsException) +void Rules::setPokerusChance(const Fraction& pokerusChance) { if (1 < pokerusChance) - error<BoundsException>("pokerusChance"); + { + boundsError("pokerusChance"); + return; + } m_pokerusChance = pokerusChance; } diff --git a/pokemod/Rules.h b/pokemod/Rules.h index 39d9b2b0..1bb8c28d 100644 --- a/pokemod/Rules.h +++ b/pokemod/Rules.h @@ -22,7 +22,6 @@ #include "Object.h" // General includes -#include "../general/Exception.h" #include "../general/Fraction.h" class Rules : public Object @@ -35,7 +34,7 @@ class Rules : public Object Rules(const Rules& rules, const Object* parent); Rules(const QDomElement& xml, const Object* parent); - void load(const QDomElement& xml, const int = 0) throw(Exception); + void load(const QDomElement& xml, const int = 0); QDomElement save() const; void setGenderAllowed(const bool genderAllowed); @@ -46,24 +45,24 @@ class Rules : public Object void setNatureAllowed(const bool natureAllowed); void setNumBoxes(const int numBoxes); void setBoxSize(const int boxSize); - void setMaxParty(const int maxParty) throw(BoundsException); - void setMaxFight(const int maxFight) throw(BoundsException); - void setMaxPlayers(const int maxPlayers) throw(BoundsException); - void setMaxMoves(const int maxMoves) throw(BoundsException); - void setMaxLevel(const int maxLevel) throw(BoundsException); + void setMaxParty(const int maxParty); + void setMaxFight(const int maxFight); + void setMaxPlayers(const int maxPlayers); + void setMaxMoves(const int maxMoves); + void setMaxLevel(const int maxLevel); void setMaxMoney(const int maxMoney); void setHardCash(const bool hardCash); void setSpecialSplit(const bool specialSplit); void setSpecialDVSplit(const bool specialDVSplit); - void setMaxDVValue(const unsigned char maxDV) throw(BoundsException); + void setMaxDVValue(const unsigned char maxDV); void setHappiness(const bool happiness); void setHappyFaintLoss(const int happyFaint); void setHappyLevelGain(const int happyLevel); void setHappySteps(const int happySteps); void setEffortValuesAllowed(const bool effortValues); - void setMaxTotalEV(const int maxTotalEV) throw(BoundsException); - void setMaxEVPerStat(const int maxEVPerStat) throw(BoundsException); - void setPokerusChance(const Fraction& pokerusChance) throw(BoundsException); + void setMaxTotalEV(const int maxTotalEV); + void setMaxEVPerStat(const int maxEVPerStat); + void setPokerusChance(const Fraction& pokerusChance); bool genderAllowed() const; bool breedingAllowed() const; @@ -94,7 +93,7 @@ class Rules : public Object Rules& operator=(const Rules& rhs); private: - bool validate() const; + void validate(QTextStream& stream); bool m_genderAllowed; bool m_breedingAllowed; diff --git a/pokemod/Species.cpp b/pokemod/Species.cpp index a992f6e6..7b64b764 100644 --- a/pokemod/Species.cpp +++ b/pokemod/Species.cpp @@ -27,6 +27,7 @@ // Qt includes #include <QBuffer> +#include <QSet> const QStringList Species::StyleStr = QStringList() << "Fluctuating" << "Fading" << "Slow" << "Normal" << "Fast" << "Erratic"; @@ -83,148 +84,102 @@ Species::~Species() clear(); } -bool Species::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Species \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is not defined"); -// valid = false; -// } -// for (int i = 0; i < (static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY); ++i) -// { -// if (!m_baseStat[i]) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Invalid baseStats[%1]").arg(i)); -// valid = false; -// } -// } -// if (End <= m_growth) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid growth style"); -// valid = false; -// } -// if (!m_weight) -// static_cast<const Pokemod*>(pokemod())->validationMsg("Species weighs nothing", Pokemod::V_Warn); -// if (12 <= m_heightInches) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid height inches"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->speciesIndex(m_eggSpecies) == INT_MAX) -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid egg species", Pokemod::V_Warn); -// else -// { -// if (static_cast<const Pokemod*>(pokemod())->species(m_eggSpecies)->growth() != m_growth) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Growth styles do not match for egg species"); -// valid = false; -// } -// if (!m_eggSteps) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid egg steps"); -// valid = false; -// } -// } -// QMap<int, bool> idChecker; -// QMap<int, bool> valueChecker; -// foreach (int type, m_types) -// { -// if (static_cast<const Pokemod*>(pokemod())->typeIndex(type) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid type"); -// valid = false; -// } -// if (valueChecker[type]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate of type %1").arg(type)); -// valueChecker[type] = true; -// } -// valueChecker.clear(); -// foreach (int eggGroup, m_eggGroups) -// { -// if (static_cast<const Pokemod*>(pokemod())->eggGroupIndex(eggGroup) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid egg group"); -// valid = false; -// } -// if (valueChecker[eggGroup]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate of egg group %1").arg(eggGroup)); -// valueChecker[eggGroup] = true; -// } -// valueChecker.clear(); -// if (static_cast<const Pokemod*>(pokemod())->rules()->abilityAllowed()) -// { -// if (!abilityCount()) -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no m_abilities", Pokemod::V_Warn); -// foreach (SpeciesAbility* ability, m_abilities) -// { -// if (!ability->isValid()) -// valid = false; -// if (idChecker[ability->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate ability with id %1").arg(ability->id())); -// idChecker[ability->id()] = true; -// if (valueChecker[ability->ability()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate of ability %1").arg(ability->ability())); -// valueChecker[ability->ability()] = true; -// } -// idChecker.clear(); -// valueChecker.clear(); -// } -// if (!evolutionCount()) -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no m_evolutions", Pokemod::V_Warn); -// foreach (SpeciesEvolution* evolution, m_evolutions) -// { -// if (!evolution->isValid()) -// valid = false; -// if (evolution->species() == id()) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Evolution is of the same species"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->species(evolution->species())->growth() != m_growth) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Growth styles do not match for m_evolutions"); -// valid = false; -// } -// if (idChecker[evolution->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate evolution with id %1").arg(evolution->id())); -// idChecker[evolution->id()] = true; -// } -// idChecker.clear(); -// if (static_cast<const Pokemod*>(pokemod())->rules()->holdItems()) -// { -// if (!itemCount()) -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no m_items", Pokemod::V_Warn); -// foreach (SpeciesItem* item, m_items) -// { -// if (!item->isValid()) -// valid = false; -// if (idChecker[item->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate item with id %1").arg(item->id())); -// idChecker[item->id()] = true; -// if (valueChecker[item->item()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate of item %1").arg(item->item())); -// valueChecker[item->item()] = true; -// } -// idChecker.clear(); -// valueChecker.clear(); -// } -// if (!moveCount()) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no m_moves"); -// valid = false; -// } -// foreach (SpeciesMove* move, m_moves) -// { -// if (!move->isValid()) -// valid = false; -// if (idChecker[move->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate move with id %1").arg(move->id())); -// idChecker[move->id()] = true; -// } -// return valid; +void Species::validate(QTextStream& stream) +{ + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST_ARRAY(setBaseStat, baseStat, static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY); + TEST(setGrowth, growth); + TEST(setRunChance, runChance); + TEST(setFleeChance, fleeChance); + TEST(setItemChance, itemChance); + TEST(setWeight, weight); + TEST(setHeightInches, heightInches); + TEST(setFrontMaleSprite, frontMaleSprite); + TEST(setBackMaleSprite, backMaleSprite); + TEST(setFrontFemaleSprite, frontFemaleSprite); + TEST(setBackFemaleSprite, backFemaleSprite); + TEST(setListSprite, listSprite); + if ((m_pokedexNumber != INT_MAX) && m_pokedexEntry.isEmpty()) + error(stream, "Pokedex entry is empty"); + TEST(setGenderFactor, genderFactor); + if (static_cast<const Pokemod*>(pokemod())->rules()->breedingAllowed()) + { + if (static_cast<const Pokemod*>(pokemod())->speciesIndex(m_eggSpecies) == INT_MAX) + boundsError(stream, "egg species"); + else + { + if (static_cast<const Pokemod*>(pokemod())->species(m_eggSpecies)->growth() != m_growth) + error(stream, "Growth mismatch with egg species"); + TEST(setEggSteps, eggSteps); + } + } + TEST_LIST(setType, type); + TEST_LIST(setEggGroup, eggGroup); + QSet<int> idChecker; + QSet<int> valueChecker; + if (static_cast<const Pokemod*>(pokemod())->rules()->abilityAllowed()) + { + if (!abilityCount()) + warning(stream, "There are no abilities"); + foreach (SpeciesAbility* ability, m_abilities) + { + if (!ability->isValid(stream)) + setValid(false); + if (idChecker.contains(ability->id())) + subclassError(stream, "ability", ability->id()); + idChecker.insert(ability->id()); + if (valueChecker.contains(ability->ability())) + subclassError(stream, "ability", ability->ability()); + valueChecker.insert(ability->ability()); + } + idChecker.clear(); + valueChecker.clear(); + } + if (!evolutionCount()) + warning(stream, "There are no evolutions"); + foreach (SpeciesEvolution* evolution, m_evolutions) + { + if (!evolution->isValid(stream)) + setValid(false); + if (evolution->species() == id()) + error(stream, "Evolution into self"); + if (static_cast<const Pokemod*>(pokemod())->species(evolution->species())->growth() != m_growth) + error(stream, "Growth mismatch"); + if (idChecker.contains(evolution->id())) + subclassError(stream, "evolution", evolution->id()); + idChecker.insert(evolution->id()); + } + idChecker.clear(); + if (static_cast<const Pokemod*>(pokemod())->rules()->holdItems()) + { + if (!itemCount()) + warning(stream, "There are no items"); + foreach (SpeciesItem* item, m_items) + { + if (!item->isValid(stream)) + setValid(false); + if (idChecker.contains(item->id())) + subclassError(stream, "item", item->id()); + idChecker.insert(item->id()); + if (valueChecker.contains(item->item())) + subclassError(stream, "item", item->item()); + valueChecker.insert(item->item()); + } + idChecker.clear(); + valueChecker.clear(); + } + if (!moveCount()) + error(stream, "There are no moves"); + foreach (SpeciesMove* move, m_moves) + { + if (!move->isValid(stream)) + setValid(false); + if (idChecker.contains(move->id())) + subclassError(stream, "move", move->id()); + idChecker.insert(move->id()); + } } void Species::load(const QDomElement& xml, int id) @@ -248,8 +203,8 @@ void Species::load(const QDomElement& xml, int id) LOAD(int, eggSpecies); LOAD(int, eggSteps); LOAD(int, nidoranGroup); - LOAD_LIST(int, types); - LOAD_LIST(int, eggGroups); + LOAD_LIST(int, type); + LOAD_LIST(int, eggGroup); LOAD_SUB(newAbility, SpeciesAbility); LOAD_SUB(newEvolution, SpeciesEvolution); LOAD_SUB(newItem, SpeciesItem); @@ -277,8 +232,8 @@ QDomElement Species::save() const SAVE(int, eggSpecies); SAVE(int, eggSteps); SAVE(int, nidoranGroup); - SAVE_LIST(int, types); - SAVE_LIST(int, eggGroups); + SAVE_LIST(int, type); + SAVE_LIST(int, eggGroup); SAVE_SUB(SpeciesAbility, abilities); SAVE_SUB(SpeciesEvolution, evolutions); SAVE_SUB(SpeciesItem, items); @@ -291,28 +246,43 @@ void Species::setName(const QString& name) m_name = name; } -void Species::setBaseStat(const int stat, const int baseStat) throw(BoundsException) +void Species::setBaseStat(const int stat, const int baseStat) { if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) - error<BoundsException>("stat"); + { + boundsError("stat"); + return; + } m_baseStat[stat] = baseStat; } -void Species::setEffortValue(const int stat, const int effortValue) throw(Exception) +void Species::setEffortValue(const int stat, const int effortValue) { if (!static_cast<const Pokemod*>(pokemod())->rules()->effortValuesAllowed()) - throw(Exception(className(), "effortValues not allowed")); + { + error("Effort Values not allowed"); + return; + } if (static_cast<const Pokemod*>(pokemod())->rules()->maxEVPerStat() < effortValue) - error<BoundsException>("effortValue"); + { + boundsError("effortValue"); + return; + } if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) - error<BoundsException>("stat"); + { + boundsError("stat"); + return; + } m_effortValue[stat] = effortValue; } -void Species::setGrowth(const int growth) throw(BoundsException) +void Species::setGrowth(const int growth) { if (End <= growth) - error<BoundsException>("growth"); + { + boundsError("growth"); + return; + } m_growth = growth; } @@ -321,31 +291,43 @@ void Species::setExperienceValue(const int experienceValue) m_experienceValue = experienceValue; } -void Species::setCatchValue(const int catchValue) throw(BoundsException) +void Species::setCatchValue(const int catchValue) { if (255 < catchValue) - error<BoundsException>("catchValue"); + { + boundsError("catchValue"); + return; + } m_catchValue = catchValue; } -void Species::setRunChance(const Fraction& runChance) throw(BoundsException) +void Species::setRunChance(const Fraction& runChance) { if (1 < runChance) - error<BoundsException>("runChance"); + { + boundsError("runChance"); + return; + } m_runChance = runChance; } -void Species::setFleeChance(const Fraction& fleeChance) throw(BoundsException) +void Species::setFleeChance(const Fraction& fleeChance) { if (1 < fleeChance) - error<BoundsException>("fleeChance"); + { + boundsError("fleeChance"); + return; + } m_fleeChance = fleeChance; } -void Species::setItemChance(const Fraction& itemChance) throw(BoundsException) +void Species::setItemChance(const Fraction& itemChance) { if (1 < itemChance) - error<BoundsException>("itemChance"); + { + boundsError("itemChance"); + return; + } m_itemChance = itemChance; } @@ -364,10 +346,13 @@ void Species::setHeightFeet(const int feet) m_heightFeet = feet; } -void Species::setHeightInches(const int inches) throw(BoundsException) +void Species::setHeightInches(const int inches) { if (12 <= inches) - error<BoundsException>("heightInches"); + { + boundsError("heightInches"); + return; + } m_heightInches = inches; } @@ -376,64 +361,103 @@ void Species::setPokedexEntry(const QString& pokedexEntry) m_pokedexEntry = pokedexEntry; } -void Species::setFrontMaleSprite(const QPixmap& frontMaleSprite) throw(Exception) +void Species::setFrontMaleSprite(const QPixmap& frontMaleSprite) { if (m_genderFactor.numerator() == m_genderFactor.denominator()) - error<Exception>("cannot be male"); + { + error("Cannot be male"); + return; + } if (frontMaleSprite.size() != QSize(128, 128)) - error<SizeException>("frontMaleSprite"); + { + sizeError("frontMaleSprite"); + return; + } m_frontMaleSprite = frontMaleSprite; } -void Species::setBackMaleSprite(const QPixmap& backMaleSprite) throw(Exception) +void Species::setBackMaleSprite(const QPixmap& backMaleSprite) { if (m_genderFactor.numerator() == m_genderFactor.denominator()) - error<Exception>("cannot be male"); + { + error("Cannot be male"); + return; + } if (backMaleSprite.size() != QSize(128, 128)) - error<SizeException>("backMaleSprite"); + { + sizeError("backMaleSprite"); + return; + } m_backMaleSprite = backMaleSprite; } -void Species::setFrontFemaleSprite(const QPixmap& frontFemaleSprite) throw(Exception) +void Species::setFrontFemaleSprite(const QPixmap& frontFemaleSprite) { if (!static_cast<const Pokemod*>(pokemod())->rules()->genderAllowed()) - throw(Exception(className(), "gender is not allowed")); + { + error("Gender is not allowed"); + return; + } if (!m_genderFactor.numerator()) - error<Exception>("cannot be female"); + { + error("Cannot be female"); + return; + } if (frontFemaleSprite.size() != QSize(128, 128)) - error<SizeException>("frontFemaleSprite"); + { + sizeError("frontFemaleSprite"); + return; + } m_frontFemaleSprite = frontFemaleSprite; } -void Species::setBackFemaleSprite(const QPixmap& backFemaleSprite) throw(Exception) +void Species::setBackFemaleSprite(const QPixmap& backFemaleSprite) { if (!static_cast<const Pokemod*>(pokemod())->rules()->genderAllowed()) - throw(Exception(className(), "gender is not allowed")); + { + error("Gender is not allowed"); + return; + } if (!m_genderFactor.numerator()) - error<Exception>("cannot be female"); + { + error("Cannot be female"); + return; + } if (backFemaleSprite.size() != QSize(128, 128)) - error<SizeException>("backFemaleSprite"); + { + sizeError("backFemaleSprite"); + return; + } m_backFemaleSprite = backFemaleSprite; } -void Species::setListSprite(const QPixmap& listSprite) throw(SizeException) +void Species::setListSprite(const QPixmap& listSprite) { if (listSprite.size() != QSize(64, 128)) - error<SizeException>("listSprite"); + { + sizeError("listSprite"); + return; + } m_listSprite = listSprite; } -void Species::setGenderFactor(const Fraction& genderFactor) throw(BoundsException) +void Species::setGenderFactor(const Fraction& genderFactor) { if (1 < genderFactor) - error<BoundsException>("genderFactor"); + { + boundsError("genderFactor"); + return; + } m_genderFactor = genderFactor; } -void Species::setEggSpecies(const int eggSpecies) throw(BoundsException) +void Species::setEggSpecies(const int eggSpecies) { if (static_cast<const Pokemod*>(pokemod())->speciesIndex(eggSpecies) == INT_MAX) - error<BoundsException>("eggSpecies"); + { + boundsError("eggSpecies"); + return; + } m_eggSpecies = eggSpecies; } @@ -447,30 +471,36 @@ void Species::setNidoranGroup(const int nidoranGroup) m_nidoranGroup = nidoranGroup; } -void Species::setType(const int type, const bool state) throw(Exception) +void Species::setType(const int type, const bool state) { if (static_cast<const Pokemod*>(pokemod())->typeIndex(type) == INT_MAX) - error<BoundsException>("type"); + { + boundsError("type"); + return; + } if (state) { - if (!m_types.contains(type)) - m_types.append(type); + if (!m_type.contains(type)) + m_type.append(type); } else - m_types.removeAll(type); + m_type.removeAll(type); } -void Species::setEggGroup(const int eggGroup, const bool state) throw(Exception) +void Species::setEggGroup(const int eggGroup, const bool state) { if (static_cast<const Pokemod*>(pokemod())->eggGroupIndex(eggGroup) == INT_MAX) - error<BoundsException>("eggGroup"); + { + boundsError("eggGroup"); + return; + } if (state) { - if (!m_types.contains(eggGroup)) - m_eggGroups.append(eggGroup); + if (!m_eggGroup.contains(eggGroup)) + m_eggGroup.append(eggGroup); } else - m_eggGroups.removeAll(eggGroup); + m_eggGroup.removeAll(eggGroup); } QString Species::name() const @@ -478,17 +508,19 @@ QString Species::name() const return m_name; } -int Species::baseStat(const int stat) const throw(BoundsException) +int Species::baseStat(const int stat) const { + // TODO: Message about fetching out-of-bounds if (Pokemod::ST_End_GSC <= stat) - warning<BoundsException>("stat"); + return 0; return m_baseStat[stat]; } -int Species::effortValue(const int stat) const throw(BoundsException) +int Species::effortValue(const int stat) const { + // TODO: Message about fetching out-of-bounds if (Pokemod::ST_End_GSC <= stat) - warning<BoundsException>("stat"); + return 0; return m_effortValue[stat]; } @@ -594,34 +626,34 @@ int Species::nidoranGroup() const bool Species::type(const int type) const { - return m_types.contains(type); + return m_type.contains(type); } bool Species::eggGroup(const int eggGroup) const { - return m_eggGroups.contains(eggGroup); + return m_eggGroup.contains(eggGroup); } -const SpeciesAbility* Species::ability(const int index) const throw(IndexException) +const SpeciesAbility* Species::ability(const int index) const { if (abilityCount() <= index) - warning<IndexException>("ability"); + return NULL; return m_abilities.at(index); } -SpeciesAbility* Species::ability(const int index) throw(IndexException) +SpeciesAbility* Species::ability(const int index) { if (abilityCount() <= index) - error<IndexException>("ability"); + return NULL; return m_abilities[index]; } -const SpeciesAbility* Species::abilityById(const int id) const throw(IndexException) +const SpeciesAbility* Species::abilityById(const int id) const { return ability(abilityIndex(id)); } -SpeciesAbility* Species::abilityById(const int id) throw(IndexException) +SpeciesAbility* Species::abilityById(const int id) { return ability(abilityIndex(id)); } @@ -662,15 +694,15 @@ SpeciesAbility* Species::newAbility(SpeciesAbility* ability) return ability; } -void Species::deleteAbility(const int index) throw(IndexException) +void Species::deleteAbility(const int index) { if (abilityCount() <= index) - error<IndexException>("ability"); + return; delete m_abilities[index]; m_abilities.removeAt(index); } -void Species::deleteAbilityById(const int id) throw(IndexException) +void Species::deleteAbilityById(const int id) { deleteAbility(abilityIndex(id)); } @@ -683,26 +715,26 @@ int Species::newAbilityId() const return i; } -const SpeciesEvolution* Species::evolution(const int index) const throw(IndexException) +const SpeciesEvolution* Species::evolution(const int index) const { if (evolutionCount() <= index) - warning<IndexException>("evolution"); + return NULL; return m_evolutions.at(index); } -SpeciesEvolution* Species::evolution(const int index) throw(IndexException) +SpeciesEvolution* Species::evolution(const int index) { if (evolutionCount() <= index) - error<IndexException>("evolution"); + return NULL; return m_evolutions[index]; } -const SpeciesEvolution* Species::evolutionById(const int id) const throw(IndexException) +const SpeciesEvolution* Species::evolutionById(const int id) const { return evolution(evolutionIndex(id)); } -SpeciesEvolution* Species::evolutionById(const int id) throw(IndexException) +SpeciesEvolution* Species::evolutionById(const int id) { return evolution(evolutionIndex(id)); } @@ -743,15 +775,15 @@ SpeciesEvolution* Species::newEvolution(SpeciesEvolution* evolution) return evolution; } -void Species::deleteEvolution(const int index) throw(IndexException) +void Species::deleteEvolution(const int index) { if (evolutionCount() <= index) - error<IndexException>("evolution"); + return; delete m_evolutions[index]; m_evolutions.removeAt(index); } -void Species::deleteEvolutionById(const int id) throw(IndexException) +void Species::deleteEvolutionById(const int id) { deleteEvolution(evolutionIndex(id)); } @@ -764,26 +796,26 @@ int Species::newEvolutionId() const return i; } -const SpeciesItem* Species::item(const int index) const throw(IndexException) +const SpeciesItem* Species::item(const int index) const { if (itemCount() <= index) - warning<IndexException>("item"); + return NULL; return m_items.at(index); } -SpeciesItem* Species::item(const int index) throw(IndexException) +SpeciesItem* Species::item(const int index) { if (itemCount() <= index) - error<IndexException>("item"); + return NULL; return m_items[index]; } -const SpeciesItem* Species::itemById(const int id) const throw(IndexException) +const SpeciesItem* Species::itemById(const int id) const { return item(itemIndex(id)); } -SpeciesItem* Species::itemById(const int id) throw(IndexException) +SpeciesItem* Species::itemById(const int id) { return item(itemIndex(id)); } @@ -824,15 +856,15 @@ SpeciesItem* Species::newItem(SpeciesItem* item) return item; } -void Species::deleteItem(const int index) throw(IndexException) +void Species::deleteItem(const int index) { if (itemCount() <= index) - error<IndexException>("item"); + return; delete m_items[index]; m_items.removeAt(index); } -void Species::deleteItemById(const int id) throw(IndexException) +void Species::deleteItemById(const int id) { deleteItem(itemIndex(id)); } @@ -845,26 +877,26 @@ int Species::newItemId() const return i; } -const SpeciesMove* Species::move(const int index) const throw(IndexException) +const SpeciesMove* Species::move(const int index) const { if (moveCount() <= index) - warning<IndexException>("move"); + return NULL; return m_moves.at(index); } -SpeciesMove* Species::move(const int index) throw(IndexException) +SpeciesMove* Species::move(const int index) { if (moveCount() <= index) - error<IndexException>("move"); + return NULL; return m_moves[index]; } -const SpeciesMove* Species::moveById(const int id) const throw(IndexException) +const SpeciesMove* Species::moveById(const int id) const { return move(moveIndex(id)); } -SpeciesMove* Species::moveById(const int id) throw(IndexException) +SpeciesMove* Species::moveById(const int id) { return move(moveIndex(id)); } @@ -905,15 +937,15 @@ SpeciesMove* Species::newMove(SpeciesMove* move) return move; } -void Species::deleteMove(const int index) throw(IndexException) +void Species::deleteMove(const int index) { if (moveCount() <= index) - error<IndexException>("move"); + return; delete m_moves[index]; m_moves.removeAt(index); } -void Species::deleteMoveById(const int id) throw(IndexException) +void Species::deleteMoveById(const int id) { deleteMove(moveIndex(id)); } @@ -949,8 +981,8 @@ Species& Species::operator=(const Species& rhs) COPY(eggSpecies); COPY(eggSteps); COPY(nidoranGroup); - COPY(types); - COPY(eggGroups); + COPY(type); + COPY(eggGroup); COPY_SUB(SpeciesAbility, abilities); COPY_SUB(SpeciesEvolution, evolutions); COPY_SUB(SpeciesItem, items); diff --git a/pokemod/Species.h b/pokemod/Species.h index e17beb77..7e438551 100644 --- a/pokemod/Species.h +++ b/pokemod/Species.h @@ -23,7 +23,6 @@ #include "Pokemod.h" // General includes -#include "../general/Exception.h" #include "../general/Fraction.h" // Qt includes @@ -60,34 +59,34 @@ class Species : public Object QDomElement save() const; void setName(const QString& name); - void setBaseStat(const int stat, const int base) throw(BoundsException); - void setEffortValue(const int stat, const int effortPoints) throw(Exception); - void setGrowth(const int growth) throw(BoundsException); + void setBaseStat(const int stat, const int base); + void setEffortValue(const int stat, const int effortPoints); + void setGrowth(const int growth); void setExperienceValue(const int experienceValue); - void setCatchValue(const int catchValue) throw(BoundsException); - void setRunChance(const Fraction& runChance) throw(BoundsException); - void setFleeChance(const Fraction& fleeChance) throw(BoundsException); - void setItemChance(const Fraction& itemChance) throw(BoundsException); + void setCatchValue(const int catchValue); + void setRunChance(const Fraction& runChance); + void setFleeChance(const Fraction& fleeChance); + void setItemChance(const Fraction& itemChance); void setPokedexNumber(const int pokedexNumber); void setWeight(const int weight); void setHeightFeet(const int feet); - void setHeightInches(const int inches) throw(BoundsException); + void setHeightInches(const int inches); void setPokedexEntry(const QString& pokedexEntry); - void setFrontMaleSprite(const QPixmap& frontMaleSprite) throw(Exception); - void setBackMaleSprite(const QPixmap& backMaleSprite) throw(Exception); - void setFrontFemaleSprite(const QPixmap& frontFemaleSprite) throw(Exception); - void setBackFemaleSprite(const QPixmap& backFemaleSprite) throw(Exception); - void setListSprite(const QPixmap& listSprite) throw(SizeException); - void setGenderFactor(const Fraction& genderFactor) throw(BoundsException); - void setEggSpecies(const int eggSpecies) throw(BoundsException); + void setFrontMaleSprite(const QPixmap& frontMaleSprite); + void setBackMaleSprite(const QPixmap& backMaleSprite); + void setFrontFemaleSprite(const QPixmap& frontFemaleSprite); + void setBackFemaleSprite(const QPixmap& backFemaleSprite); + void setListSprite(const QPixmap& listSprite); + void setGenderFactor(const Fraction& genderFactor); + void setEggSpecies(const int eggSpecies); void setEggSteps(const int eggSteps); void setNidoranGroup(const int nidoranGroup); - void setType(const int type, const bool state) throw(Exception); - void setEggGroup(const int eggGroup, const bool state) throw(Exception); + void setType(const int type, const bool state); + void setEggGroup(const int eggGroup, const bool state); QString name() const; - int baseStat(const int stat) const throw(BoundsException); - int effortValue(const int stat) const throw(BoundsException); + int baseStat(const int stat) const; + int effortValue(const int stat) const; int growth() const; int experienceValue() const; int catchValue() const; @@ -111,57 +110,57 @@ class Species : public Object bool type(const int type) const; bool eggGroup(const int eggGroup) const; - const SpeciesAbility* ability(const int index) const throw(IndexException); - SpeciesAbility* ability(const int index) throw(IndexException); - const SpeciesAbility* abilityById(const int id) const throw(IndexException); - SpeciesAbility* abilityById(const int id) throw(IndexException); + const SpeciesAbility* ability(const int index) const; + SpeciesAbility* ability(const int index); + const SpeciesAbility* abilityById(const int id) const; + SpeciesAbility* abilityById(const int id); int abilityIndex(const int id) const; int abilityCount() const; SpeciesAbility* newAbility(); SpeciesAbility* newAbility(const QDomElement& xml); SpeciesAbility* newAbility(const SpeciesAbility& ability); - void deleteAbility(const int index) throw(IndexException); - void deleteAbilityById(const int id) throw(IndexException); + void deleteAbility(const int index); + void deleteAbilityById(const int id); - const SpeciesEvolution* evolution(const int index) const throw(IndexException); - SpeciesEvolution* evolution(const int index) throw(IndexException); - const SpeciesEvolution* evolutionById(const int id) const throw(IndexException); - SpeciesEvolution* evolutionById(const int id) throw(IndexException); + const SpeciesEvolution* evolution(const int index) const; + SpeciesEvolution* evolution(const int index); + const SpeciesEvolution* evolutionById(const int id) const; + SpeciesEvolution* evolutionById(const int id); int evolutionIndex(const int id) const; int evolutionCount() const; SpeciesEvolution* newEvolution(); SpeciesEvolution* newEvolution(const QDomElement& xml); SpeciesEvolution* newEvolution(const SpeciesEvolution& evolution); - void deleteEvolution(const int index) throw(IndexException); - void deleteEvolutionById(const int id) throw(IndexException); + void deleteEvolution(const int index); + void deleteEvolutionById(const int id); - const SpeciesItem* item(const int index) const throw(IndexException); - SpeciesItem* item(const int index) throw(IndexException); - const SpeciesItem* itemById(const int i) const throw(IndexException); - SpeciesItem* itemById(const int i) throw(IndexException); + const SpeciesItem* item(const int index) const; + SpeciesItem* item(const int index); + const SpeciesItem* itemById(const int i) const; + SpeciesItem* itemById(const int i); int itemIndex(const int id) const; int itemCount() const; SpeciesItem* newItem(); SpeciesItem* newItem(const QDomElement& xml); SpeciesItem* newItem(const SpeciesItem& item); - void deleteItem(const int index) throw(IndexException); - void deleteItemById(const int id) throw(IndexException); + void deleteItem(const int index); + void deleteItemById(const int id); - const SpeciesMove* move(const int index) const throw(IndexException); - SpeciesMove* move(const int index) throw(IndexException); - const SpeciesMove* moveById(const int id) const throw(IndexException); - SpeciesMove* moveById(const int id) throw(IndexException); + const SpeciesMove* move(const int index) const; + SpeciesMove* move(const int index); + const SpeciesMove* moveById(const int id) const; + SpeciesMove* moveById(const int id); int moveIndex(const int id) const; int moveCount() const; SpeciesMove* newMove(); SpeciesMove* newMove(const QDomElement& xml); SpeciesMove* newMove(const SpeciesMove& move); - void deleteMove(const int index) throw(IndexException); - void deleteMoveById(const int id) throw(IndexException); + void deleteMove(const int index); + void deleteMoveById(const int id); Species& operator=(const Species& rhs); private: - bool validate() const; + void validate(QTextStream& stream); int newAbilityId() const; SpeciesAbility* newAbility(SpeciesAbility* ability); @@ -200,8 +199,8 @@ class Species : public Object int m_eggSpecies; int m_eggSteps; int m_nidoranGroup; - QList<int> m_types; - QList<int> m_eggGroups; + QList<int> m_type; + QList<int> m_eggGroup; QList<SpeciesAbility*> m_abilities; QList<SpeciesEvolution*> m_evolutions; QList<SpeciesItem*> m_items; diff --git a/pokemod/SpeciesAbility.cpp b/pokemod/SpeciesAbility.cpp index b1c26740..7255b65d 100644 --- a/pokemod/SpeciesAbility.cpp +++ b/pokemod/SpeciesAbility.cpp @@ -46,22 +46,11 @@ SpeciesAbility::SpeciesAbility(const QDomElement& xml, const Object* parent, con load(xml, id); } -bool SpeciesAbility::validate() const +void SpeciesAbility::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Ability with id %1---").arg(id()), Pokemod::V_Msg); -// if (static_cast<const Pokemod*>(pokemod())->abilityIndex(m_ability) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid ability"); -// valid = false; -// } -// if (!m_weight) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid weight"); -// valid = false; -// } -// return valid; + TEST_SETUP(); + TEST(setAbility, ability); + TEST(setWeight, weight); } void SpeciesAbility::load(const QDomElement& xml, int id) @@ -79,17 +68,23 @@ QDomElement SpeciesAbility::save() const return xml; } -void SpeciesAbility::setAbility(const int ability) throw(BoundsException) +void SpeciesAbility::setAbility(const int ability) { if (static_cast<const Pokemod*>(pokemod())->abilityIndex(ability) == INT_MAX) - error<BoundsException>("ability"); + { + boundsError("ability"); + return; + } m_ability = ability; } -void SpeciesAbility::setWeight(const int weight) throw(BoundsException) +void SpeciesAbility::setWeight(const int weight) { if (!weight) - error<BoundsException>("weight"); + { + boundsError("weight"); + return; + } m_weight = weight; } diff --git a/pokemod/SpeciesAbility.h b/pokemod/SpeciesAbility.h index 6d3af954..9912079a 100644 --- a/pokemod/SpeciesAbility.h +++ b/pokemod/SpeciesAbility.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - class SpeciesAbility : public Object { public: @@ -35,15 +32,15 @@ class SpeciesAbility : public Object void load(const QDomElement& xml, int id = INT_MAX); QDomElement save() const; - void setAbility(const int ability) throw(BoundsException); - void setWeight(const int weight) throw(BoundsException); + void setAbility(const int ability); + void setWeight(const int weight); int ability() const; int weight() const; SpeciesAbility& operator=(const SpeciesAbility& rhs); private: - bool validate() const; + void validate(QTextStream& stream); int m_ability; int m_weight; diff --git a/pokemod/SpeciesEvolution.cpp b/pokemod/SpeciesEvolution.cpp index 540c3302..b4e75fd9 100644 --- a/pokemod/SpeciesEvolution.cpp +++ b/pokemod/SpeciesEvolution.cpp @@ -55,72 +55,15 @@ SpeciesEvolution::SpeciesEvolution(const QDomElement& xml, const Object* parent, load(xml, id); } -bool SpeciesEvolution::validate() const +void SpeciesEvolution::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Evolution with id %1---").arg(id()), Pokemod::V_Msg); -// if (static_cast<const Pokemod*>(pokemod())->speciesIndex(m_species) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid species"); -// valid = false; -// } -// if (m_style < S_End) -// { -// bool ok = true; -// switch (m_style) -// { -// case S_Happiness: -// case S_Stat: -// case S_Personality: -// if (Pokemod::REL_End <= m_value1) -// ok = false; -// break; -// case S_Item: -// case S_TradeItem: -// if (static_cast<const Pokemod*>(pokemod())->itemIndex(m_value1) == INT_MAX) -// ok = false; -// else -// { -// for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemById(m_value1)->effectCount()) && !ok; ++i) -// ok = (static_cast<const Pokemod*>(pokemod())->itemById(m_value1)->effect(i)->effect() == ItemEffect::E_Evolution); -// } -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid m_value1"); -// valid = false; -// ok = true; -// } -// switch (m_style) -// { -// case S_Stat: -// if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= m_value2) -// ok = false; -// case S_Item: -// if ((G_End <= m_value2) || ((m_value2 == G_Hold) && !static_cast<const Pokemod*>(pokemod())->rules()->holdItems())) -// ok = false; -// break; -// } -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid m_value2"); -// valid = false; -// ok = true; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid style"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() <= m_level) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid level"); -// valid = false; -// } -// return valid; + TEST_SETUP(); + TEST(setSpecies, species); + TEST(setStyle, style); + TEST(setValue1, value1); + TEST(setValue2, value2); + TEST(setValue3, value3); + TEST(setLevel, level); } void SpeciesEvolution::load(const QDomElement& xml, int id) @@ -146,21 +89,27 @@ QDomElement SpeciesEvolution::save() const return xml; } -void SpeciesEvolution::setSpecies(const int species) throw(BoundsException) +void SpeciesEvolution::setSpecies(const int species) { if (static_cast<const Pokemod*>(pokemod())->speciesIndex(species) == INT_MAX) - error<BoundsException>("species"); + { + boundsError("species"); + return; + } m_species = species; } -void SpeciesEvolution::setStyle(const int style) throw(BoundsException) +void SpeciesEvolution::setStyle(const int style) { if (S_End <= style) - error<BoundsException>("style"); + { + boundsError("style"); + return; + } m_style = style; } -void SpeciesEvolution::setValue1(const int value1) throw(Exception) +void SpeciesEvolution::setValue1(const int value1) { bool ok = false; switch (m_style) @@ -169,43 +118,58 @@ void SpeciesEvolution::setValue1(const int value1) throw(Exception) case S_Stat: case S_Personality: if (Pokemod::REL_End <= value1) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; case S_Item: case S_TradeItem: if (static_cast<const Pokemod*>(pokemod())->itemIndex(value1) == INT_MAX) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } for (int i = 0; (i < static_cast<const Pokemod*>(pokemod())->itemById(value1)->effectCount()) && !ok; ++i) ok = (static_cast<const Pokemod*>(pokemod())->itemById(value1)->effect(i)->effect() == ItemEffect::E_Evolution); if (!ok) - error<BoundsException>("value1"); + { + boundsError("value1"); + return; + } break; default: - error<UnusedException>("value1"); - break; + unusedError("value1"); + return; } m_value1 = value1; } -void SpeciesEvolution::setValue2(const int value2) throw(Exception) +void SpeciesEvolution::setValue2(const int value2) { switch (m_style) { case S_Stat: if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value2) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } case S_Item: if ((G_End <= value2) || ((value2 == G_Hold) && !static_cast<const Pokemod*>(pokemod())->rules()->holdItems())) - error<BoundsException>("value2"); + { + boundsError("value2"); + return; + } break; default: - error<UnusedException>("value2"); - break; + unusedError("value2"); + return; } m_value2 = value2; } -void SpeciesEvolution::setValue3(const int value3) throw(UnusedException) +void SpeciesEvolution::setValue3(const int value3) { switch (m_style) { @@ -214,16 +178,19 @@ void SpeciesEvolution::setValue3(const int value3) throw(UnusedException) case S_Personality: break; default: - error<UnusedException>("value3"); - break; + unusedError("value3"); + return; } m_value3 = value3; } -void SpeciesEvolution::setLevel(const int level) throw(BoundsException) +void SpeciesEvolution::setLevel(const int level) { if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < level) - error<BoundsException>("level"); + { + boundsError("level"); + return; + } m_level = level; } diff --git a/pokemod/SpeciesEvolution.h b/pokemod/SpeciesEvolution.h index d9c94e38..e166eb3c 100644 --- a/pokemod/SpeciesEvolution.h +++ b/pokemod/SpeciesEvolution.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - class SpeciesEvolution : public Object { public: @@ -57,12 +54,12 @@ class SpeciesEvolution : public Object void load(const QDomElement& xml, int id = INT_MAX); QDomElement save() const; - void setSpecies(const int species) throw(BoundsException); - void setStyle(const int style) throw(BoundsException); - void setValue1(const int value1) throw(Exception); - void setValue2(const int value2) throw(Exception); - void setValue3(const int value3) throw(UnusedException); - void setLevel(const int level) throw(BoundsException); + void setSpecies(const int species); + void setStyle(const int style); + void setValue1(const int value1); + void setValue2(const int value2); + void setValue3(const int value3); + void setLevel(const int level); int species() const; int style() const; @@ -73,7 +70,7 @@ class SpeciesEvolution : public Object SpeciesEvolution& operator=(const SpeciesEvolution& rhs); private: - bool validate() const; + void validate(QTextStream& stream); int m_species; int m_style; diff --git a/pokemod/SpeciesItem.cpp b/pokemod/SpeciesItem.cpp index 0cadaad4..2788f18f 100644 --- a/pokemod/SpeciesItem.cpp +++ b/pokemod/SpeciesItem.cpp @@ -46,22 +46,11 @@ SpeciesItem::SpeciesItem(const QDomElement& xml, const Object* parent, const int load(xml, id); } -bool SpeciesItem::validate() const +void SpeciesItem::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Item with id %1---").arg(id()), Pokemod::V_Msg); -// if (static_cast<const Pokemod*>(pokemod())->itemIndex(m_item) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid item"); -// valid = false; -// } -// if (!m_weight) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid weight"); -// valid = false; -// } -// return valid; + TEST_SETUP(); + TEST(setItem, item); + TEST(setWeight, weight); } void SpeciesItem::load(const QDomElement& xml, int id) @@ -79,17 +68,23 @@ QDomElement SpeciesItem::save() const return xml; } -void SpeciesItem::setItem(const int item) throw(BoundsException) +void SpeciesItem::setItem(const int item) { if (static_cast<const Pokemod*>(pokemod())->itemIndex(item) == INT_MAX) - error<BoundsException>("item"); + { + boundsError("item"); + return; + } m_item = item; } -void SpeciesItem::setWeight(const int weight) throw(BoundsException) +void SpeciesItem::setWeight(const int weight) { if (!weight) - error<BoundsException>("weight"); + { + boundsError("weight"); + return; + } m_weight = weight; } diff --git a/pokemod/SpeciesItem.h b/pokemod/SpeciesItem.h index 1697e89b..70d2a268 100644 --- a/pokemod/SpeciesItem.h +++ b/pokemod/SpeciesItem.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - class SpeciesItem : public Object { public: @@ -35,15 +32,15 @@ class SpeciesItem : public Object void load(const QDomElement& xml, int id = INT_MAX); QDomElement save() const; - void setItem(const int item) throw(BoundsException); - void setWeight(const int weight) throw(BoundsException); + void setItem(const int item); + void setWeight(const int weight); int item() const; int weight() const; SpeciesItem& operator=(const SpeciesItem& rhs); private: - bool validate() const; + void validate(QTextStream& stream); int m_item; int m_weight; diff --git a/pokemod/SpeciesMove.cpp b/pokemod/SpeciesMove.cpp index 79f2db12..15857f64 100644 --- a/pokemod/SpeciesMove.cpp +++ b/pokemod/SpeciesMove.cpp @@ -47,27 +47,12 @@ SpeciesMove::SpeciesMove(const QDomElement& xml, const Object* parent, const int load(xml, id); } -bool SpeciesMove::validate() const +void SpeciesMove::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("------Move with id %1---").arg(id()), Pokemod::V_Msg); -// if (static_cast<const Pokemod*>(pokemod())->moveIndex(m_move) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid move"); -// valid = false; -// } -// if (m_level < static_cast<const Pokemod*>(pokemod())->rules()->maxLevel()) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid level"); -// valid = false; -// } -// if (m_wild < static_cast<const Pokemod*>(pokemod())->rules()->maxLevel()) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid wild level"); -// valid = false; -// } -// return valid; + TEST_SETUP(); + TEST(setMove, move); + TEST(setLevel, level); + TEST(setWild, wild); } void SpeciesMove::load(const QDomElement& xml, int id) @@ -87,24 +72,33 @@ QDomElement SpeciesMove::save() const return xml; } -void SpeciesMove::setMove(const int move) throw(BoundsException) +void SpeciesMove::setMove(const int move) { if (static_cast<const Pokemod*>(pokemod())->moveIndex(move) == INT_MAX) - error<BoundsException>("move"); + { + boundsError("move"); + return; + } m_move = move; } -void SpeciesMove::setLevel(const int level) throw(BoundsException) +void SpeciesMove::setLevel(const int level) { if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() <= level) - error<BoundsException>("level"); + { + boundsError("level"); + return; + } m_level = level; } -void SpeciesMove::setWild(const int wild) throw(BoundsException) +void SpeciesMove::setWild(const int wild) { if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() <= wild) - error<BoundsException>("wild"); + { + boundsError("wild"); + return; + } m_wild = wild; } diff --git a/pokemod/SpeciesMove.h b/pokemod/SpeciesMove.h index c483a42c..64f4c37b 100644 --- a/pokemod/SpeciesMove.h +++ b/pokemod/SpeciesMove.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - class SpeciesMove : public Object { public: @@ -35,9 +32,9 @@ class SpeciesMove : public Object void load(const QDomElement& xml, int id = INT_MAX); QDomElement save() const; - void setMove(const int move) throw(BoundsException); - void setLevel(const int level) throw(BoundsException); - void setWild(const int wild) throw(BoundsException); + void setMove(const int move); + void setLevel(const int level); + void setWild(const int wild); int move() const; int level() const; @@ -45,7 +42,7 @@ class SpeciesMove : public Object SpeciesMove& operator=(const SpeciesMove& rhs); private: - bool validate() const; + void validate(QTextStream& stream); int m_move; int m_level; diff --git a/pokemod/Store.cpp b/pokemod/Store.cpp index 27f33a6a..2ba5c553 100644 --- a/pokemod/Store.cpp +++ b/pokemod/Store.cpp @@ -45,46 +45,29 @@ Store::Store(const QDomElement& xml, const Object* parent, const int id) : load(xml, id); } -bool Store::validate() const +void Store::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Store \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is noe defiend"); -// valid = false; -// } -// if (!m_items.size()) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no items"); -// valid = false; -// } -// QMap<int, bool> valueChecker; -// foreach (int item, m_items) -// { -// if (static_cast<const Pokemod*>(pokemod())->itemIndex(item) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid item"); -// valid = false; -// } -// if (valueChecker[item]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate of item %1").arg(item)); -// valueChecker[item] = true; -// } -// return valid; + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + if (m_item.size()) + { + TEST_LIST(setItem, item); + } + else + error(stream, "No items in the store"); } void Store::load(const QDomElement& xml, int id) { LOAD_ID(); - LOAD_LIST(int, items); + LOAD_LIST(int, item); } QDomElement Store::save() const { SAVE_CREATE(); - SAVE_LIST(int, items); + SAVE_LIST(int, item); return xml; } @@ -93,17 +76,20 @@ void Store::setName(const QString& name) m_name = name; } -void Store::setItem(const int item, const bool state) throw(BoundsException) +void Store::setItem(const int item, const bool state) { if (static_cast<const Pokemod*>(pokemod())->itemIndex(item) == INT_MAX) - error<BoundsException>("item"); + { + boundsError("item"); + return; + } if (state) { - if (!m_items.contains(item)) - m_items.append(item); + if (!m_item.contains(item)) + m_item.append(item); } else - m_items.removeAll(item); + m_item.removeAll(item); } QString Store::name() const @@ -113,7 +99,7 @@ QString Store::name() const bool Store::item(const int item) const { - return m_items.contains(item); + return m_item.contains(item); } Store& Store::operator=(const Store& rhs) @@ -121,6 +107,6 @@ Store& Store::operator=(const Store& rhs) if (this == &rhs) return *this; COPY(name); - COPY(items); + COPY(item); return *this; } diff --git a/pokemod/Store.h b/pokemod/Store.h index 256b9697..fb440184 100644 --- a/pokemod/Store.h +++ b/pokemod/Store.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - // Qt includes #include <QList> @@ -39,17 +36,17 @@ class Store : public Object QDomElement save() const; void setName(const QString& name); - void setItem(const int item, const bool state) throw(BoundsException); + void setItem(const int item, const bool state); QString name() const; bool item(const int item) const; Store& operator=(const Store& rhs); private: - bool validate() const; + void validate(QTextStream& stream); QString m_name; - QList<int> m_items; + QList<int> m_item; }; #endif diff --git a/pokemod/Tile.cpp b/pokemod/Tile.cpp index c6e346cb..4c45f345 100644 --- a/pokemod/Tile.cpp +++ b/pokemod/Tile.cpp @@ -58,50 +58,17 @@ Tile::Tile(const QDomElement& xml, const Object* parent, const int id) : load(xml, id); } -bool Tile::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Tile \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is not defined"); -// valid = false; -// } -// if ((m_hmType == Pokemod::HM_Waterfall) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down])) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("A waterfall tile must be accessible from above and below"); -// valid = false; -// } -// else if ((m_hmType == Pokemod::HM_Whirlpool) && ((m_under == id()) || (static_cast<const Pokemod*>(pokemod())->tileIndex(m_under) == INT_MAX) || (static_cast<const Pokemod*>(pokemod())->tileById(m_under)->hmType() != Pokemod::HM_Surf) || (static_cast<const Pokemod*>(pokemod())->tileById(m_under)->hmType() != Pokemod::HM_Dive))) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid under tile"); -// valid = false; -// } -// else if ((m_hmType == Pokemod::HM_Whirlpool) && ((m_under == id()) || (static_cast<const Pokemod*>(pokemod())->tileIndex(m_under) == INT_MAX) || (static_cast<const Pokemod*>(pokemod())->tileById(m_under)->hmType() != Pokemod::HM_End))) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid under tile"); -// valid = false; -// } -// else if ((m_hmType == Pokemod::HM_RockClimb) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down])) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("A rock climb tile must be accessible from above and below"); -// valid = false; -// } -// if (m_forceType < End) -// { -// if (((m_forceType == Slip) || (m_forceType == Force) || (m_forceType == Push)) && (Pokemod::D_End <= m_forceDirection)) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid force direction"); -// valid = false; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid force type"); -// valid = false; -// } -// return valid; +void Tile::validate(QTextStream& stream) +{ + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setSprite, sprite); + TEST(setWildChance, wildChance); + TEST(setHmType, hmType); + TEST(setUnder, under); + TEST(setForceType, forceType); + TEST(setForceDirection, forceDirection); } void Tile::load(const QDomElement& xml, int id) @@ -136,62 +103,94 @@ void Tile::setName(const QString& name) m_name = name; } -void Tile::setSprite(const QPixmap& sprite) throw(SizeException) +void Tile::setSprite(const QPixmap& sprite) { if (sprite.size() != QSize(64, 64)) - error<SizeException>("sprte"); + { + sizeError("sprite"); + return; + } m_sprite = sprite; } -void Tile::setFrom(const int direction, const bool state) throw(BoundsException) +void Tile::setFrom(const int direction, const bool state) { if (Pokemod::D_End <= direction) - error<BoundsException>("direction"); + { + boundsError("direction"); + return; + } m_from[direction] = state; } -void Tile::setWildChance(const Fraction& wildChance) throw(BoundsException) +void Tile::setWildChance(const Fraction& wildChance) { if (1 < wildChance) - error<BoundsException>("wildChance"); + { + boundsError("wildChance"); + return; + } m_wildChance = wildChance; } -void Tile::setHMType(const int hmType) throw(BoundsException) +void Tile::setHmType(const int hmType) { if (Pokemod::HM_End <= hmType) - error<BoundsException>("hmType"); + { + boundsError("hmType"); + return; + } + if (((hmType == Pokemod::HM_Waterfall) || (hmType == Pokemod::HM_RockClimb)) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down])) + { + error("accessibility for HM type"); + return; + } m_hmType = hmType; m_under = INT_MAX; } -void Tile::setUnder(const int under) throw(Exception) +void Tile::setUnder(const int under) { if (m_hmType != INT_MAX) { if ((m_hmType != Pokemod::HM_Whirlpool) || (m_hmType != Pokemod::HM_Cut) || (m_hmType != Pokemod::HM_RockSmash)) - error<UnusedException>("under"); + { + unusedError("under"); + return; + } if ((under == id()) || (static_cast<const Pokemod*>(pokemod())->tileIndex(under) == INT_MAX)) - error<BoundsException>("under"); + { + boundsError("under"); + return; + } } m_under = under; } -void Tile::setForceType(const int forceType) throw(BoundsException) +void Tile::setForceType(const int forceType) { if (End <= forceType) - error<BoundsException>("forceType"); + { + boundsError("forceType"); + return; + } m_forceType = forceType; } -void Tile::setForceDirection(const int forceDirection) throw(Exception) +void Tile::setForceDirection(const int forceDirection) { if (m_forceType != INT_MAX) { if (m_forceType == Stop) - error<UnusedException>("forceDirection"); + { + unusedError("forceDirection"); + return; + } if (Pokemod::D_End <= forceDirection) - error<BoundsException>("forceDirection"); + { + boundsError("forceDirection"); + return; + } } m_forceDirection = forceDirection; } @@ -206,10 +205,11 @@ QPixmap Tile::sprite() const return m_sprite; } -bool Tile::from(const int direction) const throw(BoundsException) +bool Tile::from(const int direction) const { + // TODO: Message about fetching out-of-bounds if (Pokemod::D_End <= direction) - warning<BoundsException>("direction"); + return false; return m_from[direction]; } diff --git a/pokemod/Tile.h b/pokemod/Tile.h index d13a4b51..4d7401d2 100644 --- a/pokemod/Tile.h +++ b/pokemod/Tile.h @@ -23,7 +23,6 @@ #include "Pokemod.h" // General includes -#include "../general/Exception.h" #include "../general/Fraction.h" class Tile : public Object @@ -48,17 +47,17 @@ class Tile : public Object QDomElement save() const; void setName(const QString& name); - void setSprite(const QPixmap& sprite) throw(SizeException); - void setFrom(const int direction, const bool state) throw(BoundsException); - void setWildChance(const Fraction& wildChance) throw(BoundsException); - void setHMType(const int hmType) throw(BoundsException); - void setUnder(const int under) throw(Exception); - void setForceType(const int forceType) throw(BoundsException); - void setForceDirection(const int forceDirection) throw(Exception); + void setSprite(const QPixmap& sprite); + void setFrom(const int direction, const bool state); + void setWildChance(const Fraction& wildChance); + void setHmType(const int hmType); + void setUnder(const int under); + void setForceType(const int forceType); + void setForceDirection(const int forceDirection); QString name() const; QPixmap sprite() const; - bool from(const int direction) const throw(BoundsException); + bool from(const int direction) const; Fraction wildChance() const; int hmType() const; int under() const; @@ -67,7 +66,7 @@ class Tile : public Object Tile& operator=(const Tile& rhs); private: - bool validate() const; + void validate(QTextStream& stream); QString m_name; QPixmap m_sprite; diff --git a/pokemod/Time.cpp b/pokemod/Time.cpp index 50754361..e04b69f8 100644 --- a/pokemod/Time.cpp +++ b/pokemod/Time.cpp @@ -47,27 +47,13 @@ Time::Time(const QDomElement& xml, const Object* parent, const int id) : load(xml, id); } -bool Time::validate() const +void Time::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Time \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name not defined"); -// valid = false; -// } -// if (23 < m_hour) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid starting hour"); -// valid = false; -// } -// if (59 < m_minute) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid start minute"); -// valid = false; -// } -// return valid; + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setHour, hour); + TEST(setMinute, minute); } void Time::load(const QDomElement& xml, int id) @@ -92,17 +78,23 @@ void Time::setName(const QString& name) m_name = name; } -void Time::setHour(const int hour) throw(BoundsException) +void Time::setHour(const int hour) { if (24 <= hour) - error<BoundsException>("hour"); + { + boundsError("hour"); + return; + } m_hour = hour; } -void Time::setMinute(const int minute) throw(BoundsException) +void Time::setMinute(const int minute) { if (60 <= minute) - error<BoundsException>("minute"); + { + boundsError("minute"); + return; + } m_minute = minute; } diff --git a/pokemod/Time.h b/pokemod/Time.h index 74998ac2..c03030e4 100644 --- a/pokemod/Time.h +++ b/pokemod/Time.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - class Time : public Object { public: @@ -36,8 +33,8 @@ class Time : public Object QDomElement save() const; void setName(const QString& name); - void setHour(const int hour) throw(BoundsException); - void setMinute(const int minutes) throw(BoundsException); + void setHour(const int hour); + void setMinute(const int minutes); QString name() const; int hour() const; @@ -45,7 +42,7 @@ class Time : public Object Time& operator=(const Time& rhs); private: - bool validate() const; + void validate(QTextStream& stream); QString m_name; int m_hour; diff --git a/pokemod/Trainer.cpp b/pokemod/Trainer.cpp index 270df528..eddb5972 100644 --- a/pokemod/Trainer.cpp +++ b/pokemod/Trainer.cpp @@ -50,22 +50,13 @@ Trainer::Trainer(const QDomElement& xml, const Object* parent, const int id) : load(xml, id); } -bool Trainer::validate() const +void Trainer::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Trainer \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name not defined"); -// valid = false; -// } -// if (m_moneyFactor < 0) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid money factor"); -// valid = false; -// } -// return valid; + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setMoneyFactor, moneyFactor); + TEST(setSkin, skin); } void Trainer::load(const QDomElement& xml, int id) @@ -90,21 +81,27 @@ void Trainer::setName(const QString& name) m_name = name; } -void Trainer::setMoneyFactor(const int moneyFactor) throw(BoundsException) +void Trainer::setMoneyFactor(const int moneyFactor) { if (moneyFactor < 0) - error<BoundsException>("moneyFactor"); + { + boundsError("moneyFactor"); + return; + } m_moneyFactor = moneyFactor; } -void Trainer::setSkin(const QPixmap& skin) throw(SizeException) +void Trainer::setSkin(const QPixmap& skin) { if (skin.size() != QSize(192, 128)) - error<SizeException>("skin"); + { + sizeError("skin"); + return; + } m_skin = skin; } -// void Trainer::setAi(const QString& fileName) throw(Exception) +// void Trainer::setAi(const QString& fileName) // { // QFile file(ai()); // if (file.exists() && !file.remove()) diff --git a/pokemod/Trainer.h b/pokemod/Trainer.h index 28e74239..194cb15a 100644 --- a/pokemod/Trainer.h +++ b/pokemod/Trainer.h @@ -21,9 +21,6 @@ // Pokemod includes #include "Object.h" -// General includes -#include "../general/Exception.h" - // Qt includes #include <QPixmap> @@ -39,9 +36,9 @@ class Trainer : public Object QDomElement save() const; void setName(const QString& name); - void setMoneyFactor(const int moneyFactor) throw(BoundsException); - void setSkin(const QPixmap& skin) throw(SizeException); -// void setAi(const QString& fileName) throw(Exception); + void setMoneyFactor(const int moneyFactor); + void setSkin(const QPixmap& skin); +// void setAi(const QString& fileName); QString name() const; int moneyFactor() const; @@ -50,7 +47,7 @@ class Trainer : public Object Trainer& operator=(const Trainer& rhs); private: - bool validate() const; + void validate(QTextStream& stream); QString m_name; int m_moneyFactor; diff --git a/pokemod/Type.cpp b/pokemod/Type.cpp index 6180c78a..4ccc7131 100644 --- a/pokemod/Type.cpp +++ b/pokemod/Type.cpp @@ -48,17 +48,10 @@ Type::Type(const QDomElement& xml, const Object* parent, const int id) : load(xml, id); } -bool Type::validate() const +void Type::validate(QTextStream& stream) { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Type \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("No name defined"); -// valid = false; -// } -// return valid; + if (m_name.isEmpty()) + error(stream, "Name is empty"); } void Type::load(const QDomElement& xml, int id) @@ -83,17 +76,23 @@ void Type::setName(const QString& name) m_name = name; } -void Type::setStab(const Fraction& stab) throw(BoundsException) +void Type::setStab(const Fraction& stab) { if (1 < stab) - error<BoundsException>("stab"); + { + boundsError("stab"); + return; + } m_stab = stab; } -void Type::setImmunity(const int status, const bool immune) throw(BoundsException) +void Type::setImmunity(const int status, const bool immune) { if (Pokemod::STS_End <= status) - error<BoundsException>("immunnity"); + { + boundsError("immunnity"); + return; + } m_immunity[status] = immune; } @@ -107,10 +106,11 @@ Fraction Type::stab() const return m_stab; } -bool Type::immunity(const int status) const throw(BoundsException) +bool Type::immunity(const int status) const { + // TODO: Message about fetching out-of-bounds if (Pokemod::STS_End <= status) - warning<BoundsException>("immunnity"); + return false; return m_immunity[status]; } diff --git a/pokemod/Type.h b/pokemod/Type.h index 8d8fc867..29145b42 100644 --- a/pokemod/Type.h +++ b/pokemod/Type.h @@ -37,16 +37,16 @@ class Type : public Object QDomElement save() const; void setName(const QString& name); - void setStab(const Fraction& stab) throw(BoundsException); - void setImmunity(const int status, const bool immune) throw(BoundsException); + void setStab(const Fraction& stab); + void setImmunity(const int status, const bool immune); QString name() const; Fraction stab() const; - bool immunity(const int status) const throw(BoundsException); + bool immunity(const int status) const; Type& operator=(const Type& rhs); private: - bool validate() const; + void validate(QTextStream& stream); QString m_name; Fraction m_stab; diff --git a/pokemod/pokemod.pro b/pokemod/pokemod.pro index cfe81a1c..64668dc8 100644 --- a/pokemod/pokemod.pro +++ b/pokemod/pokemod.pro @@ -6,9 +6,8 @@ LIBS += -L../../bin \ CONFIG += qt \ warn_on \ - dll \ - exceptions -!win32:CONFIG += debug + dll +!win32 : CONFIG += debug QT += xml win32 { @@ -38,6 +37,7 @@ SOURCES += Ability.cpp \ Move.cpp \ MoveEffect.cpp \ Nature.cpp \ + Object.cpp \ Pokemod.cpp \ Rules.cpp \ SpeciesAbility.cpp \ @@ -87,10 +87,10 @@ HEADERS += AbilityEffect.h \ Type.h INSTALLS += target -isEmpty(PREFIX) { +isEmpty(PREFIX){ PREFIX = $$(PREFIX)/lib } -isEmpty(PREFIX) { +isEmpty(PREFIX){ PREFIX = /usr/lib`kde4-config --libsuffix` } target.path = $$PREFIX |
