- Timestamp:
- Oct 9, 2005, 12:02:13 AM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/defs/functor_list.h
r5331 r5332 42 42 ParameterFloat = 32, 43 43 ParameterLong = 64, 44 ParameterXML = 128, 44 45 /* ... */ 45 46 } ParameterType; -
trunk/src/orxonox.cc
r5303 r5332 49 49 50 50 #include "class_list.h" 51 #include "substring.h"52 #include "shell.h"53 51 #include "shell_command.h" 54 52 #include "shell_buffer.h" … … 95 93 FastFactory::deleteAll(); 96 94 ShellCommandClass::unregisterAllCommands(); 95 97 96 LoadClassDescription::deleteAllDescriptions(); 98 97 -
trunk/src/util/loading/load_param.cc
r5227 r5332 13 13 co-programmer: ... 14 14 */ 15 16 #include "functor_list.h" 15 17 16 18 #include "load_param.h" … … 64 66 65 67 this->paramDesc->paramCount = paramCount; 66 this->paramDesc->types = new char*[paramCount];68 this->paramDesc->types = new int[paramCount]; 67 69 this->paramDesc->defaultValues = new char*[paramCount]; 68 70 … … 73 75 { 74 76 // parameters parsed 75 const char* tmpTypeName = va_arg (types, const char*); 76 this->paramDesc->types[i] = new char[strlen(tmpTypeName)+1]; 77 strcpy(this->paramDesc->types[i], tmpTypeName); 78 79 //! @todo SWITCH CASE WITH l_[TYPE]_TYPE -> much faster 80 // default value description 81 if (!strcmp(tmpTypeName, l_INT_NAME)) 77 int tmpType = va_arg (types, int); 78 this->paramDesc->types[i] = tmpType; 79 80 //! @todo SWITCH CASE WITH l_[TYPE]_TYPE -> much faster (more usefull) 81 switch (tmpType) 82 82 { 83 sprintf(defaultVal, "%d", va_arg(types, l_INT_TYPE)); 84 } 85 else if (!strcmp(tmpTypeName, l_LONG_NAME)) 86 { 87 sprintf(defaultVal, "%0.3f", va_arg(types, l_LONG_TYPE)); 88 } 89 /* else if (!strcmp(tmpTypeName, l_SHORT_NAME)) 90 { 91 sprintf(defaultVal, "%d", va_arg(types, l_SHORT_TYPE)); 92 }*/ 93 else if (!strcmp(tmpTypeName, l_FLOAT_NAME)) 94 { 95 sprintf(defaultVal, "%0.3f", va_arg(types, double)); 96 } 97 else if (!strcmp(tmpTypeName, l_STRING_NAME)) 98 { 99 sprintf(defaultVal, "%s", va_arg(types, l_STRING_TYPE)); 100 } 101 else if (!strcmp(tmpTypeName, l_XML_ELEM_NAME)) 102 { 103 sprintf(defaultVal, ""); 83 case ParameterInt: 84 sprintf(defaultVal, "%d", va_arg(types, l_INT_TYPE)); 85 break; 86 case ParameterLong: 87 sprintf(defaultVal, "%0.3f", va_arg(types, l_LONG_TYPE)); 88 break; 89 case ParameterFloat: 90 sprintf(defaultVal, "%0.3f", va_arg(types, double)); 91 break; 92 case ParameterString: 93 sprintf(defaultVal, "%s", va_arg(types, l_STRING_TYPE)); 94 break; 95 case ParameterXML: 96 sprintf(defaultVal, ""); 97 break; 104 98 } 105 99 … … 144 138 LoadParamDescription::~LoadParamDescription() 145 139 { 146 if (this->types != NULL)147 {148 for(int i = 0; i < this->paramCount; i++)149 {150 delete []this->types[i];151 }152 }153 140 if (this->defaultValues != NULL) 154 141 { … … 184 171 if (i > 0) 185 172 PRINT(3)(","); 186 PRINT(3)("%s", this->types[i]); 173 switch (this->types[i]) 174 { 175 default: 176 PRINTF(3)("none"); 177 break; 178 case ParameterBool: 179 PRINT(3)("bool"); 180 break; 181 case ParameterChar: 182 PRINT(3)("char"); 183 break; 184 case ParameterString: 185 PRINT(3)("string"); 186 break; 187 case ParameterInt: 188 PRINT(3)("int"); 189 break; 190 case ParameterUInt: 191 PRINT(3)("Uint"); 192 break; 193 case ParameterFloat: 194 PRINT(3)("float"); 195 break; 196 case ParameterLong: 197 PRINT(3)("long"); 198 break; 199 case ParameterXML: 200 PRINT(3)("XML"); 201 break; 202 } 187 203 } 188 204 PRINT(3)("</%s>", this->paramName); … … 197 213 if (i > 0) 198 214 PRINT(3)(", "); 199 if ( !strcmp(this->types[i], l_STRING_NAME))215 if (this->types[i] & ParameterString) 200 216 { // leave brackets !! 201 217 PRINT(3)("\"%s\"", this->defaultValues[i]); -
trunk/src/util/loading/load_param.h
r5301 r5332 22 22 #define _LOAD_PARAM_H 23 23 24 #include "functor_list.h" 24 25 #include "base_object.h" 25 26 … … 33 34 template<class T> class tList; 34 35 36 /************************ 37 *** DESCRIPTION STUFF *** 38 ************************/ 39 //! A class that handles the description of loadable parameters 40 class LoadParamDescription 41 { 42 friend class BaseLoadParam; 43 friend class LoadClassDescription; 44 public: 45 LoadParamDescription(const char* paramName); 46 ~LoadParamDescription(); 47 48 void setDescription(const char* descriptionText); 49 /** @returns the descriptionString */ 50 const char* getDescription() { return this->description; }; 51 52 void print() const; 53 private: 54 char* paramName; //!< The name of the parameter. 55 int paramCount; //!< The count of parameters. 56 int* types; //!< What kind of parameters does this function take ?? 57 char* description; //!< A longer description about this function. 58 char** defaultValues; //!< The 'Default Values'. 59 }; 60 61 //! A class for descriptions of a loadable module 62 class LoadClassDescription 63 { 64 friend class BaseLoadParam; 65 public: 66 LoadClassDescription(const char* className); 67 ~LoadClassDescription(); 68 69 static LoadClassDescription* addClass(const char* className); 70 LoadParamDescription* addParam(const char* paramName); 71 72 static void deleteAllDescriptions(); 73 74 static void printAll(const char* fileName = NULL); 75 static tList<const char>* searchClassWithShort(const char* classNameBegin); 76 // static const LoadParamDescription* getClass(const char* className); 77 78 private: 79 static bool parametersDescription; //!< if parameter-description should be enabled. 80 static tList<LoadClassDescription>* classList; //!< a list, that holds all the loadable classes. (after one instance has been loaded) 81 char* className; //!< name of the class 82 tList<LoadParamDescription>* paramList; //!< List of parameters this class knows. 83 }; 84 85 86 /************************** 87 **** REAL DECLARATIONS **** 88 **************************/ 89 //! abstract Base class for a Loadable parameter 90 class BaseLoadParam : public BaseObject 91 { 92 public: 93 BaseLoadParam* describe(const char* descriptionText); 94 95 protected: 96 BaseLoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName, int paramCount, bool multi, const void* pointerToParam, ...); 97 98 protected: 99 LoadClassDescription* classDesc; //!< The LoadClassDescription of this LoadParameter 100 LoadParamDescription* paramDesc; //!< The LoadParameterDescription of this LoadParameter 101 const char* loadString; //!< The string loaded by this LoadParam 102 const void* pointerToParam; //!< A Pointer to a Parameter. 103 }; 104 105 35 106 //! macro that makes it even more easy to load a Parameter 36 107 /** … … 51 122 element = root->FirstChildElement(); \ 52 123 while( element != NULL) \ 53 54 /** 55 * closes a LoadParam Loop56 * @see LOAD_PARAM_START_CYCLE124 { 125 /** 126 * closes a LoadParam Loop 127 * @see LOAD_PARAM_START_CYCLE 57 128 */ 58 129 #define LOAD_PARAM_END_CYCLE element = element->NextSiblingElement(); \ 59 130 } 60 131 61 132 … … 65 136 // 0. TYPES 66 137 /** 67 * 138 * a Macro to easily implement many different Constructors for the LoadParam-Class with no argument 68 139 */ 69 140 #define LoadParam0() \ … … 79 150 // 1. TYPE 80 151 /** 81 * 82 * @param type1 The type of the first functionParameter 83 */152 * a Macro to easily implement many different Constructors for the LoadParam-Class with 1 argument 153 * @param type1 The type of the first functionParameter 154 */ 84 155 #define LoadParam1(type1) \ 85 156 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE), \ 86 157 bool multi = false, type1##_TYPE default1 = type1##_DEFAULT) \ 87 : BaseLoadParam(root, pt2Object, paramName, 1, multi, NULL, type1##_ NAME, default1) \88 158 : BaseLoadParam(root, pt2Object, paramName, 1, multi, NULL, type1##_PARAM, default1) \ 159 { \ 89 160 if (loadString != NULL && root != NULL) \ 90 161 (*pt2Object.*function)(type1##_FUNC(loadString, default1)); \ 91 162 else \ 92 163 PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 93 164 } 94 165 95 166 // 2. TYPES 96 167 /** 97 * 168 * a Macro to easily implement many different Constructors for the LoadParam-Class with 2 arguments 98 169 * @param type1 The type of the first functionParameter 99 170 * @param type2 The type of the second functionParameter 100 */171 */ 101 172 #define LoadParam2(type1, type2) \ 102 173 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE), \ 103 174 bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \ 104 : BaseLoadParam(root, pt2Object, paramName, 2, multi, NULL, type1##_ NAME, default1, type2##_NAME, default2) \105 106 if (loadString != NULL && root != NULL) \ 107 175 : BaseLoadParam(root, pt2Object, paramName, 2, multi, NULL, type1##_PARAM, default1, type2##_PARAM, default2) \ 176 { \ 177 if (loadString != NULL && root != NULL) \ 178 { \ 108 179 SubString subLoads(loadString); \ 109 180 if (subLoads.getCount() == 2) \ … … 112 183 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \ 113 184 paramName, pt2Object->getClassName(), 2, subLoads.getCount()); \ 114 115 else \ 116 PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 117 185 } \ 186 else \ 187 PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 188 } 118 189 119 190 120 191 // 3. TYPES 121 192 /** 122 * 193 * a Macro to easily implement many different Constructors for the LoadParam-Class with 3 arguments 123 194 * @param type1 The type of the first functionParameter 124 195 * @param type2 The type of the second functionParameter 125 196 * @param type3 The type of the third functionParameter 126 */197 */ 127 198 #define LoadParam3(type1, type2, type3) \ 128 199 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE), \ 129 200 bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT, type3##_TYPE default3 = type3##_DEFAULT)\ 130 : BaseLoadParam(root, pt2Object, paramName, 3, multi, NULL, type1##_ NAME, default1, type2##_NAME, default2, type3##_NAME, default3) \131 132 if (loadString != NULL && root != NULL) \ 133 201 : BaseLoadParam(root, pt2Object, paramName, 3, multi, NULL, type1##_PARAM, default1, type2##_PARAM, default2, type3##_PARAM, default3) \ 202 { \ 203 if (loadString != NULL && root != NULL) \ 204 { \ 134 205 SubString subLoads(loadString); \ 135 206 if (subLoads.getCount() == 3) \ … … 138 209 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \ 139 210 paramName, pt2Object->getClassName(), 3, subLoads.getCount()); \ 140 141 else \ 142 PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 143 211 } \ 212 else \ 213 PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 214 } 144 215 145 216 146 217 // 4. TYPES 147 218 /** 148 * 219 * a Macro to easily implement many different Constructors for the LoadParam-Class with 4 arguments 149 220 * @param type1 The type of the first functionParameter 150 221 * @param type2 The type of the second functionParameter 151 222 * @param type3 The type of the third functionParameter 152 223 * @param type4 The type of the forth functionParameter 153 */224 */ 154 225 #define LoadParam4(type1, type2, type3, type4) \ 155 226 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE), \ 156 227 bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT, type3##_TYPE default3 = type3##_DEFAULT, \ 157 228 type4##_TYPE default4 = type4##_DEFAULT) \ 158 : BaseLoadParam(root, pt2Object, paramName, 4, multi, NULL, type1##_ NAME, default1, type2##_NAME, default2, type3##_NAME, default3, \159 type4##_ NAME, default4) \160 161 if (loadString != NULL && root != NULL) \ 162 229 : BaseLoadParam(root, pt2Object, paramName, 4, multi, NULL, type1##_PARAM, default1, type2##_PARAM, default2, type3##_PARAM, default3, \ 230 type4##_PARAM, default4) \ 231 { \ 232 if (loadString != NULL && root != NULL) \ 233 { \ 163 234 SubString subLoads(loadString); \ 164 235 if (subLoads.getCount() == 4) \ … … 167 238 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \ 168 239 paramName, pt2Object->getClassName(), 4, subLoads.getCount()); \ 169 170 else \ 171 PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 172 240 } \ 241 else \ 242 PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 243 } 173 244 174 245 175 246 // 5. TYPES 176 247 /** 177 * 248 * a Macro to easily implement many different Constructors for the LoadParam-Class with 5 arguments 178 249 * @param type1 The type of the first functionParameter 179 250 * @param type2 The type of the second functionParameter … … 181 252 * @param type4 The type of the forth functionParameter 182 253 * @param type5 The type of the fifth functionParameter 183 */254 */ 184 255 #define LoadParam5(type1, type2, type3, type4, type5) \ 185 256 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, \ … … 187 258 bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT, type3##_TYPE default3 = type3##_DEFAULT, \ 188 259 type4##_TYPE default4 = type4##_DEFAULT, type5##_TYPE default5 = type5##_DEFAULT ) \ 189 : BaseLoadParam(root, pt2Object, paramName, 5, multi, NULL, type1##_ NAME, default1, type2##_NAME, default2, type3##_NAME, default3, \190 type4##_ NAME, default4, type5##_NAME, default5) \191 192 if (loadString != NULL && root != NULL) \ 193 260 : BaseLoadParam(root, pt2Object, paramName, 5, multi, NULL, type1##_PARAM, default1, type2##_PARAM, default2, type3##_PARAM, default3, \ 261 type4##_PARAM, default4, type5##_PARAM, default5) \ 262 { \ 263 if (loadString != NULL && root != NULL) \ 264 { \ 194 265 SubString subLoads(loadString); \ 195 266 if (subLoads.getCount() == 5) \ … … 198 269 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \ 199 270 paramName, pt2Object->getClassName(), 5, subLoads.getCount()); \ 200 201 else \ 202 PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 203 271 } \ 272 else \ 273 PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 274 } 204 275 205 276 // Pointer TYPE 206 277 /** 207 * 278 * a Macro to easily implement many different Constructors for the LoadParam-Class with one Pointer argument 208 279 * @param type1 The type of the Pointer 209 280 */ 210 281 #define LoadParamPT(type1) \ 211 282 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE), type1##_TYPE pointerToParam, bool multi = false) \ 212 : BaseLoadParam(root, pt2Object, paramName, 1, multi, pointerToParam, type1##_ NAME) \283 : BaseLoadParam(root, pt2Object, paramName, 1, multi, pointerToParam, type1##_PARAM) \ 213 284 { \ 214 285 if (pointerToParam != NULL && root != NULL) \ … … 217 288 PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 218 289 } 219 220 /************************221 *** DESCRIPTION STUFF ***222 ************************/223 //! A class that handles the description of loadable parameters224 class LoadParamDescription225 {226 friend class BaseLoadParam;227 friend class LoadClassDescription;228 public:229 LoadParamDescription(const char* paramName);230 ~LoadParamDescription();231 232 void setDescription(const char* descriptionText);233 /** @returns the descriptionString */234 const char* getDescription() { return this->description; };235 236 void print() const;237 private:238 char* paramName; //!< The name of the parameter.239 int paramCount; //!< The count of parameters.240 char** types; //!< What kind of parameters does this function take ??241 char* description; //!< A longer description about this function.242 char** defaultValues; //!< The 'Default Values'.243 };244 245 //! A class for descriptions of a loadable module246 class LoadClassDescription247 {248 friend class BaseLoadParam;249 public:250 LoadClassDescription(const char* className);251 ~LoadClassDescription();252 253 static LoadClassDescription* addClass(const char* className);254 LoadParamDescription* addParam(const char* paramName);255 256 static void deleteAllDescriptions();257 258 static void printAll(const char* fileName = NULL);259 static tList<const char>* searchClassWithShort(const char* classNameBegin);260 // static const LoadParamDescription* getClass(const char* className);261 262 private:263 static bool parametersDescription; //!< if parameter-description should be enabled.264 static tList<LoadClassDescription>* classList; //!< a list, that holds all the loadable classes. (after one instance has been loaded)265 char* className; //!< name of the class266 tList<LoadParamDescription>* paramList; //!< List of parameters this class knows.267 };268 269 270 /**************************271 **** REAL DECLARATIONS ****272 **************************/273 //! abstract Base class for a Loadable parameter274 class BaseLoadParam : public BaseObject275 {276 public:277 BaseLoadParam* describe(const char* descriptionText);278 279 protected:280 BaseLoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName, int paramCount, bool multi, const void* pointerToParam, ...);281 282 protected:283 LoadClassDescription* classDesc; //!< The LoadClassDescription of this LoadParameter284 LoadParamDescription* paramDesc; //!< The LoadParameterDescription of this LoadParameter285 const char* loadString; //!< The string loaded by this LoadParam286 const void* pointerToParam; //!< A Pointer to a Parameter.287 };288 289 290 290 291 //! derived template class, so all the Classes can load something.
Note: See TracChangeset
for help on using the changeset viewer.