/*! \file factory.h \brief philosophy stuff */ #ifndef _FACTORY_H #define _FACTORY_H class BaseObject; #include "tinyxml.h" #include "load_param.h" #include "debug.h" /** Creates a factory to a Loadable Class. this should be used at the beginning of all the Classes that should be loadable (in the cc-file) */ #define CREATE_FACTORY(x) tFactory* global_ ## x ## Factory = new tFactory(#x) //! The Factory is /** Very philosophic description, huh? */ class Factory { public: Factory (const char* name = NULL); ~Factory (); virtual BaseObject* fabricate( TiXmlElement* root); void initialize(); void registerFactory( Factory* factory); void setFactoryName(const char* name); const char* getFactoryName() {return factoryName;}; void setNext( Factory* factory) {next = factory;} Factory* getNext() {return next;} private: char* factoryName; Factory* next; }; template class tFactory : public Factory { public: tFactory(const char* name); virtual ~tFactory(); private: BaseObject* fabricate( TiXmlElement* root); }; template tFactory::tFactory(const char* name) : Factory(name) { PRINTF(5)("fileName: %s\n", name); } template tFactory::~tFactory() {} template BaseObject* tFactory::fabricate( TiXmlElement* root) { if(!strcmp(root->Value(), getFactoryName())) return new T ( root); else if( getNext() != NULL) return getNext()->fabricate( root); else return NULL; } // helper function const char* grabParameter(const TiXmlElement* root, const char* name); #endif /* _FACTORY_H */