Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5538 in orxonox.OLD


Ignore:
Timestamp:
Nov 11, 2005, 12:30:53 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: more elaborate MultiType, all get*() written

File:
1 edited

Legend:

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

    r5537 r5538  
    8888  else if (this->type & MT_CHAR) return (this->value.Char == '\0')? false : true;
    8989  else if (this->type & MT_STRING) return (!strncmp(this->value.String, "true", 4) || !strncmp(this->value.String, "TRUE", 4) || !strncmp(this->value.String, "1", 1))? true : false;
     90
     91  return false;
    9092}
    9193
     
    99101  else if (this->type & MT_FLOAT) return (int) this->value.Float;
    100102  else if (this->type & MT_CHAR) return (int) this->value.Char;
    101   else if (this->type & MT_STRING) return 1; //! @TODO
     103  else if (this->type & MT_STRING) {
     104    char* endPtr = NULL;
     105    int result = strtol(this->value.String, &endPtr, 10);
     106    if ( endPtr >= this->value.String && endPtr < this->value.String + strlen(this->value.String))
     107      return 0;
     108    else
     109      return result;
     110  }
     111
     112  return 0;
    102113}
    103114
     
    111122  else if (this->type & MT_INT) return (float) this->value.Int;
    112123  else if (this->type & MT_CHAR) return (float) this->value.Char;
    113   else if (this->type & MT_STRING) return 1; //! @TODO
     124  else if (this->type & MT_STRING) {
     125    char* endPtr = NULL;
     126    double result = strtod(this->value.String, &endPtr);
     127
     128    if ( endPtr >= this->value.String && endPtr < this->value.String + strlen(this->value.String))
     129      return 0.0f;
     130    else
     131      return result;
     132  }
     133
     134  return 0.0f;
    114135}
    115136
     
    123144  else if (this->type & MT_INT) return (int) this->value.Int;
    124145  else if (this->type & MT_FLOAT) return (char) this->value.Float;
    125   else if (this->type & MT_STRING) return 1; //! @TODO
     146  else if (this->type & MT_STRING) return *this->value.String;
     147
     148  return '\0';
    126149}
    127150
     
    131154  if (this->type & MT_STRING)
    132155    return this->value.String;
    133 /*  else if (this->type & MT_BOOL) return (this->value.Bool)? 1 : 0;
    134   else if (this->type & MT_INT) return 1; //! @TODO
    135   else if (this->type & MT_FLOAT) return (int) this->value.Float;
    136   else if (this->type & MT_CHAR) return (int) this->value.Char;*/
     156  else
     157  {
     158    if (this->type & MT_BOOL) return (this->value.Bool)? "true" : "false";
     159    else if (this->type & MT_CHAR) &this->value.Char;
     160
     161    char tmpString[128];
     162    if (this->storedString != NULL)
     163    {
     164      delete[] this->storedString;
     165      this->storedString = NULL;
     166    }
     167
     168    if (this->type & MT_INT)
     169    {
     170      sprintf(tmpString, "%d", this->value.Int);
     171      this->storedString = new char[strlen (tmpString)+1];
     172      strcpy (this->storedString, tmpString);
     173      return this->storedString;
     174    }
     175    if (this->type & MT_FLOAT)
     176    {
     177      sprintf(tmpString, "%f", this->value.Float);
     178      this->storedString = new char[strlen (tmpString)+1];
     179      strcpy (this->storedString, tmpString);
     180      return this->storedString;
     181    }
     182  }
     183
     184  return "";
    137185}
    138186
Note: See TracChangeset for help on using the changeset viewer.