Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5552 in orxonox.OLD for trunk/src/lib/shell


Ignore:
Timestamp:
Nov 12, 2005, 1:40:06 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: ShellCommand now uses MultiType instead of many different strange constellations →
saves space and complexity (a bit complexity at least)

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

Legend:

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

    r5374 r5552  
    259259tList<ShellCommandAlias>* ShellCommandClass::aliasList = NULL;
    260260
     261
     262
     263
     264
     265
     266
     267
     268
     269
     270////////////////////////
     271// SHELL COMMAND BASE //
     272////////////////////////
    261273/**
    262274 * constructs and registers a new Command
     
    282294  this->paramCount = paramCount;
    283295  this->parameters = new unsigned int[paramCount];
     296  this->defaultValue = new MultiType[paramCount];
    284297
    285298  va_list parameterList;
    286299  va_start(parameterList, paramCount);
    287300
     301  // What Parameters we have got
    288302  for (unsigned int i = 0; i < paramCount; i++)
    289   {
    290303    this->parameters[i] = va_arg(parameterList, int);
    291 
    292     switch (this->parameters[i])
    293     {
    294       case ParameterBool:
    295         this->defaultBools[i] = va_arg(parameterList, int);
    296         break;
    297       case ParameterChar:
    298         this->defaultStrings[i] = new char[2];
    299         sprintf(this->defaultStrings[0], "%c",  va_arg(parameterList, int));
    300         break;
    301       case ParameterString:
    302         this->defaultStrings[i] = va_arg(parameterList, char*);
    303         break;
    304       case ParameterInt:
    305         this->defaultInts[i] = va_arg(parameterList, int);
    306         break;
    307       case ParameterUInt:
    308         this->defaultInts[i] = va_arg(parameterList, unsigned int);
    309         break;
    310       case ParameterFloat:
    311         this->defaultFloats[i] = va_arg(parameterList, double);
    312         break;
    313       case ParameterLong:
    314         this->defaultInts[i] = va_arg(parameterList, long);
    315         break;
    316       default:
    317         break;
    318     }
    319   }
    320304}
    321305
     
    327311{
    328312  delete[] this->parameters;
     313  delete[] this->defaultValue;
    329314  if (this->alias != NULL && ShellCommandClass::aliasList != NULL)
    330315  {
     
    598583  for (unsigned int i = 0; i < count; i++)
    599584  {
     585
     586
    600587    switch (this->parameters[i])
    601588    {
    602589      case ParameterBool:
    603         this->defaultBools[i] = va_arg(defaultList, int);
     590        this->defaultValue[i].setInt(va_arg(defaultList, int));
    604591        break;
    605592      case ParameterChar:
    606         this->defaultStrings[i] = new char[2];
    607         sprintf(this->defaultStrings[0], "%c",  va_arg(defaultList, int));
     593        this->defaultValue[i].setChar((char)va_arg(defaultList, int));
    608594        break;
    609595      case ParameterString:
    610         this->defaultStrings[i] = va_arg(defaultList, char*);
     596        this->defaultValue[i].setString(va_arg(defaultList, char*));
    611597        break;
    612598      case ParameterInt:
    613         this->defaultInts[i] = va_arg(defaultList, int);
     599        this->defaultValue[i].setInt(va_arg(defaultList, int));
    614600        break;
    615601      case ParameterUInt:
    616         this->defaultInts[i] = va_arg(defaultList, unsigned int);
     602        this->defaultValue[i].setInt((int)va_arg(defaultList, unsigned int));
    617603        break;
    618604      case ParameterFloat:
    619         this->defaultFloats[i] = va_arg(defaultList, double);
     605        this->defaultValue[i].setFloat(va_arg(defaultList, double));
    620606        break;
    621607      case ParameterLong:
    622         this->defaultInts[i] = va_arg(defaultList, long);
     608        this->defaultValue[i].setInt((int) va_arg(defaultList, long));
    623609        break;
    624610      default:
     
    626612    }
    627613  }
    628 
    629614  return this;
    630615}
  • trunk/src/lib/shell/shell_command.h

    r5551 r5552  
    1010
    1111#include "helper_functions.h"
     12#include "multi_type.h"
    1213#include "substring.h"
    1314#include "functor_list.h"
     
    133134    unsigned int                     paramCount;                           //!< the count of parameters.
    134135    unsigned int*                    parameters;                           //!< Parameters the function of this Command takes.
    135     char*                            defaultStrings[FUNCTOR_MAX_ARGUMENTS];//!< A list of default Strings stored.
    136     int                              defaultInts[FUNCTOR_MAX_ARGUMENTS];   //!< A list of default Ints stored.
    137     float                            defaultFloats[FUNCTOR_MAX_ARGUMENTS]; //!< A list of default Floats stored.
    138     bool                             defaultBools[FUNCTOR_MAX_ARGUMENTS];  //!< A list of default Bools stored.
    139 
     136    MultiType*                       defaultValue;                         //!< Default Values.
    140137
    141138  private:
     
    153150/////////////////////////////////
    154151//! where to chek for default BOOL values
    155 #define   l_BOOL_DEFGRAB(i)         this->defaultBools[i]
     152#define   l_BOOL_DEFGRAB(i)         this->defaultValue[i].getBool()
    156153//! where to chek for default INT values
    157 #define   l_INT_DEFGRAB(i)          this->defaultInts[i]
     154#define   l_INT_DEFGRAB(i)          this->defaultValue[i].getInt()
    158155//! where to chek for default UINT values
    159 #define   l_UINT_DEFGRAB(i)         (unsigned int)this->defaultInts[i]
     156#define   l_UINT_DEFGRAB(i)         (unsigned int)this->defaultValue[i].getInt()
    160157//! where to chek for default LONG values
    161 #define   l_LONG_DEFGRAB(i)         (long)this->defaultInts[i]
     158#define   l_LONG_DEFGRAB(i)         (long)this->defaultValue[i].getInt()
    162159//! where to chek for default FLOAT values
    163 #define   l_FLOAT_DEFGRAB(i)        this->defaultFloats[i]
     160#define   l_FLOAT_DEFGRAB(i)        this->defaultValue[i].getFloat()
    164161//! where to chek for default STRING values
    165 #define   l_STRING_DEFGRAB(i)       this->defaultStrings[i]
     162#define   l_STRING_DEFGRAB(i)       this->defaultValue[i].getString()
    166163
    167164//////////////////////////
     
    183180//! registers a command with 1 parameter
    184181#define ShellCommandRegister1(t1) \
    185   static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE), t1##_TYPE d1 = t1##_DEFAULT) \
     182  static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE)) \
    186183  { \
    187184    if (isRegistered(commandName, className, 1, t1##_PARAM)== true) \
    188185      return NULL; \
    189     return new SHELLCOMMAND<T>(commandName, className, function, d1); \
     186    return new SHELLCOMMAND<T>(commandName, className, function); \
    190187  }
    191188
    192189//! registers a command with 2 parameters
    193190#define ShellCommandRegister2(t1,t2) \
    194   static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT) \
     191  static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE)) \
    195192  { \
    196193    if (isRegistered(commandName, className, 2, t1##_PARAM, t2##_PARAM)== true) \
    197194      return NULL; \
    198     return new SHELLCOMMAND<T>(commandName, className, function, d1, d2); \
     195    return new SHELLCOMMAND<T>(commandName, className, function); \
    199196  }
    200197
    201198//! registers a command with 3 parameters
    202199#define ShellCommandRegister3(t1,t2,t3) \
    203   static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT) \
     200  static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE)) \
    204201  { \
    205202    if (isRegistered(commandName, className, 3, t1##_PARAM, t2##_PARAM, t3##_PARAM)== true) \
    206203      return NULL; \
    207     return new SHELLCOMMAND<T>(commandName, className, function, d1, d2, d3); \
     204    return new SHELLCOMMAND<T>(commandName, className, function); \
    208205  }
    209206
    210207//! registers a command with 4 parameters
    211208#define ShellCommandRegister4(t1,t2,t3,t4) \
    212   static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT) \
     209  static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE)) \
    213210  { \
    214211    if (isRegistered(commandName, className, 4, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM)== true) \
    215212      return NULL; \
    216     return new SHELLCOMMAND<T>(commandName, className, function, d1, d2, d3, d4); \
     213    return new SHELLCOMMAND<T>(commandName, className, function); \
    217214  }
    218215
    219216//! registers a command with 5 parameters
    220217#define ShellCommandRegister5(t1,t2,t3,t4,t5) \
    221   static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT, t5##_TYPE d5 = t5##_DEFAULT) \
     218  static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE)) \
    222219  { \
    223220    if (isRegistered(commandName, className, 5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM)== true) \
    224221      return NULL; \
    225     return new ShellCommand<T>(commandName, className, function, d1, d2, d3, d4, d5); \
     222    return new ShellCommand<T>(commandName, className, function); \
    226223  }
    227224
     
    264261//! creates a command that takes one parameter
    265262#define ShellCommandConstructor1(t1) \
    266   SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE), t1##_TYPE d1) \
    267   : ShellCommandBase(commandName, className, 1, t1##_PARAM, d1) \
     263  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE)) \
     264  : ShellCommandBase(commandName, className, 1, t1##_PARAM) \
    268265  { \
    269266    this->functorType = SHELLCOMMANDTYPE; \
     
    273270//! creates a command that takes two parameters
    274271#define ShellCommandConstructor2(t1,t2) \
    275   SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1, t2##_TYPE d2) \
    276   : ShellCommandBase(commandName, className, 2, t1##_PARAM, d1, t2##_PARAM, d2) \
     272  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE)) \
     273  : ShellCommandBase(commandName, className, 2, t1##_PARAM, t2##_PARAM) \
    277274  { \
    278275    this->functorType = SHELLCOMMANDTYPE; \
     
    282279//! creates a command that takes three parameter
    283280#define ShellCommandConstructor3(t1,t2,t3) \
    284   SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3) \
    285   : ShellCommandBase(commandName, className, 3, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3) \
     281  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE)) \
     282  : ShellCommandBase(commandName, className, 3, t1##_PARAM, t2##_PARAM, t3##_PARAM) \
    286283  { \
    287284    this->functorType = SHELLCOMMANDTYPE; \
     
    291288//! creates a command that takes four parameter
    292289#define ShellCommandConstructor4(t1,t2,t3,t4) \
    293   SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4) \
    294   : ShellCommandBase(commandName, className, 4, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4) \
     290  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE)) \
     291  : ShellCommandBase(commandName, className, 4, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM) \
    295292  { \
    296293    this->functorType = SHELLCOMMANDTYPE; \
     
    300297//! creates a command that takes five parameter
    301298#define ShellCommandConstructor5(t1,t2,t3,t4,t5) \
    302   SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4, t5##_TYPE d5) \
    303   : ShellCommandBase(commandName, className, 5, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4, t5##_PARAM, d5) \
     299  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE)) \
     300  : ShellCommandBase(commandName, className, 5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM) \
    304301  { \
    305302    this->functorType = SHELLCOMMANDTYPE; \
Note: See TracChangeset for help on using the changeset viewer.