00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00031
00032 #pragma once
00033
00034 #include "../System/exception.h"
00035 #include "../System/sharedptr.h"
00036
00039 template <typename P1, typename P2, typename P3, typename P4, typename P5>
00040 class CL_Callback_Impl_v5
00041 {
00042 public:
00043 virtual ~CL_Callback_Impl_v5()
00044 {
00045 }
00046
00047 virtual void invoke(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) const = 0;
00048 };
00049
00052 template <typename P1, typename P2, typename P3, typename P4, typename P5>
00053 class CL_Callback_Impl_v5_static : public CL_Callback_Impl_v5<P1, P2, P3, P4, P5>
00054 {
00055 public:
00056 CL_Callback_Impl_v5_static(void (*static_func)(P1, P2, P3, P4, P5))
00057 : static_func(static_func)
00058 {
00059 }
00060
00061 void invoke(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) const
00062 {
00063 static_func(p1, p2, p3, p4, p5);
00064 }
00065
00066 void (*static_func)(P1, P2, P3, P4, P5);
00067 };
00068
00071 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename UserData>
00072 class CL_Callback_Impl_v5_static_user : public CL_Callback_Impl_v5<P1, P2, P3, P4, P5>
00073 {
00074 public:
00075 CL_Callback_Impl_v5_static_user(
00076 void (*static_func)(P1, P2, P3, P4, P5, UserData), const UserData &user_data)
00077 : static_func(static_func), user_data(user_data)
00078 {
00079 }
00080
00081 void invoke(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) const
00082 {
00083 static_func(p1, p2, p3, p4, p5, user_data);
00084 }
00085
00086 void (*static_func)(P1, P2, P3, P4, P5, UserData);
00087
00088 UserData user_data;
00089 };
00090
00093 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename InstanceClass>
00094 class CL_Callback_Impl_v5_member : public CL_Callback_Impl_v5<P1, P2, P3, P4, P5>
00095 {
00096 public:
00097 CL_Callback_Impl_v5_member(InstanceClass *instance,
00098 void (InstanceClass::*member_func)(P1, P2, P3, P4, P5))
00099 : instance(instance), member_func(member_func)
00100 {
00101 }
00102
00103 void invoke(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) const
00104 {
00105 (instance->*member_func)(p1, p2, p3, p4, p5);
00106 }
00107
00108 InstanceClass *instance;
00109
00110 void (InstanceClass::*member_func)(P1, P2, P3, P4, P5);
00111 };
00112
00115 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename InstanceClass, typename UserData>
00116 class CL_Callback_Impl_v5_member_user : public CL_Callback_Impl_v5<P1, P2, P3, P4, P5>
00117 {
00118 public:
00119 CL_Callback_Impl_v5_member_user(InstanceClass *instance,
00120 void (InstanceClass::*member_func)(P1, P2, P3, P4, P5, UserData), const UserData &user_data)
00121 : instance(instance), member_func(member_func), user_data(user_data)
00122 {
00123 }
00124
00125 void invoke(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) const
00126 {
00127 (instance->*member_func)(p1, p2, p3, p4, p5, user_data);
00128 }
00129
00130 InstanceClass *instance;
00131
00132 void (InstanceClass::*member_func)(P1, P2, P3, P4, P5, UserData);
00133
00134 UserData user_data;
00135 };
00136
00139 template <class P1, class P2, class P3, class P4, class P5, class Functor>
00140 class CL_Callback_Impl_v5_functor : public CL_Callback_Impl_v5<P1, P2, P3, P4, P5>
00141 {
00142 public:
00143 CL_Callback_Impl_v5_functor(Functor functor)
00144 : functor(functor)
00145 {
00146 }
00147
00148 void invoke(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) const
00149 {
00150 functor(p1, p2, p3, p4, p5);
00151 }
00152
00153 Functor functor;
00154 };
00155
00159 template <typename P1, typename P2, typename P3, typename P4, typename P5>
00160 class CL_Callback_v5
00161 {
00162 public:
00163 CL_Callback_v5()
00164 {
00165 }
00166
00167 CL_Callback_v5(const CL_Callback_v5 ©)
00168 : impl(copy.impl)
00169 {
00170 }
00171
00172 CL_Callback_v5(CL_Callback_Impl_v5<P1, P2, P3, P4, P5> *impl)
00173 : impl(impl)
00174 {
00175 }
00176
00177 CL_Callback_v5(void (*function)(P1, P2, P3, P4, P5))
00178 : impl(new CL_Callback_Impl_v5_static<P1, P2, P3, P4, P5>(function))
00179 {
00180 }
00181
00182 template<typename UserData>
00183 CL_Callback_v5(void (*function)(P1, P2, P3, P4, P5, UserData), const UserData &user_data)
00184 : impl(new CL_Callback_Impl_v5_static_user<P1, P2, P3, P4, P5, UserData>(function, user_data))
00185 {
00186 }
00187
00188 template<class InstanceClass>
00189 CL_Callback_v5(InstanceClass *instance, void (InstanceClass::*function)(P1, P2, P3, P4, P5))
00190 : impl(new CL_Callback_Impl_v5_member<P1, P2, P3, P4, P5, InstanceClass>(instance, function))
00191 {
00192 }
00193
00194 template<class InstanceClass, typename UserData>
00195 CL_Callback_v5(InstanceClass *instance, void (InstanceClass::*function)(P1, P2, P3, P4, P5, UserData), const UserData &user_data)
00196 : impl(new CL_Callback_Impl_v5_member_user<P1, P2, P3, P4, P5, InstanceClass, UserData>(instance, function, user_data))
00197 {
00198 }
00199
00200 void set(void (*function)(P1, P2, P3, P4, P5))
00201 {
00202 impl = CL_SharedPtr< CL_Callback_Impl_v5<P1, P2, P3, P4, P5> >(new CL_Callback_Impl_v5_static<P1, P2, P3, P4, P5>(function));
00203 }
00204
00205 template<typename UserData>
00206 void set(void (*function)(P1, P2, P3, P4, P5, UserData), const UserData &user_data)
00207 {
00208 impl = CL_SharedPtr< CL_Callback_Impl_v5<P1, P2, P3, P4, P5> >(new CL_Callback_Impl_v5_static_user<P1, P2, P3, P4, P5, UserData>(function, user_data));
00209 }
00210
00211 template<class InstanceClass>
00212 void set(InstanceClass *instance, void (InstanceClass::*function)(P1, P2, P3, P4, P5))
00213 {
00214 impl = CL_SharedPtr< CL_Callback_Impl_v5<P1, P2, P3, P4, P5> >(new CL_Callback_Impl_v5_member<P1, P2, P3, P4, P5, InstanceClass>(instance, function));
00215 }
00216
00217 template<class InstanceClass, typename UserData>
00218 void set(InstanceClass *instance, void (InstanceClass::*function)(P1, P2, P3, P4, P5, UserData), const UserData &user_data)
00219 {
00220 impl = CL_SharedPtr< CL_Callback_Impl_v5<P1, P2, P3, P4, P5> >(new CL_Callback_Impl_v5_member_user<P1, P2, P3, P4, P5, InstanceClass, UserData>(instance, function, user_data));
00221 }
00222
00223 void clear()
00224 {
00225 impl = CL_SharedPtr< CL_Callback_Impl_v5<P1, P2, P3, P4, P5> >();
00226 }
00227
00228 void invoke(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) const
00229 {
00230 impl->invoke(p1, p2, p3, p4, p5);
00231 }
00232
00233 bool is_null() const
00234 {
00235 return !impl;
00236 }
00237
00238 private:
00239 CL_SharedPtr< CL_Callback_Impl_v5<P1, P2, P3, P4, P5> > impl;
00240 };
00241
00245 template <typename P1, typename P2, typename P3, typename P4, typename P5>
00246 class CL_Callback_v5_functor : public CL_Callback_v5<P1, P2, P3, P4, P5>
00247 {
00248 public:
00249 CL_Callback_v5_functor()
00250 {
00251 }
00252
00253 CL_Callback_v5_functor(const CL_Callback_v5_functor ©)
00254 : CL_Callback_v5<P1, P2, P3, P4, P5>(copy)
00255 {
00256 }
00257
00258 template<class Functor>
00259 CL_Callback_v5_functor(Functor functor)
00260 : CL_Callback_v5<P1, P2, P3, P4, P5>(new CL_Callback_Impl_v5_functor<P1, P2, P3, P4, P5, Functor>(functor))
00261 {
00262 }
00263 };
00264
00265