Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5633 in orxonox.OLD for trunk


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

orxonox/trunk: Executor works just fine.
Changed: Paramerte* to MT_*, to make things more general

Location:
trunk/src/lib/util
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/executor/executor.cc

    r5632 r5633  
    4747  if (paramCount > FUNCTOR_MAX_ARGUMENTS)
    4848    paramCount = FUNCTOR_MAX_ARGUMENTS;
     49  // reading in Parameters.
    4950  this->paramCount = paramCount;
    50   this->parameters = new unsigned int[paramCount];
    5151  this->defaultValue = new MultiType[paramCount];
    5252
     
    5656  // What Parameters we have got
    5757  for (unsigned int i = 0; i < paramCount; i++)
    58     this->parameters[i] = va_arg(parameterList, int);
     58    this->defaultValue[i].setType(va_arg(parameterList, int));
    5959}
    6060
     
    6464Executor::~Executor()
    6565{
    66   delete[] this->parameters;
    6766  delete[] this->defaultValue;
    6867}
     
    106105  for (unsigned int i = 0; i < count; i++)
    107106  {
    108 
    109 
    110     switch (this->parameters[i])
     107    switch (this->defaultValue[i].getType())
    111108    {
    112       case ParameterBool:
     109      case MT_BOOL:
    113110        this->defaultValue[i].setInt(va_arg(defaultList, int));
    114111        break;
    115       case ParameterChar:
     112      case MT_CHAR:
    116113        this->defaultValue[i].setChar((char)va_arg(defaultList, int));
    117114        break;
    118       case ParameterString:
     115      case MT_STRING:
    119116        this->defaultValue[i].setString(va_arg(defaultList, char*));
    120117        break;
    121       case ParameterInt:
     118      case MT_INT:
    122119        this->defaultValue[i].setInt(va_arg(defaultList, int));
    123120        break;
    124       case ParameterUInt:
     121/*      case MT_UINT:
    125122        this->defaultValue[i].setInt((int)va_arg(defaultList, unsigned int));
    126         break;
    127       case ParameterFloat:
     123        break;*/
     124      case MT_FLOAT:
    128125        this->defaultValue[i].setFloat(va_arg(defaultList, double));
    129126        break;
    130       case ParameterLong:
     127/*      case MT_LONG:
    131128        this->defaultValue[i].setInt((int) va_arg(defaultList, long));
    132         break;
     129        break;*/
    133130      default:
    134131        break;
  • trunk/src/lib/util/executor/executor.h

    r5632 r5633  
    3737    Executor* defaultValues(unsigned int count, ...);
    3838
    39     /** @returns the CommandList of the Shell */
    40     static void unregisterCommand(const char* commandName, const char* className);
     39    /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */
     40    virtual void execute (BaseObject* object, const char* parameters) = 0;
     41
    4142
    4243    static void debug();
     
    4950    inline Executor_Type getType() { return this->functorType; };
    5051
    51     static bool isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...);
    52     static const char* paramToString(long parameter);
    53 
    54   private:
    55     /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */
    56     virtual void executeCommand (BaseObject* object, const char* parameters) = 0;
    57 
    5852  protected:
    5953    Executor_Type                    functorType;                          //!< The type of Function we've got (either static or objective).
    60     void*                            functionPointer;                      //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
    6154    unsigned int                     paramCount;                           //!< the count of parameters.
    62     unsigned int*                    parameters;                           //!< Parameters the function of this Command takes.
    6355    MultiType*                       defaultValue;                         //!< Default Values.
    6456
     
    9385// EXECUTORINCLASS
    9486// EXECUTORTYPE
    95 //! registers a command without any parameters
    96 #define ExecutorRegister0() \
    97   static EXECUTOR<T>* registerCommand(const char* commandName, const char* className, void EXECUTORINCLASS(*function)()) \
    98   { \
    99     if (isRegistered(commandName, className, 0)== true) \
    100       return NULL; \
    101     return new EXECUTOR<T>(commandName, className, function); \
    102   }
    103 
    104 //! registers a command with 1 parameter
    105 #define ExecutorRegister1(t1) \
    106   static EXECUTOR<T>* registerCommand(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE)) \
    107   { \
    108     if (isRegistered(commandName, className, 1, t1##_PARAM)== true) \
    109       return NULL; \
    110     return new EXECUTOR<T>(commandName, className, function); \
    111   }
    112 
    113 //! registers a command with 2 parameters
    114 #define ExecutorRegister2(t1,t2) \
    115   static EXECUTOR<T>* registerCommand(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE)) \
    116   { \
    117     if (isRegistered(commandName, className, 2, t1##_PARAM, t2##_PARAM)== true) \
    118       return NULL; \
    119     return new EXECUTOR<T>(commandName, className, function); \
    120   }
    121 
    122 //! registers a command with 3 parameters
    123 #define ExecutorRegister3(t1,t2,t3) \
    124   static EXECUTOR<T>* registerCommand(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE)) \
    125   { \
    126     if (isRegistered(commandName, className, 3, t1##_PARAM, t2##_PARAM, t3##_PARAM)== true) \
    127       return NULL; \
    128     return new EXECUTOR<T>(commandName, className, function); \
    129   }
    130 
    131 //! registers a command with 4 parameters
    132 #define ExecutorRegister4(t1,t2,t3,t4) \
    133   static EXECUTOR<T>* registerCommand(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE)) \
    134   { \
    135     if (isRegistered(commandName, className, 4, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM)== true) \
    136       return NULL; \
    137     return new EXECUTOR<T>(commandName, className, function); \
    138   }
    139 
    140 //! registers a command with 5 parameters
    141 #define ExecutorRegister5(t1,t2,t3,t4,t5) \
    142   static EXECUTOR<T>* registerCommand(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE)) \
    143   { \
    144     if (isRegistered(commandName, className, 5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM)== true) \
    145       return NULL; \
    146     return new EXECUTOR<T>(commandName, className, function); \
    147   }
    14887
    14988///////////////////////
     
    238177//! execute-macro for functions with one parameter
    239178#define ExecutorExecute1(t1) \
    240    else if (this->paramCount == 1 && this->parameters[0] == t1##_PARAM) \
     179   else if (this->paramCount == 1 && this->defaultValue[0].getType() == t1##_PARAM) \
    241180    EXECUTOREXECUTER(_1_##t1)(t1##_FUNC(parameters, t1##_DEFGRAB(0)))
    242181
    243182//! execute-macro for functions with two parameters
    244183#define ExecutorExecute2(t1,t2) \
    245    else if (this->paramCount == 2 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM) \
     184   else if (this->paramCount == 2 && this->defaultValue[0].getType() == t1##_PARAM && this->defaultValue[1].getType() == t2##_PARAM) \
    246185    EXECUTOREXECUTER(_2_##t1##_##t2)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)))
    247186
    248187//! execute-macro for functions with three parameters
    249188#define ExecutorExecute3(t1,t2,t3) \
    250    else if (this->paramCount == 3 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM) \
     189   else if (this->paramCount == 3 && this->defaultValue[0].getType() == t1##_PARAM && this->defaultValue[1].getType() == t2##_PARAM && this->defaultValue[2].getType() == t3##_PARAM) \
    251190    EXECUTOREXECUTER(_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)))
    252191
    253192//! execute-macro for functions with four parameters
    254193#define ExecutorExecute4(t1,t2,t3,t4) \
    255    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) \
     194   else if (this->paramCount == 4 && this->defaultValue[0].getType() == t1##_PARAM && this->defaultValue[1].getType() == t2##_PARAM && this->defaultValue[2].getType() == t3##_PARAM && this->defaultValue[3].getType() == t4##_PARAM) \
    256195    EXECUTOREXECUTER(_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)))
    257196
    258197//! execute-macro for functions with five parameters
    259198#define ExecutorExecute5(t1,t2,t3,t4,t5) \
    260    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) \
     199   else if (this->paramCount == 5 && this->defaultValue[0].getType() == t1##_PARAM && this->defaultValue[1].getType() == t2##_PARAM && this->defaultValue[2].getType() == t3##_PARAM && this->defaultValue[3].getType() == t4##_PARAM && this->defaultValue[4].getType() == t5##_PARAM) \
    261200    EXECUTOREXECUTER(_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)))
    262201
     
    268207// DYNAMIC FUNCTOR //
    269208///////////\/////////
     209#ifdef FUNCTOR_LIST
     210#undef FUNCTOR_LIST
     211#endif
     212#ifdef EXECUTOR
     213#undef EXECUTOR
     214#endif
     215#define EXECUTOR                       ExecutorObjective
     216#ifdef EXECUTOREXECUTER
     217#undef EXECUTOREXECUTER
     218#endif
     219#define EXECUTOREXECUTER(nameExt)      (dynamic_cast<T*>(object)->*(fp.functionPointer##nameExt))
     220#ifdef EXECUTORINCLASS
     221#undef EXECUTORINCLASS
     222#endif
     223#define EXECUTORINCLASS(FUNCTION)      (T::FUNCTION)
     224#ifdef EXECUTORTYPE
     225#undef EXECUTORTYPE
     226#endif
     227#define EXECUTORTYPE                   Executor_Objective
    270228//! keeps information about a Executor
    271229template<class T> class ExecutorObjective : public Executor
    272230{
     231
    273232  public:
    274 #ifdef FUNCTOR_LIST
    275 #undef FUNCTOR_LIST
    276 #endif
    277 #ifdef EXECUTOR
    278 #undef EXECUTOR
    279 #endif
    280 #define EXECUTOR                       ExecutorObjective
    281 #ifdef EXECUTOREXECUTER
    282 #undef EXECUTOREXECUTER
    283 #endif
    284 #define EXECUTOREXECUTER(nameExt)      (dynamic_cast<T*>(object)->*(fp.functionPointer##nameExt))
    285 #ifdef EXECUTORINCLASS
    286 #undef EXECUTORINCLASS
    287 #endif
    288 #define EXECUTORINCLASS(FUNCTION)      (T::FUNCTION)
    289 #ifdef EXECUTORTYPE
    290 #undef EXECUTORTYPE
    291 #endif
    292 #define EXECUTORTYPE                   Executor_Objective
    293 //! FUNCTOR_LIST is the List of command-registerers
    294 #define FUNCTOR_LIST(x) ExecutorRegister ## x
    295 #include "functor_list.h"
    296 #undef FUNCTOR_LIST
    297 
     233//! FUNCTOR_LIST is the List of CommandConstructors
     234#define FUNCTOR_LIST(x) ExecutorConstructor ## x
     235#include "functor_list.h"
     236#undef FUNCTOR_LIST
    298237
    299238  private:
     
    305244    } fp;
    306245
    307 //! FUNCTOR_LIST is the List of CommandConstructors
    308 #define FUNCTOR_LIST(x) ExecutorConstructor ## x
    309 #include "functor_list.h"
    310 #undef FUNCTOR_LIST
    311 
    312     virtual void executeCommand (BaseObject* object, const char* parameters)
     246    virtual void execute (BaseObject* object, const char* parameters)
    313247    {
    314248      SubString sub(parameters, true);
     
    321255
    322256
    323 
    324257////////////////////
    325258// STATIC FUNCTOR //
    326259////////////////////
     260#ifdef FUNCTOR_LIST
     261#undef FUNCTOR_LIST
     262#endif
     263#ifdef EXECUTOR
     264#undef EXECUTOR
     265#endif
     266#define EXECUTOR                      ExecutorStatic
     267#ifdef EXECUTOREXECUTER
     268#undef EXECUTOREXECUTER
     269#endif
     270#define EXECUTOREXECUTER(nameExt)     fp.functionPointer##nameExt
     271#ifdef EXECUTORINCLASS
     272#undef EXECUTORINCLASS
     273#endif
     274#define EXECUTORINCLASS(FUNCTION)     (FUNCTION)
     275#ifdef EXECUTORTYPE
     276#undef EXECUTORTYPE
     277#endif
     278#define EXECUTORTYPE                   Executor_Static
     279
    327280//! keeps information about a Executor, that points to a Static Function
    328281template<class T> class ExecutorStatic : public Executor
    329282{
    330283  public:
    331 #ifdef FUNCTOR_LIST
    332 #undef FUNCTOR_LIST
    333 #endif
    334 #ifdef EXECUTOR
    335 #undef EXECUTOR
    336 #endif
    337 #define EXECUTOR                      ExecutorStatic
    338 #ifdef EXECUTOREXECUTER
    339 #undef EXECUTOREXECUTER
    340 #endif
    341 #define EXECUTOREXECUTER(nameExt)     fp.functionPointer##nameExt
    342 #ifdef EXECUTORINCLASS
    343 #undef EXECUTORINCLASS
    344 #endif
    345 #define EXECUTORINCLASS(FUNCTION)     (FUNCTION)
    346 #ifdef EXECUTORTYPE
    347 #undef EXECUTORTYPE
    348 #endif
    349 #define EXECUTORTYPE                   Executor_Static
    350 
    351 //! FUNCTOR_LIST is the List of command-registerers
    352 #define FUNCTOR_LIST(x) ExecutorRegister ## x
     284//! FUNCTOR_LIST is the List of CommandConstructors
     285#define FUNCTOR_LIST(x) ExecutorConstructor ## x
    353286#include "functor_list.h"
    354287#undef FUNCTOR_LIST
     
    362295    } fp;
    363296
    364 //! FUNCTOR_LIST is the List of CommandConstructors
    365 #define FUNCTOR_LIST(x) ExecutorConstructor ## x
    366 #include "functor_list.h"
    367 #undef FUNCTOR_LIST
    368297
    369298    virtual void executeCommand (BaseObject* object, const char* parameters)
  • trunk/src/lib/util/multi_type.cc

    r5552 r5633  
    120120
    121121
    122 void MultiType::setType(MT_Type)
    123 {
     122void MultiType::setType(int type)
     123{
     124  this->type = (MT_Type)type;
     125
     126  /// @todo check if this works...
    124127
    125128}
  • trunk/src/lib/util/multi_type.h

    r5552 r5633  
    1515  MT_BOOL            = 1,                  //!< A bool Value.
    1616  MT_INT             = 2,                  //!< An int Value.
     17  MT_UINT            = 2,
     18  MT_LONG            = 2,
    1719  MT_FLOAT           = 4,                  //!< A float Value.
    1820  MT_CHAR            = 8,                  //!< A single char.
    1921  MT_STRING          = 16,                 //!< An entire String.
     22  MT_EXT1            = 32,                 //!< An external Type.
     23  MT_EXT2            = 64,                 //!< An external Type.
    2024
    2125} MT_Type;
     
    4044    MultiType operator= (const MultiType& mt);
    4145
    42     void setType(MT_Type);
     46    void setType(int type);
    4347
    4448    void setBool(bool value);
Note: See TracChangeset for help on using the changeset viewer.