[4838] | 1 | /*! |
---|
[9737] | 2 | * @file executor_generic.h |
---|
| 3 | * Definition of a Generic Executor |
---|
[5391] | 4 | */ |
---|
[1853] | 5 | |
---|
[7716] | 6 | /* |
---|
| 7 | orxonox - the future of 3D-vertical-scrollers |
---|
[1853] | 8 | |
---|
[7716] | 9 | Copyright (C) 2004 orx |
---|
[1853] | 10 | |
---|
[7716] | 11 | This program is free software; you can redistribute it and/or modify |
---|
| 12 | it under the terms of the GNU General Public License as published by |
---|
| 13 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 14 | any later version. |
---|
[5141] | 15 | |
---|
[7716] | 16 | ### File Specific: |
---|
| 17 | main-programmer: Benjamin Grauer |
---|
| 18 | co-programmer: ... |
---|
| 19 | */ |
---|
[5652] | 20 | |
---|
[5328] | 21 | |
---|
[9740] | 22 | |
---|
[9742] | 23 | #ifndef __EXECUTOR_SUBSTRING_H_ |
---|
| 24 | #define __EXECUTOR_SUBSTRING_H_ |
---|
[5641] | 25 | |
---|
[9740] | 26 | |
---|
[9742] | 27 | #include "executor_generic.h" |
---|
[9728] | 28 | #include "substring.h" |
---|
[9745] | 29 | #ifdef FUNCTOR_CALL_TYPE |
---|
| 30 | #undef FUNCTOR_CALL_TYPE |
---|
| 31 | #endif |
---|
| 32 | #define FUNCTOR_CALL_TYPE const SubString |
---|
[5641] | 33 | |
---|
[8035] | 34 | template<typename type> type fromString(const std::string& input, type defaultValue) { return defaultValue; }; |
---|
[7721] | 35 | template<> bool fromString<bool>(const std::string& input, bool defaultValue); |
---|
| 36 | template<> int fromString<int>(const std::string& input, int defaultValue); |
---|
| 37 | template<> unsigned int fromString<unsigned int>(const std::string& input, unsigned int defaultValue); |
---|
| 38 | template<> float fromString<float>(const std::string& input, float defaultValue); |
---|
| 39 | template<> char fromString<char>(const std::string& input, char defaultValue); |
---|
| 40 | template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue); |
---|
[5641] | 41 | |
---|
[8035] | 42 | template<typename type> type fromMulti(const MultiType& multi) { /* return defaultValue; */ }; |
---|
| 43 | template<> bool fromMulti<bool>(const MultiType& multi); |
---|
| 44 | template<> int fromMulti<int>(const MultiType& multi); |
---|
| 45 | template<> unsigned int fromMulti<unsigned int>(const MultiType& multi); |
---|
| 46 | template<> float fromMulti<float>(const MultiType& multi); |
---|
| 47 | template<> char fromMulti<char>(const MultiType& multi); |
---|
| 48 | template<> const std::string& fromMulti<const std::string&>(const MultiType& multi); |
---|
| 49 | |
---|
| 50 | |
---|
[7716] | 51 | template<typename type> type getDefault(const MultiType* const defaultValues, unsigned int i) { return (type)0; }; |
---|
[7721] | 52 | template<> bool getDefault<bool>(const MultiType* const defaultValues, unsigned int i); |
---|
| 53 | template<> int getDefault<int>(const MultiType* const defaultValues, unsigned int i); |
---|
| 54 | template<> unsigned int getDefault<unsigned int>(const MultiType* const defaultValues, unsigned int i); |
---|
| 55 | template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i); |
---|
| 56 | template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i); |
---|
| 57 | template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i); |
---|
[5161] | 58 | |
---|
[9730] | 59 | |
---|
| 60 | /** |
---|
| 61 | * @brief to remove writing errors, this function is Used. |
---|
| 62 | * @param sub The SubString to use |
---|
| 63 | * @param default The default Values. |
---|
| 64 | */ |
---|
[9736] | 65 | template<> class ExecutorEvaluater <const SubString> |
---|
[9730] | 66 | { |
---|
[9731] | 67 | public: |
---|
[9736] | 68 | /** @brief Executes the Evaluater |
---|
[9735] | 69 | * @param CallValue the Value that should be converted |
---|
| 70 | * @param defaults the default Values. |
---|
| 71 | */ |
---|
[9736] | 72 | template <typename ToType, int index> |
---|
| 73 | ToType operator()(const SubString& CallValue, const MultiType* const defaults) |
---|
[9731] | 74 | { |
---|
[9732] | 75 | return (CallValue.size() > index) ? |
---|
| 76 | fromString<ToType>(CallValue[index], getDefault<ToType>(defaults, index)) : |
---|
[9731] | 77 | fromMulti<ToType>(defaults[index]); |
---|
| 78 | } |
---|
[9736] | 79 | static const SubString& defaultValue() { return SubString::NullSubString; }; |
---|
[9730] | 80 | }; |
---|
| 81 | |
---|
[9742] | 82 | #endif /* __EXECUTOR_SUBSTRING_H_ */ |
---|