Changeset 4254 in orxonox.OLD for orxonox/branches/levelLoader/src/util/loading
- Timestamp:
- May 22, 2005, 1:43:16 AM (20 years ago)
- Location:
- orxonox/branches/levelLoader/src/util/loading
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/levelLoader/src/util/loading/factory.cc
r4253 r4254 93 93 const TiXmlNode* node; 94 94 95 assert( root != NULL); 95 if (root == NULL) 96 return NULL; 96 97 assert( name != NULL); 97 98 -
orxonox/branches/levelLoader/src/util/loading/factory.h
r4253 r4254 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) tFactory<CLASS_NAME>* global_##CLASS_NAME##Factory = new tFactory<CLASS_NAME>(#CLASS_NAME); \ 36 CREATE_LOAD_DOC(CLASS_NAME) 37 38 39 35 #define CREATE_FACTORY(CLASS_NAME) tFactory<CLASS_NAME>* global_##CLASS_NAME##Factory = new tFactory<CLASS_NAME>(#CLASS_NAME) 40 36 //! The Factory is 41 37 class Factory { -
orxonox/branches/levelLoader/src/util/loading/load_param.cc
r4252 r4254 16 16 #include "load_param.h" 17 17 18 #include "list.h" 19 #include "base_object.h" 18 20 19 BaseLoadParam::BaseLoadParam(BaseObject* object, const char* type1, const char* type2, 20 const char* type3, const char* type4, const char* type5) 21 #include <stdarg.h> 22 23 24 BaseLoadParam::BaseLoadParam(BaseObject* object, const char* paramName, int paramCount, ...) 21 25 { 22 26 if (LoadClassDescription::parametersDescription) 27 { 28 // locating the class 29 this->classDesc = LoadClassDescription::addClass(object->getClassName()); 30 this->paramDesc = this->classDesc->addParam(paramName); 31 32 this->paramDesc->types = new char*[paramCount]; 33 this->paramDesc->paramCount = paramCount; 34 35 va_list types; 36 va_start (types, paramCount); 37 for(int i = 0; i < paramCount; i++) 38 { 39 const char* tmpTypeName = va_arg (types, const char*); 40 this->paramDesc->types[i] = new char[strlen(tmpTypeName)+1]; 41 strcpy(this->paramDesc->types[i], tmpTypeName); 42 } 43 va_end(types); 44 45 int argCount = 0; 46 } 23 47 } 48 49 50 void BaseLoadParam::describe(const char* descriptionText) 51 { 52 if (this->paramDesc) 53 { 54 55 } 56 57 } 58 59 60 LoadParamDescription::LoadParamDescription(const char* paramName) 61 { 62 this->types = NULL; 63 this->paramName = new char[strlen(paramName)+1]; 64 strcpy(this->paramName, paramName); 65 } 66 67 LoadParamDescription::~LoadParamDescription(void) 68 { 69 for(int i = 0; i < this->paramCount; i++) 70 { 71 delete this->types[i]; 72 } 73 delete []this->types; 74 delete []this->paramName; 75 } 76 77 78 tList<LoadClassDescription>* LoadClassDescription::classList = new tList<LoadClassDescription>; 24 79 25 80 /** 26 81 \brief if the description of Parameters should be executed 27 82 */ 28 bool LoadClassDescription::parametersDescription = false; 83 bool LoadClassDescription::parametersDescription = true; 84 85 LoadClassDescription::LoadClassDescription(const char* className) 86 { 87 this->className = new char[strlen(className)+1]; 88 strcpy(this->className, className); 89 90 classList->add(this); 91 92 this->paramList = new tList<LoadParamDescription>; 93 } 94 95 LoadClassDescription::~LoadClassDescription(void) 96 { 97 delete []this->className; 98 99 tIterator<LoadParamDescription>* iterator = this->paramList->getIterator(); 100 LoadParamDescription* enumParamDesc = iterator->nextElement(); 101 while (enumParamDesc) 102 { 103 delete enumParamDesc; 104 enumParamDesc = iterator->nextElement(); 105 } 106 delete iterator; 107 108 } 109 110 111 LoadClassDescription* LoadClassDescription::addClass(const char* className) 112 { 113 tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator(); 114 LoadClassDescription* enumClassDesc = iterator->nextElement(); 115 while (enumClassDesc) 116 { 117 if (!strcmp(enumClassDesc->className, className)) 118 { 119 delete iterator; 120 return enumClassDesc; 121 } 122 enumClassDesc = iterator->nextElement(); 123 } 124 delete iterator; 125 126 return new LoadClassDescription(className); 127 } 128 129 130 LoadParamDescription* LoadClassDescription::addParam(const char* paramName) 131 { 132 tIterator<LoadParamDescription>* iterator = this->paramList->getIterator(); 133 LoadParamDescription* enumParamDesc = iterator->nextElement(); 134 while (enumParamDesc) 135 { 136 if (!strcmp(enumParamDesc->paramName, paramName)) 137 { 138 delete iterator; 139 this->paramList->add(enumParamDesc); 140 return enumParamDesc; 141 } 142 enumParamDesc = iterator->nextElement(); 143 } 144 delete iterator; 145 146 this->paramList->add(new LoadParamDescription(paramName)); 147 return paramList->lastElement(); 148 } -
orxonox/branches/levelLoader/src/util/loading/load_param.h
r4253 r4254 65 65 #define LoadParam1(type1) \ 66 66 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE)) \ 67 : BaseLoadParam(pt2Object, type1##_NAME) \67 : BaseLoadParam(pt2Object, paramName, 1, type1##_NAME) \ 68 68 { \ 69 69 const char* loadString = grabParameter(root, paramName); \ … … 78 78 #define LoadParam2(type1, type2) \ 79 79 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE)) \ 80 : BaseLoadParam(pt2Object, type1##_NAME, type2##_NAME) \80 : BaseLoadParam(pt2Object, paramName, 2, type1##_NAME, type2##_NAME) \ 81 81 { \ 82 82 const char* loadString = grabParameter(root, paramName); \ … … 98 98 #define LoadParam3(type1, type2, type3) \ 99 99 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE))\ 100 : BaseLoadParam(pt2Object, type1##_NAME, type2##_NAME, type3##_NAME) \100 : BaseLoadParam(pt2Object, paramName, 3, type1##_NAME, type2##_NAME, type3##_NAME) \ 101 101 { \ 102 102 const char* loadString = grabParameter(root, paramName); \ … … 118 118 #define LoadParam4(type1, type2, type3, type4) \ 119 119 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE)) \ 120 : BaseLoadParam(pt2Object, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME) \120 : BaseLoadParam(pt2Object, paramName, 4, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME) \ 121 121 { \ 122 122 const char* loadString = grabParameter(root, paramName); \ … … 138 138 #define LoadParam5(type1, type2, type3, type4, type5) \ 139 139 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE, type5##_TYPE)) \ 140 : BaseLoadParam(pt2Object, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME, type5##_NAME) \140 : BaseLoadParam(pt2Object, paramName, 5, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME, type5##_NAME) \ 141 141 { \ 142 142 const char* loadString = grabParameter(root, paramName); \ … … 155 155 156 156 157 158 #define CREATE_LOAD_DOC(CLASS_NAME) \159 void documentLoadClass##CLASS_NAME(void) \160 { \161 if(LoadClassDescription::parametersDescription) \162 { \163 CLASS_NAME docuClass; \164 docuClass.loadParams(NULL); \165 } \166 }167 // documentLoadClass();168 169 170 157 class LoadParamDescription 171 158 { 159 friend class BaseLoadParam; 160 friend class LoadClassDescription; 161 public: 162 LoadParamDescription(const char* paramName); 163 ~LoadParamDescription(void); 172 164 private: 165 char* paramName; 173 166 int paramCount; 174 167 char** types; 175 const char* className;176 177 168 }; 178 169 179 170 class LoadClassDescription 180 171 { 172 friend class BaseLoadParam; 181 173 public: 182 174 LoadClassDescription(const char* className); 175 ~LoadClassDescription(void); 176 177 static LoadClassDescription* addClass(const char* className); 178 LoadParamDescription* addParam(const char* paramName); 183 179 184 180 static bool parametersDescription; 185 181 182 static tList<LoadClassDescription>* classList; 186 183 private: 184 char* className; 187 185 tList<LoadParamDescription>* paramList; 188 186 }; … … 192 190 { 193 191 protected: 194 BaseLoadParam(BaseObject* object, const char* type1 = NULL, const char* type2 = NULL,195 const char* type3 = NULL, const char* type4 = NULL, const char* type5 = NULL);192 BaseLoadParam(BaseObject* object, const char* paramName, int paramCount, ...); 193 void describe(const char* descriptionText); 196 194 197 195 protected: 198 LoadParamDescription* description; 196 LoadClassDescription* classDesc; 197 LoadParamDescription* paramDesc; 199 198 }; 200 199
Note: See TracChangeset
for help on using the changeset viewer.