00001 00002 #if !defined(INCLUDED_FUNCTIONAL_H) 00003 #define INCLUDED_FUNCTIONAL_H 00004 00005 template < typename Object, typename R, R (Object::*member)() > 00006 class Member { 00007 public: 00008 typedef Object& first_argument_type; 00009 typedef R result_type; 00010 static result_type call(first_argument_type object) { 00011 return (object.*member)(); 00012 } 00013 }; 00014 00015 template < typename Object, typename R, R (Object::*member)() const > 00016 class ConstMember { 00017 public: 00018 typedef const Object& first_argument_type; 00019 typedef R result_type; 00020 static result_type call(first_argument_type object) { 00021 return (object.*member)(); 00022 } 00023 }; 00024 00025 template < typename Object, typename A1, typename R, R (Object::*member)(A1) > 00026 class Member1 { 00027 public: 00028 typedef Object& first_argument_type; 00029 typedef A1 second_argument_type; 00030 typedef R result_type; 00031 static result_type call(first_argument_type object, second_argument_type a1) { 00032 return (object.*member)(a1); 00033 } 00034 }; 00035 00036 template < typename Object, typename A1, typename R, R (Object::*member)(A1) const > 00037 class ConstMember1 { 00038 public: 00039 typedef const Object& first_argument_type; 00040 typedef A1 second_argument_type; 00041 typedef R result_type; 00042 static result_type call(first_argument_type object, second_argument_type a1) { 00043 return (object.*member)(a1); 00044 } 00045 }; 00046 00047 template < typename Object, typename A2, typename A3, typename R, R (Object::*member)(A2, A3) > 00048 class Member2 { 00049 public: 00050 typedef Object& first_argument_type; 00051 typedef A2 second_argument_type; 00052 typedef A3 third_argument_type; 00053 typedef R result_type; 00054 static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3) { 00055 return (object.*member)(a2, a3); 00056 } 00057 }; 00058 00059 template < typename Object, typename A2, typename A3, typename R, R (Object::*member)(A2, A3) const > 00060 class ConstMember2 { 00061 public: 00062 typedef const Object& first_argument_type; 00063 typedef A2 second_argument_type; 00064 typedef A3 third_argument_type; 00065 typedef R result_type; 00066 static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3) { 00067 return (object.*member)(a2, a3); 00068 } 00069 }; 00070 00071 template < typename Object, typename A2, typename A3, typename A4, typename R, R (Object::*member)(A2, A3, A4) > 00072 class Member3 { 00073 public: 00074 typedef Object& first_argument_type; 00075 typedef A2 second_argument_type; 00076 typedef A3 third_argument_type; 00077 typedef A4 fourth_argument_type; 00078 typedef R result_type; 00079 static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3, fourth_argument_type a4) { 00080 return (object.*member)(a2, a3, a4); 00081 } 00082 }; 00083 00084 template < typename Object, typename A2, typename A3, typename A4, typename R, R (Object::*member)(A2, A3, A4) const > 00085 class ConstMember3 { 00086 public: 00087 typedef const Object& first_argument_type; 00088 typedef A2 second_argument_type; 00089 typedef A3 third_argument_type; 00090 typedef A4 fourth_argument_type; 00091 typedef R result_type; 00092 static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3, fourth_argument_type a4) { 00093 return (object.*member)(a2, a3, a4); 00094 } 00095 }; 00096 00097 template < typename R, R (*func)() > 00098 class Function0 { 00099 public: 00100 typedef R result_type; 00101 static result_type call() { 00102 return (func)(); 00103 } 00104 }; 00105 00106 template < typename A1, typename R, R (*func)(A1) > 00107 class Function1 { 00108 public: 00109 typedef A1 first_argument_type; 00110 typedef R result_type; 00111 static result_type call(first_argument_type a1) { 00112 return (func)(a1); 00113 } 00114 }; 00115 00116 template < typename A1, typename A2, typename R, R (*func)(A1, A2) > 00117 class Function2 { 00118 public: 00119 typedef A1 first_argument_type; 00120 typedef A2 second_argument_type; 00121 typedef R result_type; 00122 static result_type call(first_argument_type a1, second_argument_type a2) { 00123 return (func)(a1, a2); 00124 } 00125 }; 00126 00127 template < typename A1, typename A2, typename A3, typename R, R (*func)(A1, A2, A3) > 00128 class Function3 { 00129 public: 00130 typedef A1 first_argument_type; 00131 typedef A2 second_argument_type; 00132 typedef A3 third_argument_type; 00133 typedef R result_type; 00134 static result_type call(first_argument_type a1, second_argument_type a2, third_argument_type a3) { 00135 return (func)(a1, a2, a3); 00136 } 00137 }; 00138 00139 template < typename A1, typename A2, typename A3, typename A4, typename R, R (*func)(A1, A2, A3, A4) > 00140 class Function4 { 00141 public: 00142 typedef A1 first_argument_type; 00143 typedef A2 second_argument_type; 00144 typedef A3 third_argument_type; 00145 typedef A4 fourth_argument_type; 00146 typedef R result_type; 00147 static result_type call(first_argument_type a1, second_argument_type a2, third_argument_type a3, fourth_argument_type a4) { 00148 return (func)(a1, a2, a3, a4); 00149 } 00150 }; 00151 00152 template < typename Caller, typename FirstArgument = void* > 00153 class Caller0To1 { 00154 public: 00155 typedef FirstArgument first_argument_type; 00156 typedef typename Caller::result_type result_type; 00157 static result_type call(first_argument_type) { 00158 return Caller::call(); 00159 } 00160 }; 00161 00162 template < typename Caller, typename FirstArgument = void* > 00163 class Caller1To2 { 00164 public: 00165 typedef FirstArgument first_argument_type; 00166 typedef typename Caller::first_argument_type second_argument_type; 00167 typedef typename Caller::result_type result_type; 00168 static result_type call(first_argument_type, second_argument_type a2) { 00169 return Caller::call(a2); 00170 } 00171 }; 00172 00173 template < typename Caller, typename FirstArgument = void* > 00174 class Caller2To3 { 00175 public: 00176 typedef FirstArgument first_argument_type; 00177 typedef typename Caller::first_argument_type second_argument_type; 00178 typedef typename Caller::second_argument_type third_argument_type; 00179 typedef typename Caller::result_type result_type; 00180 static result_type call(first_argument_type, second_argument_type a2, third_argument_type a3) { 00181 return Caller::call(a2, a3); 00182 } 00183 }; 00184 00185 template < typename Caller, typename FirstArgument = void* > 00186 class Caller3To4 { 00187 public: 00188 typedef FirstArgument first_argument_type; 00189 typedef typename Caller::first_argument_type second_argument_type; 00190 typedef typename Caller::second_argument_type third_argument_type; 00191 typedef typename Caller::third_argument_type fourth_argument_type; 00192 typedef typename Caller::result_type result_type; 00193 static result_type call(first_argument_type, second_argument_type a2, third_argument_type a3, fourth_argument_type a4) { 00194 return Caller::call(a2, a3, a4); 00195 } 00196 }; 00197 00198 template<typename Functor> 00199 class FunctorInvoke { 00200 public: 00201 typedef typename Functor::result_type result_type; 00202 inline result_type operator()(Functor functor) { 00203 return functor(); 00204 } 00205 }; 00206 00207 template<typename Functor> 00208 class Functor1Invoke { 00209 typename Functor::first_argument_type a1; 00210 public: 00211 typedef typename Functor::first_argument_type first_argument_type; 00212 typedef typename Functor::result_type result_type; 00213 Functor1Invoke(first_argument_type a1) : a1(a1) { 00214 } 00215 inline result_type operator()(Functor functor) { 00216 return functor(a1); 00217 } 00218 }; 00219 00220 template<typename Functor> 00221 class Functor2Invoke { 00222 typename Functor::first_argument_type a1; 00223 typename Functor::second_argument_type a2; 00224 public: 00225 typedef typename Functor::first_argument_type first_argument_type; 00226 typedef typename Functor::second_argument_type second_argument_type; 00227 typedef typename Functor::result_type result_type; 00228 Functor2Invoke(first_argument_type a1, second_argument_type a2) 00229 : a1(a1), a2(a2) { 00230 } 00231 inline result_type operator()(Functor functor) { 00232 return functor(a1, a2); 00233 } 00234 }; 00235 00236 template<typename Functor> 00237 class Functor3Invoke { 00238 typename Functor::first_argument_type a1; 00239 typename Functor::second_argument_type a2; 00240 typename Functor::third_argument_type a3; 00241 public: 00242 typedef typename Functor::first_argument_type first_argument_type; 00243 typedef typename Functor::second_argument_type second_argument_type; 00244 typedef typename Functor::third_argument_type third_argument_type; 00245 typedef typename Functor::result_type result_type; 00246 Functor3Invoke(first_argument_type a1, second_argument_type a2, third_argument_type a3) 00247 : a1(a1), a2(a2), a3(a3) { 00248 } 00249 inline result_type operator()(Functor functor) { 00250 return functor(a1, a2, a3); 00251 } 00252 }; 00253 00254 template<typename Other, typename True, typename False, typename Type> 00255 class TypeEqual { 00256 public: 00257 typedef False type; 00258 }; 00259 template<typename Other, typename True, typename False> 00260 class TypeEqual<Other, True, False, Other> { 00261 public: 00262 typedef True type; 00263 }; 00264 00265 00266 #endif