X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject_factory.hpp;h=0e0d0d3502fd9de24faaf2b3389e1727a707fbd3;hb=4053ea240a0dc47f360a7293c0097f1cc515137c;hp=6014c2ee221d2bd378fd7759893af593dec417e9;hpb=5b7f9214cb929399f1a855ef5807018a9447d510;p=supertux.git diff --git a/src/object_factory.hpp b/src/object_factory.hpp index 6014c2ee2..0e0d0d350 100644 --- a/src/object_factory.hpp +++ b/src/object_factory.hpp @@ -1,7 +1,8 @@ // $Id$ // -// SuperTux - A Jump'n Run +// SuperTux // Copyright (C) 2004 Ricardo Cruz +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -22,24 +23,28 @@ #include #include -#include "lisp/lisp.hpp" -#include "game_object.hpp" -#include "math/vector.hpp" +namespace lisp { class Lisp; } +class Vector; +class GameObject; class Factory { public: virtual ~Factory() { } - + /** Creates a new gameobject from a lisp node. * Remember to delete the objects later */ virtual GameObject* create_object(const lisp::Lisp& reader) = 0; -}; -typedef std::map Factories; -extern Factories* object_factories; + typedef std::map Factories; + static Factories &get_factories() + { + static Factories object_factories; + return object_factories; + } +}; GameObject* create_object(const std::string& name, const lisp::Lisp& reader); GameObject* create_object(const std::string& name, const Vector& pos); @@ -56,10 +61,12 @@ class INTERN_##CLASS##Factory : public Factory \ public: \ INTERN_##CLASS##Factory() \ { \ - if(object_factories == 0) \ - object_factories = new Factories; \ + get_factories()[NAME] = this; \ + } \ \ - object_factories->insert(std::make_pair(NAME, this)); \ + ~INTERN_##CLASS##Factory() \ + { \ + get_factories().erase(NAME); \ } \ \ virtual GameObject* create_object(const lisp::Lisp& reader) \