Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5636 in orxonox.OLD for trunk


Ignore:
Timestamp:
Nov 18, 2005, 6:55:18 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: adapting ShellCommand to use Executor.
On the go

Location:
trunk/src
Files:
6 edited

Legend:

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

    r5634 r5636  
    4040  this->className = className;
    4141  this->classID = CL_NULL;
    42   this->commandList = new tList<ShellCommandBase>;
     42  this->commandList = new tList<ShellCommand>;
    4343
    4444  ShellCommandClass::commandClassList->add(this);
     
    5050ShellCommandClass::~ShellCommandClass()
    5151{
    52   tIterator<ShellCommandBase>* iterator = this->commandList->getIterator();
    53   ShellCommandBase* elem = iterator->firstElement();
     52  tIterator<ShellCommand>* iterator = this->commandList->getIterator();
     53  ShellCommand* elem = iterator->firstElement();
    5454  while(elem != NULL)
    5555  {
     
    7878    if (!strcmp (elem->getName(), className))
    7979    {
    80       tIterator<ShellCommandBase>* itFkt = elem->commandList->getIterator();
    81       ShellCommandBase* command = itFkt->firstElement();
     80      tIterator<ShellCommand>* itFkt = elem->commandList->getIterator();
     81      ShellCommand* command = itFkt->firstElement();
    8282      while (command != NULL)
    8383      {
     
    120120void ShellCommandClass::unregisterAllCommands()
    121121{
    122   // unregister all commands
     122  if (ShellCommandClass::commandClassList != NULL)
     123  {
     124    // unregister all commands
     125    tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
     126    ShellCommandClass* elem = iterator->firstElement();
     127    while(elem != NULL)
     128    {
     129      delete elem;
     130
     131      elem = iterator->nextElement();
     132    }
     133    delete iterator;
     134
     135    delete ShellCommandClass::commandClassList;
     136    ShellCommandClass::commandClassList = NULL;
     137  }
     138
     139  // unregister all aliases (there should be nothing to do here :))
     140  if (ShellCommandClass::aliasList != NULL)
     141  {
     142    tIterator<ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator();
     143    ShellCommandAlias* elemAL = itAL->firstElement();
     144    while(elemAL != NULL)
     145    {
     146      delete elemAL;
     147      elemAL = itAL->nextElement();
     148    }
     149    delete itAL;
     150    delete ShellCommandClass::aliasList;
     151    ShellCommandClass::aliasList = NULL;
     152  }
     153}
     154
     155/**
     156 * checks if a Class is already registered to the Commands' class-stack
     157 * @param className the Name of the Class to check for
     158 * @returns the CommandClass if found, NULL otherwise
     159 */
     160const ShellCommandClass* ShellCommandClass::isRegistered(const char* className)
     161{
     162  if (ShellCommandClass::commandClassList == NULL)
     163    initCommandClassList();
     164
    123165  tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
    124166  ShellCommandClass* elem = iterator->firstElement();
    125167  while(elem != NULL)
    126168  {
    127     delete elem;
    128 
     169    if (!strcmp(className, elem->className))
     170    {
     171      if (elem->classID == CL_NULL)
     172        elem->classID = ClassList::StringToID(className);
     173
     174      delete iterator;
     175      return elem;
     176    }
    129177    elem = iterator->nextElement();
    130178  }
    131179  delete iterator;
    132 
    133   delete ShellCommandClass::commandClassList;
    134   ShellCommandClass::commandClassList = NULL;
    135 
    136   // unregister all aliases (there should be nothing to do here :))
    137   if (ShellCommandClass::aliasList != NULL)
    138   {
    139     tIterator<ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator();
    140     ShellCommandAlias* elemAL = itAL->firstElement();
    141     while(elemAL != NULL)
    142     {
    143       delete elemAL;
    144       elemAL = itAL->nextElement();
    145     }
    146     delete itAL;
    147     delete ShellCommandClass::aliasList;
    148     ShellCommandClass::aliasList = NULL;
    149   }
    150 }
    151 
    152 /**
    153  * checks if a Class is already registered to the Commands' class-stack
    154  * @param className the Name of the Class to check for
    155  * @returns the CommandClass if found, NULL otherwise
    156  */
    157 const ShellCommandClass* ShellCommandClass::isRegistered(const char* className)
     180  return NULL;
     181}
     182
     183/**
     184 * searches for a CommandClass
     185 * @param className the name of the CommandClass
     186 * @returns the CommandClass if found, or a new CommandClass if not
     187 */
     188ShellCommandClass* ShellCommandClass::getCommandClass(const char* className)
    158189{
    159190  if (ShellCommandClass::commandClassList == NULL)
     
    166197    if (!strcmp(className, elem->className))
    167198    {
    168       if (elem->classID == CL_NULL)
    169         elem->classID = ClassList::StringToID(className);
    170 
    171199      delete iterator;
    172200      return elem;
     
    175203  }
    176204  delete iterator;
    177   return NULL;
    178 }
    179 
    180 /**
    181  * searches for a CommandClass
    182  * @param className the name of the CommandClass
    183  * @returns the CommandClass if found, or a new CommandClass if not
    184  */
    185 ShellCommandClass* ShellCommandClass::getCommandClass(const char* className)
     205  return new ShellCommandClass(className);
     206}
     207
     208/**
     209 * initializes the CommandList (if it is NULL)
     210 */
     211void ShellCommandClass::initCommandClassList()
    186212{
    187213  if (ShellCommandClass::commandClassList == NULL)
    188     initCommandClassList();
    189 
    190   tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
    191   ShellCommandClass* elem = iterator->firstElement();
    192   while(elem != NULL)
    193   {
    194     if (!strcmp(className, elem->className))
    195     {
    196       delete iterator;
    197       return elem;
    198     }
    199     elem = iterator->nextElement();
    200   }
    201   delete iterator;
    202   return new ShellCommandClass(className);
    203 }
    204 
    205 /**
    206  * initializes the CommandList (if it is NULL)
    207  */
    208 void ShellCommandClass::initCommandClassList()
    209 {
    210   if (ShellCommandClass::commandClassList == NULL)
    211214  {
    212215    ShellCommandClass::commandClassList = new tList<ShellCommandClass>;
    213     ShellCommandStatic<ShellCommandBase>::registerCommand("debug", "ShellCommand", ShellCommandBase::debug);
     216    ShellCommand::registerCommand("debug", "ShellCommand", new ExecutorStatic<ShellCommand>(ShellCommand::debug));
    214217  }
    215218}
     
    228231      {
    229232        PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
    230         tIterator<ShellCommandBase>* iterator = elemCL->commandList->getIterator();
    231         const ShellCommandBase* elem = iterator->firstElement();
     233        tIterator<ShellCommand>* iterator = elemCL->commandList->getIterator();
     234        const ShellCommand* elem = iterator->firstElement();
    232235        while(elem != NULL)
    233236        {
    234237          PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount);
    235238          for (unsigned int i = 0; i< elem->paramCount; i++)
    236             PRINT(0)("%s ", ShellCommandBase::paramToString(elem->parameters[i]));
     239            PRINT(0)("%s ", ShellCommand::paramToString(elem->parameters[i]));
    237240          if (elem->description != NULL)
    238241            PRINT(0)("- %s", elem->description);
     
    277280 * @param paramCount the count of parameters this command takes
    278281 */
    279 ShellCommandBase::ShellCommandBase(const char* commandName, const char* className, unsigned int paramCount, ...)
     282ShellCommand::ShellCommand(const char* commandName, const char* className, unsigned int paramCount, ...)
    280283{
    281284  this->setClassID(CL_SHELL_COMMAND, "ShellCommand");
     
    306309 * deconstructs a ShellCommand
    307310 */
    308 ShellCommandBase::~ShellCommandBase()
     311ShellCommand::~ShellCommand()
    309312{
    310313  delete[] this->parameters;
     
    318321
    319322/**
     323 * registers a new ShellCommand
     324 */
     325ShellCommand* ShellCommand::registerCommand(const char* commandName, const char* className, Executor* executor)
     326{
     327  return NULL;
     328
     329}
     330
     331
     332
     333
     334/**
    320335 * unregister an existing commandName
    321336 * @param className the name of the Class the command belongs to.
    322337 * @param commandName the name of the command itself
    323338 */
    324 void ShellCommandBase::unregisterCommand(const char* commandName, const char* className)
     339void ShellCommand::unregisterCommand(const char* commandName, const char* className)
    325340{
    326341  if (ShellCommandClass::commandClassList == NULL)
     
    331346 if (checkClass != NULL)
    332347  {
    333     tIterator<ShellCommandBase>* iterator = checkClass->commandList->getIterator();
    334     ShellCommandBase* elem = iterator->firstElement();
     348    tIterator<ShellCommand>* iterator = checkClass->commandList->getIterator();
     349    ShellCommand* elem = iterator->firstElement();
    335350    while(elem != NULL)
    336351    {
     
    363378 * This is checked in the registerCommand-function.
    364379 */
    365 bool ShellCommandBase::isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...)
     380bool ShellCommand::isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...)
    366381{
    367382  if (ShellCommandClass::commandClassList == NULL)
     
    374389  if (checkClass != NULL)
    375390  {
    376     tIterator<ShellCommandBase>* iterator = checkClass->commandList->getIterator();
    377     ShellCommandBase* elem = iterator->firstElement();
     391    tIterator<ShellCommand>* iterator = checkClass->commandList->getIterator();
     392    ShellCommand* elem = iterator->firstElement();
    378393    while(elem != NULL)
    379394   {
     
    400415 * @return true on success, false otherwise.
    401416 */
    402 bool ShellCommandBase::execute(const char* executionString)
     417bool ShellCommand::execute(const char* executionString)
    403418{
    404419  if (ShellCommandClass::commandClassList == NULL)
     
    489504      if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.getCount() >= 3)))
    490505      {
    491         tIterator<ShellCommandBase>* itCMD = commandClass->commandList->getIterator();
    492         ShellCommandBase* enumCMD = itCMD->firstElement();
     506        tIterator<ShellCommand>* itCMD = commandClass->commandList->getIterator();
     507        ShellCommand* enumCMD = itCMD->firstElement();
    493508        while (enumCMD != NULL)
    494509        {
     
    520535 * @param description the description of the Given command
    521536 */
    522 ShellCommandBase* ShellCommandBase::describe(const char* description)
     537ShellCommand* ShellCommand::describe(const char* description)
    523538{
    524539  if (this == NULL)
     
    536551 * @returns itself
    537552 */
    538 ShellCommandBase* ShellCommandBase::setAlias(const char* alias)
     553ShellCommand* ShellCommand::setAlias(const char* alias)
    539554{
    540555  if (this == NULL)
     
    566581 * count, [EXACTLY THE SAME AS IF YOU WOULD CALL THE FUNCTION UP TO count ARGUMENTS]
    567582 */
    568 ShellCommandBase* ShellCommandBase::defaultValues(unsigned int count, ...)
     583ShellCommand* ShellCommand::defaultValues(unsigned int count, ...)
    569584{
    570585  if (this == NULL)
     
    615630 * prints out nice information about the Shells Commands
    616631 */
    617 void ShellCommandBase::debug()
     632void ShellCommand::debug()
    618633{
    619634  if (ShellCommandClass::commandClassList == NULL)
     
    628643  {
    629644    PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
    630     tIterator<ShellCommandBase>* iterator = elemCL->commandList->getIterator();
    631     const ShellCommandBase* elem = iterator->firstElement();
     645    tIterator<ShellCommand>* iterator = elemCL->commandList->getIterator();
     646    const ShellCommand* elem = iterator->firstElement();
    632647    while(elem != NULL)
    633648    {
    634649      PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount);
    635650      for (unsigned int i = 0; i< elem->paramCount; i++)
    636        printf("%s ", ShellCommandBase::paramToString(elem->parameters[i]));
     651       printf("%s ", ShellCommand::paramToString(elem->parameters[i]));
    637652      if (elem->description != NULL)
    638653       printf("- %s", elem->description);
     
    652667 * @returns the Name of the Parameter at Hand
    653668 */
    654 const char* ShellCommandBase::paramToString(long parameter)
     669const char* ShellCommand::paramToString(long parameter)
    655670{
    656671  return MultiType::MultiTypeToString((MT_Type)parameter);
  • trunk/src/lib/shell/shell_command.h

    r5552 r5636  
    1313#include "substring.h"
    1414#include "functor_list.h"
    15 
     15#include "executor/executor.h"
    1616#include <stdarg.h>
    1717
     
    3030 *
    3131 * MEANING:
    32  *  ShellCommandBase* someUniqueVarName =
     32 *  ShellCommand* someUniqueVarName =
    3333 *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
    3434 *
     
    3636 * $ ClassName [ObjectName] commandNameInShell [parameters]
    3737 */
     38//#define SHELL_COMMAND(command, class, function) \
     39//        ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)
    3840#define SHELL_COMMAND(command, class, function) \
    39         ShellCommandBase* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)
     41           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorObjective<class>(&class::function))
     42
    4043/**
    4144 * an easy to use Macro to create a Command
     
    4548 *
    4649 * MEANING:
    47  *  ShellCommandBase* someUniqueVarName =
     50 *  ShellCommand* someUniqueVarName =
    4851 *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
    4952 *
     
    5255 */
    5356#define SHELL_COMMAND_STATIC(command, class, function) \
    54                          ShellCommandBase* shell_command_##class##_##command = ShellCommandStatic<class>::registerCommand(#command, #class, function)
     57           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorStatic<class>(function))
    5558
    5659
     
    6467// BASE CLASS //
    6568////////////////
    66 class ShellCommandBase;
     69class ShellCommand;
    6770class ShellCommandAlias;
    6871
     
    7073class ShellCommandClass : public BaseObject
    7174{
    72   friend class ShellCommandBase;
     75  friend class ShellCommand;
    7376
    7477  public:
     
    9396    const char*                      className;                 //!< The Name of the Class. This should match the ClassName of the Commands Class.
    9497    long                             classID;                   //!< The classID of this Class
    95     tList<ShellCommandBase>*         commandList;               //!< A list of Commands from this Class
     98    tList<ShellCommand>*         commandList;               //!< A list of Commands from this Class
    9699    static tList<ShellCommandClass>* commandClassList;          //!< A list of Classes
    97100    static tList<ShellCommandAlias>* aliasList;                 //!< An Alias to A Command. (only for classes with one Instance)
     
    100103
    101104//! a baseClass for all possible ShellCommands
    102 class ShellCommandBase : public BaseObject
     105class ShellCommand : public BaseObject
    103106{
    104107  friend class ShellCommandClass;
     
    106109    static bool execute (const char* executionString);
    107110
    108     ShellCommandBase* describe(const char* description);
    109     ShellCommandBase* setAlias(const char* alias);
    110     ShellCommandBase* defaultValues(unsigned int count, ...);
     111    ShellCommand* describe(const char* description);
     112    ShellCommand* setAlias(const char* alias);
     113    ShellCommand* defaultValues(unsigned int count, ...);
    111114
    112     /** @returns the CommandList of the Shell */
     115    static ShellCommand* registerCommand(const char* commandName, const char* className, Executor* executor);
     116
    113117    static void unregisterCommand(const char* commandName, const char* className);
    114118
     
    116120
    117121  protected:
    118     ShellCommandBase(const char* commandName, const char* className, unsigned int paramCount, ...);
    119     ~ShellCommandBase();
     122    ShellCommand(const char* commandName, const char* className, unsigned int paramCount, ...);
     123    ~ShellCommand();
    120124
    121125    /** @returns the Type of this Function (either static or objective) */
     
    141145
    142146    const char*                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
    143 };
     147    Executor*                        executor;
    144148
    145 ///////////////////////////////////////////////////
    146 ///////////////////////////////////////////////////
    147 
    148 /////////////////////////////////
    149 // MACRO DEFINITION EXTENSIONS //
    150 /////////////////////////////////
    151 //! where to chek for default BOOL values
    152 #define   l_BOOL_DEFGRAB(i)         this->defaultValue[i].getBool()
    153 //! where to chek for default INT values
    154 #define   l_INT_DEFGRAB(i)          this->defaultValue[i].getInt()
    155 //! where to chek for default UINT values
    156 #define   l_UINT_DEFGRAB(i)         (unsigned int)this->defaultValue[i].getInt()
    157 //! where to chek for default LONG values
    158 #define   l_LONG_DEFGRAB(i)         (long)this->defaultValue[i].getInt()
    159 //! where to chek for default FLOAT values
    160 #define   l_FLOAT_DEFGRAB(i)        this->defaultValue[i].getFloat()
    161 //! where to chek for default STRING values
    162 #define   l_STRING_DEFGRAB(i)       this->defaultValue[i].getString()
    163 
    164 //////////////////////////
    165 // COMMAND REGISTRATION //
    166 //////////////////////////
    167 // SHELLCOMMAND can be redefined as ShellCommand or ShellCommandStatic
    168 // SHELLCOMMANDEXECUTER can be redefined too.
    169 // SHELLCOMMANDINCLASS
    170 // SHELLCOMMANDTYPE
    171 //! registers a command without any parameters
    172 #define ShellCommandRegister0() \
    173   static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)()) \
    174   { \
    175     if (isRegistered(commandName, className, 0)== true) \
    176       return NULL; \
    177     return new SHELLCOMMAND<T>(commandName, className, function); \
    178   }
    179 
    180 //! registers a command with 1 parameter
    181 #define ShellCommandRegister1(t1) \
    182   static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE)) \
    183   { \
    184     if (isRegistered(commandName, className, 1, t1##_PARAM)== true) \
    185       return NULL; \
    186     return new SHELLCOMMAND<T>(commandName, className, function); \
    187   }
    188 
    189 //! registers a command with 2 parameters
    190 #define ShellCommandRegister2(t1,t2) \
    191   static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE)) \
    192   { \
    193     if (isRegistered(commandName, className, 2, t1##_PARAM, t2##_PARAM)== true) \
    194       return NULL; \
    195     return new SHELLCOMMAND<T>(commandName, className, function); \
    196   }
    197 
    198 //! registers a command with 3 parameters
    199 #define ShellCommandRegister3(t1,t2,t3) \
    200   static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE)) \
    201   { \
    202     if (isRegistered(commandName, className, 3, t1##_PARAM, t2##_PARAM, t3##_PARAM)== true) \
    203       return NULL; \
    204     return new SHELLCOMMAND<T>(commandName, className, function); \
    205   }
    206 
    207 //! registers a command with 4 parameters
    208 #define ShellCommandRegister4(t1,t2,t3,t4) \
    209   static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE)) \
    210   { \
    211     if (isRegistered(commandName, className, 4, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM)== true) \
    212       return NULL; \
    213     return new SHELLCOMMAND<T>(commandName, className, function); \
    214   }
    215 
    216 //! registers a command with 5 parameters
    217 #define ShellCommandRegister5(t1,t2,t3,t4,t5) \
    218   static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE)) \
    219   { \
    220     if (isRegistered(commandName, className, 5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM)== true) \
    221       return NULL; \
    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 
    248 
    249 //////////////////
    250 // CONSTRUCTORS //
    251 /////////////////
    252 //! creates a command that takes no parameters
    253 #define ShellCommandConstructor0() \
    254   SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)()) \
    255   : ShellCommandBase(commandName, className, 0) \
    256   { \
    257     this->functorType = SHELLCOMMANDTYPE; \
    258     this->fp.functionPointer_0 = function; \
    259   }
    260 
    261 //! creates a command that takes one parameter
    262 #define ShellCommandConstructor1(t1) \
    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; \
    268   }
    269 
    270 //! creates a command that takes two parameters
    271 #define ShellCommandConstructor2(t1,t2) \
    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; \
    277   }
    278 
    279 //! creates a command that takes three parameter
    280 #define ShellCommandConstructor3(t1,t2,t3) \
    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; \
    286   }
    287 
    288 //! creates a command that takes four parameter
    289 #define ShellCommandConstructor4(t1,t2,t3,t4) \
    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; \
    295   }
    296 
    297 //! creates a command that takes five parameter
    298 #define ShellCommandConstructor5(t1,t2,t3,t4,t5) \
    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; \
    304   }
    305 
    306 ///////////////
    307 // EXECUTION //
    308 ///////////////
    309 //! execute-macro for functions with no parameters
    310 #define ShellCommandExecute0() \
    311   if (this->paramCount == 0) \
    312     SHELLCOMMANDEXECUTER(_0)()
    313 
    314 //! execute-macro for functions with one parameter
    315 #define ShellCommandExecute1(t1) \
    316    else if (this->paramCount == 1 && this->parameters[0] == t1##_PARAM) \
    317     SHELLCOMMANDEXECUTER(_1_##t1)(t1##_FUNC(parameters, t1##_DEFGRAB(0)))
    318 
    319 //! execute-macro for functions with two parameters
    320 #define ShellCommandExecute2(t1,t2) \
    321    else if (this->paramCount == 2 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM) \
    322     SHELLCOMMANDEXECUTER(_2_##t1##_##t2)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)))
    323 
    324 //! execute-macro for functions with three parameters
    325 #define ShellCommandExecute3(t1,t2,t3) \
    326    else if (this->paramCount == 3 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM) \
    327     SHELLCOMMANDEXECUTER(_3_##t1##_##t2##_##t3)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)))
    328 
    329 //! execute-macro for functions with four parameters
    330 #define ShellCommandExecute4(t1,t2,t3,t4) \
    331    else if (this->paramCount == 4 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM && this->parameters[3] == t4##_PARAM) \
    332     SHELLCOMMANDEXECUTER(_4_##t1##_##t2##_##t3##_##t4)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3)))
    333 
    334 //! execute-macro for functions with five parameters
    335 #define ShellCommandExecute5(t1,t2,t3,t4,t5) \
    336    else if (this->paramCount == 5 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM && this->parameters[3] == t4##_PARAM && this->parameters[4] == t5##_PARAM) \
    337     SHELLCOMMANDEXECUTER(_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3)), t5##_FUNC(sub.getString(4), t5##_DEFGRAB(4)))
    338 
    339 
    340 //! keeps information about a ShellCommand
    341 template<class T> class ShellCommand : public ShellCommandBase
    342 {
    343   public:
    344 #ifdef FUNCTOR_LIST
    345 #undef FUNCTOR_LIST
    346 #endif
    347 #ifdef SHELLCOMMAND
    348 #undef SHELLCOMMAND
    349 #endif
    350 #define SHELLCOMMAND                       ShellCommand
    351 #ifdef SHELLCOMMANDEXECUTER
    352 #undef SHELLCOMMANDEXECUTER
    353 #endif
    354 #define SHELLCOMMANDEXECUTER(nameExt)      (dynamic_cast<T*>(object)->*(fp.functionPointer##nameExt))
    355 #ifdef SHELLCOMMANDINCLASS
    356 #undef SHELLCOMMANDINCLASS
    357 #endif
    358 #define SHELLCOMMANDINCLASS(FUNCTION)      (T::FUNCTION)
    359 #ifdef SHELLCOMMANDTYPE
    360 #undef SHELLCOMMANDTYPE
    361 #endif
    362 #define SHELLCOMMANDTYPE                   ShellCommand_Objective
    363 //! FUNCTOR_LIST is the List of command-registerers
    364 #define FUNCTOR_LIST(x) ShellCommandRegister ## x
    365 #include "functor_list.h"
    366 #undef FUNCTOR_LIST
    367 
    368 
    369   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 
    377 //! FUNCTOR_LIST is the List of CommandConstructors
    378 #define FUNCTOR_LIST(x) ShellCommandConstructor ## x
    379 #include "functor_list.h"
    380 #undef FUNCTOR_LIST
    381 
    382     virtual void executeCommand (BaseObject* object, const char* parameters)
    383     {
    384       SubString sub(parameters, true);
    385 //! FUNCTOR_LIST is the List of Executive Functions
    386 #define FUNCTOR_LIST(x) ShellCommandExecute ## x
    387 #include "functor_list.h"
    388 #undef FUNCTOR_LIST
    389     }
    390 };
    391 
    392 //! keeps information about a ShellCommand, that points to a Static Function
    393 template<class T> class ShellCommandStatic : public ShellCommandBase
    394 {
    395   public:
    396 #ifdef FUNCTOR_LIST
    397 #undef FUNCTOR_LIST
    398 #endif
    399 #ifdef SHELLCOMMAND
    400 #undef SHELLCOMMAND
    401 #endif
    402 #define SHELLCOMMAND                      ShellCommandStatic
    403 #ifdef SHELLCOMMANDEXECUTER
    404 #undef SHELLCOMMANDEXECUTER
    405 #endif
    406 #define SHELLCOMMANDEXECUTER(nameExt)     fp.functionPointer##nameExt
    407 #ifdef SHELLCOMMANDINCLASS
    408 #undef SHELLCOMMANDINCLASS
    409 #endif
    410 #define SHELLCOMMANDINCLASS(FUNCTION)     (FUNCTION)
    411 #ifdef SHELLCOMMANDTYPE
    412 #undef SHELLCOMMANDTYPE
    413 #endif
    414 #define SHELLCOMMANDTYPE                   ShellCommand_Static
    415 
    416 //! FUNCTOR_LIST is the List of command-registerers
    417 #define FUNCTOR_LIST(x) ShellCommandRegister ## x
    418 #include "functor_list.h"
    419 #undef FUNCTOR_LIST
    420 
    421   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 
    429 //! FUNCTOR_LIST is the List of CommandConstructors
    430 #define FUNCTOR_LIST(x) ShellCommandConstructor ## x
    431 #include "functor_list.h"
    432 #undef FUNCTOR_LIST
    433 
    434     virtual void executeCommand (BaseObject* object, const char* parameters)
    435     {
    436   SubString sub(parameters, true);
    437 //! FUNCTOR_LIST is the List of Executive Functions
    438 #define FUNCTOR_LIST(x) ShellCommandExecute ## x
    439 #include "functor_list.h"
    440 #undef FUNCTOR_LIST
    441     }
    442149};
    443150
     
    445152class ShellCommandAlias
    446153{
    447   friend class ShellCommandBase;
     154  friend class ShellCommand;
    448155  public:
    449156    /** @returns the Name of the Alias. */
    450157    const char* getName() const { return this->aliasName; };
    451158    /** @returns the Command, this Alias is asociated with */
    452     ShellCommandBase* getCommand() const { return this->command; };
     159    ShellCommand* getCommand() const { return this->command; };
    453160
    454161  private:
    455162    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
    456     ShellCommandAlias(const char* aliasName, ShellCommandBase* command) { this->aliasName = aliasName; this->command = command; };
     163    ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
    457164
    458165  private:
    459166    const char*         aliasName;       //!< the name of the Alias
    460     ShellCommandBase*   command;         //!< a pointer to the command, this alias executes.
     167    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
    461168};
    462169
  • trunk/src/lib/shell/shell_input.cc

    r5369 r5636  
    214214  strcpy(newCommand, this->inputLine);
    215215
    216   ShellCommandBase::execute(newCommand);
     216  ShellCommand::execute(newCommand);
    217217
    218218  // removing the eventually added Entry (from scrolling) to the List
  • trunk/src/lib/util/executor/executor.cc

    r5635 r5636  
    3838 * @param paramCount the count of parameters this command takes
    3939 */
    40 Executor::Executor(const char* commandName, const char* className, unsigned int paramCount, ...)
     40Executor::Executor(unsigned int paramCount, ...)
    4141{
    4242  this->setClassID(CL_EXECUTOR, "Executor");
    43   this->setName(commandName);
    4443
    45 //  this->classID = classID;
    46   // handling parameters, and storing them:
    4744  if (paramCount > FUNCTOR_MAX_ARGUMENTS)
    4845    paramCount = FUNCTOR_MAX_ARGUMENTS;
  • trunk/src/lib/util/executor/executor.h

    r5635 r5636  
    4141
    4242  protected:
    43     Executor(const char* commandName, const char* className, unsigned int paramCount, ...);
     43    Executor(unsigned int paramCount, ...);
    4444    ~Executor();
    4545
     
    7777// COMMAND REGISTRATION //
    7878//////////////////////////
    79 // EXECUTOR can be redefined as Executor or ExecutorStatic
    80 // EXECUTOREXECUTER can be redefined too.
     79// EXECUTOR             can be redefined as Executor or ExecutorStatic
     80// EXECUTOREXECUTER     can be redefined too.
    8181// EXECUTORINCLASS
    8282// EXECUTORTYPE
     83
    8384
    8485///////////////////////
     
    111112//! creates a command that takes no parameters
    112113#define ExecutorConstructor0() \
    113   EXECUTOR(const char* commandName, const char* className, void EXECUTORINCLASS(*function)()) \
    114   : Executor(commandName, className, 0) \
     114  EXECUTOR(void EXECUTORINCLASS(*function)()) \
     115  : Executor(0) \
    115116  { \
    116117    this->functorType = EXECUTORTYPE; \
     
    120121//! creates a command that takes one parameter
    121122#define ExecutorConstructor1(t1) \
    122   EXECUTOR(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE)) \
    123   : Executor(commandName, className, 1, t1##_PARAM) \
     123  EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE)) \
     124  : Executor(1, t1##_PARAM) \
    124125  { \
    125126    this->functorType = EXECUTORTYPE; \
     
    129130//! creates a command that takes two parameters
    130131#define ExecutorConstructor2(t1,t2) \
    131   EXECUTOR(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE)) \
    132   : Executor(commandName, className, 2, t1##_PARAM, t2##_PARAM) \
     132  EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE)) \
     133  : Executor(2, t1##_PARAM, t2##_PARAM) \
    133134  { \
    134135    this->functorType = EXECUTORTYPE; \
     
    138139//! creates a command that takes three parameter
    139140#define ExecutorConstructor3(t1,t2,t3) \
    140   EXECUTOR(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE)) \
    141   : Executor(commandName, className, 3, t1##_PARAM, t2##_PARAM, t3##_PARAM) \
     141  EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE)) \
     142  : Executor(3, t1##_PARAM, t2##_PARAM, t3##_PARAM) \
    142143  { \
    143144    this->functorType = EXECUTORTYPE; \
     
    147148//! creates a command that takes four parameter
    148149#define ExecutorConstructor4(t1,t2,t3,t4) \
    149   EXECUTOR(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE)) \
    150   : Executor(commandName, className, 4, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM) \
     150  EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE)) \
     151  : Executor(4, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM) \
    151152  { \
    152153    this->functorType = EXECUTORTYPE; \
     
    156157//! creates a command that takes five parameter
    157158#define ExecutorConstructor5(t1,t2,t3,t4,t5) \
    158   EXECUTOR(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE)) \
    159   : Executor(commandName, className, 5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM) \
     159  EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE)) \
     160  : Executor(5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM) \
    160161  { \
    161162    this->functorType = EXECUTORTYPE; \
     
    292293
    293294
    294     virtual void executeCommand (BaseObject* object, const char* parameters)
     295    virtual void execute (BaseObject* object, const char* parameters)
    295296    {
    296297  SubString sub(parameters, true);
  • trunk/src/world_entities/player.cc

    r5635 r5636  
    119119void Player::init()
    120120{
    121   Executor* test =  new ExecutorObjective<Player>("test", "Player", &Player::ADDWEAPON);
    122 
    123121//  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
    124122  this->setClassID(CL_PLAYER, "Player");
Note: See TracChangeset for help on using the changeset viewer.