[4592] | 1 | /* |
---|
[4250] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
[4233] | 3 | |
---|
[4250] | 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Benjamin Grauer |
---|
| 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
[4592] | 16 | /*! |
---|
[5039] | 17 | * @file load_param.h |
---|
[4836] | 18 | * A Class and macro-functions, that makes our lives easy to load-in parameters |
---|
[4250] | 19 | */ |
---|
| 20 | |
---|
[4233] | 21 | #ifndef _LOAD_PARAM_H |
---|
| 22 | #define _LOAD_PARAM_H |
---|
| 23 | |
---|
[4597] | 24 | #include "base_object.h" |
---|
[4734] | 25 | #include "vector.h" |
---|
[4239] | 26 | #include "factory.h" |
---|
| 27 | #include "debug.h" |
---|
[4241] | 28 | #include "substring.h" |
---|
[4598] | 29 | #include "tinyxml.h" |
---|
[4233] | 30 | |
---|
[4251] | 31 | // Forward Declaration // |
---|
| 32 | template<class T> class tList; |
---|
[5111] | 33 | template<class T> class Array; |
---|
[4251] | 34 | |
---|
[4495] | 35 | //! macro that makes it even more easy to load a Parameter |
---|
[4249] | 36 | /** |
---|
[4834] | 37 | * @param className the name of the class to load |
---|
| 38 | * @param parameterName the name of the parameter to load as written in the XML-file |
---|
| 39 | * @param function the function to call |
---|
| 40 | */ |
---|
[4495] | 41 | #define LOAD_PARAM(className, parameterName, paramFunction) \ |
---|
| 42 | LoadParam<className>(root, #parameterName, this, &className::paramFunction) |
---|
| 43 | |
---|
| 44 | /** |
---|
[4834] | 45 | * this Starts a Cycle in the Loading Process |
---|
| 46 | * be aware, that in the cycle the first parameter of load_param should because |
---|
| 47 | * called element, and that you must say true at the Fith parameter, or it will fail |
---|
| 48 | * also you will have to close the Cycle again with LOAD_PARAM_END_CYCLE |
---|
| 49 | */ |
---|
| 50 | #define LOAD_PARAM_START_CYCLE const TiXmlElement* element; \ |
---|
| 51 | element = root->FirstChildElement(); \ |
---|
| 52 | while( element != NULL) \ |
---|
| 53 | { |
---|
| 54 | /** |
---|
| 55 | * closes a LoadParam Loop |
---|
| 56 | * @see LOAD_PARAM_START_CYCLE |
---|
| 57 | */ |
---|
| 58 | #define LOAD_PARAM_END_CYCLE element = element->NextSiblingElement(); \ |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | /** |
---|
[4249] | 64 | useable FunctionParameters are: |
---|
[4598] | 65 | l_INT: int |
---|
| 66 | l_LONG: long |
---|
| 67 | l_SHORT: short |
---|
| 68 | l_FLOAT: float |
---|
| 69 | l_STRING: const char* |
---|
| 70 | l_XML_ELEM: TiXmlElement* |
---|
[4249] | 71 | */ |
---|
[4233] | 72 | |
---|
[4860] | 73 | #define l_BOOL_TYPE bool //!< The type of an BOOL |
---|
| 74 | #define l_BOOL_FUNC isBool //!< The function to call to parse BOOL |
---|
| 75 | #define l_BOOL_NAME "bool" //!< The name of an BOOL |
---|
[4972] | 76 | #define l_BOOL_DEFAULT false //!< a default Value for an BOOL |
---|
[4860] | 77 | |
---|
| 78 | |
---|
[4623] | 79 | #define l_INT_TYPE int //!< The type of an INT |
---|
[4624] | 80 | #define l_INT_FUNC isInt //!< The function to call to parse INT |
---|
[4623] | 81 | #define l_INT_NAME "int" //!< The name of an INT |
---|
[4972] | 82 | #define l_INT_DEFAULT 0 //!< a default Value for an INT |
---|
[4233] | 83 | |
---|
[4972] | 84 | #define l_UINT_TYPE unsigned int //!< The type of an UINT |
---|
| 85 | #define l_UINT_FUNC isInt //!< The function to call to parse UINT |
---|
| 86 | #define l_UINT_NAME "unsigned int" //!< The name of an UINT |
---|
| 87 | #define l_UINT_DEFAULT 0 //!< a default Value for an UINT |
---|
| 88 | |
---|
[4623] | 89 | #define l_LONG_TYPE long //!< The type of a LONG |
---|
[4624] | 90 | #define l_LONG_FUNC isInt //!< The function to parse a LONG |
---|
[4623] | 91 | #define l_LONG_NAME "long" //!< The name of a LONG |
---|
| 92 | #define l_LONG_DEFAULT 0 //!< a default Value for a LONG |
---|
[4233] | 93 | |
---|
[4623] | 94 | // #define l_SHORT_TYPE short //!< The type of a SHORT |
---|
| 95 | // #define l_SHORT_FUNC atoi //!< The function to parse a SHORT |
---|
| 96 | // #define l_SHORT_NAME "short" //!< The name of a SHORT |
---|
| 97 | // #define l_SHORT_DEFAULT 0 //!< a default Value for a SHORT |
---|
[4242] | 98 | |
---|
[4623] | 99 | #define l_FLOAT_TYPE float //!< The type of a FLOAT |
---|
[4624] | 100 | #define l_FLOAT_FUNC isFloat //!< The function to parse a FLOAT |
---|
[4623] | 101 | #define l_FLOAT_NAME "float" //!< The name of a FLOAT |
---|
| 102 | #define l_FLOAT_DEFAULT 0.0 //!< a default Value for a FLOAT |
---|
[4242] | 103 | |
---|
[4734] | 104 | //#define l_VECTOR_TYPE const Vector& //!< The type of a VECTOR |
---|
| 105 | //#define l_VECTOR_FUNC isVector //!< The function to parse a VECTOR |
---|
| 106 | //#define l_VECTOR_NAME "Vector[x/y/z]" //!< The name of a VECTOR |
---|
| 107 | //#define l_VECTOR_DEFAULT Vector(0,0,0) //!< Default value for a VECTOR |
---|
| 108 | |
---|
[4623] | 109 | #define l_STRING_TYPE const char* //!< The type of a STRING |
---|
[4624] | 110 | #define l_STRING_FUNC isString //!< The function to parse a STRING |
---|
[4623] | 111 | #define l_STRING_NAME "string" //!< The name of a STRING |
---|
| 112 | #define l_STRING_DEFAULT "" //!< a default Value for an STRING |
---|
[4242] | 113 | |
---|
[4623] | 114 | #define l_XML_ELEM_TYPE const TiXmlElement* //!< The type of an XML_ELEM |
---|
| 115 | #define l_XML_ELEM_FUNC //!< The function to parse an XML_ELEM |
---|
| 116 | #define l_XML_ELEM_NAME "XML" //!< The name of an XML_ELEM |
---|
| 117 | #define l_XML_ELEM_DEFAULT NULL //!< The dafault Value for an XML_ELEM |
---|
[4598] | 118 | |
---|
[4623] | 119 | |
---|
| 120 | /***************************************** |
---|
| 121 | **** MACROS DEFINITIONS OF LOADABLES ***** |
---|
| 122 | *****************************************/ |
---|
[4487] | 123 | // 1. TYPE |
---|
[4249] | 124 | /** |
---|
[4836] | 125 | * a Macro to easily implement many different Constructors for the LoadParam-Class with 1 argument |
---|
| 126 | * @param type1 The type of the first functionParameter |
---|
[4249] | 127 | */ |
---|
| 128 | #define LoadParam1(type1) \ |
---|
[4623] | 129 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE), \ |
---|
| 130 | bool multi = false, type1##_TYPE default1 = type1##_DEFAULT) \ |
---|
| 131 | : BaseLoadParam(root, pt2Object, paramName, 1, multi, NULL, type1##_NAME, default1) \ |
---|
[4249] | 132 | { \ |
---|
[4252] | 133 | if (loadString != NULL && root != NULL) \ |
---|
[4624] | 134 | (*pt2Object.*function)(type1##_FUNC(loadString, default1)); \ |
---|
[4249] | 135 | else \ |
---|
[4592] | 136 | PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ |
---|
[4249] | 137 | } |
---|
[4241] | 138 | |
---|
[4249] | 139 | // 2. TYPES |
---|
[4487] | 140 | /** |
---|
[4836] | 141 | * a Macro to easily implement many different Constructors for the LoadParam-Class with 2 arguments |
---|
| 142 | * @param type1 The type of the first functionParameter |
---|
| 143 | * @param type2 The type of the second functionParameter |
---|
[4487] | 144 | */ |
---|
[4250] | 145 | #define LoadParam2(type1, type2) \ |
---|
[4623] | 146 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE), \ |
---|
| 147 | bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \ |
---|
| 148 | : BaseLoadParam(root, pt2Object, paramName, 2, multi, NULL, type1##_NAME, default1, type2##_NAME, default2) \ |
---|
[4249] | 149 | { \ |
---|
[4252] | 150 | if (loadString != NULL && root != NULL) \ |
---|
[4592] | 151 | { \ |
---|
| 152 | SubString subLoads(loadString); \ |
---|
| 153 | if (subLoads.getCount() == 2) \ |
---|
[4624] | 154 | (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0), default1), type2##_FUNC(subLoads.getString(1), default2)); \ |
---|
[4592] | 155 | else \ |
---|
| 156 | PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \ |
---|
| 157 | paramName, pt2Object->getClassName(), 2, subLoads.getCount()); \ |
---|
| 158 | } \ |
---|
[4249] | 159 | else \ |
---|
[4592] | 160 | PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ |
---|
[4251] | 161 | } |
---|
[4241] | 162 | |
---|
[4243] | 163 | |
---|
[4249] | 164 | // 3. TYPES |
---|
[4487] | 165 | /** |
---|
[4836] | 166 | * a Macro to easily implement many different Constructors for the LoadParam-Class with 3 arguments |
---|
| 167 | * @param type1 The type of the first functionParameter |
---|
| 168 | * @param type2 The type of the second functionParameter |
---|
| 169 | * @param type3 The type of the third functionParameter |
---|
[4487] | 170 | */ |
---|
[4250] | 171 | #define LoadParam3(type1, type2, type3) \ |
---|
[4623] | 172 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE), \ |
---|
| 173 | bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT, type3##_TYPE default3 = type3##_DEFAULT)\ |
---|
| 174 | : BaseLoadParam(root, pt2Object, paramName, 3, multi, NULL, type1##_NAME, default1, type2##_NAME, default2, type3##_NAME, default3) \ |
---|
[4249] | 175 | { \ |
---|
[4252] | 176 | if (loadString != NULL && root != NULL) \ |
---|
[4592] | 177 | { \ |
---|
| 178 | SubString subLoads(loadString); \ |
---|
| 179 | if (subLoads.getCount() == 3) \ |
---|
[4624] | 180 | (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0), default1), type2##_FUNC(subLoads.getString(1), default2), type3##_FUNC(subLoads.getString(2), default3)); \ |
---|
[4592] | 181 | else \ |
---|
| 182 | PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \ |
---|
| 183 | paramName, pt2Object->getClassName(), 3, subLoads.getCount()); \ |
---|
| 184 | } \ |
---|
[4249] | 185 | else \ |
---|
[4592] | 186 | PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ |
---|
[4251] | 187 | } |
---|
[4241] | 188 | |
---|
[4249] | 189 | |
---|
| 190 | // 4. TYPES |
---|
[4487] | 191 | /** |
---|
[4836] | 192 | * a Macro to easily implement many different Constructors for the LoadParam-Class with 4 arguments |
---|
| 193 | * @param type1 The type of the first functionParameter |
---|
| 194 | * @param type2 The type of the second functionParameter |
---|
| 195 | * @param type3 The type of the third functionParameter |
---|
| 196 | * @param type4 The type of the forth functionParameter |
---|
[4487] | 197 | */ |
---|
[4250] | 198 | #define LoadParam4(type1, type2, type3, type4) \ |
---|
[4623] | 199 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE), \ |
---|
| 200 | bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT, type3##_TYPE default3 = type3##_DEFAULT, \ |
---|
| 201 | type4##_TYPE default4 = type4##_DEFAULT) \ |
---|
| 202 | : BaseLoadParam(root, pt2Object, paramName, 4, multi, NULL, type1##_NAME, default1, type2##_NAME, default2, type3##_NAME, default3, \ |
---|
| 203 | type4##_NAME, default4) \ |
---|
[4249] | 204 | { \ |
---|
[4252] | 205 | if (loadString != NULL && root != NULL) \ |
---|
[4592] | 206 | { \ |
---|
| 207 | SubString subLoads(loadString); \ |
---|
| 208 | if (subLoads.getCount() == 4) \ |
---|
[4624] | 209 | (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0), default1), type2##_FUNC(subLoads.getString(1), default2), type3##_FUNC(subLoads.getString(2), default3), type4##_FUNC(subLoads.getString(3), default4)); \ |
---|
[4592] | 210 | else \ |
---|
| 211 | PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \ |
---|
| 212 | paramName, pt2Object->getClassName(), 4, subLoads.getCount()); \ |
---|
| 213 | } \ |
---|
[4249] | 214 | else \ |
---|
[4592] | 215 | PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ |
---|
[4251] | 216 | } |
---|
[4241] | 217 | |
---|
[4250] | 218 | |
---|
| 219 | // 5. TYPES |
---|
[4487] | 220 | /** |
---|
[4836] | 221 | * a Macro to easily implement many different Constructors for the LoadParam-Class with 5 arguments |
---|
| 222 | * @param type1 The type of the first functionParameter |
---|
| 223 | * @param type2 The type of the second functionParameter |
---|
| 224 | * @param type3 The type of the third functionParameter |
---|
| 225 | * @param type4 The type of the forth functionParameter |
---|
| 226 | * @param type5 The type of the fifth functionParameter |
---|
[4487] | 227 | */ |
---|
[4250] | 228 | #define LoadParam5(type1, type2, type3, type4, type5) \ |
---|
[4623] | 229 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, \ |
---|
| 230 | void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE, type5##_TYPE), \ |
---|
| 231 | bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT, type3##_TYPE default3 = type3##_DEFAULT, \ |
---|
[4725] | 232 | type4##_TYPE default4 = type4##_DEFAULT, type5##_TYPE default5 = type5##_DEFAULT ) \ |
---|
[4623] | 233 | : BaseLoadParam(root, pt2Object, paramName, 5, multi, NULL, type1##_NAME, default1, type2##_NAME, default2, type3##_NAME, default3, \ |
---|
| 234 | type4##_NAME, default4, type5##_NAME, default5) \ |
---|
[4250] | 235 | { \ |
---|
[4252] | 236 | if (loadString != NULL && root != NULL) \ |
---|
[4592] | 237 | { \ |
---|
| 238 | SubString subLoads(loadString); \ |
---|
| 239 | if (subLoads.getCount() == 5) \ |
---|
[4624] | 240 | (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0), default1), type2##_FUNC(subLoads.getString(1), default2), type3##_FUNC(subLoads.getString(2), default3), type4##_FUNC(subLoads.getString(3), default4), type5##_FUNC(subLoads.getString(4), default5)); \ |
---|
[4592] | 241 | else \ |
---|
| 242 | PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \ |
---|
| 243 | paramName, pt2Object->getClassName(), 5, subLoads.getCount()); \ |
---|
| 244 | } \ |
---|
[4250] | 245 | else \ |
---|
[4592] | 246 | PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ |
---|
[4251] | 247 | } |
---|
[4250] | 248 | |
---|
[4598] | 249 | // Pointer TYPE |
---|
| 250 | /** |
---|
[4836] | 251 | * a Macro to easily implement many different Constructors for the LoadParam-Class with one Pointer argument |
---|
| 252 | * @param type1 The type of the Pointer |
---|
[4598] | 253 | */ |
---|
| 254 | #define LoadParamPT(type1) \ |
---|
| 255 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE), type1##_TYPE pointerToParam, bool multi = false) \ |
---|
| 256 | : BaseLoadParam(root, pt2Object, paramName, 1, multi, pointerToParam, type1##_NAME) \ |
---|
| 257 | { \ |
---|
| 258 | if (pointerToParam != NULL && root != NULL) \ |
---|
| 259 | (*pt2Object.*function)((type1##_TYPE) pointerToParam); \ |
---|
| 260 | else \ |
---|
| 261 | PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ |
---|
| 262 | } |
---|
[4250] | 263 | |
---|
[4624] | 264 | |
---|
| 265 | /*********************** |
---|
| 266 | *** HELPER FUNCTIONS *** |
---|
| 267 | ***********************/ |
---|
[4860] | 268 | bool isBool(const char* BOOL, bool defaultValue); |
---|
[4734] | 269 | int isInt(const char* INT, int defaultValue); |
---|
| 270 | float isFloat(const char* FLOAT, float defaultValue); |
---|
| 271 | //const Vector& isVector(const char* VECTOR, const Vector& defaultValue); |
---|
| 272 | const char* isString(const char* STRING, const char* defaultValue); |
---|
| 273 | |
---|
[4624] | 274 | //TiXmlEmlemnt* isXmlElem(const) |
---|
| 275 | |
---|
| 276 | |
---|
| 277 | /************************ |
---|
| 278 | *** DESCRIPTION STUFF *** |
---|
| 279 | ************************/ |
---|
[4256] | 280 | //! A class that handles the description of loadable parameters |
---|
[4250] | 281 | class LoadParamDescription |
---|
[4249] | 282 | { |
---|
[4254] | 283 | friend class BaseLoadParam; |
---|
| 284 | friend class LoadClassDescription; |
---|
| 285 | public: |
---|
| 286 | LoadParamDescription(const char* paramName); |
---|
[4746] | 287 | ~LoadParamDescription(); |
---|
[4255] | 288 | |
---|
| 289 | void setDescription(const char* descriptionText); |
---|
[4836] | 290 | /** @returns the descriptionString */ |
---|
[4746] | 291 | const char* getDescription() { return this->description; }; |
---|
[4255] | 292 | |
---|
[4746] | 293 | void print() const; |
---|
[4250] | 294 | private: |
---|
[4623] | 295 | char* paramName; //!< The name of the parameter. |
---|
| 296 | int paramCount; //!< The count of parameters. |
---|
[4487] | 297 | char** types; //!< What kind of parameters does this function take ?? |
---|
[4623] | 298 | char* description; //!< A longer description about this function. |
---|
| 299 | char** defaultValues; //!< The 'Default Values'. |
---|
[4250] | 300 | }; |
---|
| 301 | |
---|
[4487] | 302 | //! A class for descriptions of a loadable module |
---|
[4251] | 303 | class LoadClassDescription |
---|
| 304 | { |
---|
[4254] | 305 | friend class BaseLoadParam; |
---|
[4251] | 306 | public: |
---|
[4254] | 307 | LoadClassDescription(const char* className); |
---|
[4746] | 308 | ~LoadClassDescription(); |
---|
[4251] | 309 | |
---|
[4254] | 310 | static LoadClassDescription* addClass(const char* className); |
---|
| 311 | LoadParamDescription* addParam(const char* paramName); |
---|
[4251] | 312 | |
---|
[4260] | 313 | static void printAll(const char* fileName = NULL); |
---|
[5111] | 314 | static Array<char*>* searchClassWithShort(const char* classNameBegin); |
---|
[5100] | 315 | // static const LoadParamDescription* getClass(const char* className); |
---|
[4255] | 316 | |
---|
[4251] | 317 | private: |
---|
[4496] | 318 | static bool parametersDescription; //!< if parameter-description should be enabled. |
---|
| 319 | static tList<LoadClassDescription>* classList; //!< a list, that holds all the loadable classes. (after one instance has been loaded) |
---|
| 320 | char* className; //!< name of the class |
---|
| 321 | tList<LoadParamDescription>* paramList; //!< List of parameters this class knows. |
---|
[4251] | 322 | }; |
---|
| 323 | |
---|
[4624] | 324 | |
---|
| 325 | /************************** |
---|
| 326 | **** REAL DECLARATIONS **** |
---|
| 327 | **************************/ |
---|
[4487] | 328 | //! abstract Base class for a Loadable parameter |
---|
[4597] | 329 | class BaseLoadParam : public BaseObject |
---|
[4250] | 330 | { |
---|
[4255] | 331 | public: |
---|
[4260] | 332 | BaseLoadParam* describe(const char* descriptionText); |
---|
[4255] | 333 | |
---|
[4251] | 334 | protected: |
---|
[4598] | 335 | BaseLoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName, int paramCount, bool multi, const void* pointerToParam, ...); |
---|
[4251] | 336 | |
---|
| 337 | protected: |
---|
[4487] | 338 | LoadClassDescription* classDesc; //!< The LoadClassDescription of this LoadParameter |
---|
| 339 | LoadParamDescription* paramDesc; //!< The LoadParameterDescription of this LoadParameter |
---|
| 340 | const char* loadString; //!< The string loaded by this LoadParam |
---|
[4598] | 341 | const void* pointerToParam; //!< A Pointer to a Parameter. |
---|
[4249] | 342 | }; |
---|
[4243] | 343 | |
---|
[4241] | 344 | |
---|
[4256] | 345 | //! derived template class, so all the Classes can load something. |
---|
[4250] | 346 | template<class T> class LoadParam : public BaseLoadParam |
---|
[4249] | 347 | { |
---|
| 348 | public: |
---|
[4501] | 349 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(), bool multi = false) |
---|
[4598] | 350 | : BaseLoadParam(root, pt2Object, paramName, 0, multi, NULL, "") |
---|
[4592] | 351 | { |
---|
[4501] | 352 | if (loadString != NULL && root != NULL) |
---|
[4592] | 353 | (*pt2Object.*function)(); |
---|
| 354 | else |
---|
| 355 | PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); |
---|
[4501] | 356 | } |
---|
| 357 | |
---|
| 358 | |
---|
[4487] | 359 | //! makes functions with one string loadable |
---|
[4249] | 360 | LoadParam1(l_STRING); |
---|
[4487] | 361 | //! makes functions with two strings loadable |
---|
[4249] | 362 | LoadParam2(l_STRING, l_STRING); |
---|
[4487] | 363 | //! makes functions with three strings loadable |
---|
[4249] | 364 | LoadParam3(l_STRING, l_STRING, l_STRING); |
---|
[4487] | 365 | //! makes functions with four strings loadable |
---|
[4249] | 366 | LoadParam4(l_STRING, l_STRING, l_STRING, l_STRING); |
---|
[4243] | 367 | |
---|
[4860] | 368 | //! makes functions with one bool loadeable |
---|
| 369 | LoadParam1(l_BOOL); |
---|
| 370 | |
---|
[4487] | 371 | //! makes functions with one int loadable |
---|
[4249] | 372 | LoadParam1(l_INT); |
---|
[4487] | 373 | //! makes functions with two ints loadable |
---|
[4249] | 374 | LoadParam2(l_INT, l_INT); |
---|
[4487] | 375 | //! makes functions with three ints loadable |
---|
[4249] | 376 | LoadParam3(l_INT, l_INT, l_INT); |
---|
[4487] | 377 | //! makes functions with four ints loadable |
---|
[4249] | 378 | LoadParam4(l_INT, l_INT, l_INT, l_INT); |
---|
[4241] | 379 | |
---|
[4972] | 380 | |
---|
| 381 | //! makes functions with one unsigned int loadable |
---|
| 382 | LoadParam1(l_UINT); |
---|
| 383 | //! makes functions with two unsigned ints loadable |
---|
| 384 | LoadParam2(l_UINT, l_UINT); |
---|
| 385 | //! makes functions with three unsigned ints loadable |
---|
| 386 | LoadParam3(l_UINT, l_UINT, l_UINT); |
---|
| 387 | //! makes functions with four unsigned ints loadable |
---|
| 388 | LoadParam4(l_UINT, l_UINT, l_UINT, l_UINT); |
---|
| 389 | |
---|
[4487] | 390 | //! makes functions with one float loadable |
---|
[4249] | 391 | LoadParam1(l_FLOAT); |
---|
[4487] | 392 | //! makes functions with two floats loadable |
---|
[4249] | 393 | LoadParam2(l_FLOAT, l_FLOAT); |
---|
[4487] | 394 | //! makes functions with three floats loadable |
---|
[4249] | 395 | LoadParam3(l_FLOAT, l_FLOAT, l_FLOAT); |
---|
[4487] | 396 | //! makes functions with four floats loadable |
---|
[4249] | 397 | LoadParam4(l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT); |
---|
[4725] | 398 | //! makes functions with four floats loadable |
---|
| 399 | LoadParam5(l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT); |
---|
[4598] | 400 | |
---|
[4972] | 401 | //! mixed values: |
---|
| 402 | LoadParam2(l_STRING, l_FLOAT); |
---|
| 403 | |
---|
[4734] | 404 | //! makes functions with one Vector loadable |
---|
| 405 | //LoadParam1(l_VECTOR); |
---|
| 406 | |
---|
[4726] | 407 | // loads a Ti-XML-element |
---|
[4599] | 408 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(const TiXmlElement*), bool multi = false) |
---|
[4625] | 409 | : BaseLoadParam(root, pt2Object, paramName, 1, multi, NULL, "XML") |
---|
[4599] | 410 | { |
---|
| 411 | if (root != NULL) |
---|
| 412 | { |
---|
| 413 | const TiXmlElement* elem = root->FirstChildElement(paramName); |
---|
| 414 | if (likely(elem != NULL)) |
---|
| 415 | (*pt2Object.*function)(elem); |
---|
| 416 | else |
---|
| 417 | PRINTF(2)("%s of %s is empty", paramName, pt2Object->getClassName()); |
---|
| 418 | } |
---|
| 419 | else |
---|
| 420 | PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | //LoadParamPT(l_XML_ELEM); |
---|
[4233] | 424 | }; |
---|
| 425 | |
---|
[4492] | 426 | // helper function |
---|
[4233] | 427 | |
---|
[4492] | 428 | const char* grabParameter(const TiXmlElement* root, const char* parameterName); |
---|
| 429 | |
---|
[4233] | 430 | #endif /* _LOAD_PARAM_H */ |
---|