Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Mar 8, 2006, 10:46:37 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: MultiType rework (now uses std::string) this is more compliant, and better to handle

Location:
trunk/src/lib
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/render2D/element_2d.cc

    r7198 r7199  
    142142
    143143  LoadParam(root, "bind-node", this, Element2D, setBindNode)
    144       .describe("sets a node, this 2D-Element should be shown upon (name of the node)")
    145       .defaultValues(NULL);
     144      .describe("sets a node, this 2D-Element should be shown upon (name of the node)");
    146145
    147146  LoadParam(root, "visibility", this, Element2D, setVisibility)
  • trunk/src/lib/lang/class_list.cc

    r7198 r7199  
    3131SHELL_COMMAND_STATIC(debug, ClassList, ClassList::debugS)
    3232    ->describe("Shows all registered classes, if param1: is a valid ClassName only values of this class are shown. param2: how much output")
    33     ->defaultValues(NULL, 1);
     33    ->defaultValues(MT_NULL, 1);
    3434#endif
    3535
  • trunk/src/lib/particles/particle_system.cc

    r7198 r7199  
    128128  LoadParam(root, "precache", this, ParticleSystem, precache)
    129129      .describe("Precaches the ParticleSystem for %1 seconds, %2 times per Second")
    130       .defaultValues(1, 25);
     130      .defaultValues(1.0, 25.0);
    131131}
    132132
  • trunk/src/lib/physics/fields/field.cc

    r7198 r7199  
    6262  LoadParam(root, "magnitude", this, Field, setMagnitude)
    6363      .describe("sets the magnitude of this Field")
    64       .defaultValues(1);
     64      .defaultValues(1.0f);
    6565
    6666  LoadParam(root, "attenuation", this, Field, setAttenuation)
  • trunk/src/lib/shell/shell_command.cc

    r7198 r7199  
    3939{
    4040  this->setClassID(CL_SHELL_COMMAND, "ShellCommand");
     41  PRINTF(5)("create shellcommand %s %s\n", commandName, className);
    4142  this->setName(commandName);
    4243  this->description = NULL;
  • trunk/src/lib/util/executor/executor.cc

    r7198 r7199  
    4545  this->setClassID(CL_EXECUTOR, "Executor");
    4646
    47 
    4847  // What Parameters have we got
    4948  this->defaultValue[0] = param0;
     
    5352  this->defaultValue[4] = param4;
    5453
     54  this->paramCount = 0;
    5555  for (unsigned int i = 0; i < FUNCTOR_MAX_ARGUMENTS; i++)
    5656  {
     
    6161    }
    6262  }
    63   assert (paramCount <= FUNCTOR_MAX_ARGUMENTS);
    6463}
    6564
     
    109108  {
    110109    if (*value[i] != MT_NULL)
    111     {
    112       if (this->defaultValue[i].getType() == value[i]->getType())
    113       {
    114         this->defaultValue[i] = *value[i];
    115       }
    116       else
    117       {
    118         PRINTF(1)("Unable to set this Value, as it is not of type %s\n", MultiType::MultiTypeToString(this->defaultValue[i].getType()));
    119       }
    120     }
     110        this->defaultValue[i].setValueOf(*value[i]);
    121111  }
    122112  return this;
  • trunk/src/lib/util/executor/executor.h

    r7198 r7199  
    1313#include "substring.h"
    1414#include "functor_list.h" //< MUST BE INCLUDED HERE AT LEAST ONCE.
    15 
    16 #include <stdarg.h>
    1715
    1816//! an enumerator for the definition of the Type.
     
    8987#define   l_FLOAT_DEFGRAB(i)        this->defaultValue[i].getFloat()
    9088//! where to chek for default STRING values
    91 #define   l_STRING_DEFGRAB(i)       this->defaultValue[i].getString()
     89#define   l_CSTRING_DEFGRAB(i)      this->defaultValue[i].getCString()
    9290
    9391//////////////////////////
  • trunk/src/lib/util/executor/functor_list.h

    r5995 r7199  
    2121   l_SHORT:     short
    2222   l_FLOAT:     float
    23    l_STRING:    const char*
     23   l_CSTRING:    const char*
    2424   l_XML_ELEM:  TiXmlElement*
    2525 */
     
    6060// #define l_SHORT_FUNC       atoi                 //!< The function to parse a SHORT
    6161// #define l_SHORT_NAME       "short"              //!< The name of a SHORT
    62 //#define l_SHORT_PARAM       ParameterShort       //!< the type of the parameter SHORT
     62// #define l_SHORT_PARAM      ParameterShort       //!< the type of the parameter SHORT
    6363// #define l_SHORT_DEFAULT    0                    //!< a default Value for a SHORT
    6464
     
    7474//#define l_VECTOR_DEFAULT   Vector(0,0,0)        //!< Default value for a VECTOR
    7575
    76 #define l_STRING_TYPE      const char*          //!< The type of a STRING
     76#define l_CSTRING_TYPE     const char*          //!< The type of a STRING
     77#define l_CSTRING_FUNC     isString             //!< The function to parse a STRING
     78#define l_CSTRING_NAME     "string"             //!< The name of a STRING
     79#define l_CSTRING_PARAM    MT_STRING            //!< the type of the parameter STRING
     80#define l_CSTRING_DEFAULT  ""                   //!< a default Value for an STRING
     81
     82#define l_STRING_TYPE      const std::string&   //!< The type of a STRING
    7783#define l_STRING_FUNC      isString             //!< The function to parse a STRING
    7884#define l_STRING_NAME      "string"             //!< The name of a STRING
     
    9399  FUNCTOR_LIST(0)();
    94100  //! makes functions with one string
    95   FUNCTOR_LIST(1)(l_STRING);
     101  FUNCTOR_LIST(1)(l_CSTRING);
    96102  //! makes functions with two strings
    97   FUNCTOR_LIST(2)(l_STRING, l_STRING);
     103  FUNCTOR_LIST(2)(l_CSTRING, l_CSTRING);
    98104  //! makes functions with three strings
    99   FUNCTOR_LIST(3)(l_STRING, l_STRING, l_STRING);
     105  FUNCTOR_LIST(3)(l_CSTRING, l_CSTRING, l_CSTRING);
    100106  //! makes functions with four strings
    101   FUNCTOR_LIST(4)(l_STRING, l_STRING, l_STRING, l_STRING);
     107  FUNCTOR_LIST(4)(l_CSTRING, l_CSTRING, l_CSTRING, l_CSTRING);
    102108
    103109  //! makes functions with one bool
     
    135141
    136142  //! mixed values:
    137   FUNCTOR_LIST(2)(l_STRING, l_FLOAT);
     143  FUNCTOR_LIST(2)(l_CSTRING, l_FLOAT);
    138144  FUNCTOR_LIST(2)(l_UINT, l_LONG);
    139   FUNCTOR_LIST(2)(l_STRING, l_UINT);
     145  FUNCTOR_LIST(2)(l_CSTRING, l_UINT);
    140146
    141   FUNCTOR_LIST(3)(l_STRING, l_FLOAT, l_UINT);
     147  FUNCTOR_LIST(3)(l_CSTRING, l_FLOAT, l_UINT);
    142148
    143149
  • trunk/src/lib/util/loading/resource_manager.cc

    r7196 r7199  
    451451        tmpResource->param[0] = param0;
    452452        tmpResource->param[1] = param1;
    453         tmpResource->pointer = new MD2Data(fullName, tmpResource->param[0].getString(), tmpResource->param[1].getFloat());
     453        tmpResource->pointer = new MD2Data(fullName, tmpResource->param[0].getCString(), tmpResource->param[1].getFloat());
    454454      }
    455455      break;
     
    520520        {
    521521          MultiType param = param0; /// HACK
    522           char* secFullName = ResourceManager::getFullName(param.getString());
     522          char* secFullName = ResourceManager::getFullName(param.getCString());
    523523          if (ResourceManager::isFile(secFullName))
    524524          {
     
    747747  int len = strlen(ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));
    748748  len += strlen(this->resourceList[i]->name);
    749   if (this->resourceList[i]->param[0].getString()) len += strlen(this->resourceList[i]->param[0].getString()) +1;
    750   if (this->resourceList[i]->param[1].getString()) len += strlen(this->resourceList[i]->param[1].getString()) +1;
    751   if (this->resourceList[i]->param[2].getString()) len += strlen(this->resourceList[i]->param[2].getString()) +1;
     749  if (this->resourceList[i]->param[0].getCString()) len += strlen(this->resourceList[i]->param[0].getCString()) +1;
     750  if (this->resourceList[i]->param[1].getCString()) len += strlen(this->resourceList[i]->param[1].getCString()) +1;
     751  if (this->resourceList[i]->param[2].getCString()) len += strlen(this->resourceList[i]->param[2].getCString()) +1;
    752752  len += 10;
    753753  char* tmp = new char[len];
     
    756756  strcat(tmp,",");
    757757  strcat (tmp, this->resourceList[i]->name);
    758   if (this->resourceList[i]->param[0].getString() && this->resourceList[i]->param[0].getString() != '\0')
     758  if (this->resourceList[i]->param[0].getCString() && this->resourceList[i]->param[0].getCString() != '\0')
    759759  {
    760760    strcat(tmp,",");
    761     strcat( tmp, this->resourceList[i]->param[0].getString());
    762   }
    763   if (this->resourceList[i]->param[1].getString() && this->resourceList[i]->param[1].getString() != '\0')
     761    strcat( tmp, this->resourceList[i]->param[0].getCString());
     762  }
     763  if (this->resourceList[i]->param[1].getCString() && this->resourceList[i]->param[1].getCString() != '\0')
    764764  {
    765765    strcat(tmp,",");
    766     strcat( tmp, this->resourceList[i]->param[1].getString());
    767   }
    768   if (this->resourceList[i]->param[2].getString() && this->resourceList[i]->param[2].getString() != '\0')
     766    strcat( tmp, this->resourceList[i]->param[1].getCString());
     767  }
     768  if (this->resourceList[i]->param[2].getCString() && this->resourceList[i]->param[2].getCString() != '\0')
    769769  {
    770770    strcat(tmp,",");
    771     strcat( tmp, this->resourceList[i]->param[2].getString());
     771    strcat( tmp, this->resourceList[i]->param[2].getCString());
    772772  }
    773773  return tmp;
  • trunk/src/lib/util/multi_type.cc

    r7197 r7199  
    2323#include <string.h>
    2424#include <stdio.h>
     25#include <sstream>
    2526
    2627#ifdef DEBUG
     
    3132
    3233/**
    33  * creates a multiType without any stored value at all.
     34 * @brief creates a multiType without any stored value at all.
    3435 */
    3536MultiType::MultiType(MT_Type type)
     
    3940}
    4041/**
    41  * creates a multiType out of a boolean
     42 * @brief creates a multiType out of a boolean
    4243 * @param value the Value of this MulitType
    4344 */
     
    4950
    5051/**
    51  * creates a multiType out of an integer
     52 * @brief creates a multiType out of an integer
    5253 * @param value the Value of this MulitType
    5354 */
     
    5960
    6061/**
    61  * creates a multiType out of a float (double)
     62 * @brief creates a multiType out of a float (double)
    6263 * @param value the Value of this MulitType
    6364 */
     
    6970
    7071/**
    71  * creates a multiType out of a char
     72 * @brief creates a multiType out of a char
    7273 * @param value the Value of this MulitType
    7374 */
     
    7980
    8081/**
    81  * creates a multiType out of a String
     82 * @brief creates a multiType out of a C-String
    8283 * @param value the Value of this MulitType
    8384 */
     
    8889}
    8990
     91/**
     92 * @brief creates a multiType out of a String
     93 * @param value the Value of this MulitType
     94 */
     95MultiType::MultiType(const std::string& value)
     96{
     97  this->init();
     98  this->setString(value);
     99}
     100
     101/**
     102 * @brief constructs a new MultiType from another one (copy)
     103 */
    90104MultiType::MultiType(const MultiType& multiType)
    91105{
    92   this->init();
    93106  *this = multiType;
    94107}
    95108
    96109/**
    97  * standard deconstructor
     110 * @brief standard deconstructor
    98111*/
    99112MultiType::~MultiType ()
    100 {
    101   if (this->storedString != NULL)
    102     delete[] this->storedString;
    103 }
    104 
    105 /**
    106  * copy Constructor
     113{ }
     114
     115/**
     116 * @brief copy operator
    107117 * @param mt: the entity to copy
    108  * @returns a Copy of itself. (strings inside are copied as well)
     118 * @returns A Copy of itself. (strings inside are copied as well)
    109119 */
    110120MultiType& MultiType::operator= (const MultiType& mt)
     
    112122  this->type = mt.type;
    113123  this->value = mt.value;
    114   if (mt.type == MT_STRING && mt.storedString != NULL)
    115   {
    116     this->setString(mt.storedString);
    117   }
    118   else
    119     this->storedString = NULL;
     124  this->storedString = mt.storedString;
     125
    120126  return *this;
    121127}
     
    148154      return (this->value.Float == mt.value.Float);
    149155    case MT_STRING:
    150       if (this->value.String != NULL && mt.value.String != NULL)
    151         return (!strcmp(this->value.String, mt.value.String));
    152       else
    153         return (this->value.String == NULL && mt.value.String == NULL);
    154   }
    155 }
    156 
    157 /**
    158  * @brief checks if the internal value matches the boolean value.
    159  * @param value to check against this one
    160  * @returns true on match. false otherwise
     156      return (this->storedString == mt.storedString);
     157  }
     158}
     159
     160
     161/**
     162 * @brief initializes the MultiType
     163 */
     164void MultiType::init()
     165{
     166  this->type = MT_NULL;
     167  this->value.Float = 0.0f;
     168}
     169
     170
     171/**
     172 * @brief sets the type of this MultiType and resets to the default value
     173 * @param type the new Type
     174 */
     175void MultiType::setType(MT_Type type)
     176{
     177  if (this->type == type)
     178    return;
     179
     180  switch (type)
     181  {
     182    case MT_BOOL:
     183      this->setBool(this->getBool());
     184      break;
     185    case MT_INT:
     186      this->setInt(this->getInt());
     187      break;
     188    case MT_FLOAT:
     189      this->setFloat(this->getFloat());
     190      break;
     191    case MT_CHAR:
     192      this->setChar(this->getChar());
     193      break;
     194    case MT_STRING:
     195      this->setString(this->getString());
     196      break;
     197  }
     198}
     199
     200/**
     201 * @brief sets the Value of mt without changing the type of this MultiType
     202 * @param mt: the MultiType to get the value from
    161203 *
    162  * Two MultiType match if and only if
    163  *  1. the stored values match the given Value
    164  */
    165 bool MultiType::operator==(const char* value) const
    166 {
    167   if (this->value.String != NULL && value != NULL)
    168     return (!strcmp(this->value.String, value));
    169   else
    170     return (this->value.String == NULL && value == NULL);
    171 }
    172 
    173 
    174 /**
    175  * initializes the MultiType
    176  */
    177 void MultiType::init()
    178 {
    179   this->type = MT_NULL;
    180   this->storedString = NULL;
    181   this->value.Float = 0.0f;
    182 }
    183 
    184 
    185 /**
    186  * sets the type of this MultiType and resets to the default value
    187  * @param type the new Type
    188  */
    189 void MultiType::setType(MT_Type type)
    190 {
    191   if (this->type != type)
    192     this->type = type;
    193 }
    194 
    195 /**
    196  * sets a new Value to the MultiType
     204 * This is a pure Value copy. The current type will be preserved.
     205 *
     206 * @TODO speedup
     207 */
     208void MultiType::setValueOf(const MultiType& mt)
     209{
     210  MT_Type prevType = this->type;
     211
     212  *this = mt;
     213  this->setType(prevType);
     214}
     215
     216
     217/**
     218 * @brief sets a new Value to the MultiType
    197219 * @param value the new Value as a bool
    198220 */
     
    204226
    205227/**
    206  * sets a new Value to the MultiType
     228 * @brief sets a new Value to the MultiType
    207229 * @param value the new Value as an int
    208230 */
     
    214236
    215237/**
    216  * sets a new Value to the MultiType
     238 * @brief sets a new Value to the MultiType
    217239 * @param value the new Value as a float
    218240 */
     
    224246
    225247/**
    226  * sets a new Value to the MultiType
     248 * @brief sets a new Value to the MultiType
    227249 * @param value the new Value as a char
    228250 */
     
    234256
    235257/**
    236  * sets a new Value to the MultiType
     258 * @brief sets a new Value to the MultiType
    237259 * @param value the new Value as a String
    238260 */
    239 void MultiType::setString(const char* value)
     261void MultiType::setString(const std::string& value)
    240262{
    241263  this->type = MT_STRING;
    242 
    243   if (this->storedString != NULL)
    244     delete[] this->storedString;
    245 
    246   if (value == NULL)
    247   {
    248     this->storedString = new char[1];
    249     this->storedString[0] = '\0';
    250     this->value.String = this->storedString;
    251     return;
    252   }
    253   else
    254   {
    255     this->storedString = new char[strlen(value)+1];
    256     strcpy(storedString, value);
    257     this->value.String = this->storedString;
    258   }
    259 }
    260 
    261 
    262 
    263 
    264 
     264  this->storedString = value;
     265}
     266
     267
     268/**************************
     269*** RETRIEVAL FUNCTIONS ***
     270**************************/
    265271/**
    266272 * @returns the Value of this MultiType as a int
     
    275281  else if (this->type & MT_FLOAT) return (this->value.Float == 0.0f)? false : true;
    276282  else if (this->type & MT_CHAR) return (this->value.Char == '\0')? false : true;
    277   else if (this->type & MT_STRING && this->value.String != NULL) return (!strncmp(this->value.String, "true", 4) || !strncmp(this->value.String, "TRUE", 4) || !strncmp(this->value.String, "1", 1))? true : false; //! @TODO make this better.
     283  else if (this->type & MT_STRING) return (this->storedString == "true" ||
     284                                            this->storedString == "TRUE" ||
     285                                            this->storedString != "0"); //! @TODO make this better...
    278286
    279287  return false;
     
    291299  else if (this->type & MT_FLOAT) return (int) this->value.Float;
    292300  else if (this->type & MT_CHAR) return (int) this->value.Char;
    293   else if (this->type & MT_STRING && this->value.String != NULL) {
     301  else if (this->type & MT_STRING)
     302  {
    294303    char* endPtr = NULL;
    295     int result = strtol(this->value.String, &endPtr, 10);
    296     if ( endPtr >= this->value.String && endPtr < this->value.String + strlen(this->value.String))
     304    int result = strtol(this->storedString.c_str(), &endPtr, 10);
     305    if ( endPtr >= this->storedString.c_str() && endPtr < this->storedString.c_str() + strlen(this->storedString.c_str()))
    297306      return 0;
    298307    else
    299308      return result;
    300309  }
    301 
    302310  return 0;
    303311}
    304312
     313
    305314/**
    306315 * @returns the Value of this MultiType as a float
     
    308317float MultiType::getFloat() const
    309318{
    310  // default case:
     319  // default case:
    311320  if (this->type & MT_FLOAT)
    312321    return this->value.Float;
     
    314323  else if (this->type & MT_INT) return (float) this->value.Int;
    315324  else if (this->type & MT_CHAR) return (float) this->value.Char;
    316   else if (this->type & MT_STRING && this->value.String != NULL) {
     325  else if (this->type & MT_STRING)
     326  {
    317327    char* endPtr = NULL;
    318     double result = strtod(this->value.String, &endPtr);
    319     if ( endPtr >= this->value.String && endPtr < this->value.String + strlen(this->value.String))
     328    double result = strtod(this->storedString.c_str(), &endPtr);
     329    if ( endPtr >= this->storedString.c_str() && endPtr < this->storedString.c_str() + strlen(this->storedString.c_str()))
    320330      return 0.0f;
    321331    else
    322332      return result;
    323333  }
    324 
    325334  return 0.0f;
    326335}
     
    332341char MultiType::getChar() const
    333342{
    334  // default case:
     343  // default case:
    335344  if (this->type & MT_INT)
    336345    return this->value.Int;
     
    338347  else if (this->type & MT_INT) return (int) this->value.Int;
    339348  else if (this->type & MT_FLOAT) return (char) this->value.Float;
    340   else if (this->type & MT_STRING && this->value.String != NULL) return *this->value.String;
     349  else if (this->type & MT_STRING) return this->storedString[0];
    341350
    342351  return '\0';
    343352}
    344353
     354
    345355/**
    346356 * @returns the Value of this MultiType as a String
    347357 */
    348 const char* MultiType::getString()
    349 {
    350  // default case:
     358std::string MultiType::getString() const
     359{
     360  // default case:
    351361  if (this->type & MT_STRING)
    352     return (this->value.String != NULL)? this->value.String : "";
     362    return this->storedString;
    353363  else
    354364  {
    355365    if (this->type & MT_BOOL) return (this->value.Bool)? "true" : "false";
    356     char tmpString[128];
    357     if (this->storedString != NULL)
    358     {
    359       delete[] this->storedString;
    360       this->storedString = NULL;
    361     }
     366
    362367    if (this->type & MT_CHAR)
    363368    {
    364       this->storedString = new char[2];
    365       this->storedString[0] = this->value.Char;
    366       this->storedString[1] = '\0';
    367       return this->storedString;
     369      char tmpString[2];
     370      tmpString[0] = this->value.Char;
     371      tmpString[1] = '\0';
     372      return tmpString;
    368373    }
    369374    else if (this->type & MT_INT)
    370375    {
     376      char tmpString[32];
    371377      sprintf(tmpString, "%d", this->value.Int);
    372       this->storedString = new char[strlen(tmpString)+1];
    373       strcpy (this->storedString, tmpString);
    374       return this->storedString;
     378      return tmpString;
    375379    }
    376     if (this->type & MT_FLOAT)
     380    else if (this->type & MT_FLOAT)
    377381    {
     382      char tmpString[64];
    378383      sprintf(tmpString, "%f", this->value.Float);
    379       this->storedString = new char[strlen (tmpString)+1];
    380       strcpy (this->storedString, tmpString);
    381       return this->storedString;
     384      return tmpString;
    382385    }
    383386  }
    384 
    385387  return "";
    386388}
    387389
    388390/**
    389  * prints out some nice debug output
    390  */
    391 void MultiType::debug()
     391 * @returns a formated c-string of the held value
     392 */
     393const char* MultiType::getCString()
     394{
     395  if (this->type & MT_STRING) return this->storedString.c_str();
     396  else
     397  {
     398    this->storedString = this->getString();
     399    return this->storedString.c_str();
     400  }
     401}
     402
     403/**
     404 * @brief prints out some nice debug output
     405 */
     406void MultiType::debug() const
    392407{
    393408#ifdef DEBUG
     
    396411  printf
    397412#endif
    398       ("MultiType of Type '%s' :: Values: BOOL: '%d', INT: '%d', FLOAT: '%f', CHAR: '%c', STRING '%s'\n",
    399          MultiType::MultiTypeToString(this->type),
    400          this->getBool(),
    401          this->getInt(),
    402          this->getFloat(),
    403          this->getChar(),
    404          this->getString()
    405       );
    406 
    407 
    408 }
    409 
    410 /**
    411  * Resets the MultiType to default values.
     413  ("MultiType of Type '%s' :: Values: BOOL: '%d', INT: '%d', FLOAT: '%f', CHAR: '%c', STRING '%s'\n",
     414   MultiType::MultiTypeToString(this->type),
     415   this->getBool(),
     416   this->getInt(),
     417   this->getFloat(),
     418   this->getChar(),
     419   this->getString().c_str()
     420  );
     421}
     422
     423
     424/**
     425 * @brief Resets the MultiType to default values.
    412426 */
    413427void MultiType::reset()
     
    438452
    439453/**
    440  * converts a MT_Type into a String
     454 * @brief converts a MT_Type into a String
    441455 * @param type: the MT_Type
    442456 * @returns: the Type as a constant String (do not delete)
     
    446460  switch ( type )
    447461  {
    448    default:
    449     return "NONE";
    450    case MT_BOOL:
    451     return "bool";
    452    case MT_INT:
    453     return "int";
    454    case MT_FLOAT:
    455     return "float";
    456    case MT_CHAR:
    457     return "char";
    458    case MT_STRING:
    459     return "string";
    460   }
    461 }
    462 
    463 /**
    464  * converts a String into a MT_Type
     462    default:
     463      return "NONE";
     464    case MT_BOOL:
     465      return "bool";
     466    case MT_INT:
     467      return "int";
     468    case MT_FLOAT:
     469      return "float";
     470    case MT_CHAR:
     471      return "char";
     472    case MT_STRING:
     473      return "string";
     474  }
     475}
     476
     477/**
     478 * @brief converts a String into a MT_Type
    465479 * @param type: the Type as a String
    466480 * @returns: the Type as MT_Type
  • trunk/src/lib/util/multi_type.h

    r7197 r7199  
    11/*!
    22 * @file multi_type.h
    3  * @brief Definition of ...
     3 * @brief Definition of a MultiType, that is able to hold one Value of many types.
    44 */
    55
    66#ifndef _MULTI_TYPE_H
    77#define _MULTI_TYPE_H
     8
     9#include <string>
    810
    911// FORWARD DECLARATION
     
    3840    MultiType(char value);
    3941    MultiType(const char* value);
     42    MultiType(const std::string& value);
    4043    MultiType(const MultiType& multiType);
    4144    virtual ~MultiType();
     
    4750    MultiType& operator=(char value) { this->setChar(value); return *this; };
    4851    MultiType& operator=(const char* value) { this->setString(value); return *this; };
     52    MultiType& operator=(const std::string& value) { this->setString(value); return *this; };
    4953
    5054    bool operator==(const MultiType& mt) const;
     
    5357    bool operator==(float value) const { return (this->getFloat() ==  value); };
    5458    bool operator==(char value) const { return (this->getChar() == value); };
    55     bool operator==(const char* value) const;
     59    bool operator==(const std::string& value) const { return (this->getString() == value); };
    5660    bool operator==(MT_Type type) const { return (this->type == type); }
    5761    bool operator!=(MT_Type type) const { return (this->type != type); }
     
    6367    void setFloat(float value);
    6468    void setChar(char value);
    65     void setString(const char* value);
     69    void setString(const std::string& value);
    6670
    6771    // for your convenience.
     
    7175    inline void setValue(char value) { this->setChar(value); };
    7276    inline void setValue(const char* value) { this->setString(value); };
     77    inline void setValue(const std::string& value) { this->setString(value); };
     78    void setValueOf(const MultiType& mt);
    7379
    7480    /** @returns the Type of the Value stored in this MultiType */
     
    8187    float getFloat() const;
    8288    char getChar() const;
    83     const char* getString();
     89    const char* getCString();
     90    std::string getString() const;
    8491
    8592    void reset();
    8693
    87     void debug();
     94    void debug() const;
    8895
    8996    static const char* MultiTypeToString(MT_Type type);
     
    101108      float             Float;
    102109      char              Char;
    103       char*             String;
    104 
     110//      std::string*      String;
    105111    }                   value;
    106112
    107113    MT_Type             type;
    108114
    109     char*               storedString;
     115    std::string         storedString;
    110116};
    111117
Note: See TracChangeset for help on using the changeset viewer.