Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7715 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
May 19, 2006, 1:48:12 AM (19 years ago)
Author:
bensch
Message:

trunk: mighty templates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/orxonox.cc

    r7714 r7715  
    444444template<class T> class Executor0Params : public Executor
    445445{
    446   private:
    447     void (T::*functionPointer)();
    448 
    449   public:
    450     Executor0Params (void (T::*functionPointer)())
    451   : Executor()
    452     {
    453       this->functorType = Executor_Objective;
    454       this->functionPointer = functionPointer;
    455     }
    456     virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
    457     {
    458       (dynamic_cast<T*>(object)->*functionPointer)();
    459     };
    460 
    461     Executor* clone() const {};
     446private:
     447  void (T::*functionPointer)();
     448
     449public:
     450  Executor0Params (void (T::*functionPointer)())
     451      : Executor()
     452  {
     453    this->functorType = Executor_Objective;
     454    this->functionPointer = functionPointer;
     455  }
     456  virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
     457  {
     458    (dynamic_cast<T*>(object)->*functionPointer)();
     459  };
     460
     461  Executor* clone() const {};
    462462};
    463463
     
    512512};
    513513
     514
     515template<class T> Executor* createExecutor(void (T::*functionPointer)())
     516{
     517  return new Executor0Params<T>(functionPointer);
     518}
     519template<class T> Executor* createExecutor(void (T::*functionPointer)(bool))
     520{
     521  return new Executor1Params<T, bool>(functionPointer);
     522}
     523template<class T> Executor* createExecutor(void (T::*functionPointer)(int))
     524{
     525  return new Executor1Params<T, int>(functionPointer);
     526}
     527template<class T> Executor* createExecutor(void (T::*functionPointer)(bool, int))
     528{
     529  return new Executor2Params<T, bool, int>(functionPointer);
     530}
     531
     532
    514533class TestClass : public BaseObject
    515534{
     
    527546  TestClass test;
    528547  SubString testStrings("1, 2, 3", ",", SubString::WhiteSpaces, false);
    529   (Executor0Params<TestClass>(&TestClass::printTest))(&test, testStrings);
    530   (Executor1Params<TestClass,int>(&TestClass::printTestInt))(&test, testStrings);
    531   (Executor1Params<TestClass,bool>(&TestClass::printTestBool))(&test, testStrings);
    532   (Executor2Params<TestClass,bool, int>(&TestClass::printTwoVals))(&test, testStrings);
     548  (*createExecutor(&TestClass::printTest))(&test, testStrings);
     549  (*createExecutor(&TestClass::printTestInt))(&test, testStrings);
     550  (*createExecutor(&TestClass::printTestBool))(&test, testStrings);
     551  (*createExecutor(&TestClass::printTwoVals))(&test, testStrings);
    533552
    534553}
Note: See TracChangeset for help on using the changeset viewer.