Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 13, 2005, 3:10:49 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/world_entities: merged the Trunk to the world_entities branche
merged with command
svn merge -r5516:HEAD ../trunk/ world_entities/
no conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/world_entities/src/lib/shell/shell_command.h

    r5391 r5558  
    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); \
    226   }
     222    return new ShellCommand<T>(commandName, className, function); \
     223  }
     224
     225///////////////////////
     226// FUNCTION POINTERS //
     227///////////////////////
     228#define ShellCommandFunctionPoiter0() \
     229  void SHELLCOMMANDINCLASS(*functionPointer_0)();
     230
     231#define ShellCommandFunctionPoiter1(t1) \
     232  void SHELLCOMMANDINCLASS(*functionPointer_1_##t1)(t1##_TYPE);
     233
     234#define ShellCommandFunctionPoiter2(t1, t2) \
     235  void SHELLCOMMANDINCLASS(*functionPointer_2_##t1##_##t2)(t1##_TYPE, t2##_TYPE);
     236
     237
     238#define ShellCommandFunctionPoiter3(t1, t2, t3) \
     239  void SHELLCOMMANDINCLASS(*functionPointer_3_##t1##_##t2##_##t3)(t1##_TYPE, t2##_TYPE, t3##_TYPE);
     240
     241#define ShellCommandFunctionPoiter4(t1, t2, t3, t4) \
     242  void SHELLCOMMANDINCLASS(*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE);
     243
     244
     245#define ShellCommandFunctionPoiter5(t1, t2, t3, t4, t5) \
     246  void SHELLCOMMANDINCLASS(*functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE); \
     247
    227248
    228249//////////////////
     
    231252//! creates a command that takes no parameters
    232253#define ShellCommandConstructor0() \
    233   void SHELLCOMMANDINCLASS(*functionPointer_0)(); \
    234254  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)()) \
    235255  : ShellCommandBase(commandName, className, 0) \
    236256  { \
    237257    this->functorType = SHELLCOMMANDTYPE; \
    238     this->functionPointer_0 = function; \
     258    this->fp.functionPointer_0 = function; \
    239259  }
    240260
    241261//! creates a command that takes one parameter
    242262#define ShellCommandConstructor1(t1) \
    243   void SHELLCOMMANDINCLASS(*functionPointer_1_##t1)(t1##_TYPE); \
    244   SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE), t1##_TYPE d1) \
    245   : ShellCommandBase(commandName, className, 1, t1##_PARAM, d1) \
    246   { \
    247     this->functorType = SHELLCOMMANDTYPE; \
    248     this->functionPointer_1_##t1 = function; \
     263  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE)) \
     264  : ShellCommandBase(commandName, className, 1, t1##_PARAM) \
     265  { \
     266    this->functorType = SHELLCOMMANDTYPE; \
     267    this->fp.functionPointer_1_##t1 = function; \
    249268  }
    250269
    251270//! creates a command that takes two parameters
    252271#define ShellCommandConstructor2(t1,t2) \
    253   void SHELLCOMMANDINCLASS(*functionPointer_2_##t1##_##t2)(t1##_TYPE, t2##_TYPE); \
    254   SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1, t2##_TYPE d2) \
    255   : ShellCommandBase(commandName, className, 2, t1##_PARAM, d1, t2##_PARAM, d2) \
    256   { \
    257     this->functorType = SHELLCOMMANDTYPE; \
    258     this->functionPointer_2_##t1##_##t2 = function; \
     272  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE)) \
     273  : ShellCommandBase(commandName, className, 2, t1##_PARAM, t2##_PARAM) \
     274  { \
     275    this->functorType = SHELLCOMMANDTYPE; \
     276    this->fp.functionPointer_2_##t1##_##t2 = function; \
    259277  }
    260278
    261279//! creates a command that takes three parameter
    262280#define ShellCommandConstructor3(t1,t2,t3) \
    263   void SHELLCOMMANDINCLASS(*functionPointer_3_##t1##_##t2##_##t3)(t1##_TYPE, t2##_TYPE, t3##_TYPE); \
    264   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) \
    265   : ShellCommandBase(commandName, className, 3, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3) \
    266   { \
    267     this->functorType = SHELLCOMMANDTYPE; \
    268     this->functionPointer_3_##t1##_##t2##_##t3 = function; \
     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) \
     283  { \
     284    this->functorType = SHELLCOMMANDTYPE; \
     285    this->fp.functionPointer_3_##t1##_##t2##_##t3 = function; \
    269286  }
    270287
    271288//! creates a command that takes four parameter
    272289#define ShellCommandConstructor4(t1,t2,t3,t4) \
    273   void SHELLCOMMANDINCLASS(*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE); \
    274   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) \
    275   : ShellCommandBase(commandName, className, 4, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4) \
    276   { \
    277     this->functorType = SHELLCOMMANDTYPE; \
    278     this->functionPointer_4_##t1##_##t2##_##t3##_##t4 = function; \
     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) \
     292  { \
     293    this->functorType = SHELLCOMMANDTYPE; \
     294    this->fp.functionPointer_4_##t1##_##t2##_##t3##_##t4 = function; \
    279295  }
    280296
    281297//! creates a command that takes five parameter
    282298#define ShellCommandConstructor5(t1,t2,t3,t4,t5) \
    283   void SHELLCOMMANDINCLASS(*functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE); \
    284   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) \
    285   : ShellCommandBase(commandName, className, 5, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4, t5##_PARAM, d5) \
    286   { \
    287     this->functorType = SHELLCOMMANDTYPE; \
    288     this->functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5 = function; \
     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) \
     301  { \
     302    this->functorType = SHELLCOMMANDTYPE; \
     303    this->fp.functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5 = function; \
    289304  }
    290305
     
    337352#undef SHELLCOMMANDEXECUTER
    338353#endif
    339 #define SHELLCOMMANDEXECUTER(nameExt)      (dynamic_cast<T*>(object)->*functionPointer##nameExt)
     354#define SHELLCOMMANDEXECUTER(nameExt)      (dynamic_cast<T*>(object)->*(fp.functionPointer##nameExt))
    340355#ifdef SHELLCOMMANDINCLASS
    341356#undef SHELLCOMMANDINCLASS
     
    353368
    354369  private:
     370//! FUNCTOR_LIST is the List of FunctionPointers
     371    union FunctionPointers {
     372#define FUNCTOR_LIST(x) ShellCommandFunctionPoiter ## x
     373#include "functor_list.h"
     374#undef FUNCTOR_LIST
     375    } fp;
     376
    355377//! FUNCTOR_LIST is the List of CommandConstructors
    356378#define FUNCTOR_LIST(x) ShellCommandConstructor ## x
     
    382404#undef SHELLCOMMANDEXECUTER
    383405#endif
    384 #define SHELLCOMMANDEXECUTER(nameExt)     functionPointer##nameExt
     406#define SHELLCOMMANDEXECUTER(nameExt)     fp.functionPointer##nameExt
    385407#ifdef SHELLCOMMANDINCLASS
    386408#undef SHELLCOMMANDINCLASS
     
    398420
    399421  private:
     422//! FUNCTOR_LIST is the List of FunctionPointers
     423    union FunctionPointers {
     424#define FUNCTOR_LIST(x) ShellCommandFunctionPoiter ## x
     425#include "functor_list.h"
     426#undef FUNCTOR_LIST
     427    } fp;
     428
    400429//! FUNCTOR_LIST is the List of CommandConstructors
    401430#define FUNCTOR_LIST(x) ShellCommandConstructor ## x
Note: See TracChangeset for help on using the changeset viewer.