diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-03-08 19:13:26 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-03-08 19:13:26 +0000 |
commit | 405c23831a4e1363f26f848215c8140f6d6d9f78 (patch) | |
tree | edf8b8838f055a1b5d024a3976b49f5cddfa8c50 /src/gui | |
parent | e645ad2a139c332937813dd2a1e5424ded182e26 (diff) | |
download | mana-405c23831a4e1363f26f848215c8140f6d6d9f78.tar.gz mana-405c23831a4e1363f26f848215c8140f6d6d9f78.tar.bz2 mana-405c23831a4e1363f26f848215c8140f6d6d9f78.tar.xz mana-405c23831a4e1363f26f848215c8140f6d6d9f78.zip |
Added a 'dtor' helper functor to delete objects in arrays and containers using STL algorithms.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/button.cpp | 14 | ||||
-rw-r--r-- | src/gui/playerbox.cpp | 6 | ||||
-rw-r--r-- | src/gui/scrollarea.cpp | 8 | ||||
-rw-r--r-- | src/gui/skill.cpp | 9 | ||||
-rw-r--r-- | src/gui/textfield.cpp | 6 | ||||
-rw-r--r-- | src/gui/windowcontainer.cpp | 6 |
6 files changed, 21 insertions, 28 deletions
diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 78fbf7c7..8e57181e 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -34,6 +34,8 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" +#include "../utils/dtor.h" + ImageRect Button::button[4]; int Button::mInstances = 0; @@ -80,17 +82,9 @@ Button::~Button() if (mInstances == 0) { - int a, x, y, mode; - - for (mode = 0; mode < 4; mode++) + for (int mode = 0; mode < 4; mode++) { - a = 0; - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { - delete button[mode].grid[a]; - a++; - } - } + for_each(button[mode].grid, button[mode].grid + 9, dtor<Image*>()); } } } diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index 6423b8c4..e61cabde 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -32,6 +32,8 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" +#include "../utils/dtor.h" + extern std::vector<Spriteset *> hairset; extern Spriteset *playerset; @@ -76,9 +78,7 @@ PlayerBox::~PlayerBox() if (instances == 0) { - for (int a = 0; a < 9; a++) { - delete background.grid[a]; - } + for_each(background.grid, background.grid + 9, dtor<Image*>()); } } diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index 7f39b5a8..3703ead8 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -30,6 +30,8 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" +#include "../utils/dtor.h" + int ScrollArea::instances = 0; ImageRect ScrollArea::background; ImageRect ScrollArea::vMarker; @@ -60,10 +62,8 @@ ScrollArea::~ScrollArea() if (instances == 0) { - for (int a = 0; a < 9; a++) { - delete background.grid[a]; - delete vMarker.grid[a]; - } + for_each(background.grid, background.grid + 9, dtor<Image*>()); + for_each(vMarker.grid, vMarker.grid + 9, dtor<Image*>()); buttons[UP][0]->decRef(); buttons[UP][1]->decRef(); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index ba117b67..f86d2356 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -30,8 +30,10 @@ #include "scrollarea.h" #include "../localplayer.h" - #include "../graphics.h" + +#include "../utils/dtor.h" + extern Graphics *graphics; const char *skill_db[] = { @@ -193,9 +195,6 @@ void SkillDialog::setSkill(int id, int lvl, int mp) void SkillDialog::cleanList() { - for (int i = skillList.size() - 1; i >= 0; i--) - { - delete skillList[i]; - } + for_each(skillList.begin(), skillList.end(), make_dtor(skillList)); skillList.clear(); } diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index ec3b55b4..aa9d04fd 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -32,6 +32,8 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" +#include "../utils/dtor.h" + int TextField::instances = 0; ImageRect TextField::skin; @@ -74,9 +76,7 @@ TextField::~TextField() if (instances == 0) { - for (int a = 0; a < 9; a++) { - delete skin.grid[a]; - } + for_each(skin.grid, skin.grid + 9, dtor<Image*>()); } } diff --git a/src/gui/windowcontainer.cpp b/src/gui/windowcontainer.cpp index 3803b652..14aaaf68 100644 --- a/src/gui/windowcontainer.cpp +++ b/src/gui/windowcontainer.cpp @@ -23,11 +23,11 @@ #include "windowcontainer.h" +#include "../utils/dtor.h" + void WindowContainer::logic() { - for (WidgetIterator i = mDeathList.begin(); i != mDeathList.end(); i++) { - delete (*i); - } + for_each(mDeathList.begin(), mDeathList.end(), make_dtor(mDeathList)); mDeathList.clear(); gcn::Container::logic(); |