- Timestamp:
- Feb 9, 2008, 7:32:06 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core/src/orxonox/core/ConfigValueContainer.cc
r790 r792 28 28 #include <fstream> 29 29 30 #include "ConfigValueContainer.h" 30 31 #include "util/Tokenizer.h" 31 32 #include "util/Convert.h" 32 #include "ConfigValueContainer.h"33 33 34 34 #define CONFIGFILEPATH "orxonox.ini" … … 43 43 @param defvalue The default-value 44 44 */ 45 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, intdefvalue)45 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, MultiTypeMath defvalue) 46 46 { 47 47 this->bAddedDescription_ = false; 48 48 this->classname_ = classname; 49 49 this->varname_ = varname; 50 this->type_ = VT_Int; 51 52 ConvertValue(&this->defvalueString_, defvalue, std::string("0")); // Try to convert the default-value to a string 50 51 this->valueToString(&this->defvalueString_, defvalue); // Try to convert the default-value to a string 53 52 this->searchConfigFileLine(); // Search the entry in the config-file 54 53 55 54 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 56 if (!this->parseSt ing(valueString, defvalue))// Try to convert the string to a value55 if (!this->parseString(valueString, defvalue)) // Try to convert the string to a value 57 56 this->resetConfigFileEntry(); // The conversion failed 58 57 } 59 58 60 59 /** 61 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 62 @param value This is only needed to determine the right type. 63 @param classname The name of the class the variable belongs to 64 @param varname The name of the variable 65 @param defvalue The default-value 66 */ 67 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned int defvalue) 68 { 69 this->bAddedDescription_ = false; 70 this->classname_ = classname; 71 this->varname_ = varname; 72 this->type_ = VT_uInt; 73 74 ConvertValue(&this->defvalueString_, defvalue, std::string("0")); // Try to convert the default-value to a string 75 this->searchConfigFileLine(); // Search the entry in the config-file 76 77 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 78 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 79 this->resetConfigFileEntry(); // The conversion failed 80 } 81 82 /** 83 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 84 @param value This is only needed to determine the right type. 85 @param classname The name of the class the variable belongs to 86 @param varname The name of the variable 87 @param defvalue The default-value 88 */ 89 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, char defvalue) 90 { 91 this->bAddedDescription_ = false; 92 this->classname_ = classname; 93 this->varname_ = varname; 94 this->type_ = VT_Char; 95 96 ConvertValue(&this->defvalueString_, (int)defvalue, std::string("0")); // Try to convert the default-value to a string 97 this->searchConfigFileLine(); // Search the entry in the config-file 98 99 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 100 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 101 this->resetConfigFileEntry(); // The conversion failed 102 } 103 104 /** 105 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 106 @param value This is only needed to determine the right type. 107 @param classname The name of the class the variable belongs to 108 @param varname The name of the variable 109 @param defvalue The default-value 110 */ 111 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned char defvalue) 112 { 113 this->bAddedDescription_ = false; 114 this->classname_ = classname; 115 this->varname_ = varname; 116 this->type_ = VT_uChar; 117 118 ConvertValue(&this->defvalueString_, (unsigned int)defvalue, std::string("0")); // Try to convert the default-value to a string 119 this->searchConfigFileLine(); // Search the entry in the config-file 120 121 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 122 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 123 this->resetConfigFileEntry(); // The conversion failed 124 } 125 126 /** 127 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 128 @param value This is only needed to determine the right type. 129 @param classname The name of the class the variable belongs to 130 @param varname The name of the variable 131 @param defvalue The default-value 132 */ 133 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, float defvalue) 134 { 135 this->bAddedDescription_ = false; 136 this->classname_ = classname; 137 this->varname_ = varname; 138 this->type_ = VT_Float; 139 140 ConvertValue(&this->defvalueString_, defvalue, std::string("0.000000")); // Try to convert the default-value to a string 141 this->searchConfigFileLine(); // Search the entry in the config-file 142 143 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 144 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 145 this->resetConfigFileEntry(); // The conversion failed 146 } 147 148 /** 149 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 150 @param value This is only needed to determine the right type. 151 @param classname The name of the class the variable belongs to 152 @param varname The name of the variable 153 @param defvalue The default-value 154 */ 155 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, double defvalue) 156 { 157 this->bAddedDescription_ = false; 158 this->classname_ = classname; 159 this->varname_ = varname; 160 this->type_ = VT_Double; 161 162 ConvertValue(&this->defvalueString_, defvalue, std::string("0.000000")); // Try to convert the default-value to a string 163 this->searchConfigFileLine(); // Search the entry in the config-file 164 165 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 166 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 167 this->resetConfigFileEntry(); // The conversion failed 168 } 169 170 /** 171 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 172 @param value This is only needed to determine the right type. 173 @param classname The name of the class the variable belongs to 174 @param varname The name of the variable 175 @param defvalue The default-value 176 */ 177 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, long double defvalue) 178 { 179 this->bAddedDescription_ = false; 180 this->classname_ = classname; 181 this->varname_ = varname; 182 this->type_ = VT_LongDouble; 183 184 ConvertValue(&this->defvalueString_, defvalue, std::string("0.000000")); // Try to convert the default-value to a string 185 this->searchConfigFileLine(); // Search the entry in the config-file 186 187 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 188 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 189 this->resetConfigFileEntry(); // The conversion failed 190 } 191 192 /** 193 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 194 @param value This is only needed to determine the right type. 195 @param classname The name of the class the variable belongs to 196 @param varname The name of the variable 197 @param defvalue The default-value 198 */ 199 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue) 200 { 201 this->bAddedDescription_ = false; 202 this->classname_ = classname; 203 this->varname_ = varname; 204 this->type_ = VT_Bool; 205 206 // Convert the default-value from bool to string 207 if (defvalue) 208 this->defvalueString_ = "true"; 209 else 210 this->defvalueString_ = "false"; 211 212 this->searchConfigFileLine(); // Search the entry in the config-file 213 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 214 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 215 this->resetConfigFileEntry(); // The conversion failed 216 } 217 218 /** 219 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 220 @param value This is only needed to determine the right type. 221 @param classname The name of the class the variable belongs to 222 @param varname The name of the variable 223 @param defvalue The default-value 224 */ 225 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, const std::string& defvalue) 226 { 227 this->bAddedDescription_ = false; 228 this->classname_ = classname; 229 this->varname_ = varname; 230 this->type_ = VT_String; 231 232 this->defvalueString_ = "\"" + defvalue + "\""; // Convert the string to a "config-file-string" with quotes 233 this->searchConfigFileLine(); // Search the entry in the config-file 234 std::string valueString = this->parseValueString(false); // Parses the value string from the config-file-entry 235 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 236 this->resetConfigFileEntry(); // The conversion failed 237 } 238 239 /** 240 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 241 @param value This is only needed to determine the right type. 242 @param classname The name of the class the variable belongs to 243 @param varname The name of the variable 244 @param defvalue The default-value 245 */ 246 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue) 247 { 248 this->bAddedDescription_ = false; 249 this->classname_ = classname; 250 this->varname_ = varname; 251 this->type_ = VT_ConstChar; 252 253 this->defvalueString_ = "\"" + std::string(defvalue) + "\""; // Convert the string to a "config-file-string" with quotes 254 this->searchConfigFileLine(); // Search the entry in the config-file 255 std::string valueString = this->parseValueString(false); // Parses the value string from the config-file-entry 256 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 257 this->resetConfigFileEntry(); // The conversion failed 258 } 259 260 /** 261 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 262 @param value This is only needed to determine the right type. 263 @param classname The name of the class the variable belongs to 264 @param varname The name of the variable 265 @param defvalue The default-value 266 */ 267 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Vector2 defvalue) 268 { 269 this->bAddedDescription_ = false; 270 this->classname_ = classname; 271 this->varname_ = varname; 272 this->type_ = VT_Vector2; 273 274 // Try to convert the default-value from Vector2 to string 275 std::ostringstream ostream; 276 if (ostream << "(" << defvalue.x << "," << defvalue.y << ")") 277 this->defvalueString_ = ostream.str(); 278 else 279 this->defvalueString_ = "(0,0)"; 280 281 this->searchConfigFileLine(); // Search the entry in the config-file 282 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 283 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 284 this->resetConfigFileEntry(); // The conversion failed 285 } 286 287 /** 288 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 289 @param value This is only needed to determine the right type. 290 @param classname The name of the class the variable belongs to 291 @param varname The name of the variable 292 @param defvalue The default-value 293 */ 294 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Vector3 defvalue) 295 { 296 this->bAddedDescription_ = false; 297 this->classname_ = classname; 298 this->varname_ = varname; 299 this->type_ = VT_Vector3; 300 301 // Try to convert the default-value from Vector3 to string 302 std::ostringstream ostream; 303 if (ostream << "(" << defvalue.x << "," << defvalue.y << "," << defvalue.z << ")") 304 this->defvalueString_ = ostream.str(); 305 else 306 this->defvalueString_ = "(0,0,0)"; 307 308 this->searchConfigFileLine(); // Search the entry in the config-file 309 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 310 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 311 this->resetConfigFileEntry(); // The conversion failed 312 } 313 314 /** 315 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 316 @param value This is only needed to determine the right type. 317 @param classname The name of the class the variable belongs to 318 @param varname The name of the variable 319 @param defvalue The default-value 320 */ 321 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, ColourValue defvalue) 322 { 323 this->bAddedDescription_ = false; 324 this->classname_ = classname; 325 this->varname_ = varname; 326 this->type_ = VT_ColourValue; 327 328 // Try to convert the default-value from ColourValue to string 329 std::ostringstream ostream; 330 if (ostream << "(" << defvalue.r << "," << defvalue.g << "," << defvalue.b << "," << defvalue.a << ")") 331 this->defvalueString_ = ostream.str(); 332 else 333 this->defvalueString_ = "(0,0,0,0)"; 334 335 this->searchConfigFileLine(); // Search the entry in the config-file 336 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 337 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 338 this->resetConfigFileEntry(); // The conversion failed 60 @brief Converts a value to a string. 61 @param output The string to write to 62 @param input The value to convert 63 @return True if the converson was successful 64 */ 65 bool ConfigValueContainer::valueToString(std::string* output, MultiTypeMath& input) 66 { 67 if (this->value_.getType() == MT_int) 68 return ConvertValue(output, input.getInt(), std::string("0")); 69 else if (this->value_.getType() == MT_uint) 70 return ConvertValue(output, input.getUnsignedInt(), std::string("0")); 71 else if (this->value_.getType() == MT_char) 72 return ConvertValue(output, input.getChar(), std::string("0")); 73 else if (this->value_.getType() == MT_uchar) 74 return ConvertValue(output, input.getUnsignedChar(), std::string("0")); 75 else if (this->value_.getType() == MT_short) 76 return ConvertValue(output, input.getShort(), std::string("0")); 77 else if (this->value_.getType() == MT_ushort) 78 return ConvertValue(output, input.getUnsignedShort(), std::string("0")); 79 else if (this->value_.getType() == MT_long) 80 return ConvertValue(output, input.getLong(), std::string("0")); 81 else if (this->value_.getType() == MT_ulong) 82 return ConvertValue(output, input.getUnsignedLong(), std::string("0")); 83 else if (this->value_.getType() == MT_float) 84 return ConvertValue(output, input.getFloat(), std::string("0.000000")); 85 else if (this->value_.getType() == MT_double) 86 return ConvertValue(output, input.getDouble(), std::string("0.000000")); 87 else if (this->value_.getType() == MT_longdouble) 88 return ConvertValue(output, input.getChar(), std::string("0.000000")); 89 else if (this->value_.getType() == MT_bool) 90 { 91 if (input.getBool()) 92 (*output) = "true"; 93 else 94 (*output) = "false"; 95 96 return true; 97 } 98 else if (this->value_.getType() == MT_constchar) 99 { 100 (*output) = "\"" + input.getString() + "\""; 101 return true; 102 } 103 else if (this->value_.getType() == MT_string) 104 { 105 (*output) = "\"" + input.getString() + "\""; 106 return true; 107 } 108 else if (this->value_.getType() == MT_vector2) 109 { 110 std::ostringstream ostream; 111 if (ostream << "(" << input.getVector2().x << "," << input.getVector2().y << ")") 112 { 113 (*output) = ostream.str(); 114 return true; 115 } 116 else 117 { 118 (*output) = "(0,0)"; 119 return false; 120 } 121 } 122 else if (this->value_.getType() == MT_vector3) 123 { 124 std::ostringstream ostream; 125 if (ostream << "(" << input.getVector3().x << "," << input.getVector3().y << "," << input.getVector3().z << ")") 126 { 127 (*output) = ostream.str(); 128 return true; 129 } 130 else 131 { 132 (*output) = "(0,0,0)"; 133 return false; 134 } 135 } 136 else if (this->value_.getType() == MT_colourvalue) 137 { 138 std::ostringstream ostream; 139 if (ostream << "(" << input.getColourValue().r << "," << input.getColourValue().g << "," << input.getColourValue().b << "," << input.getColourValue().a << ")") 140 { 141 (*output) = ostream.str(); 142 return true; 143 } 144 else 145 { 146 (*output) = "(0,0,0,0)"; 147 return false; 148 } 149 } 150 else if (this->value_.getType() == MT_quaternion) 151 { 152 std::ostringstream ostream; 153 if (ostream << "(" << input.getQuaternion().w << "," << input.getQuaternion().x << "," << input.getQuaternion().y << "," << input.getQuaternion().z << ")") 154 { 155 (*output) = ostream.str(); 156 return true; 157 } 158 else 159 { 160 (*output) = "(0,0,0,0)"; 161 return false; 162 } 163 } 164 else if (this->value_.getType() == MT_radian) 165 return ConvertValue(output, input.getRadian(), std::string("0.000000")); 166 else if (this->value_.getType() == MT_degree) 167 return ConvertValue(output, input.getDegree(), std::string("0.000000")); 168 169 return false; 339 170 } 340 171 … … 344 175 @return True if the string was successfully parsed 345 176 */ 346 bool ConfigValueContainer::parseSting(const std::string& input) 347 { 348 if (this->type_ == ConfigValueContainer::VT_Int) 349 return this->parseSting(input, this->value_.value_int_); 350 else if (this->type_ == ConfigValueContainer::VT_uInt) 351 return this->parseSting(input, this->value_.value_uint_); 352 else if (this->type_ == ConfigValueContainer::VT_Char) 353 return this->parseSting(input, this->value_.value_char_); 354 else if (this->type_ == ConfigValueContainer::VT_uChar) 355 return this->parseSting(input, this->value_.value_uchar_); 356 else if (this->type_ == ConfigValueContainer::VT_Float) 357 return this->parseSting(input, this->value_.value_float_); 358 else if (this->type_ == ConfigValueContainer::VT_Double) 359 return this->parseSting(input, this->value_.value_double_); 360 else if (this->type_ == ConfigValueContainer::VT_LongDouble) 361 return this->parseSting(input, this->value_.value_long_double_); 362 else if (this->type_ == ConfigValueContainer::VT_Bool) 363 return this->parseSting(input, this->value_.value_bool_); 364 else if (this->type_ == ConfigValueContainer::VT_String) 365 return this->parseSting(input, this->value_string_); 366 else if (this->type_ == ConfigValueContainer::VT_ConstChar) 367 return this->parseSting(input, this->value_string_); 368 else if (this->type_ == ConfigValueContainer::VT_Vector2) 369 return this->parseSting(input, this->value_vector2_); 370 else if (this->type_ == ConfigValueContainer::VT_Vector3) 371 return this->parseSting(input, this->value_vector3_); 372 else if (this->type_ == ConfigValueContainer::VT_ColourValue) 373 return this->parseSting(input, this->value_colourvalue_); 177 bool ConfigValueContainer::parseString(const std::string& input, MultiTypeMath& defvalue) 178 { 179 if (this->value_.getType() == MT_int) 180 return this->parseString(input, defvalue.getInt()); 181 else if (this->value_.getType() == MT_uint) 182 return this->parseString(input, defvalue.getUnsignedInt()); 183 else if (this->value_.getType() == MT_char) 184 return this->parseString(input, defvalue.getChar()); 185 else if (this->value_.getType() == MT_uchar) 186 return this->parseString(input, defvalue.getUnsignedChar()); 187 else if (this->value_.getType() == MT_short) 188 return this->parseString(input, defvalue.getShort()); 189 else if (this->value_.getType() == MT_ushort) 190 return this->parseString(input, defvalue.getUnsignedShort()); 191 else if (this->value_.getType() == MT_long) 192 return this->parseString(input, defvalue.getLong()); 193 else if (this->value_.getType() == MT_ulong) 194 return this->parseString(input, defvalue.getUnsignedLong()); 195 else if (this->value_.getType() == MT_float) 196 return this->parseString(input, defvalue.getFloat()); 197 else if (this->value_.getType() == MT_double) 198 return this->parseString(input, defvalue.getDouble()); 199 else if (this->value_.getType() == MT_longdouble) 200 return this->parseString(input, defvalue.getLongDouble()); 201 else if (this->value_.getType() == MT_bool) 202 return this->parseString(input, defvalue.getBool()); 203 else if (this->value_.getType() == MT_constchar) 204 return this->parseString(input, defvalue.getString()); 205 else if (this->value_.getType() == MT_string) 206 return this->parseString(input, defvalue.getString()); 207 else if (this->value_.getType() == MT_vector2) 208 return this->parseString(input, defvalue.getVector2()); 209 else if (this->value_.getType() == MT_vector3) 210 return this->parseString(input, defvalue.getVector3()); 211 else if (this->value_.getType() == MT_colourvalue) 212 return this->parseString(input, defvalue.getColourValue()); 213 else if (this->value_.getType() == MT_quaternion) 214 return this->parseString(input, defvalue.getQuaternion()); 215 else if (this->value_.getType() == MT_radian) 216 return this->parseString(input, defvalue.getRadian()); 217 else if (this->value_.getType() == MT_degree) 218 return this->parseString(input, defvalue.getDegree()); 374 219 375 220 return false; … … 382 227 @return True if the string was successfully parsed 383 228 */ 384 bool ConfigValueContainer::parseSting(const std::string& input, int defvalue) 385 { 386 return ConvertValue(&this->value_.value_int_, input, defvalue); 229 bool ConfigValueContainer::parseString(const std::string& input, int defvalue) 230 { 231 int temp; 232 bool success = ConvertValue(&temp, input, defvalue); 233 ((MultiTypePrimitive)this->value_).setValue(temp); 234 return success; 387 235 } 388 236 … … 393 241 @return True if the string was successfully parsed 394 242 */ 395 bool ConfigValueContainer::parseSting(const std::string& input, unsigned int defvalue) 396 { 397 return ConvertValue(&this->value_.value_uint_, input, defvalue); 243 bool ConfigValueContainer::parseString(const std::string& input, unsigned int defvalue) 244 { 245 unsigned int temp; 246 bool success = ConvertValue(&temp, input, defvalue); 247 ((MultiTypePrimitive)this->value_).setValue(temp); 248 return success; 398 249 } 399 250 … … 404 255 @return True if the string was successfully parsed 405 256 */ 406 bool ConfigValueContainer::parseSt ing(const std::string& input, char defvalue)257 bool ConfigValueContainer::parseString(const std::string& input, char defvalue) 407 258 { 408 259 // I used value_int_ instead of value_char_ to avoid number <-> char confusion in the config-file 409 return ConvertValue(&this->value_.value_int_, input, (int)defvalue); 260 int temp; 261 bool success = ConvertValue(&temp, input, (int)defvalue); 262 ((MultiTypePrimitive)this->value_).setValue((char)temp); 263 return success; 410 264 } 411 265 … … 416 270 @return True if the string was successfully parsed 417 271 */ 418 bool ConfigValueContainer::parseSt ing(const std::string& input, unsigned char defvalue)272 bool ConfigValueContainer::parseString(const std::string& input, unsigned char defvalue) 419 273 { 420 274 // I used value_uint_ instead of value_uchar_ to avoid number <-> char confusion in the config-file 421 return ConvertValue(&this->value_.value_uint_, input, (unsigned int)defvalue); 275 unsigned int temp; 276 bool success = ConvertValue(&temp, input, (unsigned int)defvalue); 277 ((MultiTypePrimitive)this->value_).setValue((unsigned char)temp); 278 return success; 279 } 280 281 /** 282 @brief Parses a given std::string into a value of the type short and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 283 @param input The string to convert 284 @param defvalue The default-value 285 @return True if the string was successfully parsed 286 */ 287 bool ConfigValueContainer::parseString(const std::string& input, short defvalue) 288 { 289 short temp; 290 bool success = ConvertValue(&temp, input, defvalue); 291 ((MultiTypePrimitive)this->value_).setValue(temp); 292 return success; 293 } 294 295 /** 296 @brief Parses a given std::string into a value of the type unsigned short and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 297 @param input The string to convert 298 @param defvalue The default-value 299 @return True if the string was successfully parsed 300 */ 301 bool ConfigValueContainer::parseString(const std::string& input, unsigned short defvalue) 302 { 303 unsigned short temp; 304 bool success = ConvertValue(&temp, input, defvalue); 305 ((MultiTypePrimitive)this->value_).setValue(temp); 306 return success; 307 } 308 309 /** 310 @brief Parses a given std::string into a value of the type long and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 311 @param input The string to convert 312 @param defvalue The default-value 313 @return True if the string was successfully parsed 314 */ 315 bool ConfigValueContainer::parseString(const std::string& input, long defvalue) 316 { 317 long temp; 318 bool success = ConvertValue(&temp, input, defvalue); 319 ((MultiTypePrimitive)this->value_).setValue(temp); 320 return success; 321 } 322 323 /** 324 @brief Parses a given std::string into a value of the type unsigned long and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 325 @param input The string to convert 326 @param defvalue The default-value 327 @return True if the string was successfully parsed 328 */ 329 bool ConfigValueContainer::parseString(const std::string& input, unsigned long defvalue) 330 { 331 unsigned long temp; 332 bool success = ConvertValue(&temp, input, defvalue); 333 ((MultiTypePrimitive)this->value_).setValue(temp); 334 return success; 422 335 } 423 336 … … 428 341 @return True if the string was successfully parsed 429 342 */ 430 bool ConfigValueContainer::parseSting(const std::string& input, float defvalue) 431 { 432 return ConvertValue(&this->value_.value_float_, input, defvalue); 343 bool ConfigValueContainer::parseString(const std::string& input, float defvalue) 344 { 345 float temp; 346 bool success = ConvertValue(&temp, input, defvalue); 347 ((MultiTypePrimitive)this->value_).setValue(temp); 348 return success; 433 349 } 434 350 … … 439 355 @return True if the string was successfully parsed 440 356 */ 441 bool ConfigValueContainer::parseSting(const std::string& input, double defvalue) 442 { 443 return ConvertValue(&this->value_.value_double_, input, defvalue); 357 bool ConfigValueContainer::parseString(const std::string& input, double defvalue) 358 { 359 double temp; 360 bool success = ConvertValue(&temp, input, defvalue); 361 ((MultiTypePrimitive)this->value_).setValue(temp); 362 return success; 444 363 } 445 364 … … 450 369 @return True if the string was successfully parsed 451 370 */ 452 bool ConfigValueContainer::parseSting(const std::string& input, long double defvalue) 453 { 454 return ConvertValue(&this->value_.value_long_double_, input, defvalue); 371 bool ConfigValueContainer::parseString(const std::string& input, long double defvalue) 372 { 373 long double temp; 374 bool success = ConvertValue(&temp, input, defvalue); 375 ((MultiTypePrimitive)this->value_).setValue(temp); 376 return success; 455 377 } 456 378 … … 461 383 @return True if the string was successfully parsed 462 384 */ 463 bool ConfigValueContainer::parseSt ing(const std::string& input, bool defvalue)385 bool ConfigValueContainer::parseString(const std::string& input, bool defvalue) 464 386 { 465 387 // Try to parse the value-string - is it a word? … … 468 390 || input.find("yes") < input.size() 469 391 || input.find("Yes") < input.size()) 470 this->value_.value_bool_ = true;392 ((MultiTypePrimitive)this->value_).setValue(true); 471 393 else if (input.find("false") < input.size() 472 394 || input.find("False") < input.size() 473 395 || input.find("no") < input.size() 474 396 || input.find("No") < input.size()) 475 this->value_.value_bool_ = false;397 ((MultiTypePrimitive)this->value_).setValue(false); 476 398 else 477 399 { 478 400 // Its not a known word - is it a number? 479 return ConvertValue(&this->value_.value_bool_, input, defvalue); 401 bool temp; 402 bool success = ConvertValue(&temp, input, defvalue); 403 ((MultiTypePrimitive)this->value_).setValue(temp); 404 return success; 480 405 } 481 406 … … 489 414 @return True if the string was successfully parsed 490 415 */ 491 bool ConfigValueContainer::parseSt ing(const std::string& input, const std::string& defvalue)416 bool ConfigValueContainer::parseString(const std::string& input, const std::string& defvalue) 492 417 { 493 418 // Strip the quotes … … 499 424 { 500 425 // It was - get the string between the quotes 501 this->value_ string_ = input.substr(pos1, pos2 - pos1);426 this->value_.setValue(input.substr(pos1, pos2 - pos1)); 502 427 return true; 503 428 } 504 429 505 430 // It wasn't - use the default-value and restore the entry in the config-file. 506 this->value_ string_ = defvalue;431 this->value_.setValue(defvalue); 507 432 return false; 508 433 } … … 514 439 @return True if the string was successfully parsed 515 440 */ 516 bool ConfigValueContainer::parseSt ing(const std::string& input, const char* defvalue)441 bool ConfigValueContainer::parseString(const std::string& input, const char* defvalue) 517 442 { 518 443 // Strip the quotes … … 524 449 { 525 450 // It was - get the string between the quotes 526 this->value_ string_ = input.substr(pos1, pos2 - pos1);451 this->value_.setValue(input.substr(pos1, pos2 - pos1)); 527 452 return true; 528 453 } 529 454 530 455 // It wasn't - use the default-value and restore the entry in the config-file. 531 this->value_ string_ = defvalue;456 this->value_.setValue(defvalue); 532 457 return false; 533 458 } … … 539 464 @return True if the string was successfully parsed 540 465 */ 541 bool ConfigValueContainer::parseSt ing(const std::string& input, const Vector2& defvalue)466 bool ConfigValueContainer::parseString(const std::string& input, const Vector2& defvalue) 542 467 { 543 468 // Strip the value-string … … 549 474 { 550 475 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 551 if (!ConvertValue(&this->value_ vector2_.x, tokens[0]))552 { 553 this->value_ vector2_ = defvalue;554 return false; 555 } 556 if (!ConvertValue(&this->value_ vector2_.y, tokens[1]))557 { 558 this->value_ vector2_ = defvalue;476 if (!ConvertValue(&this->value_.getVector2().x, tokens[0])) 477 { 478 this->value_.setValue(defvalue); 479 return false; 480 } 481 if (!ConvertValue(&this->value_.getVector2().y, tokens[1])) 482 { 483 this->value_.setValue(defvalue); 559 484 return false; 560 485 } … … 563 488 } 564 489 565 this->value_ vector2_ = defvalue;490 this->value_.setValue(defvalue); 566 491 return false; 567 492 } … … 573 498 @return True if the string was successfully parsed 574 499 */ 575 bool ConfigValueContainer::parseSt ing(const std::string& input, const Vector3& defvalue)500 bool ConfigValueContainer::parseString(const std::string& input, const Vector3& defvalue) 576 501 { 577 502 // Strip the value-string … … 583 508 { 584 509 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 585 if (!ConvertValue(&this->value_ vector3_.x, tokens[0]))586 { 587 this->value_ vector3_ = defvalue;588 return false; 589 } 590 if (!ConvertValue(&this->value_ vector3_.y, tokens[1]))591 { 592 this->value_ vector3_ = defvalue;593 return false; 594 } 595 if (!ConvertValue(&this->value_ vector3_.z, tokens[2]))596 { 597 this->value_ vector3_ = defvalue;510 if (!ConvertValue(&this->value_.getVector3().x, tokens[0])) 511 { 512 this->value_.setValue(defvalue); 513 return false; 514 } 515 if (!ConvertValue(&this->value_.getVector3().y, tokens[1])) 516 { 517 this->value_.setValue(defvalue); 518 return false; 519 } 520 if (!ConvertValue(&this->value_.getVector3().z, tokens[2])) 521 { 522 this->value_.setValue(defvalue); 598 523 return false; 599 524 } … … 602 527 } 603 528 604 this->value_ vector3_ = defvalue;529 this->value_.setValue(defvalue); 605 530 return false; 606 531 } … … 612 537 @return True if the string was successfully parsed 613 538 */ 614 bool ConfigValueContainer::parseSt ing(const std::string& input, const ColourValue& defvalue)539 bool ConfigValueContainer::parseString(const std::string& input, const ColourValue& defvalue) 615 540 { 616 541 // Strip the value-string … … 622 547 { 623 548 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 624 if (!ConvertValue(&this->value_ colourvalue_.r, tokens[0]))625 { 626 this->value_ colourvalue_ = defvalue;627 return false; 628 } 629 if (!ConvertValue(&this->value_ colourvalue_.g, tokens[1]))630 { 631 this->value_ colourvalue_ = defvalue;632 return false; 633 } 634 if (!ConvertValue(&this->value_ colourvalue_.b, tokens[2]))635 { 636 this->value_ colourvalue_ = defvalue;637 return false; 638 } 639 if (!ConvertValue(&this->value_ colourvalue_.a, tokens[3]))640 { 641 this->value_ colourvalue_ = defvalue;549 if (!ConvertValue(&this->value_.getColourValue().r, tokens[0])) 550 { 551 this->value_.setValue(defvalue); 552 return false; 553 } 554 if (!ConvertValue(&this->value_.getColourValue().g, tokens[1])) 555 { 556 this->value_.setValue(defvalue); 557 return false; 558 } 559 if (!ConvertValue(&this->value_.getColourValue().b, tokens[2])) 560 { 561 this->value_.setValue(defvalue); 562 return false; 563 } 564 if (!ConvertValue(&this->value_.getColourValue().a, tokens[3])) 565 { 566 this->value_.setValue(defvalue); 642 567 return false; 643 568 } … … 646 571 } 647 572 648 this->value_ colourvalue_ = defvalue;573 this->value_.setValue(defvalue); 649 574 return false; 575 } 576 577 /** 578 @brief Parses a given std::string into a value of the type Quaternion and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 579 @param input The string to convert 580 @param defvalue The default-value 581 @return True if the string was successfully parsed 582 */ 583 bool ConfigValueContainer::parseString(const std::string& input, const Quaternion& defvalue) 584 { 585 // Strip the value-string 586 unsigned int pos1 = input.find("(") + 1; 587 unsigned int pos2 = input.find(")", pos1); 588 589 // Try to convert the stripped value-string to Vector3 590 if (pos1 < input.length() && pos2 < input.length() && pos1 < pos2) 591 { 592 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 593 if (!ConvertValue(&this->value_.getQuaternion().w, tokens[0])) 594 { 595 this->value_.setValue(defvalue); 596 return false; 597 } 598 if (!ConvertValue(&this->value_.getQuaternion().x, tokens[1])) 599 { 600 this->value_.setValue(defvalue); 601 return false; 602 } 603 if (!ConvertValue(&this->value_.getQuaternion().y, tokens[2])) 604 { 605 this->value_.setValue(defvalue); 606 return false; 607 } 608 if (!ConvertValue(&this->value_.getQuaternion().z, tokens[3])) 609 { 610 this->value_.setValue(defvalue); 611 return false; 612 } 613 614 return true; 615 } 616 617 this->value_.setValue(defvalue); 618 return false; 619 } 620 621 /** 622 @brief Parses a given std::string into a value of the type long double and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 623 @param input The string to convert 624 @param defvalue The default-value 625 @return True if the string was successfully parsed 626 */ 627 bool ConfigValueContainer::parseString(const std::string& input, const Radian& defvalue) 628 { 629 return ConvertValue(&this->value_.getRadian(), input, defvalue); 630 } 631 632 /** 633 @brief Parses a given std::string into a value of the type long double and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 634 @param input The string to convert 635 @param defvalue The default-value 636 @return True if the string was successfully parsed 637 */ 638 bool ConfigValueContainer::parseString(const std::string& input, const Degree& defvalue) 639 { 640 return ConvertValue(&this->value_.getDegree(), input, defvalue); 650 641 } 651 642 … … 664 655 void ConfigValueContainer::resetConfigValue() 665 656 { 666 this->parseSt ing(this->defvalueString_);657 this->parseString(this->defvalueString_, this->value_); 667 658 this->resetConfigFileEntry(); 668 659 }
Note: See TracChangeset
for help on using the changeset viewer.