Changeset 4004 in orxonox.OLD for orxonox/branches/ll2trunktemp/src/factory.h
- Timestamp:
- Apr 28, 2005, 7:41:27 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/ll2trunktemp/src/factory.h
r4003 r4004 11 11 #include "xmlparser/tinyxml.h" 12 12 13 #define CREATE_FACTORY(x) \ 14 class x ## Factory : public Factory { \ 15 public: \ 16 x ## Factory (){setClassname( #x );} \ 17 ~x ## Factory () {}; \ 18 private: \ 19 BaseObject* fabricate( TiXmlElement* root) \ 20 { \ 21 if(!strcmp(root->Value(), getClassname())) return new x ( root); \ 22 else if( getNext() != NULL) return getNext()->fabricate( root); \ 23 else return NULL; \ 24 } \ 25 }; \ 26 x ## Factory global_ ## x ## Factory; 13 /** 14 Creates a factory to a Loadable Class. 15 this should be used at the beginning of all the Classes that should be loadable (in the cc-file) 16 */ 17 #define CREATE_FACTORY(x) tFactory<x>* global_ ## x ## Factory = new tFactory<x>(#x); 18 19 27 20 28 21 //! The Factory is … … 33 26 34 27 public: 35 Factory ( );28 Factory (const char* name = NULL); 36 29 ~Factory (); 37 30 … … 40 33 void initialize(); 41 34 void registerFactory( Factory* factory); 42 void setClassname(c har* name) {classname = name;}43 c har* getClassname() {return classname;};35 void setClassname(const char* name); 36 const char* getClassname() {return classname;}; 44 37 void setNext( Factory* factory) {next = factory;} 45 38 Factory* getNext() {return next;} … … 51 44 }; 52 45 46 template<class T> class tFactory : public Factory 47 { 48 public: 49 tFactory(const char* name); 50 virtual ~tFactory(); 51 52 private: 53 BaseObject* fabricate( TiXmlElement* root); 54 }; 55 56 template<class T> 57 tFactory<T>::tFactory(const char* name) : Factory(name) 58 { 59 printf("fileName: %s\n", name); 60 } 61 62 63 template<class T> 64 tFactory<T>::~tFactory() 65 {} 66 67 template<class T> 68 BaseObject* tFactory<T>::fabricate( TiXmlElement* root) 69 { 70 if(!strcmp(root->Value(), getClassname())) 71 return new T ( root); 72 else if( getNext() != NULL) 73 return getNext()->fabricate( root); 74 else 75 return NULL; 76 } 77 53 78 // helper function 54 79 55 80 const char* grabParameter( TiXmlElement* root, const char* name); 56 81 82 83 84 57 85 #endif /* _FACTORY_H */ 58 86
Note: See TracChangeset
for help on using the changeset viewer.