Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9869 in orxonox.OLD for trunk/src/lib/util/multi_type.cc


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/multi_type.cc

    r9406 r9869  
    3333  {
    3434    default:
    35       this->value.Float = 0.0f;
    36       break;
     35    this->value.Float = 0.0f;
     36    break;
    3737    case MT_BOOL:
    38       this->value.Bool = false;
    39       break;
     38    this->value.Bool = false;
     39    break;
    4040    case MT_INT:
    41       this->value.Int = 0;
    42       break;
     41    this->value.Int = 0;
     42    break;
    4343    case MT_FLOAT:
    44       this->value.Float = 0.0f;
    45       break;
     44    this->value.Float = 0.0f;
     45    break;
    4646    case MT_CHAR:
    47       this->value.Char = '\0';
    48       break;
     47    this->value.Char = '\0';
     48    break;
    4949    case MT_STRING:
    50       this->storedString = "";
    51       break;
     50    this->storedString = "";
     51    break;
    5252  }
    5353}
     
    142142  {
    143143    case MT_NULL:
    144       return true;
     144    return true;
    145145    case MT_BOOL:
    146       return (this->value.Bool == mt.value.Bool);
     146    return (this->value.Bool == mt.value.Bool);
    147147    case MT_INT:
    148       return (this->value.Int == mt.value.Int);
     148    return (this->value.Int == mt.value.Int);
    149149    case MT_CHAR:
    150       return (this->value.Char == mt.value.Char);
     150    return (this->value.Char == mt.value.Char);
    151151    case MT_FLOAT:
    152       return (this->value.Float == mt.value.Float);
     152    return (this->value.Float == mt.value.Float);
    153153    case MT_STRING:
    154       return (this->storedString == mt.storedString);
     154    return (this->storedString == mt.storedString);
    155155    default:
    156       return false;
     156    return false;
    157157  }
    158158}
     
    171171  {
    172172    case MT_BOOL:
    173       this->setBool(this->getBool());
    174       break;
     173    this->setBool(this->getBool());
     174    break;
    175175    case MT_INT:
    176       this->setInt(this->getInt());
    177       break;
     176    this->setInt(this->getInt());
     177    break;
    178178    case MT_FLOAT:
    179       this->setFloat(this->getFloat());
    180       break;
     179    this->setFloat(this->getFloat());
     180    break;
    181181    case MT_CHAR:
    182       this->setChar(this->getChar());
    183       break;
     182    this->setChar(this->getChar());
     183    break;
    184184    case MT_STRING:
    185       this->setString(this->getString());
    186       break;
     185    this->setString(this->getString());
     186    break;
    187187    default:
    188       this->type = type;
     188    this->type = type;
    189189  }
    190190}
     
    195195 *
    196196 * This is a pure Value copy. The current type will be preserved.
    197  *
    198  * @TODO speedup
    199197 */
    200198void MultiType::setValueOf(const MultiType& mt)
     
    257255}
    258256
     257/**
     258 * @brief stores any value to the string.
     259 * @note this Value can be grabbed by using the getStoredString function.
     260 */
     261void MultiType::storeString()
     262{
     263  if (!(this->type & MT_STRING))
     264    this->storedString = this->getString();
     265}
    259266
    260267/**************************
     
    275282  else if (this->type & MT_STRING) return (this->storedString == "true" ||
    276283                                            this->storedString == "TRUE" ||
    277                                             this->storedString != "0"); //! @TODO make this better...
     284                                            this->storedString != "0"); // TODO make this better...
    278285
    279286  return false;
     
    381388 * @brief returns a Constant string (actually this is slower than getString()
    382389 * @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().
    384392 */
    385393const std::string& MultiType::getConstString() const
    386394{
    387 
    388395  MultiType::constString = this->getString();
    389396  return MultiType::constString;
    390397}
    391398
     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 */
     411const std::string& MultiType::getStoredString() const
     412{
     413  MultiType::constString = this->getString();
     414  return MultiType::constString;
     415}
    392416
    393417/**
     
    433457  {
    434458    case MT_BOOL:
    435       this->setBool(false);
    436       break;
     459    this->setBool(false);
     460    break;
    437461    case MT_INT:
    438       this->setInt(0);
    439       break;
     462    this->setInt(0);
     463    break;
    440464    case MT_FLOAT:
    441       this->setFloat(0.0f);
    442       break;
     465    this->setFloat(0.0f);
     466    break;
    443467    case MT_CHAR:
    444       this->setChar('\0');
    445       break;
     468    this->setChar('\0');
     469    break;
    446470    case MT_STRING:
    447       this->setString("");
    448       break;
     471    this->setString("");
     472    break;
    449473    default:
    450474#ifdef DEBUG
    451       PRINTF(2)("Unknown Type not reseting\n");
     475    PRINTF(2)("Unknown Type not reseting\n");
    452476#endif
    453       break;
     477    break;
    454478  }
    455479}
     
    465489  {
    466490    case MT_BOOL:
    467       return MultiType::typeNames[1];
     491    return MultiType::typeNames[1];
    468492    case MT_INT:
    469       return MultiType::typeNames[2];
     493    return MultiType::typeNames[2];
    470494    case MT_FLOAT:
    471       return MultiType::typeNames[3];
     495    return MultiType::typeNames[3];
    472496    case MT_CHAR:
    473       return MultiType::typeNames[4];
     497    return MultiType::typeNames[4];
    474498    case MT_STRING:
    475       return MultiType::typeNames[5];
     499    return MultiType::typeNames[5];
    476500    default:
    477       return MultiType::typeNames[0];
     501    return MultiType::typeNames[0];
    478502  }
    479503}
Note: See TracChangeset for help on using the changeset viewer.