Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5633 in orxonox.OLD for trunk/src/lib/util/executor/executor.h


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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)
Note: See TracChangeset for help on using the changeset viewer.