Changeset 5332 in orxonox.OLD for trunk/src/util/loading/load_param.h
- Timestamp:
- Oct 9, 2005, 12:02:13 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.