/*! \file levelfactory.h \brief Contains all the classes used for loading a level and its objects from a XML-file */ #ifndef _LEVELFACTORY_H #define _LEVELFACTORY_H #include "stdincl.h" #include "xmlparser/tinyxml.h" #include "xmlparser/tinystr.h" #include "base_object.h" #define FACTORY_ADD(CLASS) class CLASSFactory : public ObjectFactory { \ public: \ CLASSFactory (){setNext( NULL); setClassname = "CLASS"; initialize()}; \ ~CLASSFactory (); \ private: \ BaseObject* fabricateObject( void* data) { return new CLASS( data)}; \ }; \ CLASSFactory global_CLASSFactory(); //! The Objectfactory is a virtual class that can be stored by the LevelFactory /** The Objectfactory is just a definition of interface to be used with the LevelFactory */ class ObjectFactory { public: ObjectFactory (); ~ObjectFactory (); BaseObject* load( char* name, void* data); void initialize(); void registerFactory( ObjectFactory* factory); void setClassname(char* name) {classname = name}; void setNext( ObjectFactory* factory); private: virtual BaseObject* fabricateObject( void* data); char* classname; ObjectFactory* next; }; //! The Levelfactory is a simpleton class that serves as a central node for object archivation /** The LevelFactory is desigend to serve as a node for the loading and stroing of objects within a level based context. Any class that attaches the FACTORY_ADD() macro will register itself to the Factory at the beginning of execution, enabling the factory to recognize this type of class. */ class LevelFactory { public: LevelFactory (); ~LevelFactory (); static LevelFactory* getInstance(); void registerFactory( ObjectFactory* factory); int loadXMLFile( char* filename); private: static LevelFactory singletonRef*; ObjectFactory* first; }; #endif /* _LEVELFACTORY_H */