Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File:
1 edited

Legend:

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

    r8894 r9869  
    99#include "base_object.h"
    1010
    11 #include "helper_functions.h"
    1211#include "multi_type.h"
    13 #include "substring.h"
    14 #include "functor_list.h" //< MUST BE INCLUDED HERE AT LEAST ONCE.
    15 
    16 //! an enumerator for the definition of the Type.
    17 typedef enum {
    18   Executor_Objective         = 1,
    19   Executor_Static            = 2,
    20 
    21   Executor_NoLoadString      = 8,
    22 } Executor_Type;
     12
     13//! The maximum Count of Arguments of the Executor
     14/** This is Hardcoded, for each Executor. */
     15#define EXECUTOR_MAX_ARGUMENTS                7
     16
     17
     18/** @returns the Type of an Argument taken by the Executor */
     19template<typename type> inline MT_Type ExecutorParamType() { return MT_EXT1; };
     20/** @returns the Type of an Argument taken by the Executor in this case MT_BOOL */
     21template<> inline MT_Type ExecutorParamType<bool>() { return MT_BOOL; };
     22/** @returns the Type of an Argument taken by the Executor in this case MT_INT*/
     23template<> inline MT_Type ExecutorParamType<int>() { return MT_INT; };
     24/** @returns the Type of an Argument taken by the Executor in this case MT_UINT*/
     25template<> inline MT_Type ExecutorParamType<unsigned int>() { return MT_UINT; };
     26/** @returns the Type of an Argument taken by the Executor in this case MT_FLOAT*/
     27template<> inline MT_Type ExecutorParamType<float>() { return MT_FLOAT; };
     28/** @returns the Type of an Argument taken by the Executor in this case MT_CHAR*/
     29template<> inline MT_Type ExecutorParamType<char>() { return MT_CHAR; };
     30/** @returns the Type of an Argument taken by the Executor in this case MT_STRING*/
     31template<> inline MT_Type ExecutorParamType<const std::string&>() { return MT_STRING; };
    2332
    2433////////////////
     
    3645 *  Functions with many types (@see functor_list.h)
    3746 */
    38 class Executor : public BaseObject
     47template <typename CallType, class BaseClass = BaseObject> class Executor
    3948{
    40   public:
    41     virtual ~Executor();
    42 
    43     virtual Executor* clone () const = 0;
    44 //    virtual bool operator==(const Executor* executor) const = 0;
    45 
    46     // SETTING up the EXECUTOR
    47     Executor* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
    48                             const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
    49                             const MultiType& value4 = MT_NULL, const MultiType& param5 = MT_NULL,
    50                             const MultiType& param6 = MT_NULL);
    51     /** @param i the i'th defaultValue, @returns reference to the MultiType */
    52     inline MultiType& getDefaultValue(unsigned int i) { return defaultValue[i]; };
    53 
    54     // EXECUTE
    55     /** executes a Command. @param objec the Object, @param count how many values, @param values the Values */
    56     virtual void operator()(BaseObject* object, int& count, void* values) const = 0;
    57     /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */
    58     virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const = 0;
    59 
    60     // RETRIEVE INFORMATION
    61     /** @returns the Type of this Function (either static or objective) */
    62     inline long getType() const { return this->functorType; };
    63     /** @returns the Count of Parameters this Executor takes */
    64     inline unsigned int getParamCount() const { return this->paramCount; };
    65 
    66     static void debug();
    67 
    68   protected:
    69     Executor(const MultiType& param0 = MT_NULL, const MultiType& param1 = MT_NULL,
    70              const MultiType& param2 = MT_NULL, const MultiType& param3 = MT_NULL,
    71              const MultiType& param4 = MT_NULL, const MultiType& param5 = MT_NULL,
    72              const MultiType& param6 = MT_NULL);
    73 
    74     void cloning(Executor* executor) const;
    75 
    76   protected:
    77     short                       functorType;      //!< The type of Function we've got (either static or objective).
    78     unsigned int                paramCount;       //!< the count of parameters.
    79     MultiType                   defaultValue[7];  //!< Default Values.
     49public:
     50  //! an enumerator for the definition of the Type.
     51  typedef enum {
     52    FunctionMember,      //!< The function is neither Static nor Constant
     53    FunctionStatic,      //!< The Function is Static and pointing to either a Static Member or a C-style function.
     54    FunctionConstMember, //!< The Function is Constant and pointing to a Member that does not change the Object.
     55  } FunctionType;
     56
     57public:
     58  virtual ~Executor() {};
     59
     60  // RETRIEVE INFORMATION
     61  /** @param i the i'th defaultValue, @returns reference to the MultiType */
     62  inline MultiType& getDefaultValue(unsigned int i) { return defaultValue[i]; };
     63  /** @returns the default Values as a List */
     64  inline const MultiType* const getDefaultValues() { return defaultValue; };
     65
     66  /** @returns the Type of this Function (either static or objective) */
     67  inline FunctionType getType() const { return this->functionType; };
     68
     69  /** @returns the Count of Parameters this Executor takes */
     70  inline unsigned int getParamCount() const { return this->paramCount; };
     71  /** @returns true if the Executor has a return Value. */
     72  inline bool hasRetVal() const { return bRetVal; };
     73
     74  /** executes a Command. @param object the Object, @param values The Value of type CallType to pass to the Executor. */
     75  virtual void operator()(BaseClass* object, CallType& values) const = 0;
     76
     77  /**
     78   * @brief set the default values of the executor
     79   * @param value0 the first default value
     80   * @param value1 the second default value
     81   * @param value2 the third default value
     82   * @param value3 the fourth default value
     83   * @param value4 the fifth default value
     84   * @param value5 the sixth default value
     85   * @param value6 the seventh default value
     86   * @returns itself
     87   * @note: THIS FUNCTION WILL BE REPLACED BY A CONFIGURATOR (most probably).
     88  */
     89  Executor* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
     90                          const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
     91                          const MultiType& value4 = MT_NULL, const MultiType& value5 = MT_NULL,
     92                          const MultiType& value6 = MT_NULL)
     93  {
     94    const MultiType* value[5];
     95    value[0] = &value0;
     96    value[1] = &value1;
     97    value[2] = &value2;
     98    value[3] = &value3;
     99    value[4] = &value4;
     100    value[5] = &value5;
     101    value[6] = &value6;
     102    for (unsigned int i = 0; i < this->paramCount; i++)
     103    {
     104      if (*value[i] != MT_NULL)
     105      {
     106        this->defaultValue[i].setValueOf(*value[i]);
     107        this->defaultValue[i].storeString();
     108      }
     109    }
     110    return this;
     111  }
     112
     113  /** @returns the Clone as a new Copy of the Executor. */
     114  virtual Executor<CallType, BaseClass>* clone () const = 0;
     115
     116
     117protected:
     118  //! Now follows a List of Executor Constructors, to be fast in creating.
     119  //! Creates an Executor with no Argument.
     120  Executor(bool hasRetVal, FunctionType functionType = FunctionMember)
     121  : bRetVal(hasRetVal), paramCount(0), functionType(functionType)
     122  { };
     123
     124  //! Creates an Executor with 1 Argument.
     125  Executor(bool hasRetVal, const MultiType& param0,
     126           FunctionType functionType = FunctionMember)
     127  : bRetVal(hasRetVal), paramCount(1), functionType(functionType)
     128  {
     129    this->defaultValue[0] = param0;
     130  };
     131
     132  //! Creates an Executor with 2 Arguments.
     133  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
     134           FunctionType functionType = FunctionMember)
     135  : bRetVal(hasRetVal), paramCount(2), functionType(functionType)
     136  {
     137    this->defaultValue[0] = param0;
     138    this->defaultValue[1] = param1;
     139  };
     140
     141  //! Creates an Executor with 3 Arguments.
     142  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
     143           const MultiType& param2,
     144           FunctionType functionType = FunctionMember)
     145  : bRetVal(hasRetVal), paramCount(3), functionType(functionType)
     146  {
     147    this->defaultValue[0] = param0;
     148    this->defaultValue[1] = param1;
     149    this->defaultValue[2] = param2;
     150  };
     151
     152  //! Creates an Executor with 4 Arguments.
     153  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
     154           const MultiType& param2, const MultiType& param3,
     155           FunctionType functionType = FunctionMember)
     156  : bRetVal(hasRetVal), paramCount(4), functionType(functionType)
     157  {
     158    this->defaultValue[0] = param0;
     159    this->defaultValue[1] = param1;
     160    this->defaultValue[2] = param2;
     161    this->defaultValue[3] = param3;
     162  };
     163
     164  //! Creates an Executor with 5 Arguments.
     165  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
     166           const MultiType& param2, const MultiType& param3,
     167           const MultiType& param4,
     168           FunctionType functionType = FunctionMember)
     169  : bRetVal(hasRetVal), paramCount(5), functionType(functionType)
     170  {
     171    this->defaultValue[0] = param0;
     172    this->defaultValue[1] = param1;
     173    this->defaultValue[2] = param2;
     174    this->defaultValue[3] = param3;
     175    this->defaultValue[4] = param4;
     176  };
     177
     178  //! Creates an Executor with 6 Arguments.
     179  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
     180           const MultiType& param2, const MultiType& param3,
     181           const MultiType& param4, const MultiType& param5,
     182           FunctionType functionType = FunctionMember)
     183  : bRetVal(hasRetVal), paramCount(6), functionType(functionType)
     184  {
     185    this->defaultValue[0] = param0;
     186    this->defaultValue[1] = param1;
     187    this->defaultValue[2] = param2;
     188    this->defaultValue[3] = param3;
     189    this->defaultValue[4] = param4;
     190    this->defaultValue[5] = param5;
     191  };
     192
     193  //! Creates an Executor with 7 Arguments.
     194  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
     195           const MultiType& param2, const MultiType& param3,
     196           const MultiType& param4, const MultiType& param5,
     197           const MultiType& param6,
     198           FunctionType functionType = FunctionMember)
     199  : bRetVal(hasRetVal), paramCount(7), functionType(functionType)
     200  {
     201    this->defaultValue[0] = param0;
     202    this->defaultValue[1] = param1;
     203    this->defaultValue[2] = param2;
     204    this->defaultValue[3] = param3;
     205    this->defaultValue[4] = param4;
     206    this->defaultValue[5] = param5;
     207    this->defaultValue[6] = param6;
     208  };
     209
     210protected:
     211  const bool                  bRetVal;          //!< True if the Executor has a return Value.
     212  const unsigned int          paramCount;       //!< the count of parameters.
     213  MultiType                   defaultValue[7];  //!< Default Values.
     214
     215  const FunctionType          functionType;     //!< What Type of Function it is.
    80216};
    81217
    82 #include "executor/executor_functional.h"
    83 #define EXECUTOR_FUNCTIONAL_USE_CONST
    84 #include "executor/executor_functional.h"
    85 #define EXECUTOR_FUNCTIONAL_USE_STATIC
    86 #include "executor/executor_functional.h"
    87 
    88218#endif /* _EXECUTOR_H */
Note: See TracChangeset for help on using the changeset viewer.