- Timestamp:
- Dec 10, 2007, 3:40:55 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/core/ConfigValueContainer.cc
r449 r450 144 144 145 145 /** 146 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_vector 3_.146 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_vector2_. 147 147 @param classname The name of the class the variable belongs to 148 148 @param varname The name of the variable 149 149 @param defvalue The default-value 150 150 */ 151 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector 3defvalue)152 { 153 // Try to convert the default-value from Vector 3to string151 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector2 defvalue) 152 { 153 // Try to convert the default-value from Vector2 to string 154 154 std::ostringstream ostream; 155 if (ostream << "(" << defvalue.x << "," << defvalue.y << " ," << defvalue.z << ")")155 if (ostream << "(" << defvalue.x << "," << defvalue.y << ")") 156 156 this->defvalue_ = ostream.str(); 157 157 else 158 this->defvalue_ = "(0,0 ,0)";158 this->defvalue_ = "(0,0)"; 159 159 160 160 // Set the default values, then get the value-string … … 187 187 } 188 188 189 if (count != 2)190 bEntryIsCorrupt = true; 191 192 // Try to convert the stripped value-string to Vector 3189 if (count != 1) 190 bEntryIsCorrupt = true; 191 192 // Try to convert the stripped value-string to Vector2 193 193 if (!bEntryIsCorrupt) 194 194 { 195 195 std::istringstream istream(valueString); 196 if (!(istream >> this->value_vector3_.x)) 197 { 198 // The conversion failed - use the default value and restore the entry in the config-file 199 this->value_vector3_.x = defvalue.x; 200 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 201 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 202 } 203 if (!(istream >> this->value_vector3_.y)) 204 { 205 // The conversion failed - use the default value and restore the entry in the config-file 206 this->value_vector3_.y = defvalue.y; 207 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 208 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 209 } 210 if (!(istream >> this->value_vector3_.z)) 211 { 212 // The conversion failed - use the default value and restore the entry in the config-file 213 this->value_vector3_.z = defvalue.z; 196 if (!(istream >> this->value_vector2_.x)) 197 { 198 // The conversion failed - use the default value and restore the entry in the config-file 199 this->value_vector2_.x = defvalue.x; 200 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 201 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 202 } 203 if (!(istream >> this->value_vector2_.y)) 204 { 205 // The conversion failed - use the default value and restore the entry in the config-file 206 this->value_vector2_.y = defvalue.y; 214 207 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 215 208 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); … … 219 212 { 220 213 // The conversion failed - use the default value and restore the entry in the config-file 221 this->value_vector 3_ = defvalue;214 this->value_vector2_ = defvalue; 222 215 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 223 216 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); … … 226 219 227 220 /** 228 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_ colourvalue_.221 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_vector3_. 229 222 @param classname The name of the class the variable belongs to 230 223 @param varname The name of the variable 231 224 @param defvalue The default-value 232 225 */ 233 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre:: ColourValuedefvalue)234 { 235 // Try to convert the default-value from ColourValueto string226 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector3 defvalue) 227 { 228 // Try to convert the default-value from Vector3 to string 236 229 std::ostringstream ostream; 237 if (ostream << "(" << defvalue. r << "," << defvalue.g << "," << defvalue.b << "," << defvalue.a<< ")")230 if (ostream << "(" << defvalue.x << "," << defvalue.y << "," << defvalue.z << ")") 238 231 this->defvalue_ = ostream.str(); 239 232 else 240 this->defvalue_ = "(0,0,0 ,0)";233 this->defvalue_ = "(0,0,0)"; 241 234 242 235 // Set the default values, then get the value-string … … 269 262 } 270 263 264 if (count != 2) 265 bEntryIsCorrupt = true; 266 267 // Try to convert the stripped value-string to Vector3 268 if (!bEntryIsCorrupt) 269 { 270 std::istringstream istream(valueString); 271 if (!(istream >> this->value_vector3_.x)) 272 { 273 // The conversion failed - use the default value and restore the entry in the config-file 274 this->value_vector3_.x = defvalue.x; 275 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 276 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 277 } 278 if (!(istream >> this->value_vector3_.y)) 279 { 280 // The conversion failed - use the default value and restore the entry in the config-file 281 this->value_vector3_.y = defvalue.y; 282 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 283 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 284 } 285 if (!(istream >> this->value_vector3_.z)) 286 { 287 // The conversion failed - use the default value and restore the entry in the config-file 288 this->value_vector3_.z = defvalue.z; 289 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 290 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 291 } 292 } 293 else 294 { 295 // The conversion failed - use the default value and restore the entry in the config-file 296 this->value_vector3_ = defvalue; 297 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; 298 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 299 } 300 } 301 302 /** 303 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_colourvalue_. 304 @param classname The name of the class the variable belongs to 305 @param varname The name of the variable 306 @param defvalue The default-value 307 */ 308 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::ColourValue defvalue) 309 { 310 // Try to convert the default-value from ColourValue to string 311 std::ostringstream ostream; 312 if (ostream << "(" << defvalue.r << "," << defvalue.g << "," << defvalue.b << "," << defvalue.a << ")") 313 this->defvalue_ = ostream.str(); 314 else 315 this->defvalue_ = "(0,0,0,0)"; 316 317 // Set the default values, then get the value-string 318 this->setDefaultValues(classname, varname); 319 std::string valueString = this->getValueString(); 320 321 // Strip the value-string 322 bool bEntryIsCorrupt = false; 323 valueString = this->getStrippedLine(valueString); 324 unsigned int pos1, pos2, pos3; 325 pos1 = valueString.find("("); 326 if (pos1 == 0) 327 valueString.erase(pos1, 1); 328 else 329 bEntryIsCorrupt = true; 330 331 pos2 = valueString.find(")"); 332 if (pos2 == valueString.length() - 1) 333 valueString.erase(pos2, 1); 334 else 335 bEntryIsCorrupt = true; 336 337 int count = 0; 338 while ((pos3 = valueString.find(",")) < valueString.length()) 339 { 340 count++; 341 valueString.replace(pos3, 1, " "); 342 if (pos3 < pos1) 343 bEntryIsCorrupt = true; 344 } 345 271 346 if (count != 3) 272 347 bEntryIsCorrupt = true; … … 333 408 this->value_bool_ = false; 334 409 this->value_string_ = ""; 410 this->value_vector2_ = Ogre::Vector2(0, 0); 335 411 this->value_vector3_ = Ogre::Vector3(0, 0, 0); 336 412 this->value_colourvalue_ = Ogre::ColourValue(0, 0, 0, 0);
Note: See TracChangeset
for help on using the changeset viewer.