Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5544 in orxonox.OLD


Ignore:
Timestamp:
Nov 11, 2005, 3:39:27 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: more elaborate MultiType

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

Legend:

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

    r5541 r5544  
    147147
    148148
    149 bool MultiType::getBool()
     149bool MultiType::getBool() const
    150150{
    151151  // default case:
     
    162162
    163163
    164 int MultiType::getInt()
     164int MultiType::getInt() const
    165165{
    166166  // default case:
     
    183183
    184184
    185 float MultiType::getFloat()
     185float MultiType::getFloat() const
    186186{
    187187 // default case:
     
    204204
    205205
    206 char MultiType::getChar()
     206char MultiType::getChar() const
    207207{
    208208 // default case:
     
    253253}
    254254
     255
     256void MultiType::debug()
     257{
     258  printf("MultiType of Type: %s is: BOOL: %d, INT: %d, FLOAT: %f, CHAR: %c, STRING %s\n",
     259         MultiType::MultiTypeToString(this->type),
     260         this->getBool(),
     261         this->getInt(),
     262         this->getFloat(),
     263         this->getChar(),
     264         this->getString()
     265  );
     266
     267
     268}
     269
     270const char* MultiType::MultiTypeToString(MT_Type type)
     271{
     272  switch (type)
     273  {
     274   default:
     275    return "NONE";
     276   case MT_BOOL:
     277    return "bool";
     278   case MT_INT:
     279    return "int";
     280   case MT_FLOAT:
     281    return "float";
     282   case MT_CHAR:
     283    return "char";
     284   case MT_STRING:
     285    return "string";
     286  }
     287}
     288
     289MT_Type MultiType::StringToMultiType(const char* type)
     290{
     291  if (!strncmp(type, "bool", 4))
     292    return MT_BOOL;
     293  if (!strncmp(type, "int", 3))
     294    return MT_INT;
     295  if (!strncmp(type, "float", 5))
     296    return MT_FLOAT;
     297  if (!strncmp(type, "char", 4))
     298    return MT_CHAR;
     299  if (!strncmp(type, "string", 6))
     300    return MT_STRING;
     301}
  • trunk/src/lib/util/multi_type.h

    r5541 r5544  
    5858  inline MT_Type getType() const { return this->type; };
    5959
    60   bool getBool();
    61   int getInt();
    62   float getFloat();
    63   char getChar();
     60  bool getBool() const;
     61  int getInt() const;
     62  float getFloat() const;
     63  char getChar() const;
    6464  const char* getString();
    6565
     66
     67  void debug();
     68
     69  static const char* MultiTypeToString(MT_Type type);
     70  static MT_Type StringToMultiType(const char* type);
    6671
    6772 private:
     
    6974   union Type
    7075   {
    71      bool             Bool;
    72      int              Int;
    73      float            Float;
    74      char             Char;
    75      char*            String;
    76    } value;
     76     bool              Bool;
     77     int               Int;
     78     float             Float;
     79     char              Char;
     80     char*             String;
    7781
    78    char* storedString;
     82   }                   value;
     83
     84   char*               storedString;
    7985};
    8086
Note: See TracChangeset for help on using the changeset viewer.