summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-12-08 21:13:38 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-12-08 21:22:43 +0100
commitddc93c461070fb3d868fbb5426e8361d1b93ee38 (patch)
tree250eacd391542d36a51c4d3aa398d4f6346619fb
parentd129ce9776a6fd0e165b676a3addd14186c5d85d (diff)
downloadmana-ddc93c461070fb3d868fbb5426e8361d1b93ee38.tar.gz
mana-ddc93c461070fb3d868fbb5426e8361d1b93ee38.tar.bz2
mana-ddc93c461070fb3d868fbb5426e8361d1b93ee38.tar.xz
mana-ddc93c461070fb3d868fbb5426e8361d1b93ee38.zip
Introduced another template to make deleting all values in a container easier.
Inspired by qDeleteAll() from Qt. Conflicts: ChangeLog src/beingmanager.cpp src/channelmanager.cpp src/gui/skill.cpp src/map.cpp src/resources/monsterinfo.cpp (cherry picked from mainline)
-rw-r--r--src/being.cpp3
-rw-r--r--src/beingmanager.cpp4
-rw-r--r--src/flooritemmanager.cpp4
-rw-r--r--src/gui/setup.cpp2
-rw-r--r--src/gui/shop.cpp4
-rw-r--r--src/gui/skill.cpp4
-rw-r--r--src/gui/windowcontainer.cpp4
-rw-r--r--src/map.cpp7
-rw-r--r--src/resources/imageset.cpp4
-rw-r--r--src/resources/itemdb.cpp3
-rw-r--r--src/resources/monsterinfo.cpp5
-rw-r--r--src/utils/dtor.h7
12 files changed, 20 insertions, 31 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 5f7ad73f..e1c370c3 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -20,7 +20,6 @@
*/
#include "being.h"
-#include <algorithm>
#include <cassert>
#include "animatedsprite.h"
@@ -96,7 +95,7 @@ Being::Being(int id, int job, Map *map):
Being::~Being()
{
- std::for_each(mSprites.begin(), mSprites.end(), make_dtor(mSprites));
+ delete_all(mSprites);
clearPath();
setMap(NULL);
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp
index 51d45213..a1cb61e8 100644
--- a/src/beingmanager.cpp
+++ b/src/beingmanager.cpp
@@ -19,8 +19,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <algorithm>
-
#include "beingmanager.h"
#include "localplayer.h"
@@ -191,7 +189,7 @@ void BeingManager::clear()
mBeings.remove(player_node);
}
- for_each(mBeings.begin(), mBeings.end(), make_dtor(mBeings));
+ delete_all(mBeings);
mBeings.clear();
if (player_node)
diff --git a/src/flooritemmanager.cpp b/src/flooritemmanager.cpp
index 006d62c1..68c84b5b 100644
--- a/src/flooritemmanager.cpp
+++ b/src/flooritemmanager.cpp
@@ -19,8 +19,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <algorithm>
-
#include "flooritemmanager.h"
#include "floor_item.h"
@@ -48,7 +46,7 @@ void FloorItemManager::destroy(FloorItem *item)
void FloorItemManager::clear()
{
- for_each(mFloorItems.begin(), mFloorItems.end(), make_dtor(mFloorItems));
+ delete_all(mFloorItems);
mFloorItems.clear();
}
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index e8e0905e..2f6c6140 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -99,7 +99,7 @@ Setup::Setup():
Setup::~Setup()
{
- for_each(mTabs.begin(), mTabs.end(), make_dtor(mTabs));
+ delete_all(mTabs);
}
void Setup::action(const gcn::ActionEvent &event)
diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp
index 085e93ce..a4478a62 100644
--- a/src/gui/shop.cpp
+++ b/src/gui/shop.cpp
@@ -23,8 +23,6 @@
#include "../utils/dtor.h"
-#include <algorithm>
-
ShopItems::~ShopItems()
{
clear();
@@ -59,7 +57,7 @@ ShopItem* ShopItems::at(int i) const
void ShopItems::clear()
{
- std::for_each(mShopItems.begin(), mShopItems.end(), make_dtor(mShopItems));
+ delete_all(mShopItems);
mShopItems.clear();
}
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index cadde0b9..1b7466ff 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -19,8 +19,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <algorithm>
-
#include <guichan/widgets/label.hpp>
#include "skill.h"
@@ -248,7 +246,7 @@ void SkillDialog::setSkill(int id, int lvl, int mp)
void SkillDialog::cleanList()
{
- for_each(mSkillList.begin(), mSkillList.end(), make_dtor(mSkillList));
+ delete_all(mSkillList);
mSkillList.clear();
}
diff --git a/src/gui/windowcontainer.cpp b/src/gui/windowcontainer.cpp
index f92e8388..d8535f73 100644
--- a/src/gui/windowcontainer.cpp
+++ b/src/gui/windowcontainer.cpp
@@ -19,15 +19,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <algorithm>
-
#include "windowcontainer.h"
#include "../utils/dtor.h"
void WindowContainer::logic()
{
- for_each(mDeathList.begin(), mDeathList.end(), make_dtor(mDeathList));
+ delete_all(mDeathList);
mDeathList.clear();
gcn::Container::logic();
diff --git a/src/map.cpp b/src/map.cpp
index 928a0154..6e33d255 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -21,7 +21,6 @@
#include "map.h"
-#include <algorithm>
#include <queue>
#include "beingmanager.h"
@@ -153,9 +152,9 @@ Map::~Map()
{
// delete metadata, layers, tilesets and overlays
delete[] mMetaTiles;
- for_each(mLayers.begin(), mLayers.end(), make_dtor(mLayers));
- for_each(mTilesets.begin(), mTilesets.end(), make_dtor(mTilesets));
- for_each(mOverlays.begin(), mOverlays.end(), make_dtor(mOverlays));
+ delete_all(mLayers);
+ delete_all(mTilesets);
+ delete_all(mOverlays);
}
void Map::initializeOverlays()
diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp
index d7398c17..1c0f9373 100644
--- a/src/resources/imageset.cpp
+++ b/src/resources/imageset.cpp
@@ -19,8 +19,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <algorithm>
-
#include "imageset.h"
#include "../log.h"
@@ -44,7 +42,7 @@ ImageSet::ImageSet(Image *img, int width, int height)
ImageSet::~ImageSet()
{
- for_each(mImages.begin(), mImages.end(), make_dtor(mImages));
+ delete_all(mImages);
}
Image*
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index e6f2fd1f..c05d4604 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -19,7 +19,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <algorithm>
#include <cassert>
#include <libxml/tree.h>
@@ -144,7 +143,7 @@ void ItemDB::unload()
delete mUnknown;
mUnknown = NULL;
- for_each(mItemInfos.begin(), mItemInfos.end(), make_dtor(mItemInfos));
+ delete_all(mItemInfos);
mItemInfos.clear();
mLoaded = false;
}
diff --git a/src/resources/monsterinfo.cpp b/src/resources/monsterinfo.cpp
index 7661c86b..4a71a122 100644
--- a/src/resources/monsterinfo.cpp
+++ b/src/resources/monsterinfo.cpp
@@ -19,8 +19,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <algorithm>
-
#include "monsterinfo.h"
#include "../utils/dtor.h"
@@ -33,8 +31,7 @@ MonsterInfo::MonsterInfo()
MonsterInfo::~MonsterInfo()
{
// kill vectors in mSoundEffects
- for_each (mSounds.begin(), mSounds.end(),
- make_dtor(mSounds));
+ delete_all(mSounds);
mSounds.clear();
}
diff --git a/src/utils/dtor.h b/src/utils/dtor.h
index f7c790c6..9aa92c84 100644
--- a/src/utils/dtor.h
+++ b/src/utils/dtor.h
@@ -22,6 +22,7 @@
#ifndef _TMW_UTILS_DTOR_H
#define _TMW_UTILS_DTOR_H
+#include <algorithm>
#include <functional>
#include <utility>
@@ -44,4 +45,10 @@ inline dtor<typename Cont::value_type> make_dtor(Cont const&)
return dtor<typename Cont::value_type>();
}
+template<typename Container>
+inline void delete_all(Container &c)
+{
+ std::for_each(c.begin(), c.end(), make_dtor(c));
+}
+
#endif