[1505] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #ifndef _Functor_H__ |
---|
| 30 | #define _Functor_H__ |
---|
| 31 | |
---|
[7179] | 32 | #include <typeinfo> |
---|
| 33 | |
---|
[7203] | 34 | #include "core/CorePrereqs.h" |
---|
[1505] | 35 | |
---|
[3196] | 36 | #include "util/Debug.h" |
---|
[1747] | 37 | #include "util/MultiType.h" |
---|
[7196] | 38 | #include "FunctorPtr.h" |
---|
[1505] | 39 | |
---|
| 40 | namespace orxonox |
---|
| 41 | { |
---|
[1786] | 42 | const unsigned int MAX_FUNCTOR_ARGUMENTS = 5; |
---|
[1784] | 43 | |
---|
[1505] | 44 | template <class T> |
---|
[7212] | 45 | inline std::string _typeToString() { return "unknown"; } |
---|
[1505] | 46 | |
---|
[7212] | 47 | template <> inline std::string _typeToString<void>() { return ""; } |
---|
| 48 | template <> inline std::string _typeToString<int>() { return "int"; } |
---|
| 49 | template <> inline std::string _typeToString<unsigned int>() { return "uint"; } |
---|
| 50 | template <> inline std::string _typeToString<char>() { return "char"; } |
---|
| 51 | template <> inline std::string _typeToString<unsigned char>() { return "uchar"; } |
---|
| 52 | template <> inline std::string _typeToString<short>() { return "short"; } |
---|
| 53 | template <> inline std::string _typeToString<unsigned short>() { return "ushort"; } |
---|
| 54 | template <> inline std::string _typeToString<long>() { return "long"; } |
---|
| 55 | template <> inline std::string _typeToString<unsigned long>() { return "ulong"; } |
---|
| 56 | template <> inline std::string _typeToString<long long>() { return "longlong"; } |
---|
| 57 | template <> inline std::string _typeToString<unsigned long long>() { return "ulonglong"; } |
---|
| 58 | template <> inline std::string _typeToString<float>() { return "float"; } |
---|
| 59 | template <> inline std::string _typeToString<double>() { return "double"; } |
---|
| 60 | template <> inline std::string _typeToString<long double>() { return "longdouble"; } |
---|
| 61 | template <> inline std::string _typeToString<bool>() { return "bool"; } |
---|
| 62 | template <> inline std::string _typeToString<std::string>() { return "string"; } |
---|
| 63 | template <> inline std::string _typeToString<Vector2>() { return "Vector2"; } |
---|
| 64 | template <> inline std::string _typeToString<Vector3>() { return "Vector3"; } |
---|
| 65 | template <> inline std::string _typeToString<Quaternion>() { return "Quaternion"; } |
---|
| 66 | template <> inline std::string _typeToString<ColourValue>() { return "ColourValue"; } |
---|
| 67 | template <> inline std::string _typeToString<Radian>() { return "Radian"; } |
---|
| 68 | template <> inline std::string _typeToString<Degree>() { return "Degree"; } |
---|
[1505] | 69 | |
---|
[7212] | 70 | template <class T> |
---|
| 71 | inline std::string typeToString() { return _typeToString<typename Loki::TypeTraits<T>::UnqualifiedReferredType>(); } |
---|
[1505] | 72 | |
---|
| 73 | class _CoreExport Functor |
---|
| 74 | { |
---|
| 75 | public: |
---|
[7188] | 76 | struct Type |
---|
| 77 | { |
---|
| 78 | enum Enum |
---|
| 79 | { |
---|
| 80 | Static, |
---|
[7212] | 81 | Member |
---|
[7188] | 82 | }; |
---|
| 83 | }; |
---|
| 84 | |
---|
| 85 | public: |
---|
[7189] | 86 | virtual MultiType operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) = 0; |
---|
[1505] | 87 | |
---|
[7270] | 88 | virtual FunctorPtr clone() = 0; |
---|
| 89 | |
---|
[7188] | 90 | virtual Type::Enum getType() const = 0; |
---|
| 91 | virtual unsigned int getParamCount() const = 0; |
---|
| 92 | virtual bool hasReturnvalue() const = 0; |
---|
[1505] | 93 | |
---|
[7188] | 94 | virtual std::string getTypenameParam(unsigned int param) const = 0; |
---|
| 95 | virtual std::string getTypenameReturnvalue() const = 0; |
---|
| 96 | |
---|
[1747] | 97 | virtual void evaluateParam(unsigned int index, MultiType& param) const = 0; |
---|
[1505] | 98 | |
---|
[7179] | 99 | virtual void setRawObjectPointer(void* object) {} |
---|
| 100 | virtual void* getRawObjectPointer() const { return 0; } |
---|
| 101 | |
---|
[7212] | 102 | template <class F> |
---|
| 103 | inline bool setFunction(F* function) |
---|
| 104 | { |
---|
| 105 | if (this->getFullIdentifier() == typeid(F*)) |
---|
| 106 | { |
---|
| 107 | modifyFunctor(this, function); |
---|
| 108 | return true; |
---|
| 109 | } |
---|
| 110 | return false; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | virtual const std::type_info& getFullIdentifier() const = 0; |
---|
[7179] | 114 | virtual const std::type_info& getHeaderIdentifier() const = 0; |
---|
[7214] | 115 | virtual const std::type_info& getHeaderIdentifier(unsigned int params) const = 0; |
---|
[1505] | 116 | }; |
---|
| 117 | |
---|
[7213] | 118 | namespace detail |
---|
| 119 | { |
---|
| 120 | template <class O> |
---|
| 121 | struct FunctorTypeStatic |
---|
| 122 | { enum { result = false }; }; |
---|
| 123 | template <> |
---|
| 124 | struct FunctorTypeStatic<void> |
---|
| 125 | { enum { result = true }; }; |
---|
| 126 | } |
---|
| 127 | |
---|
[7212] | 128 | template <class O> |
---|
[1505] | 129 | class FunctorMember : public Functor |
---|
| 130 | { |
---|
| 131 | public: |
---|
[7212] | 132 | FunctorMember(O* object = 0) : object_(object) {} |
---|
[1505] | 133 | |
---|
[7212] | 134 | virtual MultiType operator()(O* object, const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) = 0; |
---|
[1505] | 135 | |
---|
[7212] | 136 | MultiType operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) |
---|
[1505] | 137 | { |
---|
[7213] | 138 | if (detail::FunctorTypeStatic<O>::result || this->object_) |
---|
[7189] | 139 | return (*this)(this->object_, param1, param2, param3, param4, param5); |
---|
[1505] | 140 | else |
---|
| 141 | { |
---|
[7212] | 142 | COUT(1) << "Error: Can't execute FunctorMember, no object set." << std::endl; |
---|
[7189] | 143 | return MT_Type::Null; |
---|
[1505] | 144 | } |
---|
| 145 | } |
---|
| 146 | |
---|
[7212] | 147 | Functor::Type::Enum getType() const |
---|
[7213] | 148 | { return detail::FunctorTypeStatic<O>::result ? Functor::Type::Static : Functor::Type::Member; } |
---|
[1505] | 149 | |
---|
[7212] | 150 | inline void setObject(O* object) |
---|
| 151 | { this->object_ = object;} |
---|
| 152 | inline O* getObject() const |
---|
| 153 | { return this->object_; } |
---|
[1505] | 154 | |
---|
[7212] | 155 | inline void setRawObjectPointer(void* object) |
---|
| 156 | { this->object_ = (O*)object; } |
---|
| 157 | inline void* getRawObjectPointer() const |
---|
| 158 | { return this->object_; } |
---|
[7179] | 159 | |
---|
[7212] | 160 | protected: |
---|
| 161 | O* object_; |
---|
| 162 | }; |
---|
[7179] | 163 | |
---|
[7212] | 164 | typedef FunctorMember<void> FunctorStatic; |
---|
[1505] | 165 | |
---|
[7213] | 166 | template <class F, class O = void> |
---|
[7212] | 167 | class FunctorPointer : public FunctorMember<O> |
---|
| 168 | { |
---|
| 169 | public: |
---|
| 170 | FunctorPointer(F functionPointer, O* object = 0) : FunctorMember<O>(object), functionPointer_(functionPointer) {} |
---|
[1505] | 171 | |
---|
[7212] | 172 | inline void setFunction(F functionPointer) |
---|
| 173 | { this->functionPointer_ = functionPointer; } |
---|
| 174 | inline F getFunction() const |
---|
| 175 | { return this->functionPointer_; } |
---|
[7179] | 176 | |
---|
[7212] | 177 | const std::type_info& getFullIdentifier() const |
---|
| 178 | { return typeid(F); } |
---|
[7179] | 179 | |
---|
[7212] | 180 | protected: |
---|
| 181 | F functionPointer_; |
---|
| 182 | }; |
---|
[7179] | 183 | |
---|
[7212] | 184 | namespace detail |
---|
[7179] | 185 | { |
---|
[7212] | 186 | template <class R, class O, bool isconst, class P1, class P2, class P3, class P4, class P5> struct FunctionPointer { typedef R (O::*Type)(P1, P2, P3, P4, P5); }; |
---|
| 187 | template <class R, class O, class P1, class P2, class P3, class P4, class P5> struct FunctionPointer<R, O, false, P1, P2, P3, P4, P5> { typedef R (O::*Type)(P1, P2, P3, P4, P5); }; |
---|
| 188 | template <class R, class O, class P1, class P2, class P3, class P4> struct FunctionPointer<R, O, false, P1, P2, P3, P4, void> { typedef R (O::*Type)(P1, P2, P3, P4); }; |
---|
| 189 | template <class R, class O, class P1, class P2, class P3> struct FunctionPointer<R, O, false, P1, P2, P3, void, void> { typedef R (O::*Type)(P1, P2, P3); }; |
---|
| 190 | template <class R, class O, class P1, class P2> struct FunctionPointer<R, O, false, P1, P2, void, void, void> { typedef R (O::*Type)(P1, P2); }; |
---|
| 191 | template <class R, class O, class P1> struct FunctionPointer<R, O, false, P1, void, void, void, void> { typedef R (O::*Type)(P1); }; |
---|
| 192 | template <class R, class O> struct FunctionPointer<R, O, false, void, void, void, void, void> { typedef R (O::*Type)(); }; |
---|
| 193 | template <class R, class O, class P1, class P2, class P3, class P4, class P5> struct FunctionPointer<R, O, true, P1, P2, P3, P4, P5> { typedef R (O::*Type)(P1, P2, P3, P4, P5) const; }; |
---|
| 194 | template <class R, class O, class P1, class P2, class P3, class P4> struct FunctionPointer<R, O, true, P1, P2, P3, P4, void> { typedef R (O::*Type)(P1, P2, P3, P4) const; }; |
---|
| 195 | template <class R, class O, class P1, class P2, class P3> struct FunctionPointer<R, O, true, P1, P2, P3, void, void> { typedef R (O::*Type)(P1, P2, P3) const; }; |
---|
| 196 | template <class R, class O, class P1, class P2> struct FunctionPointer<R, O, true, P1, P2, void, void, void> { typedef R (O::*Type)(P1, P2) const; }; |
---|
| 197 | template <class R, class O, class P1> struct FunctionPointer<R, O, true, P1, void, void, void, void> { typedef R (O::*Type)(P1) const; }; |
---|
| 198 | template <class R, class O> struct FunctionPointer<R, O, true, void, void, void, void, void> { typedef R (O::*Type)() const; }; |
---|
| 199 | template <class R, class P1, class P2, class P3, class P4, class P5> struct FunctionPointer<R, void, false, P1, P2, P3, P4, P5> { typedef R (*Type)(P1, P2, P3, P4, P5); }; |
---|
| 200 | template <class R, class P1, class P2, class P3, class P4> struct FunctionPointer<R, void, false, P1, P2, P3, P4, void> { typedef R (*Type)(P1, P2, P3, P4); }; |
---|
| 201 | template <class R, class P1, class P2, class P3> struct FunctionPointer<R, void, false, P1, P2, P3, void, void> { typedef R (*Type)(P1, P2, P3); }; |
---|
| 202 | template <class R, class P1, class P2> struct FunctionPointer<R, void, false, P1, P2, void, void, void> { typedef R (*Type)(P1, P2); }; |
---|
| 203 | template <class R, class P1> struct FunctionPointer<R, void, false, P1, void, void, void, void> { typedef R (*Type)(P1); }; |
---|
| 204 | template <class R> struct FunctionPointer<R, void, false, void, void, void, void, void> { typedef R (*Type)(); }; |
---|
[7179] | 205 | |
---|
[7212] | 206 | template <class R, class O, bool isconst, class P1, class P2, class P3, class P4, class P5> struct FunctorCaller { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, P4, P5>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (object->*functionPointer)(param1, param2, param3, param4, param5); } }; |
---|
| 207 | template <class R, class O, bool isconst, class P1, class P2, class P3, class P4> struct FunctorCaller<R, O, isconst, P1, P2, P3, P4, void> { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, P4, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (object->*functionPointer)(param1, param2, param3, param4); } }; |
---|
| 208 | template <class R, class O, bool isconst, class P1, class P2, class P3> struct FunctorCaller<R, O, isconst, P1, P2, P3, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, void, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (object->*functionPointer)(param1, param2, param3); } }; |
---|
| 209 | template <class R, class O, bool isconst, class P1, class P2> struct FunctorCaller<R, O, isconst, P1, P2, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, P1, P2, void, void, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (object->*functionPointer)(param1, param2); } }; |
---|
| 210 | template <class R, class O, bool isconst, class P1> struct FunctorCaller<R, O, isconst, P1, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, P1, void, void, void, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (object->*functionPointer)(param1); } }; |
---|
| 211 | template <class R, class O, bool isconst> struct FunctorCaller<R, O, isconst, void, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, void, void, void, void, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (object->*functionPointer)(); } }; |
---|
| 212 | template <class O, bool isconst, class P1, class P2, class P3, class P4, class P5> struct FunctorCaller<void, O, isconst, P1, P2, P3, P4, P5> { static inline MultiType call(typename detail::FunctionPointer<void, O, isconst, P1, P2, P3, P4, P5>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (object->*functionPointer)(param1, param2, param3, param4, param5); return MT_Type::Null; } }; |
---|
| 213 | template <class O, bool isconst, class P1, class P2, class P3, class P4> struct FunctorCaller<void, O, isconst, P1, P2, P3, P4, void> { static inline MultiType call(typename detail::FunctionPointer<void, O, isconst, P1, P2, P3, P4, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (object->*functionPointer)(param1, param2, param3, param4); return MT_Type::Null; } }; |
---|
| 214 | template <class O, bool isconst, class P1, class P2, class P3> struct FunctorCaller<void, O, isconst, P1, P2, P3, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, O, isconst, P1, P2, P3, void, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (object->*functionPointer)(param1, param2, param3); return MT_Type::Null; } }; |
---|
| 215 | template <class O, bool isconst, class P1, class P2> struct FunctorCaller<void, O, isconst, P1, P2, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, O, isconst, P1, P2, void, void, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (object->*functionPointer)(param1, param2); return MT_Type::Null; } }; |
---|
| 216 | template <class O, bool isconst, class P1> struct FunctorCaller<void, O, isconst, P1, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, O, isconst, P1, void, void, void, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (object->*functionPointer)(param1); return MT_Type::Null; } }; |
---|
| 217 | template <class O, bool isconst> struct FunctorCaller<void, O, isconst, void, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, O, isconst, void, void, void, void, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (object->*functionPointer)(); return MT_Type::Null; } }; |
---|
| 218 | template <class R, bool isconst, class P1, class P2, class P3, class P4, class P5> struct FunctorCaller<R, void, isconst, P1, P2, P3, P4, P5> { static inline MultiType call(typename detail::FunctionPointer<R, void, isconst, P1, P2, P3, P4, P5>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (*functionPointer)(param1, param2, param3, param4, param5); } }; |
---|
| 219 | template <class R, bool isconst, class P1, class P2, class P3, class P4> struct FunctorCaller<R, void, isconst, P1, P2, P3, P4, void> { static inline MultiType call(typename detail::FunctionPointer<R, void, isconst, P1, P2, P3, P4, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (*functionPointer)(param1, param2, param3, param4); } }; |
---|
| 220 | template <class R, bool isconst, class P1, class P2, class P3> struct FunctorCaller<R, void, isconst, P1, P2, P3, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, void, isconst, P1, P2, P3, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (*functionPointer)(param1, param2, param3); } }; |
---|
| 221 | template <class R, bool isconst, class P1, class P2> struct FunctorCaller<R, void, isconst, P1, P2, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, void, isconst, P1, P2, void, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (*functionPointer)(param1, param2); } }; |
---|
| 222 | template <class R, bool isconst, class P1> struct FunctorCaller<R, void, isconst, P1, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, void, isconst, P1, void, void, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (*functionPointer)(param1); } }; |
---|
| 223 | template <class R, bool isconst> struct FunctorCaller<R, void, isconst, void, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, void, isconst, void, void, void, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (*functionPointer)(); } }; |
---|
| 224 | template <bool isconst, class P1, class P2, class P3, class P4, class P5> struct FunctorCaller<void, void, isconst, P1, P2, P3, P4, P5> { static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, P1, P2, P3, P4, P5>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (*functionPointer)(param1, param2, param3, param4, param5); return MT_Type::Null; } }; |
---|
| 225 | template <bool isconst, class P1, class P2, class P3, class P4> struct FunctorCaller<void, void, isconst, P1, P2, P3, P4, void> { static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, P1, P2, P3, P4, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (*functionPointer)(param1, param2, param3, param4); return MT_Type::Null; } }; |
---|
| 226 | template <bool isconst, class P1, class P2, class P3> struct FunctorCaller<void, void, isconst, P1, P2, P3, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, P1, P2, P3, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (*functionPointer)(param1, param2, param3); return MT_Type::Null; } }; |
---|
| 227 | template <bool isconst, class P1, class P2> struct FunctorCaller<void, void, isconst, P1, P2, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, P1, P2, void, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (*functionPointer)(param1, param2); return MT_Type::Null; } }; |
---|
| 228 | template <bool isconst, class P1> struct FunctorCaller<void, void, isconst, P1, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, P1, void, void, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (*functionPointer)(param1); return MT_Type::Null; } }; |
---|
| 229 | template <bool isconst> struct FunctorCaller<void, void, isconst, void, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, void, void, void, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (*functionPointer)(); return MT_Type::Null; } }; |
---|
[7179] | 230 | |
---|
[7212] | 231 | template <class R, class P1, class P2, class P3, class P4, class P5> |
---|
| 232 | struct FunctorHeaderIdentifier |
---|
| 233 | {}; |
---|
[7179] | 234 | |
---|
[7213] | 235 | template <class T> |
---|
[7212] | 236 | struct FunctorHasReturnvalue |
---|
| 237 | { enum { result = true }; }; |
---|
| 238 | template <> |
---|
| 239 | struct FunctorHasReturnvalue<void> |
---|
| 240 | { enum { result = false }; }; |
---|
[1505] | 241 | |
---|
[7212] | 242 | template <class P1, class P2, class P3, class P4, class P5> |
---|
| 243 | struct FunctorParamCount |
---|
| 244 | { enum { result = 5 }; }; |
---|
| 245 | template <class P1, class P2, class P3, class P4> |
---|
| 246 | struct FunctorParamCount<P1, P2, P3, P4, void> |
---|
| 247 | { enum { result = 4 }; }; |
---|
| 248 | template <class P1, class P2, class P3> |
---|
| 249 | struct FunctorParamCount<P1, P2, P3, void, void> |
---|
| 250 | { enum { result = 3 }; }; |
---|
| 251 | template <class P1, class P2> |
---|
| 252 | struct FunctorParamCount<P1, P2, void, void, void> |
---|
| 253 | { enum { result = 2 }; }; |
---|
| 254 | template <class P1> |
---|
| 255 | struct FunctorParamCount<P1, void, void, void, void> |
---|
| 256 | { enum { result = 1 }; }; |
---|
| 257 | template <> |
---|
| 258 | struct FunctorParamCount<void, void, void, void, void> |
---|
| 259 | { enum { result = 0 }; }; |
---|
[1505] | 260 | } |
---|
| 261 | |
---|
[7212] | 262 | template <class R, class O, bool isconst, class P1, class P2, class P3, class P4, class P5> |
---|
| 263 | class FunctorTemplate : public FunctorPointer<typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, P4, P5>::Type, O> |
---|
| 264 | { |
---|
| 265 | public: |
---|
| 266 | FunctorTemplate(typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, P4, P5>::Type functionPointer, O* object = 0) : FunctorPointer<typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, P4, P5>::Type, O>(functionPointer, object) {} |
---|
[1505] | 267 | |
---|
[7212] | 268 | MultiType operator()(O* object, const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) |
---|
| 269 | { |
---|
| 270 | return detail::FunctorCaller<R, O, isconst, P1, P2, P3, P4, P5>::call(this->functionPointer_, object, param1, param2, param3, param4, param5); |
---|
| 271 | } |
---|
[1505] | 272 | |
---|
[7270] | 273 | FunctorPtr clone() |
---|
| 274 | { |
---|
| 275 | return new FunctorTemplate(*this); |
---|
| 276 | } |
---|
| 277 | |
---|
[7212] | 278 | void evaluateParam(unsigned int index, MultiType& param) const |
---|
| 279 | { |
---|
| 280 | switch (index) |
---|
| 281 | { |
---|
| 282 | case 0: param.convert<P1>(); break; |
---|
| 283 | case 1: param.convert<P2>(); break; |
---|
| 284 | case 2: param.convert<P3>(); break; |
---|
| 285 | case 3: param.convert<P4>(); break; |
---|
| 286 | case 4: param.convert<P5>(); break; |
---|
| 287 | } |
---|
| 288 | } |
---|
[1505] | 289 | |
---|
[7212] | 290 | unsigned int getParamCount() const |
---|
| 291 | { |
---|
| 292 | return detail::FunctorParamCount<P1, P2, P3, P4, P5>::result; |
---|
| 293 | } |
---|
[1505] | 294 | |
---|
[7212] | 295 | bool hasReturnvalue() const |
---|
| 296 | { |
---|
| 297 | return detail::FunctorHasReturnvalue<R>::result; |
---|
| 298 | } |
---|
[1505] | 299 | |
---|
[7212] | 300 | std::string getTypenameParam(unsigned int param) const |
---|
| 301 | { |
---|
| 302 | switch (param) |
---|
| 303 | { |
---|
[7214] | 304 | case 0: return typeToString<P1>(); |
---|
| 305 | case 1: return typeToString<P2>(); |
---|
| 306 | case 2: return typeToString<P3>(); |
---|
| 307 | case 3: return typeToString<P4>(); |
---|
| 308 | case 4: return typeToString<P5>(); |
---|
[7212] | 309 | default: return ""; |
---|
| 310 | } |
---|
| 311 | } |
---|
[1505] | 312 | |
---|
[7212] | 313 | std::string getTypenameReturnvalue() const |
---|
| 314 | { |
---|
| 315 | return typeToString<R>(); |
---|
| 316 | } |
---|
[7179] | 317 | |
---|
[7212] | 318 | const std::type_info& getHeaderIdentifier() const |
---|
| 319 | { |
---|
| 320 | return typeid(detail::FunctorHeaderIdentifier<R, P1, P2, P3, P4, P5>); |
---|
| 321 | } |
---|
[7214] | 322 | |
---|
| 323 | const std::type_info& getHeaderIdentifier(unsigned int params) const |
---|
| 324 | { |
---|
| 325 | switch (params) |
---|
| 326 | { |
---|
| 327 | case 0: return typeid(detail::FunctorHeaderIdentifier<R, void, void, void, void, void>); |
---|
| 328 | case 1: return typeid(detail::FunctorHeaderIdentifier<R, P1, void, void, void, void>); |
---|
| 329 | case 2: return typeid(detail::FunctorHeaderIdentifier<R, P1, P2, void, void, void>); |
---|
| 330 | case 3: return typeid(detail::FunctorHeaderIdentifier<R, P1, P2, P3, void, void>); |
---|
| 331 | case 4: return typeid(detail::FunctorHeaderIdentifier<R, P1, P2, P3, P4, void>); |
---|
| 332 | default: return typeid(detail::FunctorHeaderIdentifier<R, P1, P2, P3, P4, P5>); |
---|
| 333 | } |
---|
| 334 | } |
---|
[7212] | 335 | }; |
---|
[1505] | 336 | |
---|
[7242] | 337 | template <class R, class O, class OO, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, P5>(functionPointer, object); } |
---|
| 338 | template <class R, class O, class OO, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, void>(functionPointer, object); } |
---|
| 339 | template <class R, class O, class OO, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, P3, void, void>(functionPointer, object); } |
---|
| 340 | template <class R, class O, class OO, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, void, void, void>(functionPointer, object); } |
---|
| 341 | template <class R, class O, class OO, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1), OO* object) { return new FunctorTemplate<R, O, false, P1, void, void, void, void>(functionPointer, object); } |
---|
| 342 | template <class R, class O, class OO> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(), OO* object) { return new FunctorTemplate<R, O, false, void, void, void, void, void>(functionPointer, object); } |
---|
| 343 | template <class R, class O, class OO, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, P5>(functionPointer, object); } |
---|
| 344 | template <class R, class O, class OO, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, void>(functionPointer, object); } |
---|
| 345 | template <class R, class O, class OO, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, P3, void, void>(functionPointer, object); } |
---|
| 346 | template <class R, class O, class OO, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, void, void, void>(functionPointer, object); } |
---|
| 347 | template <class R, class O, class OO, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1) const, OO* object) { return new FunctorTemplate<R, O, true, P1, void, void, void, void>(functionPointer, object); } |
---|
| 348 | template <class R, class O, class OO> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)() const, OO* object) { return new FunctorTemplate<R, O, true, void, void, void, void, void>(functionPointer, object); } |
---|
[1505] | 349 | |
---|
[7242] | 350 | template <class R, class O, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5)) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, P5>(functionPointer); } |
---|
| 351 | template <class R, class O, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4)) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, void>(functionPointer); } |
---|
| 352 | template <class R, class O, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3)) { return new FunctorTemplate<R, O, false, P1, P2, P3, void, void>(functionPointer); } |
---|
| 353 | template <class R, class O, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2)) { return new FunctorTemplate<R, O, false, P1, P2, void, void, void>(functionPointer); } |
---|
| 354 | template <class R, class O, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1)) { return new FunctorTemplate<R, O, false, P1, void, void, void, void>(functionPointer); } |
---|
| 355 | template <class R, class O> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)()) { return new FunctorTemplate<R, O, false, void, void, void, void, void>(functionPointer); } |
---|
| 356 | template <class R, class O, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5) const) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, P5>(functionPointer); } |
---|
| 357 | template <class R, class O, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4) const) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, void>(functionPointer); } |
---|
| 358 | template <class R, class O, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3) const) { return new FunctorTemplate<R, O, true, P1, P2, P3, void, void>(functionPointer); } |
---|
| 359 | template <class R, class O, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2) const) { return new FunctorTemplate<R, O, true, P1, P2, void, void, void>(functionPointer); } |
---|
| 360 | template <class R, class O, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1) const) { return new FunctorTemplate<R, O, true, P1, void, void, void, void>(functionPointer); } |
---|
| 361 | template <class R, class O> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)() const) { return new FunctorTemplate<R, O, true, void, void, void, void, void>(functionPointer); } |
---|
[1505] | 362 | |
---|
[7242] | 363 | template <class R, class P1, class P2, class P3, class P4, class P5> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2, P3, P4, P5)) { return new FunctorTemplate<R, void, false, P1, P2, P3, P4, P5>(functionPointer); } |
---|
| 364 | template <class R, class P1, class P2, class P3, class P4> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2, P3, P4)) { return new FunctorTemplate<R, void, false, P1, P2, P3, P4, void>(functionPointer); } |
---|
| 365 | template <class R, class P1, class P2, class P3> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2, P3)) { return new FunctorTemplate<R, void, false, P1, P2, P3, void, void>(functionPointer); } |
---|
| 366 | template <class R, class P1, class P2> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2)) { return new FunctorTemplate<R, void, false, P1, P2, void, void, void>(functionPointer); } |
---|
| 367 | template <class R, class P1> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1)) { return new FunctorTemplate<R, void, false, P1, void, void, void, void>(functionPointer); } |
---|
| 368 | template <class R> inline FunctorStaticPtr createFunctor(R (*functionPointer)()) { return new FunctorTemplate<R, void, false, void, void, void, void, void>(functionPointer); } |
---|
[1505] | 369 | } |
---|
| 370 | |
---|
| 371 | #endif /* _Functor_H__ */ |
---|