diff options
Diffstat (limited to 'pokemod/CoinList.cpp')
| -rw-r--r-- | pokemod/CoinList.cpp | 112 |
1 files changed, 44 insertions, 68 deletions
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)); } |
