Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7722 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
May 19, 2006, 4:21:01 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: Removed the old Executor, and inserted the new one into the ShellCommand

Location:
trunk/src/lib
Files:
5 edited

Legend:

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

    r7456 r7722  
    3636   * @param paramCount the count of parameters this command takes
    3737   */
    38   ShellCommand::ShellCommand(const std::string& commandName, const std::string& className, const Executor& executor)
     38  ShellCommand::ShellCommand(const std::string& commandName, const std::string& className, Executor* executor)
    3939  {
    4040    this->setClassID(CL_SHELL_COMMAND, "ShellCommand");
     
    4343
    4444    // copy the executor:
    45     this->executor = executor.clone();
     45    this->executor = executor;
    4646    this->executor->setName(commandName);
    4747
     
    7575   * @brief registers a new ShellCommand
    7676   */
    77   ShellCommand* ShellCommand::registerCommand(const std::string& commandName, const std::string& className, const Executor& executor)
     77  ShellCommand* ShellCommand::registerCommand(const std::string& commandName, const std::string& className, Executor* executor)
    7878  {
    7979    if (ShellCommand::exists(commandName, className))
    80       return NULL;
     80    {
     81      delete executor;
     82      return NULL;
     83    }
    8184    else
    8285      return new ShellCommand(commandName, className, executor);
  • trunk/src/lib/shell/shell_command.h

    r7418 r7722  
    3737  //        ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)
    3838#define SHELL_COMMAND(command, class, function) \
    39            OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, ExecutorObjective<class>(&class::function))
     39           OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class>(&class::function))
    4040
    4141  /**
     
    5353   */
    5454#define SHELL_COMMAND_STATIC(command, class, function) \
    55            OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, ExecutorStatic<class>(function))
     55           OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class>(function))
    5656
    5757
     
    7171    ShellCommand* completionPlugin(unsigned int parameter, const CompletorPlugin& completorPlugin);
    7272
    73     static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, const Executor& executor);
     73    static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, Executor* executor);
    7474    static void unregisterCommand(const std::string& commandName, const std::string& className);
    7575    static const ShellCommand* const getCommand(const std::string& commandName, const std::string& className);
     
    8787
    8888  protected:
    89     ShellCommand(const std::string& commandName, const std::string& className, const Executor& executor);
     89    ShellCommand(const std::string& commandName, const std::string& className, Executor* executor);
    9090    virtual ~ShellCommand();
    9191
  • trunk/src/lib/util/executor/executor.h

    r7714 r7722  
    7777};
    7878
    79 ///////////////////////////////////////////////////
    80 ///////////////////////////////////////////////////
    81 
    82 //////////////////////////
    83 // COMMAND REGISTRATION //
    84 //////////////////////////
    85 // EXECUTOR             can be redefined as Executor or ExecutorStatic
    86 // EXECUTOREXECUTER     can be redefined too.
    87 // EXECUTORINCLASS
    88 // EXECUTORTYPE
    89 
    90 
    91 
    92 ///////////////////////
    93 // FUNCTION POINTERS //
    94 ///////////////////////
    95 #define ExecutorFunctionPoiter0() \
    96   void EXECUTORINCLASS(*functionPointer_0)();
    97 
    98 #define ExecutorFunctionPoiter1(t1) \
    99   void EXECUTORINCLASS(*functionPointer_1_##t1)(t1##_TYPE);
    100 
    101 #define ExecutorFunctionPoiter2(t1, t2) \
    102   void EXECUTORINCLASS(*functionPointer_2_##t1##_##t2)(t1##_TYPE, t2##_TYPE);
    103 
    104 
    105 #define ExecutorFunctionPoiter3(t1, t2, t3) \
    106   void EXECUTORINCLASS(*functionPointer_3_##t1##_##t2##_##t3)(t1##_TYPE, t2##_TYPE, t3##_TYPE);
    107 
    108 #define ExecutorFunctionPoiter4(t1, t2, t3, t4) \
    109   void EXECUTORINCLASS(*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE);
    110 
    111 
    112 #define ExecutorFunctionPoiter5(t1, t2, t3, t4, t5) \
    113   void EXECUTORINCLASS(*functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE);
    114 
    115 
    116 //////////////////
    117 // CONSTRUCTORS //
    118 /////////////////
    119 //! creates a command that takes no parameters
    120 #define ExecutorConstructor0() \
    121   EXECUTOR(void EXECUTORINCLASS(*function)()) \
    122   : Executor(0) \
    123   { \
    124     this->functorType = EXECUTORTYPE; \
    125     this->fp.functionPointer_0 = function; \
    126   }
    127 
    128 //! creates a command that takes one parameter
    129 #define ExecutorConstructor1(t1) \
    130   EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE)) \
    131   : Executor(t1##_PARAM) \
    132   { \
    133     this->functorType = EXECUTORTYPE; \
    134     this->fp.functionPointer_1_##t1 = function; \
    135   }
    136 
    137 //! creates a command that takes two parameters
    138 #define ExecutorConstructor2(t1,t2) \
    139   EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE)) \
    140   : Executor(t1##_PARAM, t2##_PARAM) \
    141   { \
    142     this->functorType = EXECUTORTYPE; \
    143     this->fp.functionPointer_2_##t1##_##t2 = function; \
    144   }
    145 
    146 //! creates a command that takes three parameter
    147 #define ExecutorConstructor3(t1,t2,t3) \
    148   EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE)) \
    149   : Executor(t1##_PARAM, t2##_PARAM, t3##_PARAM) \
    150   { \
    151     this->functorType = EXECUTORTYPE; \
    152     this->fp.functionPointer_3_##t1##_##t2##_##t3 = function; \
    153   }
    154 
    155 //! creates a command that takes four parameter
    156 #define ExecutorConstructor4(t1,t2,t3,t4) \
    157   EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE)) \
    158   : Executor(t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM) \
    159   { \
    160     this->functorType = EXECUTORTYPE; \
    161     this->fp.functionPointer_4_##t1##_##t2##_##t3##_##t4 = function; \
    162   }
    163 
    164 //! creates a command that takes five parameter
    165 #define ExecutorConstructor5(t1,t2,t3,t4,t5) \
    166   EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE)) \
    167   : Executor(t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM) \
    168   { \
    169     this->functorType = EXECUTORTYPE; \
    170     this->fp.functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5 = function; \
    171   }
    172 
    173 ///////////////
    174 // EXECUTION //
    175 ///////////////
    176 //! execute-macro for functions with no parameters
    177 #define ExecutorExecute0() \
    178   if (this->paramCount == 0) \
    179     EXECUTOREXECUTER(_0)()
    180 
    181 //! execute-macro for functions with one parameter
    182 #define ExecutorExecute1(t1) \
    183    else if (this->paramCount == 1 && this->defaultValue[0] == t1##_PARAM) \
    184     EXECUTOREXECUTER(_1_##t1)(t1##_FUNC(sub[0], t1##_DEFGRAB(0)))
    185 
    186 //! execute-macro for functions with two parameters
    187 #define ExecutorExecute2(t1,t2) \
    188    else if (this->paramCount == 2 && this->defaultValue[0] == t1##_PARAM && this->defaultValue[1] == t2##_PARAM) \
    189     EXECUTOREXECUTER(_2_##t1##_##t2)(t1##_FUNC(sub[0], t1##_DEFGRAB(0)), t2##_FUNC(sub[1], t2##_DEFGRAB(1)))
    190 
    191 //! execute-macro for functions with three parameters
    192 #define ExecutorExecute3(t1,t2,t3) \
    193    else if (this->paramCount == 3 && this->defaultValue[0] == t1##_PARAM && this->defaultValue[1] == t2##_PARAM && this->defaultValue[2] == t3##_PARAM) \
    194     EXECUTOREXECUTER(_3_##t1##_##t2##_##t3)(t1##_FUNC(sub[0], t1##_DEFGRAB(0)), t2##_FUNC(sub[1], t2##_DEFGRAB(1)), t3##_FUNC(sub[2], t3##_DEFGRAB(2)))
    195 
    196 //! execute-macro for functions with four parameters
    197 #define ExecutorExecute4(t1,t2,t3,t4) \
    198    else if (this->paramCount == 4 && this->defaultValue[0] == t1##_PARAM && this->defaultValue[1] == t2##_PARAM && this->defaultValue[2] == t3##_PARAM && this->defaultValue[3] == t4##_PARAM) \
    199     EXECUTOREXECUTER(_4_##t1##_##t2##_##t3##_##t4)(t1##_FUNC(sub[0], t1##_DEFGRAB(0)), t2##_FUNC(sub[1], t2##_DEFGRAB(1)), t3##_FUNC(sub[2], t3##_DEFGRAB(2)), t4##_FUNC(sub[3], t4##_DEFGRAB(3))) \
    200 
    201 
    202 //! execute-macro for functions with five parameters
    203 #define ExecutorExecute5(t1,t2,t3,t4,t5) \
    204    else if (this->paramCount == 5 && this->defaultValue[0] == t1##_PARAM && this->defaultValue[1] == t2##_PARAM && this->defaultValue[2] == t3##_PARAM && this->defaultValue[3] == t4##_PARAM && this->defaultValue[4] == t5##_PARAM) \
    205     EXECUTOREXECUTER(_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_FUNC(sub[0], t1##_DEFGRAB(0)), t2##_FUNC(sub[1], t2##_DEFGRAB(1)), t3##_FUNC(sub[2], t3##_DEFGRAB(2)), t4##_FUNC(sub[3], t4##_DEFGRAB(3)), t5##_FUNC(sub[4], t5##_DEFGRAB(4)))
    206 
    207 
    208 
    209 
    210 /////////////////////
    211 // DYNAMIC FUNCTOR //
    212 /////////////////////
    213 #ifdef FUNCTOR_LIST
    214 #undef FUNCTOR_LIST
    215 #endif
    216 #ifdef EXECUTOR
    217 #undef EXECUTOR
    218 #endif
    219 #define EXECUTOR                       ExecutorObjective
    220 #ifdef EXECUTOREXECUTER
    221 #undef EXECUTOREXECUTER
    222 #endif
    223 #define EXECUTOREXECUTER(nameExt)      (dynamic_cast<T*>(object)->*(fp.functionPointer##nameExt))
    224 #ifdef EXECUTORINCLASS
    225 #undef EXECUTORINCLASS
    226 #endif
    227 #define EXECUTORINCLASS(FUNCTION)      (T::FUNCTION)
    228 #ifdef EXECUTORTYPE
    229 #undef EXECUTORTYPE
    230 #endif
    231 #define EXECUTORTYPE                   Executor_Objective
    232 //! keeps information about a Executor
    233 template<class T> class EXECUTOR : public Executor
    234 {
    235 public:
    236   EXECUTOR() : Executor() { };
    237   // COPY constuctor (virtual version)
    238   virtual Executor* clone () const
    239   {
    240     EXECUTOR<T>* executor = new EXECUTOR<T>();
    241     this->cloning(executor);
    242     executor->fp = this->fp;
    243     return executor;
    244   }
    245 
    246   //! FUNCTOR_LIST is the List of CommandConstructors
    247 #define FUNCTOR_LIST(x) ExecutorConstructor ## x
    248 #include "functor_list.h"
    249 #undef FUNCTOR_LIST
    250 
    251 private:
    252   //! FUNCTOR_LIST is the List of FunctionPointers
    253   union FunctionPointers {
    254 #define FUNCTOR_LIST(x) ExecutorFunctionPoiter ## x
    255 #include "functor_list.h"
    256 #undef FUNCTOR_LIST
    257   } fp;
    258 
    259   virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
    260   {
    261     //! FUNCTOR_LIST is the List of Executive Functions
    262 #define FUNCTOR_LIST(x) ExecutorExecute ## x
    263 #include "functor_list.h"
    264 #undef FUNCTOR_LIST
    265 
    266   }
    267 };
    268 
    269 
    270 ////////////////////
    271 // STATIC FUNCTOR //
    272 ////////////////////
    273 #ifdef FUNCTOR_LIST
    274 #undef FUNCTOR_LIST
    275 #endif
    276 #ifdef EXECUTOR
    277 #undef EXECUTOR
    278 #endif
    279 #define EXECUTOR                      ExecutorStatic
    280 #ifdef EXECUTOREXECUTER
    281 #undef EXECUTOREXECUTER
    282 #endif
    283 #define EXECUTOREXECUTER(nameExt)     fp.functionPointer##nameExt
    284 #ifdef EXECUTORINCLASS
    285 #undef EXECUTORINCLASS
    286 #endif
    287 #define EXECUTORINCLASS(FUNCTION)     (FUNCTION)
    288 #ifdef EXECUTORTYPE
    289 #undef EXECUTORTYPE
    290 #endif
    291 #define EXECUTORTYPE                   Executor_Static
    292 
    293 //! keeps information about a Executor, that points to a Static Function
    294 template<class T> class ExecutorStatic : public Executor
    295 {
    296 public:
    297   EXECUTOR() : Executor() { };
    298   // COPY constuctor
    299   virtual Executor* clone () const
    300   {
    301     EXECUTOR<T>* executor = new EXECUTOR<T>();
    302     this->cloning(executor);
    303     executor->fp = this->fp;
    304     return executor;
    305   }
    306 
    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 private:
    313   //! FUNCTOR_LIST is the List of FunctionPointers
    314   union FunctionPointers {
    315 #define FUNCTOR_LIST(x) ExecutorFunctionPoiter ## x
    316 #include "functor_list.h"
    317 #undef FUNCTOR_LIST
    318   } fp;
    319 
    320 
    321   virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
    322   {
    323     //! FUNCTOR_LIST is the List of Executive Functions
    324 #define FUNCTOR_LIST(x) ExecutorExecute ## x
    325 #include "functor_list.h"
    326 #undef FUNCTOR_LIST
    327 
    328   }
    329 };
     79#include "executor/executor_functional.h"
     80#define EXECUTOR_FUNCTIONAL_USE_STATIC
     81#include "executor/executor_functional.h"
    33082
    33183#endif /* _EXECUTOR_H */
  • trunk/src/lib/util/executor/executor_functional.h

    r7721 r7722  
    2323#define __EXECUTOR_FUNCTIONAL_H_
    2424
    25 #include "base_object.h"
    26 #include "multi_type.h"
    2725#include "executor.h"
    2826
  • trunk/src/lib/util/loading/load_param.h

    r7721 r7722  
    2525
    2626#include "executor/executor.h"
    27 
    28 /// HACK HACK TAKE THIS INTO THE EXECUTOR
    29 #include "executor/executor_functional.h"
    30 #define EXECUTOR_FUNCTIONAL_USE_STATIC
    31 #include "executor/executor_functional.h"
    32 
    3327#include "executor/executor_specials.h"
    34 
    35 #include "helper_functions.h"
    3628
    3729// Forward Declaration //
Note: See TracChangeset for help on using the changeset viewer.