Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Nov 12, 2005, 12:56:32 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: ShellCommands use less memory due to the use of unions.

File:
1 edited

Legend:

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

    r5391 r5551  
    226226  }
    227227
     228///////////////////////
     229// FUNCTION POINTERS //
     230///////////////////////
     231#define ShellCommandFunctionPoiter0() \
     232  void SHELLCOMMANDINCLASS(*functionPointer_0)();
     233
     234#define ShellCommandFunctionPoiter1(t1) \
     235  void SHELLCOMMANDINCLASS(*functionPointer_1_##t1)(t1##_TYPE);
     236
     237#define ShellCommandFunctionPoiter2(t1, t2) \
     238  void SHELLCOMMANDINCLASS(*functionPointer_2_##t1##_##t2)(t1##_TYPE, t2##_TYPE);
     239
     240
     241#define ShellCommandFunctionPoiter3(t1, t2, t3) \
     242  void SHELLCOMMANDINCLASS(*functionPointer_3_##t1##_##t2##_##t3)(t1##_TYPE, t2##_TYPE, t3##_TYPE);
     243
     244#define ShellCommandFunctionPoiter4(t1, t2, t3, t4) \
     245  void SHELLCOMMANDINCLASS(*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE);
     246
     247
     248#define ShellCommandFunctionPoiter5(t1, t2, t3, t4, t5) \
     249  void SHELLCOMMANDINCLASS(*functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE); \
     250
     251
    228252//////////////////
    229253// CONSTRUCTORS //
     
    231255//! creates a command that takes no parameters
    232256#define ShellCommandConstructor0() \
    233   void SHELLCOMMANDINCLASS(*functionPointer_0)(); \
    234257  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)()) \
    235258  : ShellCommandBase(commandName, className, 0) \
    236259  { \
    237260    this->functorType = SHELLCOMMANDTYPE; \
    238     this->functionPointer_0 = function; \
     261    this->fp.functionPointer_0 = function; \
    239262  }
    240263
    241264//! creates a command that takes one parameter
    242265#define ShellCommandConstructor1(t1) \
    243   void SHELLCOMMANDINCLASS(*functionPointer_1_##t1)(t1##_TYPE); \
    244266  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE), t1##_TYPE d1) \
    245267  : ShellCommandBase(commandName, className, 1, t1##_PARAM, d1) \
    246268  { \
    247269    this->functorType = SHELLCOMMANDTYPE; \
    248     this->functionPointer_1_##t1 = function; \
     270    this->fp.functionPointer_1_##t1 = function; \
    249271  }
    250272
    251273//! creates a command that takes two parameters
    252274#define ShellCommandConstructor2(t1,t2) \
    253   void SHELLCOMMANDINCLASS(*functionPointer_2_##t1##_##t2)(t1##_TYPE, t2##_TYPE); \
    254275  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1, t2##_TYPE d2) \
    255276  : ShellCommandBase(commandName, className, 2, t1##_PARAM, d1, t2##_PARAM, d2) \
    256277  { \
    257278    this->functorType = SHELLCOMMANDTYPE; \
    258     this->functionPointer_2_##t1##_##t2 = function; \
     279    this->fp.functionPointer_2_##t1##_##t2 = function; \
    259280  }
    260281
    261282//! creates a command that takes three parameter
    262283#define ShellCommandConstructor3(t1,t2,t3) \
    263   void SHELLCOMMANDINCLASS(*functionPointer_3_##t1##_##t2##_##t3)(t1##_TYPE, t2##_TYPE, t3##_TYPE); \
    264284  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) \
    265285  : ShellCommandBase(commandName, className, 3, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3) \
    266286  { \
    267287    this->functorType = SHELLCOMMANDTYPE; \
    268     this->functionPointer_3_##t1##_##t2##_##t3 = function; \
     288    this->fp.functionPointer_3_##t1##_##t2##_##t3 = function; \
    269289  }
    270290
    271291//! creates a command that takes four parameter
    272292#define ShellCommandConstructor4(t1,t2,t3,t4) \
    273   void SHELLCOMMANDINCLASS(*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE); \
    274293  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) \
    275294  : ShellCommandBase(commandName, className, 4, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4) \
    276295  { \
    277296    this->functorType = SHELLCOMMANDTYPE; \
    278     this->functionPointer_4_##t1##_##t2##_##t3##_##t4 = function; \
     297    this->fp.functionPointer_4_##t1##_##t2##_##t3##_##t4 = function; \
    279298  }
    280299
    281300//! creates a command that takes five parameter
    282301#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); \
    284302  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) \
    285303  : ShellCommandBase(commandName, className, 5, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4, t5##_PARAM, d5) \
    286304  { \
    287305    this->functorType = SHELLCOMMANDTYPE; \
    288     this->functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5 = function; \
     306    this->fp.functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5 = function; \
    289307  }
    290308
     
    337355#undef SHELLCOMMANDEXECUTER
    338356#endif
    339 #define SHELLCOMMANDEXECUTER(nameExt)      (dynamic_cast<T*>(object)->*functionPointer##nameExt)
     357#define SHELLCOMMANDEXECUTER(nameExt)      (dynamic_cast<T*>(object)->*(fp.functionPointer##nameExt))
    340358#ifdef SHELLCOMMANDINCLASS
    341359#undef SHELLCOMMANDINCLASS
     
    353371
    354372  private:
     373//! FUNCTOR_LIST is the List of FunctionPointers
     374    union FunctionPointers {
     375#define FUNCTOR_LIST(x) ShellCommandFunctionPoiter ## x
     376#include "functor_list.h"
     377#undef FUNCTOR_LIST
     378    } fp;
     379
    355380//! FUNCTOR_LIST is the List of CommandConstructors
    356381#define FUNCTOR_LIST(x) ShellCommandConstructor ## x
     
    382407#undef SHELLCOMMANDEXECUTER
    383408#endif
    384 #define SHELLCOMMANDEXECUTER(nameExt)     functionPointer##nameExt
     409#define SHELLCOMMANDEXECUTER(nameExt)     fp.functionPointer##nameExt
    385410#ifdef SHELLCOMMANDINCLASS
    386411#undef SHELLCOMMANDINCLASS
     
    398423
    399424  private:
     425//! FUNCTOR_LIST is the List of FunctionPointers
     426    union FunctionPointers {
     427#define FUNCTOR_LIST(x) ShellCommandFunctionPoiter ## x
     428#include "functor_list.h"
     429#undef FUNCTOR_LIST
     430    } fp;
     431
    400432//! FUNCTOR_LIST is the List of CommandConstructors
    401433#define FUNCTOR_LIST(x) ShellCommandConstructor ## x
Note: See TracChangeset for help on using the changeset viewer.