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 /pokemod/Ability.cpp | |
| parent | 696414f1dc8bc419427efb6c1abe1bbae0a68a56 (diff) | |
| download | sigen-822b5fcaa34b78b9668a58680f9e0d89aa3fd7bd.tar.gz sigen-822b5fcaa34b78b9668a58680f9e0d89aa3fd7bd.tar.xz sigen-822b5fcaa34b78b9668a58680f9e0d89aa3fd7bd.zip | |
[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
Diffstat (limited to 'pokemod/Ability.cpp')
| -rw-r--r-- | pokemod/Ability.cpp | 64 |
1 files changed, 27 insertions, 37 deletions
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)); } |
