Changeset 792
- Timestamp:
- Feb 9, 2008, 7:32:06 PM (17 years ago)
- Location:
- code/branches/core/src
- Files:
-
- 13 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core/src/orxonox/core/CMakeLists.txt
r790 r792 13 13 OutputHandler.cc 14 14 Language.cc 15 Loader.cc 15 16 ) 16 17 -
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 } -
code/branches/core/src/orxonox/core/ConfigValueContainer.h
r790 r792 49 49 50 50 #include "util/Math.h" 51 #include "util/MultiTypeMath.h" 51 52 #include "Language.h" 52 53 … … 72 73 { 73 74 public: 74 enum VariableType 75 { 76 VT_Int, 77 VT_uInt, 78 VT_Char, 79 VT_uChar, 80 VT_Float, 81 VT_Double, 82 VT_LongDouble, 83 VT_Bool, 84 VT_ConstChar, 85 VT_String, 86 VT_Vector2, 87 VT_Vector3, 88 VT_ColourValue 89 }; 90 91 ConfigValueContainer(const std::string& classname, const std::string& varname, int defvalue); 92 ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned int defvalue); 93 ConfigValueContainer(const std::string& classname, const std::string& varname, char defvalue); 94 ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned char defvalue); 95 ConfigValueContainer(const std::string& classname, const std::string& varname, float defvalue); 96 ConfigValueContainer(const std::string& classname, const std::string& varname, double defvalue); 97 ConfigValueContainer(const std::string& classname, const std::string& varname, long double defvalue); 98 ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue); 99 ConfigValueContainer(const std::string& classname, const std::string& varname, const std::string& defvalue); 100 ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue); 101 ConfigValueContainer(const std::string& classname, const std::string& varname, Vector2 defvalue); 102 ConfigValueContainer(const std::string& classname, const std::string& varname, Vector3 defvalue); 103 ConfigValueContainer(const std::string& classname, const std::string& varname, ColourValue defvalue); 75 ConfigValueContainer(const std::string& classname, const std::string& varname, MultiTypeMath defvalue); 104 76 105 77 /** @returns the value. @param value This is only needed to determine the right type. */ 106 inline ConfigValueContainer& getValue(int& value) { value = this->value_.value_int_; return *this; } 107 /** @returns the value. @param value This is only needed to determine the right type. */ 108 inline ConfigValueContainer& getValue(unsigned int& value) { value = this->value_.value_uint_; return *this; } 109 /** @returns the value. @param value This is only needed to determine the right type. */ 110 inline ConfigValueContainer& getValue(char& value) { value = this->value_.value_char_; return *this; } 111 /** @returns the value. @param value This is only needed to determine the right type. */ 112 inline ConfigValueContainer& getValue(unsigned char& value) { value = this->value_.value_uchar_; return *this; } 113 /** @returns the value. @param value This is only needed to determine the right type. */ 114 inline ConfigValueContainer& getValue(float& value) { value = this->value_.value_float_; return *this; } 115 /** @returns the value. @param value This is only needed to determine the right type. */ 116 inline ConfigValueContainer& getValue(double& value) { value = this->value_.value_double_; return *this; } 117 /** @returns the value. @param value This is only needed to determine the right type. */ 118 inline ConfigValueContainer& getValue(long double& value) { value = this->value_.value_long_double_; return *this; } 119 /** @returns the value. @param value This is only needed to determine the right type. */ 120 inline ConfigValueContainer& getValue(bool& value) { value = this->value_.value_bool_; return *this; } 121 /** @returns the value. @param value This is only needed to determine the right type. */ 122 inline ConfigValueContainer& getValue(std::string& value) { value = this->value_string_; return *this; } 123 /** @returns the value. @param value This is only needed to determine the right type. */ 124 inline ConfigValueContainer& getValue(const char* value) { value = this->value_string_.c_str(); return *this; } 125 /** @returns the value. @param value This is only needed to determine the right type. */ 126 inline ConfigValueContainer& getValue(Vector2& value) { value = this->value_vector2_; return *this; } 127 /** @returns the value. @param value This is only needed to determine the right type. */ 128 inline ConfigValueContainer& getValue(Vector3& value) { value = this->value_vector3_; return *this; } 129 /** @returns the value. @param value This is only needed to determine the right type. */ 130 inline ConfigValueContainer& getValue(ColourValue& value) { value = this->value_colourvalue_; return *this; } 78 /* template <typename T> 79 inline ConfigValueContainer& getValue(T& value) { this->value_.getValue(value); return *this; } 80 */ 81 inline ConfigValueContainer& getValue(int* value) { ((MultiTypePrimitive)this->value_).getValue(value); return *this; } 82 inline ConfigValueContainer& getValue(unsigned int* value) { ((MultiTypePrimitive)this->value_).getValue(value); return *this; } 83 inline ConfigValueContainer& getValue(char* value) { ((MultiTypePrimitive)this->value_).getValue(value); return *this; } 84 inline ConfigValueContainer& getValue(unsigned char* value) { ((MultiTypePrimitive)this->value_).getValue(value); return *this; } 85 inline ConfigValueContainer& getValue(short* value) { ((MultiTypePrimitive)this->value_).getValue(value); return *this; } 86 inline ConfigValueContainer& getValue(unsigned short* value) { ((MultiTypePrimitive)this->value_).getValue(value); return *this; } 87 inline ConfigValueContainer& getValue(long* value) { ((MultiTypePrimitive)this->value_).getValue(value); return *this; } 88 inline ConfigValueContainer& getValue(unsigned long* value) { ((MultiTypePrimitive)this->value_).getValue(value); return *this; } 89 inline ConfigValueContainer& getValue(float* value) { ((MultiTypePrimitive)this->value_).getValue(value); return *this; } 90 inline ConfigValueContainer& getValue(double* value) { ((MultiTypePrimitive)this->value_).getValue(value); return *this; } 91 inline ConfigValueContainer& getValue(long double* value) { ((MultiTypePrimitive)this->value_).getValue(value); return *this; } 92 inline ConfigValueContainer& getValue(bool* value) { ((MultiTypePrimitive)this->value_).getValue(value); return *this; } 93 inline ConfigValueContainer& getValue(std::string* value) { ((MultiTypeString)this->value_).getValue(value); return *this; } 94 inline ConfigValueContainer& getValue(Vector2* value) { this->value_.getValue(value); return *this; } 95 inline ConfigValueContainer& getValue(Vector3* value) { this->value_.getValue(value); return *this; } 96 inline ConfigValueContainer& getValue(ColourValue* value) { this->value_.getValue(value); return *this; } 97 inline ConfigValueContainer& getValue(Quaternion* value) { this->value_.getValue(value); return *this; } 98 inline ConfigValueContainer& getValue(Radian* value) { this->value_.getValue(value); return *this; } 99 inline ConfigValueContainer& getValue(Degree* value) { this->value_.getValue(value); return *this; } 131 100 132 101 void description(const std::string& description); 133 102 134 bool parseSting(const std::string& input); 103 bool parseString(const std::string& input, MultiTypeMath& defvalue = MT_null); 104 bool valueToString(std::string* output, MultiTypeMath& input); 135 105 void resetConfigFileEntry(); 136 106 void resetConfigValue(); … … 141 111 142 112 private: 143 bool parseSting(const std::string& input, int defvalue); 144 bool parseSting(const std::string& input, unsigned int defvalue); 145 bool parseSting(const std::string& input, char defvalue); 146 bool parseSting(const std::string& input, unsigned char defvalue); 147 bool parseSting(const std::string& input, float defvalue); 148 bool parseSting(const std::string& input, double defvalue); 149 bool parseSting(const std::string& input, long double defvalue); 150 bool parseSting(const std::string& input, bool defvalue); 151 bool parseSting(const std::string& input, const std::string& defvalue); 152 bool parseSting(const std::string& input, const char* defvalue); 153 bool parseSting(const std::string& input, const Vector2& defvalue); 154 bool parseSting(const std::string& input, const Vector3& defvalue); 155 bool parseSting(const std::string& input, const ColourValue& defvalue); 113 bool parseString(const std::string& input, int defvalue); 114 bool parseString(const std::string& input, unsigned int defvalue); 115 bool parseString(const std::string& input, char defvalue); 116 bool parseString(const std::string& input, unsigned char defvalue); 117 bool parseString(const std::string& input, short defvalue); 118 bool parseString(const std::string& input, unsigned short defvalue); 119 bool parseString(const std::string& input, long defvalue); 120 bool parseString(const std::string& input, unsigned long defvalue); 121 bool parseString(const std::string& input, float defvalue); 122 bool parseString(const std::string& input, double defvalue); 123 bool parseString(const std::string& input, long double defvalue); 124 bool parseString(const std::string& input, bool defvalue); 125 bool parseString(const std::string& input, const std::string& defvalue); 126 bool parseString(const std::string& input, const char* defvalue); 127 bool parseString(const std::string& input, const Vector2& defvalue); 128 bool parseString(const std::string& input, const Vector3& defvalue); 129 bool parseString(const std::string& input, const ColourValue& defvalue); 130 bool parseString(const std::string& input, const Quaternion& defvalue); 131 bool parseString(const std::string& input, const Radian& defvalue); 132 bool parseString(const std::string& input, const Degree& defvalue); 156 133 157 134 static std::list<std::string>& getConfigFileLines(); … … 167 144 std::string defvalueString_; //!< The string of the default-variable 168 145 169 union MultiType 170 { 171 int value_int_; //!< The value, if the variable is of the type int 172 unsigned int value_uint_; //!< The value, if the variable is of the type unsigned int 173 char value_char_; //!< The value, if the variable is of the type char 174 unsigned char value_uchar_; //!< The value, if the variable is of the type unsigned char 175 float value_float_; //!< The value, if the variable is of the type float 176 double value_double_; //!< The value, if the variable is of the type double 177 long double value_long_double_; //!< The value, if the variable is of the type long double 178 bool value_bool_; //!< The value, if the variable is of the type bool 179 } value_; //!< The value of the variable 180 181 std::string value_string_; //!< The value, if the variable is of the type string 182 Vector2 value_vector2_; //!< The value, if the variable is of the type Vector2 183 Vector3 value_vector3_; //!< The value, if the variable is of the type Vector3 184 ColourValue value_colourvalue_; //!< The value, if the variable is of the type ColourValue 146 MultiTypeMath value_; //!< The value 185 147 186 148 std::list<std::string>::iterator configFileLine_; //!< An iterator, pointing to the entry of the variable in the config-file 187 149 188 VariableType type_; //!< The type of the variable189 150 bool bAddedDescription_; //!< True if a description was added 190 151 LanguageEntryName description_; //!< The description -
code/branches/core/src/orxonox/core/CoreIncludes.h
r790 r792 139 139 this->getIdentifier()->setConfigValueContainer(#varname, container##varname); \ 140 140 } \ 141 container##varname->getValue( varname)141 container##varname->getValue(&varname) 142 142 143 143 /** … … 150 150 { \ 151 151 container##varname##reset->resetConfigValue(); \ 152 container##varname##reset->getValue( varname); \152 container##varname##reset->getValue(&varname); \ 153 153 } \ 154 154 else \ -
code/branches/core/src/orxonox/core/CorePrereqs.h
r790 r792 27 27 28 28 /** 29 @file OrxonoxPrereq.h29 @file CorePrereq.h 30 30 @brief Contains all the necessary forward declarations for all classes, structs and enums. 31 31 */ -
code/branches/core/src/orxonox/core/OrxonoxClass.h
r790 r792 47 47 //! The class all objects and interfaces of the game-logic (not the engine) are derived from. 48 48 /** 49 The BaseObject and Inter aces are derived with 'virtual public OrxonoxClass' from OrxonoxClass.49 The BaseObject and Interfaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass. 50 50 OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList. 51 51 */ -
code/branches/core/src/util/CMakeLists.txt
r790 r792 5 5 SET (UTIL_SRC_FILES 6 6 ${TINYXML_SRC_FILES} 7 Math.cc 8 String.cc 7 9 substring.cc 10 MultiTypePrimitive.cc 11 MultiTypeString.cc 12 MultiTypeMath.cc 8 13 ) 9 14 10 IF(WIN32) 11 ADD_LIBRARY( util ${UTIL_SRC_FILES} ) 12 ELSE(WIN32) 13 ADD_LIBRARY( util SHARED ${UTIL_SRC_FILES} ) 14 ENDIF(WIN32) 15 ADD_LIBRARY( util SHARED ${UTIL_SRC_FILES} ) 15 16 SET_TARGET_PROPERTIES( util PROPERTIES LINK_FLAGS "--no-undefined" ) 16 17 17 18 18 IF(TESTING_ENABLED) 19 19 ADD_SUBDIRECTORY(testing) 20 20 ENDIF(TESTING_ENABLED) 21 22 TARGET_LINK_LIBRARIES( util 23 ${OGRE_LIBRARIES} 24 ) -
code/branches/core/src/util/Convert.h
r790 r792 36 36 #include <sstream> 37 37 38 #include "UtilPrereqs.h" 38 39 39 40 // DEFAULT CLASS 40 41 template <typename FromType, typename ToType> 41 class Converter42 class _UtilExport Converter 42 43 { 43 44 public: … … 50 51 // PARTIAL SPECIALIZATION TO CONVERT TO STRINGS 51 52 template<typename FromType> 52 class Converter<FromType, std::string>53 class _UtilExport Converter<FromType, std::string> 53 54 { 54 55 public: … … 68 69 // PARTIAL SPECIALIZATION TO CONVERT FROM STRING 69 70 template<typename ToType> 70 class Converter<std::string, ToType>71 class _UtilExport Converter<std::string, ToType> 71 72 { 72 73 public: … … 83 84 // FUNCTION SO WE DO NOT HAVE TO TELL THE COMPILER ABOUT THE TYPE 84 85 template<typename FromType, typename ToType> 85 static bool ConvertValue(ToType* output, const FromType& input)86 static _UtilExport bool ConvertValue(ToType* output, const FromType& input) 86 87 { 87 88 Converter<FromType, ToType> converter; … … 91 92 // THE SAME, BUT WITH DEFAULT VALUE 92 93 template<typename FromType, typename ToType> 93 static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback)94 static _UtilExport bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback) 94 95 { 95 96 Converter<FromType, ToType> converter; -
code/branches/core/src/util/Math.h
r790 r792 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 #ifndef _Math_H__ 29 #define _Math_H__ 30 31 #include <ostream> 32 33 #include "UtilPrereqs.h" 34 1 35 #include <OgreMath.h> 2 36 #include <OgreVector2.h> … … 18 52 typedef Ogre::ColourValue ColourValue; 19 53 } 54 55 _UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Radian& radian); 56 _UtilExport std::istream& operator>>(std::istream& in, orxonox::Radian& radian); 57 _UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree); 58 _UtilExport std::istream& operator>>(std::istream& in, orxonox::Degree& degree); 59 60 template <typename T> 61 inline _UtilExport T sgn(T x) 62 { 63 return (x >= 0) ? 1 : -1; 64 } 65 66 template <typename T> 67 inline _UtilExport T min(T a, T b) 68 { 69 return (a <= b) ? a : b; 70 } 71 72 template <typename T> 73 inline _UtilExport T max(T a, T b) 74 { 75 return (a >= b) ? a : b; 76 } 77 78 template <typename T> 79 inline _UtilExport T clamp(T x, T min, T max) 80 { 81 if (x < min) 82 return min; 83 84 if (x > max) 85 return max; 86 87 return x; 88 } 89 90 template <typename T> 91 inline _UtilExport T square(T x) 92 { 93 return x*x; 94 } 95 96 template <typename T> 97 inline _UtilExport T cube(T x) 98 { 99 return x*x*x; 100 } 101 102 template <typename T> 103 inline _UtilExport int floor(T x) 104 { 105 return (int)(x); 106 } 107 108 template <typename T> 109 inline _UtilExport int ceil(T x) 110 { 111 int temp = floor(x); 112 return (temp != x) ? (temp + 1) : temp; 113 } 114 115 template <typename T> 116 inline _UtilExport int round(T x) 117 { 118 return (int)(x + 0.5); 119 } 120 121 template <typename T> 122 _UtilExport T interpolate(float time, const T& start, const T& end) 123 { 124 return time * (end - start) + start; 125 } 126 127 template <typename T> 128 _UtilExport T interpolateSmooth(float time, const T& start, const T& end) 129 { 130 return (-2 * (end - start) * cube(time)) + (3 * (end - start) * square(time)) + start; 131 } 132 133 inline _UtilExport float rnd() 134 { 135 return ((float)rand() / RAND_MAX); 136 } 137 138 inline _UtilExport float rnd(float max) 139 { 140 return rnd() * max; 141 } 142 143 inline _UtilExport float rnd(float min, float max) 144 { 145 return rnd(max - min) + min; 146 } 147 148 #endif /* _Math_H__ */ -
code/branches/core/src/util/String2Number.h
r790 r792 7 7 8 8 #include "core/Debug.h" 9 #include "UtilPrereqs.h" 9 10 10 11 /** … … 23 24 24 25 template <class T> 25 class String2Number26 class _UtilExport String2Number 26 27 { 27 28 private: -
code/branches/core/src/util/substring.h
r790 r792 59 59 #include <string> 60 60 61 #include "UtilPrereqs.h" 61 62 62 63 //! A class that can load one string and split it in multipe ones … … 65 66 * It can be used, to Split strings append them and join them again. 66 67 */ 67 class SubString68 class _UtilExport SubString 68 69 { 69 70 public:
Note: See TracChangeset
for help on using the changeset viewer.