1 | /*! |
---|
2 | * @file executor_generic.h |
---|
3 | * Definition of a Generic Executor |
---|
4 | */ |
---|
5 | |
---|
6 | /* |
---|
7 | orxonox - the future of 3D-vertical-scrollers |
---|
8 | |
---|
9 | Copyright (C) 2004 orx |
---|
10 | |
---|
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. |
---|
15 | |
---|
16 | ### File Specific: |
---|
17 | main-programmer: Benjamin Grauer |
---|
18 | co-programmer: ... |
---|
19 | */ |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | #ifndef __EXECUTOR_SUBSTRING_H_ |
---|
24 | #define __EXECUTOR_SUBSTRING_H_ |
---|
25 | |
---|
26 | |
---|
27 | #include "executor_generic.h" |
---|
28 | #include "substring.h" |
---|
29 | #ifdef FUNCTOR_CALL_TYPE |
---|
30 | #undef FUNCTOR_CALL_TYPE |
---|
31 | #endif |
---|
32 | #define FUNCTOR_CALL_TYPE const SubString |
---|
33 | |
---|
34 | template<typename type> type fromString(const std::string& input, type defaultValue) { return defaultValue; }; |
---|
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); |
---|
41 | |
---|
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 | |
---|
51 | template<typename type> type getDefault(const MultiType* const defaultValues, unsigned int i) { return (type)0; }; |
---|
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); |
---|
58 | |
---|
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 | */ |
---|
65 | template<> class ExecutorEvaluater <const SubString> |
---|
66 | { |
---|
67 | public: |
---|
68 | /** @brief Executes the Evaluater |
---|
69 | * @param CallValue the Value that should be converted |
---|
70 | * @param defaults the default Values. |
---|
71 | */ |
---|
72 | template <typename ToType, int index> |
---|
73 | static ToType getValue(const SubString& CallValue, const MultiType* const defaults) |
---|
74 | { |
---|
75 | return (CallValue.size() > index) ? |
---|
76 | fromString<ToType>(CallValue[index], getDefault<ToType>(defaults, index)) : |
---|
77 | fromMulti<ToType>(defaults[index]); |
---|
78 | } |
---|
79 | static const SubString& defaultValue() { return SubString::NullSubString; }; |
---|
80 | }; |
---|
81 | |
---|
82 | #endif /* __EXECUTOR_SUBSTRING_H_ */ |
---|