From 02d571db3ef9fa2cb73203ef3dc46827ee6960cf Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 29 Dec 2008 11:51:33 -0500 Subject: Added macros for subclass handling --- sigmod/Map.cpp | 429 ++------------------------------------------------------- 1 file changed, 10 insertions(+), 419 deletions(-) (limited to 'sigmod/Map.cpp') diff --git a/sigmod/Map.cpp b/sigmod/Map.cpp index c71bf552..af58d36f 100644 --- a/sigmod/Map.cpp +++ b/sigmod/Map.cpp @@ -169,415 +169,11 @@ CHECK(Map, Type, type) CHECK_BOUNDS(Map, int, width, 1, INT_MAX) CHECK_BOUNDS(Map, int, height, 1, INT_MAX) -const Sigmod::MapEffect* Sigmod::Map::effect(const int index) const -{ - if (index < effectCount()) - return m_effects.at(index); - return NULL; -} - -Sigmod::MapEffect* Sigmod::Map::effect(const int index) -{ - if (index < effectCount()) - return m_effects[index]; - return NULL; -} - -const Sigmod::MapEffect* Sigmod::Map::effectById(const int index) const -{ - return effect(effectIndex(index)); -} - -Sigmod::MapEffect* Sigmod::Map::effectById(const int index) -{ - return effect(effectIndex(index)); -} - -int Sigmod::Map::effectIndex(const int id) const -{ - for (int i = 0; i < effectCount(); ++i) - { - if (m_effects[i]->id() == id) - return i; - } - return INT_MAX; -} - -int Sigmod::Map::effectCount() const -{ - return m_effects.size(); -} - -Sigmod::MapEffect* Sigmod::Map::newEffect() -{ - return newEffect(new MapEffect(this, newEffectId())); -} - -Sigmod::MapEffect* Sigmod::Map::newEffect(const QDomElement& xml) -{ - return newEffect(new MapEffect(xml, this, newEffectId())); -} - -Sigmod::MapEffect* Sigmod::Map::newEffect(const MapEffect& effect) -{ - return newEffect(new MapEffect(effect, this, newEffectId())); -} - -Sigmod::MapEffect* Sigmod::Map::newEffect(MapEffect* effect) -{ - m_effects.append(effect); - return effect; -} - -void Sigmod::Map::deleteEffect(const int index) -{ - if (index < effectCount()) - { - delete m_effects[index]; - m_effects.removeAt(index); - } -} - -void Sigmod::Map::deleteEffectById(const int id) -{ - deleteEffect(effectIndex(id)); -} - -int Sigmod::Map::newEffectId() const -{ - int i = 0; - while ((i < effectCount()) && (effectIndex(i) != INT_MAX)) - ++i; - return i; -} - -const Sigmod::MapTile* Sigmod::Map::tile(const int index) const -{ - if (index < tileCount()) - return m_tiles.at(index); - return NULL; -} - -Sigmod::MapTile* Sigmod::Map::tile(const int index) -{ - if (index < tileCount()) - return m_tiles[index]; - return NULL; -} - -const Sigmod::MapTile* Sigmod::Map::tileById(const int index) const -{ - return tile(tileIndex(index)); -} - -Sigmod::MapTile* Sigmod::Map::tileById(const int index) -{ - return tile(tileIndex(index)); -} - -int Sigmod::Map::tileIndex(const int id) const -{ - for (int i = 0; i < tileCount(); ++i) - { - if (m_tiles[i]->id() == id) - return i; - } - return INT_MAX; -} - -int Sigmod::Map::tileCount() const -{ - return m_tiles.size(); -} - -Sigmod::MapTile* Sigmod::Map::newTile() -{ - return newTile(new MapTile(this, newTileId())); -} - -Sigmod::MapTile* Sigmod::Map::newTile(const QDomElement& xml) -{ - return newTile(new MapTile(xml, this, newTileId())); -} - -Sigmod::MapTile* Sigmod::Map::newTile(const MapTile& tile) -{ - return newTile(new MapTile(tile, this, newTileId())); -} - -Sigmod::MapTile* Sigmod::Map::newTile(MapTile* tile) -{ - m_tiles.append(tile); - return tile; -} - -void Sigmod::Map::deleteTile(const int index) -{ - if (index < tileCount()) - { - delete m_tiles[index]; - m_tiles.removeAt(index); - } -} - -void Sigmod::Map::deleteTileById(const int id) -{ - deleteTile(tileIndex(id)); -} - -int Sigmod::Map::newTileId() const -{ - int i = 0; - while ((i < tileCount()) && (tileIndex(i) != INT_MAX)) - ++i; - return i; -} - -const Sigmod::MapTrainer* Sigmod::Map::trainer(const int index) const -{ - if (index < trainerCount()) - return m_trainers.at(index); - return NULL; -} - -Sigmod::MapTrainer* Sigmod::Map::trainer(const int index) -{ - if (index < trainerCount()) - return m_trainers[index]; - return NULL; -} - -const Sigmod::MapTrainer* Sigmod::Map::trainerById(const int id) const -{ - return trainer(trainerIndex(id)); -} - -Sigmod::MapTrainer* Sigmod::Map::trainerById(const int id) -{ - return trainer(trainerIndex(id)); -} - -int Sigmod::Map::trainerIndex(const int id) const -{ - for (int i = 0; i < trainerCount(); ++i) - { - if (m_trainers[i]->id() == id) - return i; - } - return INT_MAX; -} - -int Sigmod::Map::trainerCount() const -{ - return m_trainers.size(); -} - -Sigmod::MapTrainer* Sigmod::Map::newTrainer() -{ - return newTrainer(new MapTrainer(this, newTrainerId())); -} - -Sigmod::MapTrainer* Sigmod::Map::newTrainer(const QDomElement& xml) -{ - return newTrainer(new MapTrainer(xml, this, newTrainerId())); -} - -Sigmod::MapTrainer* Sigmod::Map::newTrainer(const MapTrainer& trainer) -{ - return newTrainer(new MapTrainer(trainer, this, newTrainerId())); -} - -Sigmod::MapTrainer* Sigmod::Map::newTrainer(MapTrainer* trainer) -{ - m_trainers.append(trainer); - return trainer; -} - -void Sigmod::Map::deleteTrainer(const int index) -{ - if (index < trainerCount()) - { - delete m_trainers[index]; - m_trainers.removeAt(index); - } -} - -void Sigmod::Map::deleteTrainerById(const int id) -{ - deleteTrainer(trainerIndex(id)); -} - -int Sigmod::Map::newTrainerId() const -{ - int i = 0; - while ((i < trainerCount()) && (trainerIndex(i) != INT_MAX)) - ++i; - return i; -} - -const Sigmod::MapWarp* Sigmod::Map::warp(const int index) const -{ - if (index < warpCount()) - return m_warps.at(index); - return NULL; -} - -Sigmod::MapWarp* Sigmod::Map::warp(const int index) -{ - if (index < warpCount()) - return m_warps[index]; - return NULL; -} - -const Sigmod::MapWarp* Sigmod::Map::warpById(const int id) const -{ - return warp(warpIndex(id)); -} - -Sigmod::MapWarp* Sigmod::Map::warpById(const int id) -{ - return warp(warpIndex(id)); -} - -int Sigmod::Map::warpIndex(const int id) const -{ - for (int i = 0; i < warpCount(); ++i) - { - if (m_warps[i]->id() == id) - return i; - } - return INT_MAX; -} - -int Sigmod::Map::warpCount() const -{ - return m_warps.size(); -} - -Sigmod::MapWarp* Sigmod::Map::newWarp() -{ - return newWarp(new MapWarp(this, newWarpId())); -} - -Sigmod::MapWarp* Sigmod::Map::newWarp(const QDomElement& xml) -{ - return newWarp(new MapWarp(xml, this, newWarpId())); -} - -Sigmod::MapWarp* Sigmod::Map::newWarp(const MapWarp& warp) -{ - return newWarp(new MapWarp(warp, this, newWarpId())); -} - -Sigmod::MapWarp* Sigmod::Map::newWarp(MapWarp* warp) -{ - m_warps.append(warp); - return warp; -} - -void Sigmod::Map::deleteWarp(const int index) -{ - if (index < warpCount()) - { - delete m_warps[index]; - m_warps.removeAt(index); - } -} - -void Sigmod::Map::deleteWarpById(const int id) -{ - deleteWarp(warpIndex(id)); -} - -int Sigmod::Map::newWarpId() const -{ - int i = 0; - while ((i < warpCount()) && (warpIndex(i) != INT_MAX)) - ++i; - return i; -} - -const Sigmod::MapWildList* Sigmod::Map::wildList(const int index) const -{ - if (index < wildListCount()) - return m_wildLists.at(index); - return NULL; -} - -Sigmod::MapWildList* Sigmod::Map::wildList(const int index) -{ - if (index < wildListCount()) - return m_wildLists[index]; - return NULL; -} - -const Sigmod::MapWildList* Sigmod::Map::wildListById(const int id) const -{ - return wildList(wildListIndex(id)); -} - -Sigmod::MapWildList* Sigmod::Map::wildListById(const int id) -{ - return wildList(wildListIndex(id)); -} - -int Sigmod::Map::wildListIndex(const int id) const -{ - for (int i = 0; i < wildListCount(); ++i) - { - if (m_wildLists[i]->id() == id) - return i; - } - return INT_MAX; -} - -int Sigmod::Map::wildListCount() const -{ - return m_wildLists.size(); -} - -Sigmod::MapWildList* Sigmod::Map::newWildList() -{ - return newWildList(new MapWildList(this, newWildListId())); -} - -Sigmod::MapWildList* Sigmod::Map::newWildList(const QDomElement& xml) -{ - return newWildList(new MapWildList(xml, this, newWildListId())); -} - -Sigmod::MapWildList* Sigmod::Map::newWildList(const MapWildList& wildList) -{ - return newWildList(new MapWildList(wildList, this, newWildListId())); -} - -Sigmod::MapWildList* Sigmod::Map::newWildList(MapWildList* wildList) -{ - m_wildLists.append(wildList); - return wildList; -} - -void Sigmod::Map::deleteWildList(const int index) -{ - if (index < wildListCount()) - { - delete m_wildLists[index]; - m_wildLists.removeAt(index); - } -} - -void Sigmod::Map::deleteWildListById(const int id) -{ - deleteWildList(wildListIndex(id)); -} - -int Sigmod::Map::newWildListId() const -{ - int i = 0; - while ((i < warpCount()) && (warpIndex(i) != INT_MAX)) - ++i; - return i; -} +SUBCLASS(Map, Effect, effect, effects) +SUBCLASS(Map, Tile, tile, tiles) +SUBCLASS(Map, Trainer, trainer, trainers) +SUBCLASS(Map, Warp, warp, warps) +SUBCLASS(Map, WildList, wildList, wildLists) Sigmod::Map& Sigmod::Map::operator=(const Map& rhs) { @@ -599,14 +195,9 @@ Sigmod::Map& Sigmod::Map::operator=(const Map& rhs) void Sigmod::Map::clear() { - qDeleteAll(m_effects); - m_effects.clear(); - qDeleteAll(m_tiles); - m_tiles.clear(); - qDeleteAll(m_trainers); - m_trainers.clear(); - qDeleteAll(m_warps); - m_warps.clear(); - qDeleteAll(m_wildLists); - m_wildLists.clear(); + SUBCLASS_CLEAR(effects); + SUBCLASS_CLEAR(tiles); + SUBCLASS_CLEAR(trainers); + SUBCLASS_CLEAR(warps); + SUBCLASS_CLEAR(wildLists); } -- cgit