Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9736 in orxonox.OLD for branches/new_class_id/src/lib/util


Ignore:
Timestamp:
Sep 16, 2006, 12:25:40 PM (18 years ago)
Author:
bensch
Message:

more convertibles, more generic

Location:
branches/new_class_id/src/lib/util
Files:
3 edited

Legend:

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

    r9735 r9736  
    5454
    5555/**
     56 * @brief this is a Template Class used as an evaluater.
     57 *
     58 * Trait to determine a default Value for any Type,
     59 * and to define the Convertible, and how it is transformed into the
     60 * corresponding SubTypes over the operator().
     61 *
     62 * This Class must be reimplemented for each Convertible and all of its
     63 *  conversion-members.
     64 *
     65 * e.g: Convertible SubSting, that splits up into many Stings
     66 *      conversion-members: (int) can be transformed from a String.
     67 */
     68template<typename FromType> class ExecutorEvaluater
     69{
     70public:
     71  /** @brief Executes the Evaluater
     72   * @param CallValue the Value that should be converted
     73   * @param defaults the default Values.
     74   */
     75  template <typename ToType, int index>
     76  ToType operator()(FromType& CallValue, const MultiType* const defaults)
     77  {
     78    return defaultValue; /*(CallValue.size() > index) ?
     79           fromString<ToType>(CallValue[index], getDefault<ToType>(defaults, index)) :
     80    fromMulti<ToType>(defaults[index]); */
     81  }
     82  static FromType& defaultValue() { return FromType(); };
     83};
     84
     85/**
    5686 * @brief to remove writing errors, this function is Used.
    5787 * @param sub The SubString to use
    5888 * @param default The default Values.
    5989 */
    60 template<typename FromType, typename ToType, int index> class ExecutorEvaluater
    61 {
    62 public:
    63   /** @brief Executes the Evaluator
     90template<> class ExecutorEvaluater <const SubString>
     91{
     92public:
     93  /** @brief Executes the Evaluater
    6494   * @param CallValue the Value that should be converted
    6595   * @param defaults the default Values.
    6696   */
    67   ToType operator()(FromType& CallValue, const MultiType* const defaults)
     97  template <typename ToType, int index>
     98  ToType operator()(const SubString& CallValue, const MultiType* const defaults)
    6899  {
    69100    return (CallValue.size() > index) ?
     
    71102           fromMulti<ToType>(defaults[index]);
    72103  }
    73 };
     104  static const SubString& defaultValue() { return SubString::NullSubString; };
     105};
     106
     107
     108
    74109
    75110#endif /* __EXECUTOR_FUNCTIONAL_H_ */
     
    137172///////////
    138173//! @brief ExecutorClass, that can execute Functions without any parameters.
    139 template<class T, typename CallType, template<typename, typename, int> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
     174template<class T, typename CallType, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
    140175class __EXECUTOR_FUNCTIONAL_NAME(0) :public Executor<CallType, BaseClass>
    141176{
     
    160195   * @param sub the SubString to get the Parameters from.
    161196   */
    162   virtual void operator()(BaseObject* object, CallType& sub = SubString()) const
     197  virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const
    163198  {
    164199    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)();
     
    183218///////////
    184219//! @brief ExecutorClass, that can execute Functions with one parameter.
    185 template<class T, typename CallType, typename type0, template<typename, typename, int> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
     220template<class T, typename CallType, typename type0, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
    186221class __EXECUTOR_FUNCTIONAL_NAME(1) : public Executor<CallType, BaseClass>
    187222{
     
    206241   * @param sub the SubString to get the Parameters from.
    207242   */
    208   virtual void operator()(BaseObject* object, CallType& sub = SubString()) const
     243  virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const
    209244  {
    210245    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    211       Evaluater<CallType, type0, 0>()(sub, this->defaultValue));
     246      Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue));
    212247  };
    213248
     
    230265///////////
    231266//! @brief ExecutorClass, that can execute Functions with two parameters.
    232 template<class T, typename CallType, typename type0, typename type1, template<typename, typename, int> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
     267template<class T, typename CallType, typename type0, typename type1, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
    233268class __EXECUTOR_FUNCTIONAL_NAME(2) : public Executor<CallType, BaseClass>
    234269{
     
    243278   */
    244279  __EXECUTOR_FUNCTIONAL_NAME(2) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST)
    245   : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
     280      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
    246281  {
    247282    this->functionPointer = functionPointer;
     
    253288   * @param sub the SubString to get the Parameters from.
    254289   */
    255   virtual void operator()(BaseObject* object, CallType& sub = SubString()) const
     290  virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const
    256291  {
    257292    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    258       Evaluater<CallType, type0, 0>()(sub, this->defaultValue),
    259       Evaluater<CallType, type1, 1>()(sub, this->defaultValue));
     293      Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue),
     294      Evaluater<CallType>().template operator()<type1, 1>(sub, this->defaultValue));
    260295  };
    261296
     
    278313///////////
    279314//! @brief ExecutorClass, that can execute Functions with three parameters.
    280 template<class T, typename CallType, typename type0, typename type1, typename type2, template<typename, typename, int> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
     315template<class T, typename CallType, typename type0, typename type1, typename type2, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
    281316class __EXECUTOR_FUNCTIONAL_NAME(3) : public Executor<CallType, BaseClass>
    282317{
     
    291326   */
    292327  __EXECUTOR_FUNCTIONAL_NAME(3) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST)
    293   : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
     328      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
    294329  {
    295330    this->functionPointer = functionPointer;
     
    301336   * @param sub the SubString to get the Parameters from.
    302337   */
    303   virtual void operator()(BaseObject* object, CallType& sub = SubString()) const
     338  virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const
    304339  {
    305340    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    306       Evaluater<CallType, type0, 0>()(sub, this->defaultValue),
    307       Evaluater<CallType, type1, 1>()(sub, this->defaultValue),
    308       Evaluater<CallType, type2, 2>()(sub, this->defaultValue));
     341      Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue),
     342      Evaluater<CallType>().template operator()<type1, 1>(sub, this->defaultValue),
     343      Evaluater<CallType>().template operator()<type2, 2>(sub, this->defaultValue));
    309344  };
    310345
     
    327362///////////
    328363//! @brief ExecutorClass, that can execute Functions with four parameters.
    329 template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, template<typename, typename, int> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
     364template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
    330365class __EXECUTOR_FUNCTIONAL_NAME(4) : public Executor<CallType, BaseClass>
    331366{
     
    340375   */
    341376  __EXECUTOR_FUNCTIONAL_NAME(4) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST)
    342   : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
     377      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
    343378  {
    344379    this->functionPointer = functionPointer;
     
    350385  * @param sub the SubString to get the Parameters from.
    351386   */
    352   virtual void operator()(BaseObject* object, CallType& sub = SubString()) const
     387  virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const
    353388  {
    354389    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    355       Evaluater<CallType, type0, 0>()(sub, this->defaultValue),
    356       Evaluater<CallType, type1, 1>()(sub, this->defaultValue),
    357       Evaluater<CallType, type2, 2>()(sub, this->defaultValue),
    358       Evaluater<CallType, type3, 3>()(sub, this->defaultValue));
     390      Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue),
     391      Evaluater<CallType>().template operator()<type1, 1>(sub, this->defaultValue),
     392      Evaluater<CallType>().template operator()<type2, 2>(sub, this->defaultValue),
     393      Evaluater<CallType>().template operator()<type3, 3>(sub, this->defaultValue));
    359394  };
    360395
     
    378413///////////
    379414//! @brief ExecutorClass, that can execute Functions with five parameters.
    380 template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, typename type4, template<typename, typename, int> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
     415template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, typename type4, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
    381416class __EXECUTOR_FUNCTIONAL_NAME(5) : public Executor<CallType, BaseClass>
    382417{
     
    391426   */
    392427  __EXECUTOR_FUNCTIONAL_NAME(5) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST)
    393   : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), ExecutorParamType<type4>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
     428      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), ExecutorParamType<type4>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
    394429  {
    395430    this->functionPointer = functionPointer;
     
    401436  * @param sub the SubString to get the Parameters from.
    402437   */
    403   virtual void operator()(BaseObject* object, CallType& sub = SubString()) const
     438  virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const
    404439  {
    405440    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    406       Evaluater<CallType, type0, 0>()(sub, this->defaultValue),
    407       Evaluater<CallType, type1, 1>()(sub, this->defaultValue),
    408       Evaluater<CallType, type2, 2>()(sub, this->defaultValue),
    409       Evaluater<CallType, type3, 3>()(sub, this->defaultValue),
    410       Evaluater<CallType, type4, 4>()(sub, this->defaultValue));
     441      Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue),
     442      Evaluater<CallType>().template operator()<type1, 1>(sub, this->defaultValue),
     443      Evaluater<CallType>().template operator()<type2, 2>(sub, this->defaultValue),
     444      Evaluater<CallType>().template operator()<type3, 3>(sub, this->defaultValue),
     445      Evaluater<CallType>().template operator()<type4, 4>(sub, this->defaultValue));
    411446  };
    412447
  • branches/new_class_id/src/lib/util/substring.cc

    r9406 r9736  
    109109/** @brief Helper that gets you a String consisting of all WhiteSpaces and the Comma */
    110110const std::string SubString::WhiteSpacesWithComma = " \n\t,";
     111/** An Empty SubString */
     112const SubString SubString::NullSubString = SubString();
    111113
    112114/**
  • branches/new_class_id/src/lib/util/substring.h

    r9406 r9736  
    110110  static const std::string WhiteSpaces;
    111111  static const std::string WhiteSpacesWithComma;
     112  static const SubString   NullSubString;
    112113
    113114private:
Note: See TracChangeset for help on using the changeset viewer.