#include <version.h>
#include <algorithm>
+#include <memory>
#include <physfs.h>
#include <sstream>
#include <stdexcept>
if(!addons_lisp) throw std::runtime_error("Downloaded file is not an Add-on list");
lisp::ListIterator iter(addons_lisp);
- while(iter.next()) {
+ while(iter.next())
+ {
const std::string& token = iter.item();
- if(token != "supertux-addoninfo") {
+ if(token != "supertux-addoninfo")
+ {
log_warning << "Unknown token '" << token << "' in Add-on list" << std::endl;
continue;
}
- Addon* addon_ptr = new Addon();
- Addon& addon = *addon_ptr;
- addon.parse(*(iter.lisp()));
- addon.installed = false;
- addon.loaded = false;
+ std::auto_ptr<Addon> addon(new Addon());
+ addon->parse(*(iter.lisp()));
+ addon->installed = false;
+ addon->loaded = false;
// make sure the list of known Add-ons does not already contain this one
bool exists = false;
for (std::vector<Addon*>::const_iterator i = addons.begin(); i != addons.end(); i++) {
- if (**i == addon) {
+ if (**i == *addon) {
exists = true;
break;
}
- }
- if (exists) {
- delete addon_ptr;
- continue;
}
- // make sure the Add-on's file name does not contain weird characters
- if (addon.suggested_filename.find_first_not_of("match.quiz-proxy_gwenblvdjfks0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != std::string::npos) {
- log_warning << "Add-on \"" << addon.title << "\" contains unsafe file name. Skipping." << std::endl;
- delete addon_ptr;
- continue;
+ if (exists)
+ {
+ // do nothing
+ }
+ else if (addon->suggested_filename.find_first_not_of("match.quiz-proxy_gwenblvdjfks0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != std::string::npos)
+ {
+ // make sure the Add-on's file name does not contain weird characters
+ log_warning << "Add-on \"" << addon->title << "\" contains unsafe file name. Skipping." << std::endl;
+ }
+ else
+ {
+ addons.push_back(addon.release());
}
-
- addons.push_back(addon_ptr);
}
} catch(std::exception& e) {
std::stringstream msg;
#include "supertux/tile_set.hpp"
+#include <memory>
#include <stdexcept>
#include <sstream>
lisp::ListIterator iter(tiles_lisp);
while(iter.next()) {
if(iter.item() == "tile") {
- Tile* tile = new Tile(this);
+ std::auto_ptr<Tile> tile(new Tile(this));
uint32_t id = tile->parse(*(iter.lisp()));
if(id >= tiles.size())
if(tiles[id] != 0) {
log_warning << "Tile with ID " << id << " redefined" << std::endl;
- delete tile;
} else {
- tiles[id] = tile;
+ tiles[id] = tile.release();
}
} else if(iter.item() == "tilegroup") {
/* tilegroups are only interesting for the editor */
int x = 32*(i % width);
int y = 32*(i / width);
- Tile* tile = new Tile(this, images, Rect(x, y, x + 32, y + 32),
- (has_attributes ? attributes[i] : 0), (has_datas ? datas[i] : 0), animfps);
+ std::auto_ptr<Tile> tile(new Tile(this, images, Rect(x, y, x + 32, y + 32),
+ (has_attributes ? attributes[i] : 0), (has_datas ? datas[i] : 0), animfps));
if (tiles[ids[i]] == 0) {
- tiles[ids[i]] = tile;
+ tiles[ids[i]] = tile.release();
} else {
log_warning << "Tile with ID " << ids[i] << " redefined" << std::endl;
- delete tile;
}
}
} else if(iter.item() == "properties") {