const lisp::Lisp* tilesets_lisp = level->get_lisp("tilesets");
if(tilesets_lisp != NULL) {
- tileset = tile_manager->parse_tileset_definition(*tilesets_lisp);
+ tileset = tile_manager->parse_tileset_definition(*tilesets_lisp).release();
free_tileset = true;
}
std::string tileset_name;
big_font.reset();
/* Free tilesets */
- if(tile_manager != NULL)
- {
- for(TileManager::TileSets::iterator it = tile_manager->tilesets.begin();
- it != tile_manager->tilesets.end(); ++it)
- {
- delete it->second;
- it->second = NULL;
- }
- }
+ delete tile_manager;
+ tile_manager = 0;
+
if(sprite_manager != NULL)
{
delete sprite_manager;
{
}
-TileSet* TileManager::get_tileset(const std::string &filename)
+TileSet*
+TileManager::get_tileset(const std::string &filename)
{
TileSets::const_iterator i = tilesets.find(filename);
if(i != tilesets.end())
- return i->second;
-
- std::unique_ptr<TileSet> tileset (new TileSet(filename));
- tilesets.insert(std::make_pair(filename, tileset.get()));
-
- return tileset.release();
+ {
+ return i->second.get();
+ }
+ else
+ {
+ std::unique_ptr<TileSet> tileset(new TileSet(filename));
+ TileSet* result = tileset.get();
+ tilesets.insert(std::make_pair(filename, std::move(tileset)));
+ return result;
+ }
}
-TileSet* TileManager::parse_tileset_definition(const Reader& reader)
+std::unique_ptr<TileSet>
+TileManager::parse_tileset_definition(const Reader& reader)
{
- std::unique_ptr<TileSet> result(new TileSet());
+ std::unique_ptr<TileSet> result(new TileSet);
lisp::ListIterator iter(&reader);
while(iter.next()) {
result->merge(tileset, start, end, offset);
}
- return result.release();
+ return std::move(result);
}
/* EOF */
#define HEADER_SUPERTUX_SUPERTUX_TILE_MANAGER_HPP
#include <map>
+#include <memory>
#include <string>
#include "util/reader_fwd.hpp"
class TileManager
{
- friend class Resources;
private:
- typedef std::map<std::string, TileSet*> TileSets;
+ typedef std::map<std::string, std::unique_ptr<TileSet> > TileSets;
TileSets tilesets;
public:
TileSet* get_tileset(const std::string &filename);
- TileSet* parse_tileset_definition(const Reader& reader);
+ std::unique_ptr<TileSet> parse_tileset_definition(const Reader& reader);
};
#endif
const lisp::Lisp* tilesets_lisp = level->get_lisp("tilesets");
if(tilesets_lisp != NULL) {
- tileset = tile_manager->parse_tileset_definition(*tilesets_lisp);
+ tileset = tile_manager->parse_tileset_definition(*tilesets_lisp).release();
free_tileset = true;
}
std::string tileset_name;