Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7401 in orxonox.OLD


Ignore:
Timestamp:
Apr 27, 2006, 4:49:31 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: small fixes

Location:
trunk/src/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell_command.cc

    r7399 r7401  
    9090      std::vector<ShellCommand*>::iterator cmd;
    9191      for (cmd = cmdClass->commandList.begin(); cmd < cmdClass->commandList.end(); cmd++)
    92       {
    9392        if (commandName == (*cmd)->getName())
    94         {
    9593          delete (*cmd);
    96         }
    97       }
    9894    }
    9995  }
     
    166162            return true;
    167163          }
    168           /// TODO CHECK FOR STATIC functions.
    169164        }
    170165      }
     
    232227
    233228  /**
    234    * lets a command be described
     229   * @brief lets a command be described
    235230   * @param description the description of the Given command
    236231   */
     
    289284
    290285  /**
    291    * prints out nice information about the Shells Commands
     286   * @brief prints out nice information about the Shells Commands
    292287   */
    293288  void ShellCommand::debug()
     
    314309
    315310  /**
    316    * converts a Parameter to a String
     311   * @brief converts a Parameter to a String
    317312   * @param parameter the Parameter we have.
    318313   * @returns the Name of the Parameter at Hand
    319314   */
    320   const char* ShellCommand::paramToString(long parameter)
     315  const std::string& ShellCommand::paramToString(long parameter)
    321316  {
    322317    return MultiType::MultiTypeToString((MT_Type)parameter);
  • trunk/src/lib/shell/shell_command.h

    r7398 r7401  
    8282
    8383    static bool isRegistered(const std::string& commandName, const std::string& className);
    84     static const char* paramToString(long parameter);
     84    static const std::string& paramToString(long parameter);
    8585
    8686  private:
  • trunk/src/lib/util/multi_type.cc

    r7284 r7401  
    3939  switch (this->type)
    4040  {
    41     default:
     41      default:
    4242      this->value.Float = 0.0f;
    4343      break;
    44     case MT_BOOL:
     44      case MT_BOOL:
    4545      this->value.Bool = false;
    4646      break;
    47     case MT_INT:
     47      case MT_INT:
    4848      this->value.Int = 0;
    4949      break;
    50     case MT_FLOAT:
     50      case MT_FLOAT:
    5151      this->value.Float = 0.0f;
    5252      break;
    53     case MT_CHAR:
     53      case MT_CHAR:
    5454      this->value.Char = '\0';
    5555      break;
    56     case MT_STRING:
     56      case MT_STRING:
    5757      this->storedString = "";
    5858      break;
     
    148148  switch (this->type)
    149149  {
    150     case MT_NULL:
     150      case MT_NULL:
    151151      return true;
    152     case MT_BOOL:
     152      case MT_BOOL:
    153153      return (this->value.Bool == mt.value.Bool);
    154     case MT_INT:
     154      case MT_INT:
    155155      return (this->value.Int == mt.value.Int);
    156     case MT_CHAR:
     156      case MT_CHAR:
    157157      return (this->value.Char == mt.value.Char);
    158     case MT_FLOAT:
     158      case MT_FLOAT:
    159159      return (this->value.Float == mt.value.Float);
    160     case MT_STRING:
     160      case MT_STRING:
    161161      return (this->storedString == mt.storedString);
    162162  }
     
    175175  switch (type)
    176176  {
    177     case MT_BOOL:
     177      case MT_BOOL:
    178178      this->setBool(this->getBool());
    179179      break;
    180     case MT_INT:
     180      case MT_INT:
    181181      this->setInt(this->getInt());
    182182      break;
    183     case MT_FLOAT:
     183      case MT_FLOAT:
    184184      this->setFloat(this->getFloat());
    185185      break;
    186     case MT_CHAR:
     186      case MT_CHAR:
    187187      this->setChar(this->getChar());
    188188      break;
    189     case MT_STRING:
     189      case MT_STRING:
    190190      this->setString(this->getString());
    191191      break;
     
    405405#endif
    406406  ("MultiType of Type '%s' :: Values: BOOL: '%d', INT: '%d', FLOAT: '%f', CHAR: '%c', STRING '%s'\n",
    407    MultiType::MultiTypeToString(this->type),
     407   MultiType::MultiTypeToString(this->type).c_str(),
    408408   this->getBool(),
    409409   this->getInt(),
     
    422422  switch ( this->type )
    423423  {
    424     case MT_BOOL:
     424      case MT_BOOL:
    425425      this->setBool(false);
    426426      break;
    427     case MT_INT:
     427      case MT_INT:
    428428      this->setInt(0);
    429429      break;
    430     case MT_FLOAT:
     430      case MT_FLOAT:
    431431      this->setFloat(0.0f);
    432432      break;
    433     case MT_CHAR:
     433      case MT_CHAR:
    434434      this->setChar('\0');
    435435      break;
    436     case MT_STRING:
     436      case MT_STRING:
    437437      this->setString("");
    438438      break;
    439     default:
     439      default:
    440440#ifdef DEBUG
    441441      PRINTF(2)("Unknown Type not reseting\n");
     
    450450 * @returns: the Type as a constant String (do not delete)
    451451 */
    452 const char* MultiType::MultiTypeToString(MT_Type type)
     452const std::string& MultiType::MultiTypeToString(MT_Type type)
    453453{
    454454  switch ( type )
    455455  {
    456     case MT_BOOL:
    457       return "bool";
    458     case MT_INT:
    459       return "int";
    460     case MT_FLOAT:
    461       return "float";
    462     case MT_CHAR:
    463       return "char";
    464     case MT_STRING:
    465       return "string";
    466   }
    467   return "NONE";
     456      case MT_BOOL:
     457      return MultiType::typeNames[1];
     458      case MT_INT:
     459      return MultiType::typeNames[2];
     460      case MT_FLOAT:
     461      return MultiType::typeNames[3];
     462      case MT_CHAR:
     463      return MultiType::typeNames[4];
     464      case MT_STRING:
     465      return MultiType::typeNames[5];
     466  }
     467  return MultiType::typeNames[0];
    468468}
    469469
     
    475475MT_Type MultiType::StringToMultiType(const std::string& type)
    476476{
    477   if (type == "bool")
     477  if (type == MultiType::typeNames[1])
    478478    return MT_BOOL;
    479   if (type == "int")
     479  if (type == MultiType::typeNames[2])
    480480    return MT_INT;
    481   if (type, "float")
     481  if (type == MultiType::typeNames[3])
    482482    return MT_FLOAT;
    483   if (type == "char")
     483  if (type == MultiType::typeNames[4])
    484484    return MT_CHAR;
    485   if (type == "string")
     485  if (type == MultiType::typeNames[5])
    486486    return MT_STRING;
    487487
    488488  return MT_NULL;
    489489}
     490
     491
     492const std::string MultiType::typeNames[] =
     493  {
     494    "NONE",      //0
     495    "bool",      //1
     496    "int",       //2
     497    "float",     //3
     498    "char",      //4
     499    "string"     //5
     500  };
  • trunk/src/lib/util/multi_type.h

    r7225 r7401  
    9292    void debug() const;
    9393
    94     static const char* MultiTypeToString(MT_Type type);
     94    static const std::string& MultiTypeToString(MT_Type type);
    9595    static MT_Type StringToMultiType(const std::string& type);
    9696
    9797  private:
     98    //! A union, that combines types into as little memory as possible.
    9899    union MultiTypeValue
    99100    {
    100       bool              Bool;
    101       int               Int;
    102       float             Float;
    103       char              Char;
    104 //      std::string*      String;
    105     }                   value;
    106     std::string         storedString;
    107     MT_Type             type;
     101      bool                       Bool;              //!< If it is a BOOL
     102      int                        Int;               //!< If it is an INT
     103      float                      Float;             //!< If it is a FLOAT
     104      char                       Char;              //!< If it is a CHAR
     105    }                            value;             //!< The Value.
     106    std::string                  storedString;      //!< The Stored String.
     107    MT_Type                      type;              //!< The Type stored in this MultiType
     108
     109    static const std::string     typeNames[];       //!< List of TypeNames for conversion.
    108110};
    109111
Note: See TracChangeset for help on using the changeset viewer.