/*! \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" #include "orxonox.h" #include "world.h" class LoadParameters; #define FACTORY_ADD(CLASS) class CLASSFactory : public ObjectFactory { \ public: \ CLASSFactory (){setNext( NULL); setClassname = "CLASS"; initialize();} \ ~CLASSFactory (); \ private: \ BaseObject* fabricateObject( LoadParameters* 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, LoadParameters* data); void initialize(); void registerFactory( ObjectFactory* factory); void setClassname(char* name) {classname = name}; char* getClassname() {return classname}; void setNext( ObjectFactory* factory); private: virtual BaseObject* fabricateObject( LoadParameters* 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; }; //! The LoadParameters class is designed for encapsulated interfacing between TiXML and a loading costructor /** This is the liaison between the ObjectFactories and their Objects. A LoadParameters object is passed to the constructors of the objects when the ObjectFactory creates it. It can be easily parsed and features special variable handling methods to extract numeric data from strings. */ class LoadParameters { public: LoadParameters() {root = NULL;} LoadParameters(TiXMLElement* element) {root = element;} ~LoadParameters() {} const char* grabParameter( const char* name); const char* grabParameter( const char* name, int* i); const char* grabParameter( const char* name, double* d); void setElement(TiXMLElement* element) {root = element;} TiXMLElement* getElement() {return root;} private: TiXMLElement* root; }; #endif /* _LEVELFACTORY_H */