Changeset 5750 in orxonox.OLD for trunk/src/util/loading
- Timestamp:
- Nov 24, 2005, 12:13:22 AM (19 years ago)
- Location:
- trunk/src/util/loading
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/util/loading/factory.cc
r5298 r5750 34 34 set everything to zero and define factoryName 35 35 */ 36 Factory::Factory (const char* factoryName )36 Factory::Factory (const char* factoryName, ClassID classID) 37 37 { 38 38 this->setClassID(CL_FACTORY, "Factory"); … … 40 40 41 41 this->next = NULL; 42 this->classID = classID; 42 43 43 44 Factory::registerFactory(this); -
trunk/src/util/loading/factory.h
r5357 r5750 33 33 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file) 34 34 */ 35 #define CREATE_FACTORY(CLASS_NAME ) \36 tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME )35 #define CREATE_FACTORY(CLASS_NAME, CLASS_ID) \ 36 tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID) 37 37 38 38 //! The Factory is a loadable object handler … … 40 40 41 41 public: 42 Factory (const char* factoryName = NULL );42 Factory (const char* factoryName = NULL, ClassID classID = CL_NULL); 43 43 virtual ~Factory (); 44 44 45 45 void fabricate(const char* className, const char* entityName); 46 virtual BaseObject* fabricate(ClassID classID) = NULL; 46 47 virtual BaseObject* fabricate(const TiXmlElement* root) = NULL; 47 48 virtual BaseObject* fabricateDirect() = NULL; … … 57 58 Factory* getNext() const { return this->next; }; 58 59 60 61 protected: 62 ClassID classID; //!< The CLass-Identifyer of the Factory. 63 59 64 private: 60 65 Factory* next; //!< pointer to the next factory. … … 64 69 /** 65 70 * a factory that is able to load any kind of Object 66 67 */71 * (this is a Functor) 72 */ 68 73 template<class T> class tFactory : public Factory 69 74 { 70 public:71 tFactory(const char* factoryName);72 virtual ~tFactory();75 public: 76 tFactory(const char* factoryName, ClassID classID); 77 virtual ~tFactory(); 73 78 74 79 private: 75 virtual BaseObject* fabricate(const TiXmlElement* root); 76 virtual BaseObject* fabricateDirect(); 80 virtual BaseObject* fabricate(ClassID classID); 81 virtual BaseObject* fabricate(const TiXmlElement* root); 82 virtual BaseObject* fabricateDirect(); 77 83 }; 78 84 … … 82 88 */ 83 89 template<class T> 84 tFactory<T>::tFactory(const char* factoryName) : Factory(factoryName)90 tFactory<T>::tFactory(const char* factoryName, ClassID classID) : Factory(factoryName, classID) 85 91 { 86 92 PRINTF(4)("Class: %s loadable\n", this->getName()); 87 93 } 88 94 89 95 /** 96 * destructs the type-Factory 97 */ 90 98 template<class T> 91 tFactory<T>::~tFactory()99 tFactory<T>::~tFactory() 92 100 {} 93 101 102 /** 103 * fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*) 104 * @param root the TiXmlElement T should load parameters from. 105 * @return the newly fabricated T, NULL otherwise. 106 */ 94 107 template<class T> 95 BaseObject* tFactory<T>::fabricate(const TiXmlElement* root)108 BaseObject* tFactory<T>::fabricate(const TiXmlElement* root) 96 109 { 97 110 if (root == NULL) … … 106 119 } 107 120 121 122 /** 123 * fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*) 124 * @param classID the ClassID of T that should be created. 125 * @return the newly fabricated T if fabricated NULL otherwise. 126 */ 127 template<class T> 128 BaseObject* tFactory<T>::fabricate(ClassID classID) 129 { 130 if(classID == this->classID) 131 return this->fabricateDirect(); 132 else if( getNext() != NULL) 133 return getNext()->fabricate( classID); 134 else 135 return NULL; 136 } 137 138 /** 139 * directly fabricate an Entity of this factory. 140 */ 108 141 template<class T> 109 142 BaseObject* tFactory<T>::fabricateDirect()
Note: See TracChangeset
for help on using the changeset viewer.