Changeset 9869 in orxonox.OLD for trunk/src/lib/util/multi_type.cc
- Timestamp:
- Oct 3, 2006, 12:19:30 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/multi_type.cc
r9406 r9869 33 33 { 34 34 default: 35 36 35 this->value.Float = 0.0f; 36 break; 37 37 case MT_BOOL: 38 39 38 this->value.Bool = false; 39 break; 40 40 case MT_INT: 41 42 41 this->value.Int = 0; 42 break; 43 43 case MT_FLOAT: 44 45 44 this->value.Float = 0.0f; 45 break; 46 46 case MT_CHAR: 47 48 47 this->value.Char = '\0'; 48 break; 49 49 case MT_STRING: 50 51 50 this->storedString = ""; 51 break; 52 52 } 53 53 } … … 142 142 { 143 143 case MT_NULL: 144 144 return true; 145 145 case MT_BOOL: 146 146 return (this->value.Bool == mt.value.Bool); 147 147 case MT_INT: 148 148 return (this->value.Int == mt.value.Int); 149 149 case MT_CHAR: 150 150 return (this->value.Char == mt.value.Char); 151 151 case MT_FLOAT: 152 152 return (this->value.Float == mt.value.Float); 153 153 case MT_STRING: 154 154 return (this->storedString == mt.storedString); 155 155 default: 156 156 return false; 157 157 } 158 158 } … … 171 171 { 172 172 case MT_BOOL: 173 174 173 this->setBool(this->getBool()); 174 break; 175 175 case MT_INT: 176 177 176 this->setInt(this->getInt()); 177 break; 178 178 case MT_FLOAT: 179 180 179 this->setFloat(this->getFloat()); 180 break; 181 181 case MT_CHAR: 182 183 182 this->setChar(this->getChar()); 183 break; 184 184 case MT_STRING: 185 186 185 this->setString(this->getString()); 186 break; 187 187 default: 188 188 this->type = type; 189 189 } 190 190 } … … 195 195 * 196 196 * This is a pure Value copy. The current type will be preserved. 197 *198 * @TODO speedup199 197 */ 200 198 void MultiType::setValueOf(const MultiType& mt) … … 257 255 } 258 256 257 /** 258 * @brief stores any value to the string. 259 * @note this Value can be grabbed by using the getStoredString function. 260 */ 261 void MultiType::storeString() 262 { 263 if (!(this->type & MT_STRING)) 264 this->storedString = this->getString(); 265 } 259 266 260 267 /************************** … … 275 282 else if (this->type & MT_STRING) return (this->storedString == "true" || 276 283 this->storedString == "TRUE" || 277 this->storedString != "0"); // ! @TODO make this better...284 this->storedString != "0"); // TODO make this better... 278 285 279 286 return false; … … 381 388 * @brief returns a Constant string (actually this is slower than getString() 382 389 * @returns a constant string of the stored version's one. 383 * @note this could lead to a inconsistency of data 390 * @note this could lead to a inconsistency of data AND IS HIGHLY NON_THREAD_SAFE! 391 * PLEASE THINK ABOUT USING THE getStoredString function in conjunction with storeString(). 384 392 */ 385 393 const std::string& MultiType::getConstString() const 386 394 { 387 388 395 MultiType::constString = this->getString(); 389 396 return MultiType::constString; 390 397 } 391 398 399 /** 400 * @brief returns the currently stored string. 401 * @returns the Stored string. 402 * @note Storing a string works as follows: \\ 403 * MultiType a(3); // Creates a MultiType of Type int with value 3 \\ 404 * a.storeString(); // Stores the String in the internal structure. \\ 405 * std::string name = a.getStoredString(); 406 * 407 * This would be the same as 408 * name = a.getString(); 409 * but with much more const'ness. 410 */ 411 const std::string& MultiType::getStoredString() const 412 { 413 MultiType::constString = this->getString(); 414 return MultiType::constString; 415 } 392 416 393 417 /** … … 433 457 { 434 458 case MT_BOOL: 435 436 459 this->setBool(false); 460 break; 437 461 case MT_INT: 438 439 462 this->setInt(0); 463 break; 440 464 case MT_FLOAT: 441 442 465 this->setFloat(0.0f); 466 break; 443 467 case MT_CHAR: 444 445 468 this->setChar('\0'); 469 break; 446 470 case MT_STRING: 447 448 471 this->setString(""); 472 break; 449 473 default: 450 474 #ifdef DEBUG 451 475 PRINTF(2)("Unknown Type not reseting\n"); 452 476 #endif 453 477 break; 454 478 } 455 479 } … … 465 489 { 466 490 case MT_BOOL: 467 491 return MultiType::typeNames[1]; 468 492 case MT_INT: 469 493 return MultiType::typeNames[2]; 470 494 case MT_FLOAT: 471 495 return MultiType::typeNames[3]; 472 496 case MT_CHAR: 473 497 return MultiType::typeNames[4]; 474 498 case MT_STRING: 475 499 return MultiType::typeNames[5]; 476 500 default: 477 501 return MultiType::typeNames[0]; 478 502 } 479 503 }
Note: See TracChangeset
for help on using the changeset viewer.