Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5142 in orxonox.OLD for trunk


Ignore:
Timestamp:
Aug 27, 2005, 12:01:59 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: more elaborate version
now the command Structure is
SingletonClass function [parameters]

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/defs/functor_list.h

    r5137 r5142  
    2828#ifndef __FUNCTOR_PARAMETERS__
    2929#define __FUNCTOR_PARAMETERS__
     30
     31//! defines the maximum count of arguments function pointers might have
     32#define FUNCTOR_MAX_ARGUMENTS                5
    3033
    3134typedef enum ParameterType
  • trunk/src/util/shell_command.cc

    r5141 r5142  
    4545
    4646  // handling parameters, and storing them:
     47  if (paramCount > FUNCTOR_MAX_ARGUMENTS)
     48    paramCount = FUNCTOR_MAX_ARGUMENTS;
    4749  this->paramCount = paramCount;
    4850  this->parameters = new ParameterType[paramCount];
    4951
    5052  for (unsigned int i = 0; i < paramCount; i++)
     53  {
    5154    parameters[i] = va_arg(parameters, long);
     55
     56    switch (parameters[i])
     57    {
     58      case ParameterBool:
     59        this->defaultBools[i] = va_arg(parameters, int);
     60        break;
     61      case ParameterChar:
     62        this->defaultStrings[i] = new char[2];
     63        sprintf(this->defaultStrings[0], "%c",  va_arg(parameters, int));
     64        break;
     65      case ParameterString:
     66        this->defaultStrings[i] = va_arg(parameters, char*);
     67        break;
     68      case ParameterInt:
     69        this->defaultInts[i] = va_arg(parameters, int);
     70        break;
     71      case ParameterUInt:
     72        this->defaultInts[i] = va_arg(parameters, unsigned int);
     73        break;
     74      case ParameterFloat:
     75        this->defaultFloats[i] = va_arg(parameters, double);
     76        break;
     77      case ParameterLong:
     78        this->defaultInts[i] = va_arg(parameters, long);
     79        break;
     80      default:
     81        break;
     82    }
     83  }
    5284
    5385  // adding this ShellCommand to the list of known Commands
     
    6597bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...)
    6698{
    67 
    6899  va_list parameters;
    69100  va_start(parameters, paramCount);
     
    97128    return false;
    98129
    99   const char* commandEnd = strchr(executionString, ' ');
    100   if (commandEnd == NULL)
    101     commandEnd = executionString + strlen(executionString);
    102 
    103130  tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator();
    104131  ShellCommandBase* elem = iterator->firstElement();
     
    106133  {
    107134    printf("%s\n", elem->getName());
    108     if (!strncmp(executionString, elem->getName(), strlen(elem->getName())))
     135    if (!strncasecmp (executionString, elem->className, strlen(elem->className)) &&
     136         (*(executionString+strlen(elem->className)) == ' ' ||
     137          *(executionString+strlen(elem->className)) == ':' ))
    109138    {
    110       elem->executeCommand(commandEnd);
     139      const char* commandBegin = executionString + strlen(elem->className);
     140
     141      PRINTF(4)("Class %s matches\n", elem->className);
     142      BaseObject* objectPointer = NULL;
     143      if (elem->isSingleton)
     144      {
     145        while(*commandBegin == ' ')
     146          commandBegin++;
     147        if (strncmp (commandBegin, elem->getName(), strlen(elem->getName())))
     148            continue;
     149        objectPointer = ClassList::getList(elem->classID)->firstElement();
     150      }
     151      else
     152      {
     153
     154      }
     155      const char* commandEnd = strchr(commandBegin, ' ');
     156      if (commandEnd == NULL)
     157        commandEnd = executionString + strlen(executionString);
     158
     159      if (objectPointer != NULL)
     160        elem->executeCommand(objectPointer, commandEnd);
    111161      delete iterator;
    112162      return true;
  • trunk/src/util/shell_command.h

    r5141 r5142  
    2626///////////////////////
    2727
     28// COMMAND REGISTRATION
     29// NO ARGUMENTS
     30#define ShellCommandRegister0 \
     31  static void registerCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) \
     32  { \
     33    if (isRegistered(commandName, classID, 0)== true) \
     34      return; \
     35    new ShellCommand<T>(commandName, classID, functionPointer); \
     36  }
    2837
    29 #define ShellCommand2(type1, type2) \
    30  public: \
    31   static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(type1##_TYPE, type2##_TYPE) \
    32                               type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \
     38
     39#define ShellCommandConstructor0 \
     40  void (T::*functionPointer_NULL)(); \
     41  ShellCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) \
     42  : ShellCommandBase (commandName, classID, 0) \
    3343  { \
    34      if (isRegistered(commandName, classID, 2, type1##_PARAM, type2##_PARAM) == true) \
     44    this->functionPointer_NULL = functionPointer; \
     45  }
     46
     47
     48
     49
     50#define ShellCommandRegister2(t1, t2) \
     51  static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(t1##_TYPE, t2##_TYPE) \
     52                              t1##_TYPE default1 = t1##_DEFAULT, t2##_TYPE default2 = t2##_DEFAULT) \
     53  { \
     54     if (isRegistered(commandName, classID, 2, t1##_PARAM, t2##_PARAM) == true) \
    3555       return; \
    3656     else \
    3757       ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, function); \
    38   } \
    39  private: \
    40   void (T::*functionPointer_##type1_##type2)(type1##_TYPE, type2##_TYPE); \
    41   ShellCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(type1##_TYPE, type2##_TYPE) \
    42                               type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \
    43   { \
    44     this->functionPointer_##type1_##type2 = function; \
    4558  }
    4659
     60// CONSTRUCTORS AND POINTERS
     61#define ShellCommandConstructor2(t1, t2) \
     62  void (T::*functionPointer_##t1_##t2)(t1##_TYPE, t2##_TYPE); \
     63  ShellCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(t1##_TYPE, t2##_TYPE) \
     64                              t1##_TYPE default1 = t1##_DEFAULT, t2##_TYPE default2 = t2##_DEFAULT) \
     65  { \
     66    this->functionPointer_##t1_##t2 = function; \
     67  }
     68
     69//#define ShellCommand
    4770
    4871
     
    6689
    6790  private:
    68     virtual void executeCommand (const char* parameters) = NULL;
     91    virtual void executeCommand (BaseObject* object, const char* parameters) = NULL;
    6992
    7093  protected:
     
    78101    const char*                      className;           //!< The Name of the Class associated to this Command
    79102
     103    char*                            defaultStrings[FUNCTOR_MAX_ARGUMENTS];
     104    int                              defaultInts[FUNCTOR_MAX_ARGUMENTS];
     105    float                            defaultFloats[FUNCTOR_MAX_ARGUMENTS];
     106    bool                             defaultBools[FUNCTOR_MAX_ARGUMENTS];
     107
     108
    80109    // STATIC MEMBERS
    81110    static tList<ShellCommandBase>*  commandList;         //!< A list of availiable commands.
     
    83112
    84113template<class T> class ShellCommand;
    85 
     114/*
    86115template<class T> class ShellCommandSingleton : public ShellCommandBase
    87116{
     
    92121    {
    93122      this->functionPointer_NULL = functionPointer;
    94 
    95123    }
    96124    void (T::*functionPointer_NULL)();
     125
    97126    virtual void executeCommand (const char* parameters)
    98127    {
     
    100129        (T::getInstance()->*functionPointer_NULL)();
    101130    }
    102 };
     131};*/
    103132
    104133
     
    109138    static void unregisterCommand(const char* commandNaame, ClassID classID);
    110139
    111     static void registerCommand(const char* commandName, ClassID classID, void (T::*functionPointer)())
    112     {
    113       if (isRegistered(commandName, classID, 0)== true)
    114         return;
    115       else
    116       {
    117         if (classID & CL_MASK_SINGLETON == CL_MASK_SINGLETON)
    118           new ShellCommandSingleton<T>(commandName, classID, functionPointer);
    119         else
    120           new ShellCommand<T>(commandName, classID, functionPointer);
    121       }
    122     }
     140#define FUNCTOR_LIST(x) ShellCommandRegister ## x
     141//#include "functor_list.h"
     142FUNCTOR_LIST(0);
     143#undef FUNCTOR_LIST
     144
    123145
    124146  private:
    125     void (T::*functionPointer_NULL)();
    126     ShellCommand(const char* commandName, ClassID classID, void (T::*functionPointer)())
    127       : ShellCommandBase (commandName, classID, 0)
     147#define FUNCTOR_LIST(x) ShellCommandConstructor ## x
     148//#include "functor_list.h"
     149  FUNCTOR_LIST(0);
     150#undef FUNCTOR_LIST
     151
     152    virtual void executeCommand (BaseObject* object, const char* parameters)
    128153    {
    129       this->functionPointer_NULL = functionPointer;
    130     }
    131     virtual void executeCommand (const char* parameters)
    132     {
    133       printf("not implemented yet\n");
    134 /*      if (this->paramCount == 0)
    135         (objectPointer->*functionPointer_NULL)();*/
     154     printf("not implemented yet\n");
     155     if (this->paramCount == 0)
     156       (dynamic_cast<T*>(object)->*functionPointer_NULL)();
    136157    }
    137158
Note: See TracChangeset for help on using the changeset viewer.