Changeset 4249 in orxonox.OLD for orxonox/branches/levelLoader/src/util/loading
- Timestamp:
- May 21, 2005, 10:08:37 PM (20 years ago)
- Location:
- orxonox/branches/levelLoader/src/util/loading
- Files:
-
- 1 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/levelLoader/src/util/loading/factory.h
r4248 r4249 22 22 23 23 //! The Factory is 24 /**25 Very philosophic description, huh?26 */27 24 class Factory { 28 25 -
orxonox/branches/levelLoader/src/util/loading/load_param.h
r4243 r4249 7 7 #include "substring.h" 8 8 9 /** 10 useable FunctionParameters are: 11 l_INT: int 12 l_LONG: long 13 l_SHORT: short 14 l_FLOAT: float 15 l_STRING: const char* 16 */ 17 18 #define l_INT_TYPE int 19 #define l_INT_FUNC atoi 20 21 #define l_LONG_TYPE long 22 #define l_LONG_FUNC atol 23 24 #define l_SHORT_TYPE short 25 #define l_SHORT_FUNC atoi 26 27 #define l_FLOAT_TYPE float 28 #define l_FLOAT_FUNC atof 29 30 #define l_STRING_TYPE const char* 31 #define l_STRING_FUNC 32 33 34 /** 35 \brief a Macro to easily implement many different Constructors for the LoadParam-Class 36 \param type1 The type of the first functionParameter 37 */ 38 #define LoadParam1(type1) \ 39 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE)) \ 40 { \ 41 const char* loadString = grabParameter(root, paramName); \ 42 if (loadString != NULL) \ 43 (*pt2Object.*function)(type1##_FUNC(loadString)); \ 44 else \ 45 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 46 } 47 48 49 // 2. TYPES 50 #define LoadParam2(type1, type2)\ 51 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE)) \ 52 { \ 53 const char* loadString = grabParameter(root, paramName); \ 54 if (loadString != NULL) \ 55 { \ 56 SubString subLoads(loadString); \ 57 if (subLoads.getCount() == 2) \ 58 (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1))); \ 59 else \ 60 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \ 61 paramName, pt2Object->getClassName(), 2, subLoads.getCount()); \ 62 } \ 63 else \ 64 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 65 }; 66 67 68 // 3. TYPES 69 #define LoadParam3(type1, type2, type3)\ 70 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE)) \ 71 { \ 72 const char* loadString = grabParameter(root, paramName); \ 73 if (loadString != NULL) \ 74 { \ 75 SubString subLoads(loadString); \ 76 if (subLoads.getCount() == 3) \ 77 (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1)), type3##_FUNC(subLoads.getString(2))); \ 78 else \ 79 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \ 80 paramName, pt2Object->getClassName(), 3, subLoads.getCount()); \ 81 } \ 82 else \ 83 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 84 }; 85 86 87 // 4. TYPES 88 #define LoadParam4(type1, type2, type3, type4)\ 89 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE)) \ 90 { \ 91 const char* loadString = grabParameter(root, paramName); \ 92 if (loadString != NULL) \ 93 { \ 94 SubString subLoads(loadString); \ 95 if (subLoads.getCount() == 4) \ 96 (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1)), type3##_FUNC(subLoads.getString(2)), type4##_FUNC(subLoads.getString(3))); \ 97 else \ 98 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \ 99 paramName, pt2Object->getClassName(), 4, subLoads.getCount()); \ 100 } \ 101 else \ 102 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 103 }; 104 9 105 // abstract base class 10 106 class baseLoadParam 11 107 { 12 108 public: 13 // virtual void Call(const char* string)=0; // call using function109 void description(const char* description); 14 110 }; 15 111 … … 19 115 { 20 116 public: 21 // 1. CONST CHAR* 22 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(const char*)) 23 { 24 const char* loadString = grabParameter(root, paramName); 25 if (loadString != NULL) 26 (*pt2Object.*function)(loadString); 27 else 28 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); 29 }; 117 LoadParam1(l_STRING); 118 LoadParam2(l_STRING, l_STRING); 119 LoadParam3(l_STRING, l_STRING, l_STRING); 120 LoadParam4(l_STRING, l_STRING, l_STRING, l_STRING); 30 121 31 // 2. CONST CHAR* 32 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(const char*, const char*)) 33 { 34 const char* loadString = grabParameter(root, paramName); 35 if (loadString != NULL) 36 { 37 SubString subLoads(loadString); 38 if (subLoads.getCount() == 2) 39 (*pt2Object.*function)(subLoads.getString(0), subLoads.getString(1)); 40 else 41 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", 42 paramName, pt2Object->getClassName(), 2, subLoads.getCount()); 43 } 44 else 45 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); 46 }; 122 LoadParam1(l_INT); 123 LoadParam2(l_INT, l_INT); 124 LoadParam3(l_INT, l_INT, l_INT); 125 LoadParam4(l_INT, l_INT, l_INT, l_INT); 47 126 48 // 3. CONST CHAR* 49 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(const char*, const char*, const char*)) 50 { 51 const char* loadString = grabParameter(root, paramName); 52 if (loadString != NULL) 53 { 54 SubString subLoads(loadString); 55 if (subLoads.getCount() == 3) 56 (*pt2Object.*function)(subLoads.getString(0), subLoads.getString(1), subLoads.getString(2)); 57 else 58 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", 59 paramName, pt2Object->getClassName(), 3, subLoads.getCount()); 60 } 61 else 62 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); 63 }; 127 LoadParam1(l_FLOAT); 128 LoadParam2(l_FLOAT, l_FLOAT); 129 LoadParam3(l_FLOAT, l_FLOAT, l_FLOAT); 130 LoadParam4(l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT); 64 131 65 // 4. CONST CHAR*66 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(const char*, const char*, const char*, const char*))67 {68 const char* loadString = grabParameter(root, paramName);69 if (loadString != NULL)70 {71 SubString subLoads(loadString);72 if (subLoads.getCount() == 4)73 (*pt2Object.*function)(subLoads.getString(0), subLoads.getString(1), subLoads.getString(2), subLoads.getString(3));74 else75 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n",76 paramName, pt2Object->getClassName(), 4, subLoads.getCount());77 }78 else79 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName());80 };81 82 // 1. FLOAT83 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(float))84 {85 const char* loadString = grabParameter(root, paramName);86 if (loadString != NULL)87 (*pt2Object.*function)(atof(loadString));88 else89 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName());90 };91 92 // 2. FLOAT93 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(float, float))94 {95 const char* loadString = grabParameter(root, paramName);96 if (loadString != NULL)97 {98 SubString subLoads(loadString);99 if (subLoads.getCount() == 2)100 (*pt2Object.*function)(atof(subLoads.getString(0)), atof(subLoads.getString(1)));101 else102 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n",103 paramName, pt2Object->getClassName(), 2, subLoads.getCount());104 105 }106 else107 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName());108 };109 110 // 3. FLOAT111 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(float, float, float))112 {113 const char* loadString = grabParameter(root, paramName);114 if (loadString != NULL)115 {116 SubString subLoads(loadString);117 if (subLoads.getCount() == 3)118 (*pt2Object.*function)(atof(subLoads.getString(0)), atof(subLoads.getString(1)), atof(subLoads.getString(2)));119 else120 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n",121 paramName, pt2Object->getClassName(), 3, subLoads.getCount());122 }123 else124 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName());125 };126 127 // 4. FLOAT128 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(float, float, float, float))129 {130 const char* loadString = grabParameter(root, paramName);131 if (loadString != NULL)132 {133 SubString subLoads(loadString);134 if (subLoads.getCount() == 4)135 (*pt2Object.*function)(atof(subLoads.getString(0)), atof(subLoads.getString(1)), atof(subLoads.getString(2)), atof(subLoads.getString(3)));136 else137 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n",138 paramName, pt2Object->getClassName(), 4, subLoads.getCount());139 140 }141 else142 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName());143 };144 145 // 1. INT146 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(int))147 {148 const char* loadString = grabParameter(root, paramName);149 if (loadString != NULL)150 (*pt2Object.*function)(atoi(loadString));151 else152 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName());153 };154 155 // 2. INT156 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(int, int))157 {158 const char* loadString = grabParameter(root, paramName);159 if (loadString != NULL)160 {161 SubString subLoads(loadString);162 if (subLoads.getCount() == 2)163 (*pt2Object.*function)(atoi(subLoads.getString(0)), atoi(subLoads.getString(1)));164 else165 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n",166 paramName, pt2Object->getClassName(), 2, subLoads.getCount());167 168 }169 else170 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName());171 };172 173 // 3. INT174 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(int, int, int))175 {176 const char* loadString = grabParameter(root, paramName);177 if (loadString != NULL)178 {179 SubString subLoads(loadString);180 if (subLoads.getCount() == 3)181 (*pt2Object.*function)(atoi(subLoads.getString(0)), atoi(subLoads.getString(1)), atoi(subLoads.getString(2)));182 else183 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n",184 paramName, pt2Object->getClassName(), 3, subLoads.getCount());185 186 }187 else188 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName());189 };190 191 // 4. INT192 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(int, int, int, int))193 {194 const char* loadString = grabParameter(root, paramName);195 if (loadString != NULL)196 {197 SubString subLoads(loadString);198 if (subLoads.getCount() == 4)199 (*pt2Object.*function)(atoi(subLoads.getString(0)), atoi(subLoads.getString(1)), atoi(subLoads.getString(2)), atoi(subLoads.getString(3)));200 else201 PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n",202 paramName, pt2Object->getClassName(), 4, subLoads.getCount());203 }204 else205 PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName());206 };207 132 208 133 };
Note: See TracChangeset
for help on using the changeset viewer.