Changeset 667 for code/branches/FICN/src/orxonox
- Timestamp:
- Dec 22, 2007, 2:13:18 AM (17 years ago)
- Location:
- code/branches/FICN/src/orxonox
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/orxonox/Orxonox.cc
r665 r667 198 198 ogre_->startRender(); 199 199 //TODO: run engine 200 Factory::createClassHierarchy(); 200 201 createScene(); 201 202 setupScene(); … … 206 207 std::cout << "client here" << std::endl; 207 208 createFrameListener(); 208 Factory::createClassHierarchy();209 209 switch(mode_){ 210 210 case PRESENTATION: -
code/branches/FICN/src/orxonox/core/ConfigValueContainer.cc
r663 r667 27 27 28 28 #include <fstream> 29 // #include <string>30 29 #include "ConfigValueContainer.h" 31 32 //#define CONFIGFILEPATH "O:\\oh\\bin\\orxonox.ini" 30 #include "../../misc/Tokenizer.h" 31 #include "../../misc/String2Number.h" 32 33 33 #define CONFIGFILEPATH "orxonox.ini" 34 34 … … 39 39 40 40 /** 41 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_.value_int_. 41 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 42 @param value This is only needed to determine the right type. 42 43 @param classname The name of the class the variable belongs to 43 44 @param varname The name of the variable … … 46 47 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, int defvalue) 47 48 { 48 // Try to convert the default-value from int to string 49 std::ostringstream ostream; 50 if (ostream << defvalue) 51 this->defvalue_ = ostream.str(); 52 else 53 this->defvalue_ = "0"; 54 55 // Set the default values, then get the value-string 56 this->setDefaultValues(classname, varname); 57 std::string valueString = this->getValueString(); 58 59 // Try to convert the value-string to int 60 std::istringstream istream(valueString); 61 if (!(istream >> this->value_.value_int_)) 62 { 63 // The conversion failed - use the default value and restore the entry in the config-file 64 this->value_.value_int_ = defvalue; 65 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 66 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 67 } 68 } 69 70 /** 71 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_.value_double_. 49 this->classname_ = classname; 50 this->varname_ = varname; 51 this->type_ = Int; 52 53 this->defvalueString_ = number2String(defvalue, "0"); // Try to convert the default-value to a string 54 this->searchConfigFileLine(); // Search the entry in the config-file 55 56 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 57 if (!string2Number(this->value_.value_int_, valueString, defvalue)) // Try to convert the string to a value 58 this->setConfigFileEntyToDefault(); // The conversion failed 59 60 std::cout << "CVC: int: " << this->value_.value_int_ << std::endl; 61 } 62 63 /** 64 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 65 @param value This is only needed to determine the right type. 66 @param classname The name of the class the variable belongs to 67 @param varname The name of the variable 68 @param defvalue The default-value 69 */ 70 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned int defvalue) 71 { 72 this->classname_ = classname; 73 this->varname_ = varname; 74 this->type_ = uInt; 75 76 this->defvalueString_ = number2String(defvalue, "0"); // Try to convert the default-value to a string 77 this->searchConfigFileLine(); // Search the entry in the config-file 78 79 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 80 if (!string2Number(this->value_.value_uint_, valueString, defvalue)) // Try to convert the string to a value 81 this->setConfigFileEntyToDefault(); // The conversion failed 82 83 std::cout << "CVC: uint: " << this->value_.value_uint_ << std::endl; 84 } 85 86 /** 87 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 88 @param value This is only needed to determine the right type. 89 @param classname The name of the class the variable belongs to 90 @param varname The name of the variable 91 @param defvalue The default-value 92 */ 93 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, char defvalue) 94 { 95 this->classname_ = classname; 96 this->varname_ = varname; 97 this->type_ = Char; 98 99 this->defvalueString_ = number2String((int)defvalue, "0"); // Try to convert the default-value to a string 100 this->searchConfigFileLine(); // Search the entry in the config-file 101 102 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 103 // I used value_int_ instead of value_char_ to avoid number <-> char confusion in the config-file 104 if (!string2Number(this->value_.value_int_, valueString, (int)defvalue))// Try to convert the string to a value 105 this->setConfigFileEntyToDefault(); // The conversion failed 106 } 107 108 /** 109 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 110 @param value This is only needed to determine the right type. 111 @param classname The name of the class the variable belongs to 112 @param varname The name of the variable 113 @param defvalue The default-value 114 */ 115 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned char defvalue) 116 { 117 this->classname_ = classname; 118 this->varname_ = varname; 119 this->type_ = uChar; 120 121 this->defvalueString_ = number2String((unsigned int)defvalue, "0"); // Try to convert the default-value to a string 122 this->searchConfigFileLine(); // Search the entry in the config-file 123 124 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 125 // I used value_uint_ instead of value_uchar_ to avoid number <-> char confusion in the config-file 126 if (!string2Number(this->value_.value_uint_, valueString, (unsigned int)defvalue)) // Try to convert the string to a value 127 this->setConfigFileEntyToDefault(); // The conversion failed 128 } 129 130 /** 131 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 132 @param value This is only needed to determine the right type. 133 @param classname The name of the class the variable belongs to 134 @param varname The name of the variable 135 @param defvalue The default-value 136 */ 137 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, float defvalue) 138 { 139 this->classname_ = classname; 140 this->varname_ = varname; 141 this->type_ = Float; 142 143 this->defvalueString_ = number2String(defvalue, "0.000000"); // Try to convert the default-value to a string 144 this->searchConfigFileLine(); // Search the entry in the config-file 145 146 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 147 if (!string2Number(this->value_.value_float_, valueString, defvalue)) // Try to convert the string to a value 148 this->setConfigFileEntyToDefault(); // The conversion failed 149 } 150 151 /** 152 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 153 @param value This is only needed to determine the right type. 72 154 @param classname The name of the class the variable belongs to 73 155 @param varname The name of the variable … … 76 158 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, double defvalue) 77 159 { 78 // Try to convert the default-value from double to string 79 std::ostringstream ostream; 80 if (ostream << defvalue) 81 this->defvalue_ = ostream.str(); 82 else 83 this->defvalue_ = "0.000000"; 84 85 // Set the default values, then get the value-string 86 this->setDefaultValues(classname, varname); 87 std::string valueString = this->getValueString(); 88 89 // Try to convert the value-string to double 90 std::istringstream istream(valueString); 91 if (!(istream >> this->value_.value_double_)) 92 { 93 // The conversion failed - use the default value and restore the entry in the config-file 94 this->value_.value_double_ = defvalue; 95 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 96 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 97 } 98 } 99 100 /** 101 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_.value_bool_. 160 this->classname_ = classname; 161 this->varname_ = varname; 162 this->type_ = Double; 163 164 this->defvalueString_ = number2String(defvalue, "0.000000"); // Try to convert the default-value to a string 165 this->searchConfigFileLine(); // Search the entry in the config-file 166 167 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 168 if (!string2Number(this->value_.value_double_, valueString, defvalue)) // Try to convert the string to a value 169 this->setConfigFileEntyToDefault(); // The conversion failed 170 } 171 172 /** 173 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 174 @param value This is only needed to determine the right type. 102 175 @param classname The name of the class the variable belongs to 103 176 @param varname The name of the variable … … 106 179 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue) 107 180 { 181 this->classname_ = classname; 182 this->varname_ = varname; 183 this->type_ = Bool; 184 108 185 // Convert the default-value from bool to string 109 186 if (defvalue) 110 this->defvalue _ = "true";111 else 112 this->defvalue _ = "false";113 114 // Set the default values, then get the value-string115 this->setDefaultValues(classname, varname); 116 std::string valueString = this-> getValueString();187 this->defvalueString_ = "true"; 188 else 189 this->defvalueString_ = "false"; 190 191 this->searchConfigFileLine(); // Search the entry in the config-file 192 193 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 117 194 118 195 // Try to parse the value-string - is it a word? 119 if (valueString.find("true") < valueString.size() || valueString.find("yes") < valueString.size()) 196 if (valueString.find("true") < valueString.size() 197 || valueString.find("True") < valueString.size() 198 || valueString.find("yes") < valueString.size() 199 || valueString.find("Yes") < valueString.size()) 120 200 this->value_.value_bool_ = true; 121 else if (valueString.find("false") < valueString.size() || valueString.find("no") < valueString.size()) 201 else if (valueString.find("false") < valueString.size() 202 || valueString.find("False") < valueString.size() 203 || valueString.find("no") < valueString.size() 204 || valueString.find("No") < valueString.size()) 122 205 this->value_.value_bool_ = false; 123 206 else 124 207 { 125 208 // Its not a known word - is it a number? 126 std::istringstream istream(valueString); 127 if (!(istream >> this->value_.value_bool_)) 128 { 129 // The conversion failed - use the default value and restore the entry in the config-file 130 this->value_.value_bool_ = defvalue; 131 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 132 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 133 } 134 } 135 } 136 137 /** 138 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_string_. 139 @param classname The name of the class the variable belongs to 140 @param varname The name of the variable 141 @param defvalue The default-value 142 */ 143 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue) 144 { 145 // Convert the string to a "config-file-string" with quotes 146 this->defvalue_ = "\"" + std::string(defvalue) + "\""; 147 148 // Set the default-values, then get the value-string 149 this->setDefaultValues(classname, varname); 150 std::string valueString = this->getValueString(false); 209 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 210 if (!string2Number(this->value_.value_bool_, valueString, defvalue)) // Try to convert the string to a value 211 this->setConfigFileEntyToDefault(); // The conversion failed 212 } 213 } 214 215 /** 216 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 217 @param value This is only needed to determine the right type. 218 @param classname The name of the class the variable belongs to 219 @param varname The name of the variable 220 @param defvalue The default-value 221 */ 222 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, const std::string& defvalue) 223 { 224 this->classname_ = classname; 225 this->varname_ = varname; 226 this->type_ = String; 227 228 this->defvalueString_ = "\"" + defvalue + "\""; // Convert the string to a "config-file-string" with quotes 229 230 this->searchConfigFileLine(); // Search the entry in the config-file 231 std::string valueString = this->parseValueString(false); // Parses the value string from the config-file-entry 151 232 152 233 // Strip the quotes … … 165 246 // It wasn't - use the default-value and restore the entry in the config-file. 166 247 this->value_string_ = defvalue; 167 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 168 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 169 } 170 } 171 172 /** 173 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_vector2_. 248 this->setConfigFileEntyToDefault(); 249 } 250 } 251 252 /** 253 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 254 @param value This is only needed to determine the right type. 255 @param classname The name of the class the variable belongs to 256 @param varname The name of the variable 257 @param defvalue The default-value 258 */ 259 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue) 260 { 261 this->classname_ = classname; 262 this->varname_ = varname; 263 this->type_ = ConstChar; 264 265 this->defvalueString_ = "\"" + std::string(defvalue) + "\""; // Convert the string to a "config-file-string" with quotes 266 267 this->searchConfigFileLine(); // Search the entry in the config-file 268 std::string valueString = this->parseValueString(false); // Parses the value string from the config-file-entry 269 270 // Strip the quotes 271 unsigned int pos1 = valueString.find("\"") + 1; 272 unsigned int pos2 = valueString.find("\"", pos1); 273 274 // Check if the entry was correctly quoted 275 if (pos1 < valueString.length() && pos2 < valueString.length() && !(valueString.find("\"", pos2 + 1) < valueString.length())) 276 { 277 // It was - get the string between the quotes 278 valueString = valueString.substr(pos1, pos2 - pos1); 279 this->value_string_ = valueString; 280 } 281 else 282 { 283 // It wasn't - use the default-value and restore the entry in the config-file. 284 this->value_string_ = defvalue; 285 this->setConfigFileEntyToDefault(); 286 } 287 } 288 289 /** 290 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 291 @param value This is only needed to determine the right type. 174 292 @param classname The name of the class the variable belongs to 175 293 @param varname The name of the variable … … 178 296 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector2 defvalue) 179 297 { 298 this->classname_ = classname; 299 this->varname_ = varname; 300 this->type_ = Vector2; 301 180 302 // Try to convert the default-value from Vector2 to string 181 303 std::ostringstream ostream; 182 304 if (ostream << "(" << defvalue.x << "," << defvalue.y << ")") 183 this->defvalue_ = ostream.str(); 184 else 185 this->defvalue_ = "(0,0)"; 186 187 // Set the default values, then get the value-string 188 this->setDefaultValues(classname, varname); 189 std::string valueString = this->getValueString(); 305 this->defvalueString_ = ostream.str(); 306 else 307 this->defvalueString_ = "(0,0)"; 308 309 this->searchConfigFileLine(); // Search the entry in the config-file 310 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 190 311 191 312 // Strip the value-string 192 bool bEntryIsCorrupt = false; 193 valueString = this->getStrippedLine(valueString); 194 unsigned int pos1, pos2, pos3; 195 pos1 = valueString.find("("); 196 if (pos1 == 0) 197 valueString.erase(pos1, 1); 198 else 199 bEntryIsCorrupt = true; 200 201 pos2 = valueString.find(")"); 202 if (pos2 == valueString.length() - 1) 203 valueString.erase(pos2, 1); 204 else 205 bEntryIsCorrupt = true; 206 207 int count = 0; 208 while ((pos3 = valueString.find(",")) < valueString.length()) 209 { 210 count++; 211 valueString.replace(pos3, 1, " "); 212 if (pos3 < pos1) 213 bEntryIsCorrupt = true; 214 } 215 216 if (count != 1) 217 bEntryIsCorrupt = true; 313 unsigned int pos1 = valueString.find("(") + 1; 314 unsigned int pos2 = valueString.find(")", pos1); 218 315 219 316 // Try to convert the stripped value-string to Vector2 220 if (!bEntryIsCorrupt) 221 { 222 std::istringstream istream(valueString); 223 if (!(istream >> this->value_vector2_.x)) 224 { 225 // The conversion failed - use the default value and restore the entry in the config-file 226 this->value_vector2_.x = defvalue.x; 227 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 228 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 229 } 230 if (!(istream >> this->value_vector2_.y)) 231 { 232 // The conversion failed - use the default value and restore the entry in the config-file 233 this->value_vector2_.y = defvalue.y; 234 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 235 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 236 } 237 } 238 else 239 { 240 // The conversion failed - use the default value and restore the entry in the config-file 317 if (pos1 < valueString.length() && pos2 < valueString.length() && pos1 < pos2) 318 { 319 valueString = valueString.substr(pos1, pos2 - pos1); 320 std::vector<std::string> tokens = tokenize(valueString, ","); 321 if (!string2Number(this->value_vector2_.x, tokens[0], defvalue.x)) 322 this->setConfigFileEntyToDefault(); 323 if (!string2Number(this->value_vector2_.y, tokens[1], defvalue.y)) 324 this->setConfigFileEntyToDefault(); 325 } 326 else 327 { 241 328 this->value_vector2_ = defvalue; 242 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;243 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);244 245 } 246 247 /**248 @ brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_vector3_.329 this->setConfigFileEntyToDefault(); 330 } 331 } 332 333 /** 334 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 335 @param value This is only needed to determine the right type. 249 336 @param classname The name of the class the variable belongs to 250 337 @param varname The name of the variable … … 253 340 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector3 defvalue) 254 341 { 342 this->classname_ = classname; 343 this->varname_ = varname; 344 this->type_ = Vector3; 345 255 346 // Try to convert the default-value from Vector3 to string 256 347 std::ostringstream ostream; 257 348 if (ostream << "(" << defvalue.x << "," << defvalue.y << "," << defvalue.z << ")") 258 this->defvalue_ = ostream.str(); 259 else 260 this->defvalue_ = "(0,0,0)"; 261 262 // Set the default values, then get the value-string 263 this->setDefaultValues(classname, varname); 264 std::string valueString = this->getValueString(); 349 this->defvalueString_ = ostream.str(); 350 else 351 this->defvalueString_ = "(0,0,0)"; 352 353 this->searchConfigFileLine(); // Search the entry in the config-file 354 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 265 355 266 356 // Strip the value-string 267 bool bEntryIsCorrupt = false; 268 valueString = this->getStrippedLine(valueString); 269 unsigned int pos1, pos2, pos3; 270 pos1 = valueString.find("("); 271 if (pos1 == 0) 272 valueString.erase(pos1, 1); 273 else 274 bEntryIsCorrupt = true; 275 276 pos2 = valueString.find(")"); 277 if (pos2 == valueString.length() - 1) 278 valueString.erase(pos2, 1); 279 else 280 bEntryIsCorrupt = true; 281 282 int count = 0; 283 while ((pos3 = valueString.find(",")) < valueString.length()) 284 { 285 count++; 286 valueString.replace(pos3, 1, " "); 287 if (pos3 < pos1) 288 bEntryIsCorrupt = true; 289 } 290 291 if (count != 2) 292 bEntryIsCorrupt = true; 357 unsigned int pos1 = valueString.find("(") + 1; 358 unsigned int pos2 = valueString.find(")", pos1); 293 359 294 360 // Try to convert the stripped value-string to Vector3 295 if (!bEntryIsCorrupt) 296 { 297 std::istringstream istream(valueString); 298 if (!(istream >> this->value_vector3_.x)) 299 { 300 // The conversion failed - use the default value and restore the entry in the config-file 301 this->value_vector3_.x = defvalue.x; 302 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 303 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 304 } 305 if (!(istream >> this->value_vector3_.y)) 306 { 307 // The conversion failed - use the default value and restore the entry in the config-file 308 this->value_vector3_.y = defvalue.y; 309 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 310 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 311 } 312 if (!(istream >> this->value_vector3_.z)) 313 { 314 // The conversion failed - use the default value and restore the entry in the config-file 315 this->value_vector3_.z = defvalue.z; 316 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 317 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 318 } 319 } 320 else 321 { 322 // The conversion failed - use the default value and restore the entry in the config-file 361 if (pos1 < valueString.length() && pos2 < valueString.length() && pos1 < pos2) 362 { 363 valueString = valueString.substr(pos1, pos2 - pos1); 364 std::vector<std::string> tokens = tokenize(valueString, ","); 365 if (!string2Number(this->value_vector3_.x, tokens[0], defvalue.x)) 366 this->setConfigFileEntyToDefault(); 367 if (!string2Number(this->value_vector3_.y, tokens[1], defvalue.y)) 368 this->setConfigFileEntyToDefault(); 369 if (!string2Number(this->value_vector3_.z, tokens[2], defvalue.z)) 370 this->setConfigFileEntyToDefault(); 371 } 372 else 373 { 323 374 this->value_vector3_ = defvalue; 324 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;325 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);326 327 } 328 329 /**330 @ brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_colourvalue_.375 this->setConfigFileEntyToDefault(); 376 } 377 } 378 379 /** 380 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 381 @param value This is only needed to determine the right type. 331 382 @param classname The name of the class the variable belongs to 332 383 @param varname The name of the variable … … 335 386 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::ColourValue defvalue) 336 387 { 388 this->classname_ = classname; 389 this->varname_ = varname; 390 this->type_ = ColourValue; 391 337 392 // Try to convert the default-value from ColourValue to string 338 393 std::ostringstream ostream; 339 394 if (ostream << "(" << defvalue.r << "," << defvalue.g << "," << defvalue.b << "," << defvalue.a << ")") 340 this->defvalue_ = ostream.str(); 341 else 342 this->defvalue_ = "(0,0,0,0)"; 343 344 // Set the default values, then get the value-string 345 this->setDefaultValues(classname, varname); 346 std::string valueString = this->getValueString(); 395 this->defvalueString_ = ostream.str(); 396 else 397 this->defvalueString_ = "(0,0,0,0)"; 398 399 this->searchConfigFileLine(); // Search the entry in the config-file 400 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 347 401 348 402 // Strip the value-string 349 bool bEntryIsCorrupt = false; 350 valueString = this->getStrippedLine(valueString); 351 unsigned int pos1, pos2, pos3; 352 pos1 = valueString.find("("); 353 if (pos1 == 0) 354 valueString.erase(pos1, 1); 355 else 356 bEntryIsCorrupt = true; 357 358 pos2 = valueString.find(")"); 359 if (pos2 == valueString.length() - 1) 360 valueString.erase(pos2, 1); 361 else 362 bEntryIsCorrupt = true; 363 364 int count = 0; 365 while ((pos3 = valueString.find(",")) < valueString.length()) 366 { 367 count++; 368 valueString.replace(pos3, 1, " "); 369 if (pos3 < pos1) 370 bEntryIsCorrupt = true; 371 } 372 373 if (count != 3) 374 bEntryIsCorrupt = true; 403 unsigned int pos1 = valueString.find("(") + 1; 404 unsigned int pos2 = valueString.find(")", pos1); 375 405 376 406 // Try to convert the stripped value-string to Vector3 377 if (!bEntryIsCorrupt) 378 { 379 std::istringstream istream(valueString); 380 if (!(istream >> this->value_colourvalue_.r)) 381 { 382 // The conversion failed - use the default value and restore the entry in the config-file 383 this->value_colourvalue_.r = defvalue.r; 384 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 385 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 386 } 387 if (!(istream >> this->value_colourvalue_.g)) 388 { 389 // The conversion failed - use the default value and restore the entry in the config-file 390 this->value_colourvalue_.g = defvalue.g; 391 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 392 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 393 } 394 if (!(istream >> this->value_colourvalue_.b)) 395 { 396 // The conversion failed - use the default value and restore the entry in the config-file 397 this->value_colourvalue_.b = defvalue.b; 398 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 399 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 400 } 401 if (!(istream >> this->value_colourvalue_.a)) 402 { 403 // The conversion failed - use the default value and restore the entry in the config-file 404 this->value_colourvalue_.a = defvalue.a; 405 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 406 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 407 } 408 } 409 else 410 { 411 // The conversion failed - use the default value and restore the entry in the config-file 407 if (pos1 < valueString.length() && pos2 < valueString.length() && pos1 < pos2) 408 { 409 valueString = valueString.substr(pos1, pos2 - pos1); 410 std::vector<std::string> tokens = tokenize(valueString, ","); 411 if (!string2Number(this->value_colourvalue_.r, tokens[0], defvalue.r)) 412 this->setConfigFileEntyToDefault(); 413 if (!string2Number(this->value_colourvalue_.g, tokens[1], defvalue.g)) 414 this->setConfigFileEntyToDefault(); 415 if (!string2Number(this->value_colourvalue_.b, tokens[2], defvalue.b)) 416 this->setConfigFileEntyToDefault(); 417 if (!string2Number(this->value_colourvalue_.a, tokens[3], defvalue.a)) 418 this->setConfigFileEntyToDefault(); 419 } 420 else 421 { 412 422 this->value_colourvalue_ = defvalue; 413 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 414 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 415 } 416 } 417 418 /** 419 @brief Sets the default values of the container and searches the coresponding entry in the config-file. 420 @param classname The name of the class the variable belongs to 421 @param varname The name of the variable 422 */ 423 void ConfigValueContainer::setDefaultValues(const std::string& classname, const std::string& varname) 424 { 425 // Set the class and variable names 426 this->classname_ = classname; 427 this->varname_ = varname; 428 429 // Search the entry in the config-file 430 this->searchConfigFileLine(); 431 432 // Set the values of all types to zero 433 this->value_.value_int_ = 0; 434 this->value_.value_double_ = 0.000000; 435 this->value_.value_bool_ = false; 436 this->value_string_ = ""; 437 this->value_vector2_ = Ogre::Vector2(0, 0); 438 this->value_vector3_ = Ogre::Vector3(0, 0, 0); 439 this->value_colourvalue_ = Ogre::ColourValue(0, 0, 0, 0); 440 } 423 this->setConfigFileEntyToDefault(); 424 } 425 } 426 427 /** 428 @brief Sets the corresponding enty in the config-file back to the default value. 429 */ 430 void ConfigValueContainer::setConfigFileEntyToDefault() 431 { 432 (*this->configFileLine_) = this->varname_ + "=" + this->defvalueString_; 433 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 434 } 435 441 436 442 437 /** … … 503 498 { 504 499 // The next section startet, so our line isn't yet in the file - now we add it and safe the file 505 this->configFileLine_ = this->configFileLines_s->insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalue _);500 this->configFileLine_ = this->configFileLines_s->insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalueString_); 506 501 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 507 502 success = true; … … 523 518 { 524 519 // Looks like we found the right section, but the file ended without containing our variable - so we add it and safe the file 525 this->configFileLine_ = this->configFileLines_s->insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalue _);520 this->configFileLine_ = this->configFileLines_s->insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalueString_); 526 521 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 527 522 success = true; … … 535 530 { 536 531 // We obviously didn't found the right section, so we'll create it 537 this->configFileLines_s->push_back("[" + this->classname_ + "]"); // Create the section538 this->configFileLines_s->push_back(this->varname_ + "=" + this->defvalue _);// Create the line539 this->configFileLine_ = --this->configFileLines_s->end(); // Set the pointer to the last element532 this->configFileLines_s->push_back("[" + this->classname_ + "]"); // Create the section 533 this->configFileLines_s->push_back(this->varname_ + "=" + this->defvalueString_); // Create the line 534 this->configFileLine_ = --this->configFileLines_s->end(); // Set the pointer to the last element 540 535 success = true; 541 this->configFileLines_s->push_back(""); // Add an empty line - this is needed for the algorithm in the searchConfigFileLine-function542 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); // Save the changed config-file536 this->configFileLines_s->push_back(""); // Add an empty line - this is needed for the algorithm in the searchConfigFileLine-function 537 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); // Save the changed config-file 543 538 } 544 539 } … … 597 592 @return The value-string 598 593 */ 599 std::string ConfigValueContainer:: getValueString(bool bStripped)594 std::string ConfigValueContainer::parseValueString(bool bStripped) 600 595 { 601 596 std::string output; -
code/branches/FICN/src/orxonox/core/ConfigValueContainer.h
r663 r667 45 45 public: 46 46 ConfigValueContainer(const std::string& classname, const std::string& varname, int defvalue); 47 ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned int defvalue); 48 ConfigValueContainer(const std::string& classname, const std::string& varname, char defvalue); 49 ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned char defvalue); 50 ConfigValueContainer(const std::string& classname, const std::string& varname, float defvalue); 47 51 ConfigValueContainer(const std::string& classname, const std::string& varname, double defvalue); 48 52 ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue); 53 ConfigValueContainer(const std::string& classname, const std::string& varname, const std::string& defvalue); 49 54 ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue); 50 55 ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector2 defvalue); … … 52 57 ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::ColourValue defvalue); 53 58 54 void set DefaultValues(const std::string& classname, const std::string& varname);59 void setConfigFileEntyToDefault(); 55 60 void searchConfigFileLine(); 56 std::string getValueString(bool bStripped = true);61 std::string parseValueString(bool bStripped = true); 57 62 58 63 static std::string getStrippedLine(const std::string& line); … … 62 67 static void writeConfigFile(const std::string& filename); 63 68 64 /** @returns the value of the type int. @param value This is only needed to determine the right type. */69 /** @returns the value. @param value This is only needed to determine the right type. */ 65 70 inline int getValue(int value) { return this->value_.value_int_; } 66 /** @returns the value of the type double. @param value This is only needed to determine the right type. */ 71 /** @returns the value. @param value This is only needed to determine the right type. */ 72 inline unsigned int getValue(unsigned int value) { return this->value_.value_uint_; } 73 /** @returns the value. @param value This is only needed to determine the right type. */ 74 inline char getValue(char value) { return this->value_.value_char_; } 75 /** @returns the value. @param value This is only needed to determine the right type. */ 76 inline unsigned char getValue(unsigned char value) { return this->value_.value_uchar_; } 77 /** @returns the value. @param value This is only needed to determine the right type. */ 78 inline float getValue(float value) { return this->value_.value_float_; } 79 /** @returns the value. @param value This is only needed to determine the right type. */ 67 80 inline double getValue(double value) { return this->value_.value_double_; } 68 /** @returns the value of the type bool. @param value This is only needed to determine the right type. */81 /** @returns the value. @param value This is only needed to determine the right type. */ 69 82 inline bool getValue(bool value) { return this->value_.value_bool_; } 70 /** @returns the value of the type std::string. @param value This is only needed to determine the right type. */ 71 inline std::string getValue(const std::string& value) { return this->value_string_; } 72 /** @returns the value of the type Vector2. @param value This is only needed to determine the right type. */ 83 /** @returns the value. @param value This is only needed to determine the right type. */ 84 inline const std::string& getValue(const std::string& value) { return this->value_string_; } 85 /** @returns the value. @param value This is only needed to determine the right type. */ 86 inline const char* getValue(const char* value) { return this->value_string_.c_str(); } 87 /** @returns the value. @param value This is only needed to determine the right type. */ 73 88 inline Ogre::Vector2 getValue(const Ogre::Vector2& value) { return this->value_vector2_; } 74 /** @returns the value of the type Vector3. @param value This is only needed to determine the right type. */89 /** @returns the value. @param value This is only needed to determine the right type. */ 75 90 inline Ogre::Vector3 getValue(const Ogre::Vector3& value) { return this->value_vector3_; } 76 /** @returns the value of the type Colour�Value. @param value This is only needed to determine the right type. */91 /** @returns the value. @param value This is only needed to determine the right type. */ 77 92 inline Ogre::ColourValue getValue(const Ogre::ColourValue& value) { return this->value_colourvalue_; } 78 93 … … 80 95 std::string classname_; //!< The name of the class the variable belongs to 81 96 std::string varname_; //!< The name of the variable 82 std::string defvalue _;//!< The string of the default-variable97 std::string defvalueString_; //!< The string of the default-variable 83 98 84 99 union MultiType 85 100 { 86 101 int value_int_; //!< The value, if the variable is of the type int 102 unsigned int value_uint_; //!< The value, if the variable is of the type unsigned int 103 char value_char_; //!< The value, if the variable is of the type char 104 unsigned char value_uchar_; //!< The value, if the variable is of the type unsigned char 105 float value_float_; //!< The value, if the variable is of the type float 87 106 double value_double_; //!< The value, if the variable is of the type double 88 107 bool value_bool_; //!< The value, if the variable is of the type bool 89 } value_; 108 } value_; //!< The value of the variable 90 109 91 110 std::string value_string_; //!< The value, if the variable is of the type string … … 97 116 static std::list<std::string>* configFileLines_s; //!< A list, containing all entrys in the config-file 98 117 static bool readConfigFile_s; //!< True if the config-file is read and stored in the list 118 119 enum VariableType 120 { 121 Int, 122 uInt, 123 Char, 124 uChar, 125 Float, 126 Double, 127 Bool, 128 ConstChar, 129 String, 130 Vector2, 131 Vector3, 132 ColourValue 133 } type_; //!< The type of the variable 99 134 }; 100 135 } -
code/branches/FICN/src/orxonox/core/CoreIncludes.h
r531 r667 106 106 if (!container##varname) \ 107 107 { \ 108 container##varname = new orxonox::ConfigValueContainer(this->getIdentifier()->getName(), #varname, defvalue); \108 container##varname = new orxonox::ConfigValueContainer(this->getIdentifier()->getName(), #varname, varname = defvalue); \ 109 109 this->getIdentifier()->setConfigValueContainer(#varname, container##varname); \ 110 110 } \ -
code/branches/FICN/src/orxonox/core/Factory.cc
r564 r667 84 84 void Factory::createClassHierarchy() 85 85 { 86 COUT( 4) << "*** Factory -> Create class-hierarchy\n";86 COUT(3) << "*** Factory -> Create class-hierarchy\n"; 87 87 std::map<std::string, Identifier*>::iterator it; 88 88 it = getFactoryPointer()->identifierStringMap_.begin(); … … 95 95 } 96 96 (*getFactoryPointer()->identifierStringMap_.begin()).second->stopCreatingHierarchy(); 97 COUT( 4) << "*** Factory -> Finished class-hierarchy creation\n";97 COUT(3) << "*** Factory -> Finished class-hierarchy creation\n"; 98 98 } 99 99 -
code/branches/FICN/src/orxonox/objects/test3.cc
r496 r667 16 16 void Test3::setConfigValues() 17 17 { 18 SetConfigValue(value_int_, -100); 19 SetConfigValue(value_double_, 10.555678); 20 SetConfigValue(value_bool_, true); 21 SetConfigValue(value_string_, "Dies ist ein Test"); 18 SetConfigValue(value_int_, 1); 19 SetConfigValue(value_uint_, 1); 20 SetConfigValue(value_char_, 1); 21 SetConfigValue(value_uchar_, 1); 22 SetConfigValue(value_float_, 1); 23 SetConfigValue(value_double_, 1); 24 SetConfigValue(value_bool_, 1); 25 SetConfigValue(value_string_, "This is a test"); 26 SetConfigValue(value_constchar_, "This is another test"); 22 27 SetConfigValue(value_vector2_, Vector2(101, 202)); 23 28 SetConfigValue(value_vector3_, Vector3(13, 26, 39)); … … 29 34 } 30 35 31 #include <fstream>32 36 void Test3::configOutput() 33 37 { 34 38 std::cout << this->value_int_ << std::endl; 39 std::cout << this->value_uint_ << std::endl; 40 std::cout << (int)this->value_char_ << std::endl; 41 std::cout << (int)this->value_uchar_ << std::endl; 42 std::cout << this->value_float_ << std::endl; 35 43 std::cout << this->value_double_ << std::endl; 36 44 std::cout << this->value_bool_ << std::endl; 37 45 std::cout << this->value_string_ << std::endl; 46 std::cout << this->value_constchar_ << std::endl; 38 47 std::cout << this->value_vector2_ << std::endl; 39 48 std::cout << this->value_vector3_ << std::endl; … … 41 50 } 42 51 43 44 52 #define testandcout(code) \ 53 std::cout << #code << " " << code << "\n" 45 54 46 55 void Test3::usefullClassesIsATest(Test1* test1) -
code/branches/FICN/src/orxonox/objects/test3.h
r496 r667 24 24 private: 25 25 int value_int_; 26 unsigned int value_uint_; 27 char value_char_; 28 unsigned char value_uchar_; 29 float value_float_; 26 30 double value_double_; 27 31 bool value_bool_; 28 32 std::string value_string_; 33 const char* value_constchar_; 29 34 Vector2 value_vector2_; 30 35 Vector3 value_vector3_;
Note: See TracChangeset
for help on using the changeset viewer.