Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9731 in orxonox.OLD for branches


Ignore:
Timestamp:
Sep 15, 2006, 12:52:54 PM (18 years ago)
Author:
bensch
Message:

orxonox/new_class_id: more generic executor, with much more elaborate Evaluator Functionality as a Functional Object.
The Idea is to remove all the implementations of Extensions of BaseExecutors and to introduce:

  1. ExecutorBase
  2. Executor<typename CallClass, typename, convertible_class[, bool retVal [, typename type1 [, type2 [,….]]]]>Executor

then one only has to supply a new Typename vor the convertible (e.g. SubString, or lua_State) of which the executor has no knowledge at all, and voila a new Convertible is generated, that can split open Functions into multiple arguments and also return a Value of some sorts… althought about the return value i am not sure… yet :)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/util/executor/executor_functional.h

    r9730 r9731  
    5858 * @param default The default Values.
    5959 */
    60 template<typename type, int index> type Evaluate(const SubString& sub, const MultiType* const defaults)
    61 {
    62   return (sub.size() > index) ?
    63       fromString<type>(sub[index], getDefault<type>(defaults, index)) :
    64       fromMulti<type>(defaults[index]);
    65 };
    66 
     60template<typename FromType, typename ToType, int index> class ExecutorEvaluater
     61{
     62public:
     63  ToType operator()(FromType& sub, const MultiType* const defaults)
     64  {
     65    return (sub.size() > index) ?
     66           fromString<ToType>(sub[index], getDefault<ToType>(defaults, index)) :
     67           fromMulti<ToType>(defaults[index]);
     68  }
     69};
    6770
    6871#endif /* __EXECUTOR_FUNCTIONAL_H_ */
     
    7780#define __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER   T::*functionPointer
    7881
    79 #ifdef EXECUTOR_FUNCTIONAL_USE_CONST
    80  #ifdef __EXECUTOR_FUNCTIONAL_CONST_INCLUDED
     82#ifdef EXECUTOR_FUNCTIONAL_USE_CONST            //! USING CONST FUNCTIONALS
     83 #ifdef __EXECUTOR_FUNCTIONAL_CONST_INCLUDED    //!< CHECK IF ALREADY INCLUED CONST FUNCTIONALS
    8184  #define __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS
    8285 #else
     
    122125///////////
    123126//! @brief ExecutorClass, that can execute Functions without any parameters.
    124 template<class T> class __EXECUTOR_FUNCTIONAL_NAME(0) : public Executor<const SubString>
     127template<class T, typename CallType, template<typename, typename, int> class Evaluater = ExecutorEvaluater>
     128class __EXECUTOR_FUNCTIONAL_NAME(0) :public Executor<CallType>
    125129{
    126130private:
     
    134138   */
    135139  __EXECUTOR_FUNCTIONAL_NAME(0) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST )
    136       : Executor<const SubString>(false)
     140      : Executor<CallType>(false)
    137141  {
    138142    this->functorType = Executor_Objective;
     
    145149   * @param sub the SubString to get the Parameters from.
    146150   */
    147   virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
     151  virtual void operator()(BaseObject* object, CallType& sub = SubString()) const
    148152  {
    149153    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)();
     
    154158   * @returns a new Executor that's a copy of this one.
    155159   */
    156   virtual Executor<const SubString>* clone() const
    157   {
    158     return new __EXECUTOR_FUNCTIONAL_NAME(0)<T>(this->functionPointer);
     160  virtual Executor<CallType>* clone() const
     161  {
     162    return new __EXECUTOR_FUNCTIONAL_NAME(0)<T, CallType>(this->functionPointer);
    159163  };
    160164};
     
    166170///////////
    167171//! @brief ExecutorClass, that can execute Functions with one parameter.
    168 template<class T, typename type0> class __EXECUTOR_FUNCTIONAL_NAME(1) : public Executor<const SubString>
     172template<class T, typename CallType, typename type0, template<typename, typename, int> class Evaluater = ExecutorEvaluater>
     173class __EXECUTOR_FUNCTIONAL_NAME(1) : public Executor<CallType>
    169174{
    170175private:
     
    178183   */
    179184  __EXECUTOR_FUNCTIONAL_NAME(1) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST)
    180       : Executor<const SubString>(false, ExecutorParamType<type0>())
     185      : Executor<CallType>(false, ExecutorParamType<type0>())
    181186  {
    182187    this->functorType = Executor_Objective;
     
    189194   * @param sub the SubString to get the Parameters from.
    190195   */
    191   virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
     196  virtual void operator()(BaseObject* object, CallType& sub = SubString()) const
    192197  {
    193198    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    194       Evaluate<type0, 0>(sub, this->defaultValue));
     199      Evaluater<CallType, type0, 0>()(sub, this->defaultValue));
    195200  };
    196201
     
    199204   * @returns a new Executor that's a copy of this one.
    200205   */
    201   virtual Executor<const SubString>* clone() const
    202   {
    203     return  new __EXECUTOR_FUNCTIONAL_NAME(1)<T, type0>(this->functionPointer);
     206  virtual Executor<CallType>* clone() const
     207  {
     208    return  new __EXECUTOR_FUNCTIONAL_NAME(1)<T, CallType, type0>(this->functionPointer);
    204209  };
    205210};
     
    209214///////////
    210215//! @brief ExecutorClass, that can execute Functions with two parameters.
    211 template<class T, typename type0, typename type1> class __EXECUTOR_FUNCTIONAL_NAME(2) : public Executor<const SubString>
     216template<class T, typename CallType, typename type0, typename type1, template<typename, typename, int> class Evaluater = ExecutorEvaluater>
     217class __EXECUTOR_FUNCTIONAL_NAME(2) : public Executor<CallType>
    212218{
    213219private:
     
    221227   */
    222228  __EXECUTOR_FUNCTIONAL_NAME(2) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST)
    223       : Executor<const SubString>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>())
     229      : Executor<CallType>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>())
    224230  {
    225231    this->functorType = Executor_Objective;
     
    232238   * @param sub the SubString to get the Parameters from.
    233239   */
    234   virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
     240  virtual void operator()(BaseObject* object, CallType& sub = SubString()) const
    235241  {
    236242    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    237       Evaluate<type0, 0>(sub, this->defaultValue),
    238       Evaluate<type1, 1>(sub, this->defaultValue));
     243      Evaluater<CallType, type0, 0>()(sub, this->defaultValue),
     244      Evaluater<CallType, type1, 1>()(sub, this->defaultValue));
    239245  };
    240246
     
    243249   * @returns a new Executor that's a copy of this one.
    244250   */
    245   virtual Executor<const SubString>* clone() const
    246   {
    247     return new __EXECUTOR_FUNCTIONAL_NAME(2)<T, type0, type1>(this->functionPointer);
     251  virtual Executor<CallType>* clone() const
     252  {
     253    return new __EXECUTOR_FUNCTIONAL_NAME(2)<T, CallType, type0, type1>(this->functionPointer);
    248254  };
    249255};
     
    254260///////////
    255261//! @brief ExecutorClass, that can execute Functions with three parameters.
    256 template<class T, typename type0, typename type1, typename type2> class __EXECUTOR_FUNCTIONAL_NAME(3) : public Executor<const SubString>
     262template<class T, typename CallType, typename type0, typename type1, typename type2, template<typename, typename, int> class Evaluater = ExecutorEvaluater>
     263class __EXECUTOR_FUNCTIONAL_NAME(3) : public Executor<CallType>
    257264{
    258265private:
     
    266273   */
    267274  __EXECUTOR_FUNCTIONAL_NAME(3) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST)
    268       : Executor<const SubString>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>())
     275      : Executor<CallType>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>())
    269276  {
    270277    this->functorType = Executor_Objective;
     
    277284   * @param sub the SubString to get the Parameters from.
    278285   */
    279   virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
     286  virtual void operator()(BaseObject* object, CallType& sub = SubString()) const
    280287  {
    281288    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    282       Evaluate<type0, 0>(sub, this->defaultValue),
    283       Evaluate<type1, 1>(sub, this->defaultValue),
    284       Evaluate<type2, 2>(sub, this->defaultValue));
     289      Evaluater<CallType, type0, 0>()(sub, this->defaultValue),
     290      Evaluater<CallType, type1, 1>()(sub, this->defaultValue),
     291      Evaluater<CallType, type2, 2>()(sub, this->defaultValue));
    285292  };
    286293
     
    289296   * @returns a new Executor that's a copy of this one.
    290297   */
    291   virtual Executor<const SubString>* clone() const
    292   {
    293     return new __EXECUTOR_FUNCTIONAL_NAME(3)<T, type0, type1, type2>(this->functionPointer);
     298  virtual Executor<CallType>* clone() const
     299  {
     300    return new __EXECUTOR_FUNCTIONAL_NAME(3)<T, CallType, type0, type1, type2>(this->functionPointer);
    294301  };
    295302};
     
    301308///////////
    302309//! @brief ExecutorClass, that can execute Functions with four parameters.
    303 template<class T, typename type0, typename type1, typename type2, typename type3> class __EXECUTOR_FUNCTIONAL_NAME(4) : public Executor<const SubString>
     310template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, template<typename, typename, int> class Evaluater = ExecutorEvaluater>
     311class __EXECUTOR_FUNCTIONAL_NAME(4) : public Executor<CallType>
    304312{
    305313private:
     
    313321   */
    314322  __EXECUTOR_FUNCTIONAL_NAME(4) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST)
    315       : Executor<const SubString>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>())
     323      : Executor<CallType>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>())
    316324  {
    317325    this->functorType = Executor_Objective;
     
    324332  * @param sub the SubString to get the Parameters from.
    325333   */
    326   virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
     334  virtual void operator()(BaseObject* object, CallType& sub = SubString()) const
    327335  {
    328336    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    329       Evaluate<type0, 0>(sub, this->defaultValue),
    330       Evaluate<type1, 1>(sub, this->defaultValue),
    331       Evaluate<type2, 2>(sub, this->defaultValue),
    332       Evaluate<type3, 3>(sub, this->defaultValue));
     337      Evaluater<CallType, type0, 0>()(sub, this->defaultValue),
     338      Evaluater<CallType, type1, 1>()(sub, this->defaultValue),
     339      Evaluater<CallType, type2, 2>()(sub, this->defaultValue),
     340      Evaluater<CallType, type3, 3>()(sub, this->defaultValue));
    333341  };
    334342
     
    337345   * @returns a new Executor that's a copy of this one.
    338346   */
    339   virtual Executor<const SubString>* clone() const
    340   {
    341     return new __EXECUTOR_FUNCTIONAL_NAME(4)<T, type0, type1, type2, type3>(this->functionPointer);
     347  virtual Executor<CallType>* clone() const
     348  {
     349    return new __EXECUTOR_FUNCTIONAL_NAME(4)<T, CallType, type0, type1, type2, type3>(this->functionPointer);
    342350  };
    343351};
     
    349357///////////
    350358//! @brief ExecutorClass, that can execute Functions with five parameters.
    351 template<class T, typename type0, typename type1, typename type2, typename type3, typename type4> class __EXECUTOR_FUNCTIONAL_NAME(5) : public Executor<const SubString>
     359template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, typename type4, template<typename, typename, int> class Evaluater = ExecutorEvaluater>
     360class __EXECUTOR_FUNCTIONAL_NAME(5) : public Executor<CallType>
    352361{
    353362private:
     
    361370   */
    362371  __EXECUTOR_FUNCTIONAL_NAME(5) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST)
    363       : Executor<const SubString>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), ExecutorParamType<type4>())
     372      : Executor<CallType>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), ExecutorParamType<type4>())
    364373  {
    365374    this->functorType = Executor_Objective;
     
    372381  * @param sub the SubString to get the Parameters from.
    373382   */
    374   virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
     383  virtual void operator()(BaseObject* object, CallType& sub = SubString()) const
    375384  {
    376385    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    377       Evaluate<type0, 0>(sub, this->defaultValue),
    378       Evaluate<type1, 1>(sub, this->defaultValue),
    379       Evaluate<type2, 2>(sub, this->defaultValue),
    380       Evaluate<type3, 3>(sub, this->defaultValue),
    381       Evaluate<type4, 4>(sub, this->defaultValue));
     386      Evaluater<CallType, type0, 0>()(sub, this->defaultValue),
     387      Evaluater<CallType, type1, 1>()(sub, this->defaultValue),
     388      Evaluater<CallType, type2, 2>()(sub, this->defaultValue),
     389      Evaluater<CallType, type3, 3>()(sub, this->defaultValue),
     390      Evaluater<CallType, type4, 4>()(sub, this->defaultValue));
    382391  };
    383392
     
    386395   * @returns a new Executor that's a copy of this one.
    387396   */
    388   virtual Executor<const SubString>* clone() const
    389   {
    390     return new __EXECUTOR_FUNCTIONAL_NAME(5)<T, type0, type1, type2, type3, type4>(this->functionPointer);
    391   };
    392 };
    393 
    394 
    395 
     397  virtual Executor<CallType>* clone() const
     398  {
     399    return new __EXECUTOR_FUNCTIONAL_NAME(5)<T, CallType, type0, type1, type2, type3, type4>(this->functionPointer);
     400  };
     401};
     402
     403
     404
     405
     406
     407
     408
     409
     410
     411// // // // // // // // // // // // //
     412//// EXTENSION TO HIDE CONSTRUCT /////
     413// // // // // // // // // // // // //
    396414/**
    397415 * @brief enables us to easily retrieve an Executor of Class T with modular Argument-count, (without thinking about args at all)
     
    400418template<class T> Executor<const SubString>* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST) \
    401419{ \
    402   return new __EXECUTOR_FUNCTIONAL_NAME(0)<T>(functionPointer); \
     420  return new __EXECUTOR_FUNCTIONAL_NAME(0)<T, const SubString>(functionPointer); \
    403421}
    404422
     
    410428template<class T> Executor<const SubString>* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \
    411429{ \
    412   return new __EXECUTOR_FUNCTIONAL_NAME(1)<T, type0##_TYPE>(functionPointer); \
     430  return new __EXECUTOR_FUNCTIONAL_NAME(1)<T, const SubString, type0##_TYPE>(functionPointer); \
    413431}
    414432
     
    421439template<class T> Executor<const SubString>* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE, type1##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \
    422440{ \
    423   return new __EXECUTOR_FUNCTIONAL_NAME(2)<T, type0##_TYPE, type1##_TYPE>(functionPointer); \
     441  return new __EXECUTOR_FUNCTIONAL_NAME(2)<T, const SubString, type0##_TYPE, type1##_TYPE>(functionPointer); \
    424442}
    425443
     
    433451template<class T> Executor<const SubString>* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE, type1##_TYPE, type2##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \
    434452{ \
    435   return new __EXECUTOR_FUNCTIONAL_NAME(3)<T, type0##_TYPE, type1##_TYPE, type2##_TYPE>(functionPointer); \
     453  return new __EXECUTOR_FUNCTIONAL_NAME(3)<T, const SubString, type0##_TYPE, type1##_TYPE, type2##_TYPE>(functionPointer); \
    436454}
    437455
     
    446464template<class T> Executor<const SubString>* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE, type1##_TYPE, type2##_TYPE, type3##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \
    447465{ \
    448   return new __EXECUTOR_FUNCTIONAL_NAME(4)<T, type0##_TYPE, type1##_TYPE, type2##_TYPE, type3##_TYPE>(functionPointer); \
     466  return new __EXECUTOR_FUNCTIONAL_NAME(4)<T, const SubString, type0##_TYPE, type1##_TYPE, type2##_TYPE, type3##_TYPE>(functionPointer); \
    449467}
    450468
     
    460478template<class T> Executor<const SubString>* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE, type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \
    461479{ \
    462     return new __EXECUTOR_FUNCTIONAL_NAME(5)<T, type0##_TYPE, type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE>(functionPointer); \
     480    return new __EXECUTOR_FUNCTIONAL_NAME(5)<T, const SubString, type0##_TYPE, type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE>(functionPointer); \
    463481}
    464482
Note: See TracChangeset for help on using the changeset viewer.