Changeset 4623 in orxonox.OLD for orxonox/trunk/src/util
- Timestamp:
- Jun 13, 2005, 7:31:50 PM (19 years ago)
- Location:
- orxonox/trunk/src/util/loading
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/util/loading/load_param.cc
r4598 r4623 27 27 \param paramCount: how many parameters this loading-function takes 28 28 \param multi: if false LoadParam assumes only one occurence of this parameter in root, if true it assumes multiple occurences. 29 \param ...: the parameter information 29 \param ...: the parameter information (1. Parameter, 2. Default Value for the Parameter, ...) 30 30 */ 31 31 BaseLoadParam::BaseLoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName, … … 55 55 this->paramDesc = NULL; 56 56 if (LoadClassDescription::parametersDescription) 57 { 57 { 58 //! \todo this must only be done once for each class. 58 59 // locating the class 59 this->classDesc = LoadClassDescription::addClass(object->getClassName()); 60 this->paramDesc = this->classDesc->addParam(paramName); 61 60 this->classDesc = LoadClassDescription::addClass(object->getClassName()); 61 62 if ((this->paramDesc = this->classDesc->addParam(paramName)) != NULL) 63 { 64 65 this->paramDesc->paramCount = paramCount; 62 66 this->paramDesc->types = new char*[paramCount]; 63 this->paramDesc-> paramCount = paramCount;67 this->paramDesc->defaultValues = new char*[paramCount]; 64 68 65 69 va_list types; 66 70 va_start (types, pointerToParam); 71 char defaultVal[512]; 67 72 for(int i = 0; i < paramCount; i++) 68 { 69 const char* tmpTypeName = va_arg (types, const char*); 70 this->paramDesc->types[i] = new char[strlen(tmpTypeName)+1]; 71 strcpy(this->paramDesc->types[i], tmpTypeName); 72 } 73 { 74 // 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 // default value description 80 if (!strcmp(tmpTypeName, l_INT_NAME)) 81 { 82 sprintf(defaultVal, "%d", va_arg(types, l_INT_TYPE)); 83 } 84 else if (!strcmp(tmpTypeName, l_LONG_NAME)) 85 { 86 sprintf(defaultVal, "%0.3f", va_arg(types, l_LONG_TYPE)); 87 } 88 /* else if (!strcmp(tmpTypeName, l_SHORT_NAME)) 89 { 90 sprintf(defaultVal, "%d", va_arg(types, l_SHORT_TYPE)); 91 }*/ 92 else if (!strcmp(tmpTypeName, l_FLOAT_NAME)) 93 { 94 sprintf(defaultVal, "%0.3f", va_arg(types, double)); 95 } 96 else if (!strcmp(tmpTypeName, l_STRING_NAME)) 97 { 98 sprintf(defaultVal, "%s", va_arg(types, l_STRING_TYPE)); 99 } 100 else if (!strcmp(tmpTypeName, l_XML_ELEM_NAME)) 101 { 102 sprintf(defaultVal, ""); 103 } 104 105 this->paramDesc->defaultValues[i] = new char[strlen(defaultVal)+1]; 106 strcpy(this->paramDesc->defaultValues[i], defaultVal); 107 } 73 108 va_end(types); 74 109 75 110 int argCount = 0; 76 111 } 112 } 77 113 } 78 114 … … 99 135 this->paramName = new char[strlen(paramName)+1]; 100 136 strcpy(this->paramName, paramName); 137 this->defaultValues = NULL; 101 138 } 102 139 … … 107 144 { 108 145 for(int i = 0; i < this->paramCount; i++) 109 { 110 delete this->types[i]; 111 } 146 { 147 delete this->types[i]; 148 } 149 for(int i = 0; i < this->paramCount; i++) 150 { 151 delete this->defaultValues[i]; 152 } 153 112 154 delete []this->types; 155 delete []this->defaultValues; 113 156 delete []this->paramName; 114 157 delete []this->description; … … 139 182 if (this->description) 140 183 PRINT(3)(" -- %s", this->description); 184 // default values 185 if (this->paramCount > 0) 186 { 187 PRINT(3)(" (Default: "); 188 for (int i = 0; i < this->paramCount; i++) 189 { 190 if (i > 0) 191 PRINT(3)(", "); 192 PRINT(3)("%s", this->defaultValues[i]); 193 } 194 PRINT(3)(")"); 195 } 141 196 PRINT(3)("\n"); 142 197 } -
orxonox/trunk/src/util/loading/load_param.h
r4599 r4623 50 50 */ 51 51 52 #define l_INT_TYPE int //!< The type of an INT 53 #define l_INT_FUNC atoi //!< the function to call to parse INT 54 #define l_INT_NAME "int" //!< the name of an INT 55 56 #define l_LONG_TYPE long //!< The type of a LONG 57 #define l_LONG_FUNC atol //!< The function to parse a LONG 58 #define l_LONG_NAME "long" //!< The name of a LONG 59 60 #define l_SHORT_TYPE short //!< The type of a SHORT 61 #define l_SHORT_FUNC atoi //!< The function to parse a SHORT 62 #define l_SHORT_NAME "short" //!< The name of a SHORT 63 64 #define l_FLOAT_TYPE float //!< The type of a FLOAT 65 #define l_FLOAT_FUNC atof //!< The function to parse a FLOAT 66 #define l_FLOAT_NAME "float" //!< The name of a FLOAT 67 68 #define l_STRING_TYPE const char* //!< The type of a STRING 69 #define l_STRING_FUNC //!< The function to parse a STRING 70 #define l_STRING_NAME "string" //!< The name of a STRING 71 72 #define l_XML_ELEM_TYPE const TiXmlElement* //!< The type of an XML_ELEM 73 #define l_XML_ELEM_FUNC //!< The function to parse an XML_ELEM 74 #define l_XML_ELEM_NAME "XML" //!< The name of an XML_ELEM 75 52 #define l_INT_TYPE int //!< The type of an INT 53 #define l_INT_FUNC atoi //!< The function to call to parse INT 54 #define l_INT_NAME "int" //!< The name of an INT 55 #define l_INT_DEFAULT 0 //!< a default Value for an INT 56 57 #define l_LONG_TYPE long //!< The type of a LONG 58 #define l_LONG_FUNC atol //!< The function to parse a LONG 59 #define l_LONG_NAME "long" //!< The name of a LONG 60 #define l_LONG_DEFAULT 0 //!< a default Value for a LONG 61 62 // #define l_SHORT_TYPE short //!< The type of a SHORT 63 // #define l_SHORT_FUNC atoi //!< The function to parse a SHORT 64 // #define l_SHORT_NAME "short" //!< The name of a SHORT 65 // #define l_SHORT_DEFAULT 0 //!< a default Value for a SHORT 66 67 #define l_FLOAT_TYPE float //!< The type of a FLOAT 68 #define l_FLOAT_FUNC atof //!< The function to parse a FLOAT 69 #define l_FLOAT_NAME "float" //!< The name of a FLOAT 70 #define l_FLOAT_DEFAULT 0.0 //!< a default Value for a FLOAT 71 72 #define l_STRING_TYPE const char* //!< The type of a STRING 73 #define l_STRING_FUNC //!< The function to parse a STRING 74 #define l_STRING_NAME "string" //!< The name of a STRING 75 #define l_STRING_DEFAULT "" //!< a default Value for an STRING 76 77 #define l_XML_ELEM_TYPE const TiXmlElement* //!< The type of an XML_ELEM 78 #define l_XML_ELEM_FUNC //!< The function to parse an XML_ELEM 79 #define l_XML_ELEM_NAME "XML" //!< The name of an XML_ELEM 80 #define l_XML_ELEM_DEFAULT NULL //!< The dafault Value for an XML_ELEM 81 82 83 /***************************************** 84 **** MACROS DEFINITIONS OF LOADABLES ***** 85 *****************************************/ 76 86 // 1. TYPE 77 87 /** … … 80 90 */ 81 91 #define LoadParam1(type1) \ 82 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE), bool multi = false) \ 83 : BaseLoadParam(root, pt2Object, paramName, 1, multi, NULL, type1##_NAME) \ 92 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE), \ 93 bool multi = false, type1##_TYPE default1 = type1##_DEFAULT) \ 94 : BaseLoadParam(root, pt2Object, paramName, 1, multi, NULL, type1##_NAME, default1) \ 84 95 { \ 85 96 if (loadString != NULL && root != NULL) \ … … 97 108 */ 98 109 #define LoadParam2(type1, type2) \ 99 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE), bool multi = false) \ 100 : BaseLoadParam(root, pt2Object, paramName, 2, multi, NULL, type1##_NAME, type2##_NAME) \ 110 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE), \ 111 bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \ 112 : BaseLoadParam(root, pt2Object, paramName, 2, multi, NULL, type1##_NAME, default1, type2##_NAME, default2) \ 101 113 { \ 102 114 if (loadString != NULL && root != NULL) \ … … 122 134 */ 123 135 #define LoadParam3(type1, type2, type3) \ 124 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE), bool multi = false)\ 125 : BaseLoadParam(root, pt2Object, paramName, 3, multi, NULL, type1##_NAME, type2##_NAME, type3##_NAME) \ 136 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE), \ 137 bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT, type3##_TYPE default3 = type3##_DEFAULT)\ 138 : BaseLoadParam(root, pt2Object, paramName, 3, multi, NULL, type1##_NAME, default1, type2##_NAME, default2, type3##_NAME, default3) \ 126 139 { \ 127 140 if (loadString != NULL && root != NULL) \ … … 148 161 */ 149 162 #define LoadParam4(type1, type2, type3, type4) \ 150 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE), bool multi = false) \ 151 : BaseLoadParam(root, pt2Object, paramName, 4, multi, NULL, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME) \ 163 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE), \ 164 bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT, type3##_TYPE default3 = type3##_DEFAULT, \ 165 type4##_TYPE default4 = type4##_DEFAULT) \ 166 : BaseLoadParam(root, pt2Object, paramName, 4, multi, NULL, type1##_NAME, default1, type2##_NAME, default2, type3##_NAME, default3, \ 167 type4##_NAME, default4) \ 152 168 { \ 153 169 if (loadString != NULL && root != NULL) \ … … 175 191 */ 176 192 #define LoadParam5(type1, type2, type3, type4, type5) \ 177 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE, type5##_TYPE), bool multi = false) \ 178 : BaseLoadParam(root, pt2Object, paramName, 5, multi, NULL, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME, type5##_NAME) \ 193 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, \ 194 void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE, type5##_TYPE), \ 195 bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT, type3##_TYPE default3 = type3##_DEFAULT, \ 196 type4##_TYPE default4 = type4, ##_DEFAULTtype5##_TYPE default5 = type5##_DEFAULT ) \ 197 : BaseLoadParam(root, pt2Object, paramName, 5, multi, NULL, type1##_NAME, default1, type2##_NAME, default2, type3##_NAME, default3, \ 198 type4##_NAME, default4, type5##_NAME, default5) \ 179 199 { \ 180 200 if (loadString != NULL && root != NULL) \ … … 221 241 void print(void) const; 222 242 private: 223 char* paramName; //!< The name of the parameter 224 int paramCount; //!< The count of parameters 243 char* paramName; //!< The name of the parameter. 244 int paramCount; //!< The count of parameters. 225 245 char** types; //!< What kind of parameters does this function take ?? 226 char* description; //!< A longer description about this function 246 char* description; //!< A longer description about this function. 247 char** defaultValues; //!< The 'Default Values'. 227 248 }; 228 249
Note: See TracChangeset
for help on using the changeset viewer.