2 // Copyright (C) 2004 Ricardo Cruz <rick2@aeiou.pt>
3 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef HEADER_SUPERTUX_SUPERTUX_OBJECT_FACTORY_HPP
19 #define HEADER_SUPERTUX_SUPERTUX_OBJECT_FACTORY_HPP
25 #include "supertux/direction.hpp"
26 #include "util/reader_fwd.hpp"
31 class AbstractObjectFactory
34 virtual ~AbstractObjectFactory()
37 /** Creates a new gameobject from a lisp node.
38 * Remember to delete the objects later
40 virtual GameObject* create(const Reader& reader) = 0;
44 class ConcreteObjectFactory : public AbstractObjectFactory
47 ConcreteObjectFactory() {}
48 ~ConcreteObjectFactory() {}
50 GameObject* create(const Reader& reader)
59 static ObjectFactory& instance();
62 typedef std::map<std::string, std::unique_ptr<AbstractObjectFactory> > Factories;
69 GameObject* create(const std::string& name, const Reader& reader);
70 GameObject* create(const std::string& name, const Vector& pos, const Direction dir = AUTO);
74 void add_factory(const char* name)
76 assert(factories.find(name) == factories.end());
77 factories[name] = std::unique_ptr<AbstractObjectFactory>(new ConcreteObjectFactory<C>());
79 void init_factories();