Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5540 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Nov 11, 2005, 1:13:07 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: set[Type](value)-functions

Location:
trunk/src/lib/util
Files:
2 edited

Legend:

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

    r5539 r5540  
    2424using namespace std;
    2525
     26MultiType::MultiType()
     27{
     28  this->type = MT_NULL;
     29  this->storedString = NULL;
     30}
     31
     32
    2633MultiType::MultiType(bool value)
    2734{
    2835  this->init();
    29   this->type = MT_BOOL;
    30   this->value.Bool = value;
    31 
     36  this->setBool(value);
    3237}
    3338
     
    3540{
    3641  this->init();
    37   this->type = MT_INT;
    38   this->value.Int = value;
     42  this->setInt(value);
    3943}
    4044
     
    4347{
    4448  this->init();
    45   this->type = MT_FLOAT;
    46   this->value.Float = value;
     49  this->setFloat(value);
    4750}
    4851
     
    5154{
    5255  this->init();
    53   this->type = MT_CHAR;
    54   this->value.Char = value;
     56  this->setChar(value);
    5557}
    5658
     
    5961{
    6062  this->init();
    61   this->type = MT_STRING;
    62   this->value.String = new char[strlen(value)+1];
    63   strcpy(this->value.String, value);
    64 
    65   this->storedString = this->value.String;
     63  this->setString(value);
    6664}
    6765
     
    7573}
    7674
     75/**
     76 * copy Constructor
     77 * @param mt: the entity to copy
     78 * @returns a Copy of itself. (strings inside are copied as well)
     79 */
     80MultiType MultiType::operator= (const MultiType& mt)
     81{
     82  this->type = mt.type;
     83  this->value = mt.value;
     84
     85  if (mt.type == MT_STRING)
     86  {
     87    this->storedString = new char[strlen (mt.storedString)+1];
     88    strcpy(this->storedString, mt.storedString);
     89    this->value.String = this->storedString;
     90  }
     91}
     92
    7793void MultiType::init()
    7894{
     95  this->type = MT_NULL;
    7996  this->storedString = NULL;
    8097}
     98
     99
     100
     101void MultiType::setType(MT_Type)
     102{
     103
     104}
     105
     106void MultiType::setBool(bool value)
     107{
     108  this->type = MT_BOOL;
     109  this->value.Bool = value;
     110}
     111
     112
     113void MultiType::setInt(int value)
     114{
     115  this->type = MT_INT;
     116  this->value.Int = value;
     117}
     118
     119
     120void MultiType::setFloat(float value)
     121{
     122  this->type = MT_FLOAT;
     123  this->value.Float = value;
     124
     125}
     126
     127
     128void MultiType::setChar(char value)
     129{
     130  this->type = MT_CHAR;
     131  this->value.Char = value;
     132}
     133
     134
     135void MultiType::setString(const char* value)
     136{
     137  this->type = MT_STRING;
     138  this->value.String = new char[strlen(value)+1];
     139  strcpy(this->value.String, value);
     140
     141  this->storedString = this->value.String;
     142}
     143
     144
     145
     146
    81147
    82148
  • trunk/src/lib/util/multi_type.h

    r5539 r5540  
    3030
    3131 public:
     32   MultiType();
    3233   MultiType(bool value);
    3334   MultiType(int value);
     
    3839   void init();
    3940
     41   MultiType operator= (const MultiType& mt);
     42
     43   void setType(MT_Type);
     44
     45   void setBool(bool value);
     46   void setInt(int value);
     47   void setFloat(float value);
     48   void setChar(char value);
     49   void setString(const char* value);
    4050
    4151  /** @returns the Type of the Value stored in this MultiType */
Note: See TracChangeset for help on using the changeset viewer.