Changeset 450 for code/branches/objecthierarchy
- Timestamp:
- Dec 10, 2007, 3:40:55 AM (17 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox
- Files:
-
- 5 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); -
code/branches/objecthierarchy/src/orxonox/core/ConfigValueContainer.h
r447 r450 18 18 #include <string> 19 19 #include <list> 20 21 #include "OgreVector2.h" 20 22 #include "OgreVector3.h" 21 23 #include "OgreColourValue.h" … … 46 48 ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue); 47 49 ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue); 50 ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector2 defvalue); 48 51 ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector3 defvalue); 49 52 ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::ColourValue defvalue); … … 67 70 /** @returns the value of the type std::string. @param value This is only needed to determine the right type. */ 68 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. */ 73 inline Ogre::Vector2 getValue(const Ogre::Vector2& value) { return this->value_vector2_; } 69 74 /** @returns the value of the type Vector3. @param value This is only needed to determine the right type. */ 70 75 inline Ogre::Vector3 getValue(const Ogre::Vector3& value) { return this->value_vector3_; } … … 81 86 bool value_bool_; //!< The value, if the variable is of the type bool 82 87 std::string value_string_; //!< The value, if the variable is of the type string 88 Ogre::Vector2 value_vector2_; //!< The value, if the variable is of the type Vector2 83 89 Ogre::Vector3 value_vector3_; //!< The value, if the variable is of the type Vector3 84 90 Ogre::ColourValue value_colourvalue_; //!< The value, if the variable is of the type ColourValue -
code/branches/objecthierarchy/src/orxonox/core/CoreIncludes.h
r447 r450 18 18 #include "ConfigValueContainer.h" 19 19 20 #include "OgreVector2.h" 20 21 #include "OgreVector3.h" 21 22 #include "OgreColourValue.h" … … 25 26 namespace orxonox 26 27 { 28 typedef Ogre::Vector2 Vector2; 27 29 typedef Ogre::Vector3 Vector3; 28 30 typedef Ogre::ColourValue ColourValue; … … 109 111 this->getIdentifier()->setConfigValueContainer(#varname, container##varname); \ 110 112 } \ 111 this->varname = container##varname->getValue(varname)113 varname = container##varname->getValue(varname) -
code/branches/objecthierarchy/src/orxonox/objects/test3.cc
r434 r450 20 20 SetConfigValue(value_bool_, true); 21 21 SetConfigValue(value_string_, "Dies ist ein Test"); 22 SetConfigValue(value_vector2_, Vector2(101, 202)); 22 23 SetConfigValue(value_vector3_, Vector3(13, 26, 39)); 23 24 SetConfigValue(value_colourvalue_, ColourValue(1.0, 0.5, 0.25, 0.887)); … … 28 29 } 29 30 31 #include <fstream> 30 32 void Test3::configOutput() 31 33 { … … 34 36 std::cout << this->value_bool_ << std::endl; 35 37 std::cout << this->value_string_ << std::endl; 38 std::cout << this->value_vector2_ << std::endl; 36 39 std::cout << this->value_vector3_ << std::endl; 37 40 std::cout << this->value_colourvalue_ << std::endl; -
code/branches/objecthierarchy/src/orxonox/objects/test3.h
r434 r450 27 27 bool value_bool_; 28 28 std::string value_string_; 29 Vector2 value_vector2_; 29 30 Vector3 value_vector3_; 30 31 ColourValue value_colourvalue_;
Note: See TracChangeset
for help on using the changeset viewer.