Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7716 in orxonox.OLD for trunk/src/orxonox.cc


Ignore:
Timestamp:
May 19, 2006, 2:43:22 AM (19 years ago)
Author:
bensch
Message:

trunk: static and const calls all work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/orxonox.cc

    r7715 r7716  
    417417
    418418
    419 template<typename type> MT_Type ExecutorParamType() { return MT_EXT1; };
    420 template<> MT_Type ExecutorParamType<bool>() { return MT_EXT1; };
    421 template<> MT_Type ExecutorParamType<int>() { return MT_INT; };
    422 template<> MT_Type ExecutorParamType<unsigned int>() { return MT_UINT; };
    423 template<> MT_Type ExecutorParamType<float>() { return MT_FLOAT; };
    424 template<> MT_Type ExecutorParamType<char>() { return MT_CHAR; };
    425 template<> MT_Type ExecutorParamType<const std::string&>() { return MT_STRING; };
    426 
    427 template<typename type> type fromString(const std::string& input, type defaultValue) {return defaultValue; };
    428 template<> bool fromString<bool>(const std::string& input, bool defaultValue) { return isBool(input, defaultValue); };
    429 template<> int fromString<int>(const std::string& input, int defaultValue) { return isInt(input, defaultValue); };
    430 template<> unsigned int fromString<unsigned int>(const std::string& input, unsigned int defaultValue) { return isInt(input, defaultValue); };
    431 template<> float fromString<float>(const std::string& input, float defaultValue) { return isFloat(input, defaultValue); };
    432 template<> char fromString<char>(const std::string& input, char defaultValue) { return isInt(input, defaultValue); };
    433 template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue) { return isString(input, defaultValue); };
    434 
    435 template<typename type> type getDefault(const MultiType* const defaultValues, unsigned int i) { return (type)0; };
    436 template<> bool getDefault<bool>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getBool(); };
    437 template<> int getDefault<int>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getInt(); };
    438 template<> unsigned int getDefault<unsigned int>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getInt(); };
    439 template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getFloat(); };
    440 template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getChar(); };
    441 template<> std::string getDefault<std::string>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getString(); };
    442 
    443 
    444 template<class T> class Executor0Params : public Executor
    445 {
    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 {};
    462 };
    463 
    464 
    465 template<class T, typename type0> class Executor1Params : public Executor
    466 {
    467 private:
    468   void (T::*functionPointer)(type0);
    469 
    470 public:
    471   Executor1Params (void (T::*functionPointer)(type0))
    472       : Executor(ExecutorParamType<type0>())
    473   {
    474     this->functorType = Executor_Objective;
    475     this->functionPointer = functionPointer;
    476   }
    477   virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
    478   {
    479 
    480     /* // THE VERY COOL DEBUG
    481     printf("SUB[0] : %s\n", sub[0].c_str());
    482     printf("getDefault<type0>(this->defaultValue, 0):::: %d\n", getDefault<type0>(this->defaultValue, 0));
    483     printf("VALUE: %d\n", fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)));
    484     */
    485     (dynamic_cast<T*>(object)->*functionPointer)( fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) );
    486   };
    487 
    488   virtual Executor* clone() const {};
    489 };
    490 
    491 /// DOUBLE PENETRATION
    492 template<class T, typename type0, typename type1> class Executor2Params : public Executor
    493 {
    494 private:
    495   void (T::*functionPointer)(type0, type1);
    496 
    497 public:
    498   Executor2Params (void (T::*functionPointer)(type0, type1))
    499       : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>())
    500   {
    501     this->functorType = Executor_Objective;
    502     this->functionPointer = functionPointer;
    503   }
    504   virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
    505   {
    506     (dynamic_cast<T*>(object)->*functionPointer)(
    507       fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)),
    508       fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)));
    509   };
    510 
    511   virtual Executor* clone() const {};
    512 };
    513 
    514 
    515 template<class T> Executor* createExecutor(void (T::*functionPointer)())
    516 {
    517   return new Executor0Params<T>(functionPointer);
    518 }
    519 template<class T> Executor* createExecutor(void (T::*functionPointer)(bool))
    520 {
    521   return new Executor1Params<T, bool>(functionPointer);
    522 }
    523 template<class T> Executor* createExecutor(void (T::*functionPointer)(int))
    524 {
    525   return new Executor1Params<T, int>(functionPointer);
    526 }
    527 template<class T> Executor* createExecutor(void (T::*functionPointer)(bool, int))
    528 {
    529   return new Executor2Params<T, bool, int>(functionPointer);
    530 }
    531 
     419#include "executor/executor_functional.h"
     420
     421#define EXECUTOR_FUNCTIONAL_USE_STATIC
     422#include "executor/executor_functional.h"
    532423
    533424class TestClass : public BaseObject
     
    540431  void printTestBool(bool b) { printf("%d\n", (int)b); };
    541432  void printTwoVals(bool b, int i) { printf ("%d %d\n", b, i); };
     433
     434  static void printStatic() { printf("STATIC\n");};
    542435};
     436
     437template<class T> Executor* createExecutorStatic(void (*functionPointer)())
     438 {
     439   return new Executor0Params_static<TestClass>(functionPointer);
     440 }
    543441
    544442void TEST()
     
    546444  TestClass test;
    547445  SubString testStrings("1, 2, 3", ",", SubString::WhiteSpaces, false);
    548   (*createExecutor(&TestClass::printTest))(&test, testStrings);
    549   (*createExecutor(&TestClass::printTestInt))(&test, testStrings);
    550   (*createExecutor(&TestClass::printTestBool))(&test, testStrings);
    551   (*createExecutor(&TestClass::printTwoVals))(&test, testStrings);
     446  (*createExecutor<TestClass>(&TestClass::printTest))(&test, testStrings);
     447  (*createExecutor<TestClass>(&TestClass::printTestInt))(&test, testStrings);
     448  (*createExecutor<TestClass>(&TestClass::printTestBool))(&test, testStrings);
     449  (*createExecutor<TestClass>(&TestClass::printTwoVals))(&test, testStrings);
     450  (*createExecutor<TestClass>(&TestClass::printStatic))(&test, testStrings);
    552451
    553452}
Note: See TracChangeset for help on using the changeset viewer.