| 1 | /* |
|---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
|---|
| 3 | |
|---|
| 4 | Copyright (C) 2004 orx |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
|---|
| 9 | any later version. |
|---|
| 10 | |
|---|
| 11 | ### File Specific: |
|---|
| 12 | main-programmer: Benjamin Grauer |
|---|
| 13 | co-programmer: ... |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | #include "executor.h" |
|---|
| 17 | |
|---|
| 18 | std::string ExecutorFunctional_returningString_from; |
|---|
| 19 | std::string ExecutorFunctional_returningString_default; |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | template<> MT_Type ExecutorParamType<bool>() { return MT_BOOL; }; |
|---|
| 23 | template<> MT_Type ExecutorParamType<int>() { return MT_INT; }; |
|---|
| 24 | template<> MT_Type ExecutorParamType<unsigned int>() { return MT_UINT; }; |
|---|
| 25 | template<> MT_Type ExecutorParamType<float>() { return MT_FLOAT; }; |
|---|
| 26 | template<> MT_Type ExecutorParamType<char>() { return MT_CHAR; }; |
|---|
| 27 | template<> MT_Type ExecutorParamType<const std::string&>() { return MT_STRING; }; |
|---|
| 28 | |
|---|
| 29 | template<> bool fromString<bool>(const std::string& input, bool defaultValue) { return isBool(input, defaultValue); }; |
|---|
| 30 | template<> int fromString<int>(const std::string& input, int defaultValue) { return isInt(input, defaultValue); }; |
|---|
| 31 | template<> unsigned int fromString<unsigned int>(const std::string& input, unsigned int defaultValue) { return isInt(input, defaultValue); }; |
|---|
| 32 | template<> float fromString<float>(const std::string& input, float defaultValue) { return isFloat(input, defaultValue); }; |
|---|
| 33 | template<> char fromString<char>(const std::string& input, char defaultValue) { return isInt(input, defaultValue); }; |
|---|
| 34 | template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue) { return ExecutorFunctional_returningString_from = isString(input, defaultValue); }; |
|---|
| 35 | |
|---|
| 36 | template<> bool getDefault<bool>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getBool(); }; |
|---|
| 37 | template<> int getDefault<int>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getInt(); }; |
|---|
| 38 | template<> unsigned int getDefault<unsigned int>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getInt(); }; |
|---|
| 39 | template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getFloat(); }; |
|---|
| 40 | template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getChar(); }; |
|---|
| 41 | template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i) { return ExecutorFunctional_returningString_default = defaultValues[i].getString(); }; |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * A LITTLE TESTING SUITE FOR THE EXECUTOR. |
|---|
| 49 | * |
|---|
| 50 | #include "executor/executor_functional.h" |
|---|
| 51 | |
|---|
| 52 | #define EXECUTOR_FUNCTIONAL_USE_STATIC |
|---|
| 53 | #include "executor/executor_functional.h" |
|---|
| 54 | |
|---|
| 55 | class TestClass : public BaseObject |
|---|
| 56 | { |
|---|
| 57 | public: |
|---|
| 58 | TestClass() {}; |
|---|
| 59 | |
|---|
| 60 | void printTest() { printf ("TEST\n"); }; |
|---|
| 61 | void printTestInt(int i) { printf ("%d\n", i); }; |
|---|
| 62 | void printTestBool(bool b) { printf("%d\n", (int)b); }; |
|---|
| 63 | void printTwoVals(int b, int i) { printf ("%d %d\n", b, i); }; |
|---|
| 64 | void printStrings(const std::string& name) { printf("String:: '%s'\n", name.c_str()); }; |
|---|
| 65 | static void printStatic() { printf("STATIC\n");}; |
|---|
| 66 | }; |
|---|
| 67 | |
|---|
| 68 | void TEST() |
|---|
| 69 | { |
|---|
| 70 | TestClass test; |
|---|
| 71 | SubString testStrings("1 SCHEISSE, 2, 3", ",", SubString::WhiteSpaces, false); |
|---|
| 72 | (*createExecutor<TestClass>(&TestClass::printTest))(&test, testStrings); |
|---|
| 73 | (*createExecutor<TestClass>(&TestClass::printTestInt))(&test, testStrings); |
|---|
| 74 | (*createExecutor<TestClass>(&TestClass::printTestBool))(&test, testStrings); |
|---|
| 75 | (*createExecutor<TestClass>(&TestClass::printTwoVals))(&test, testStrings); |
|---|
| 76 | (*createExecutor<TestClass>(&TestClass::printStatic))(&test, testStrings); |
|---|
| 77 | (*createExecutor<TestClass>(&TestClass::printStrings))(&test, testStrings); |
|---|
| 78 | |
|---|
| 79 | } |
|---|
| 80 | */ |
|---|