00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00018 #ifndef _FU_EVENT_H_
00019 #define _FU_EVENT_H_
00020
00021 #ifndef _FU_FUNCTOR_H_
00022 #include "FUtils/FUFunctor.h"
00023 #endif // _FU_FUNCTOR_H_
00024
00029 class FUEvent0
00030 {
00031 private:
00032 typedef IFunctor0<void> Handler;
00033 typedef fm::pvector<Handler> HandlerList;
00034 HandlerList handlers;
00035
00036 public:
00038 FUEvent0() {}
00039
00041 ~FUEvent0()
00042 {
00043 FUAssert(handlers.empty(), CLEAR_POINTER_VECTOR(handlers));
00044 }
00045
00048 size_t GetHandlerCount() { return handlers.size(); }
00049
00053 template <class Class>
00054 void InsertHandler(Class* handle, void (Class::*_function)())
00055 {
00056 handlers.push_back(new FUFunctor0<Class, void>(handle, _function));
00057 }
00058
00062 void InsertHandler(Handler* functor)
00063 {
00064 handlers.push_back(functor);
00065 }
00066
00069 void InsertHandler(void (*_function)())
00070 {
00071 handlers.push_back(new FUStaticFunctor0<void>(_function));
00072 }
00073
00078 void ReleaseHandler(void* handle, void* function)
00079 {
00080 HandlerList::iterator it;
00081 for (it = handlers.begin(); it != handlers.end(); ++it)
00082 {
00083 if ((*it)->Compare(handle, function))
00084 {
00085 delete (*it);
00086 handlers.erase(it);
00087 break;
00088 }
00089 }
00090 }
00091
00095 template <class Class>
00096 void ReleaseHandler(Class* handle, void (Class::*_function)())
00097 {
00098 void* function = *(void**)(size_t)&_function;
00099 ReleaseHandler((void*) handle, function);
00100 }
00101
00104 void ReleaseHandler(void (*_function)())
00105 {
00106 void* function = *(void**)(size_t)&_function;
00107 ReleaseHandler(NULL, function);
00108 }
00109
00113 void operator()()
00114 {
00115 intptr_t index = handlers.size() - 1;
00116 for (; index >= 0; --index)
00117 {
00118 (*handlers[index])();
00119 }
00120 }
00121 };
00122
00127 template <class Arg1>
00128 class FUEvent1
00129 {
00130 private:
00131 typedef IFunctor1<Arg1, void> Handler;
00132 typedef fm::pvector<Handler> HandlerList;
00133 HandlerList handlers;
00134
00135 public:
00137 FUEvent1() {}
00138
00140 ~FUEvent1()
00141 {
00142 FUAssert(handlers.empty(), CLEAR_POINTER_VECTOR(handlers));
00143 }
00144
00147 size_t GetHandlerCount() { return handlers.size(); }
00148
00152 template <class Class>
00153 void InsertHandler(Class* handle, void (Class::*_function)(Arg1))
00154 {
00155 handlers.push_back(NewFUFunctor1(handle, _function));
00156 }
00157
00161 void InsertHandler(Handler* functor)
00162 {
00163 handlers.push_back(functor);
00164 }
00165
00168 void InsertHandler(void (*_function)(Arg1))
00169 {
00170 handlers.push_back(new FUStaticFunctor1<Arg1, void>(_function));
00171 }
00172
00177 void ReleaseHandler(void* handle, void* function)
00178 {
00179 typename HandlerList::iterator it;
00180 for (it = handlers.begin(); it != handlers.end(); ++it)
00181 {
00182 if ((*it)->Compare(handle, function))
00183 {
00184 delete (*it);
00185 handlers.erase(it);
00186 break;
00187 }
00188 }
00189 }
00190
00194 template <class Class>
00195 void ReleaseHandler(Class* handle, void (Class::*_function)(Arg1))
00196 {
00197 void* function = *(void**)(size_t)&_function;
00198 ReleaseHandler((void*) handle, function);
00199 }
00200
00203 void ReleaseHandler(void (*_function)(Arg1))
00204 {
00205 void* function = *(void**)(size_t)&_function;
00206 ReleaseHandler(NULL, function);
00207 }
00208
00213 void operator()(Arg1 argument1)
00214 {
00215 intptr_t index = handlers.size() - 1;
00216 for (; index >= 0; --index)
00217 {
00218 (*handlers[index])(argument1);
00219 }
00220 }
00221 };
00222
00227 template <class Arg1, class Arg2>
00228 class FUEvent2
00229 {
00230 private:
00231 typedef IFunctor2<Arg1, Arg2, void> Handler;
00232 typedef fm::pvector<Handler> HandlerList;
00233 HandlerList handlers;
00234
00235 public:
00237 FUEvent2() {}
00238
00240 ~FUEvent2()
00241 {
00242 FUAssert(handlers.empty(), CLEAR_POINTER_VECTOR(handlers));
00243 }
00244
00247 size_t GetHandlerCount() { return handlers.size(); }
00248
00252 template <class Class>
00253 void InsertHandler(Class* handle, void (Class::*_function)(Arg1, Arg2))
00254 {
00255 handlers.push_back(new FUFunctor2<Class, Arg1, Arg2, void>(handle, _function));
00256 }
00257
00261 void InsertHandler(Handler* functor)
00262 {
00263 handlers.push_back(functor);
00264 }
00265
00268 void InsertHandler(void (*_function)(Arg1, Arg2))
00269 {
00270 handlers.push_back(new FUStaticFunctor2<Arg1, Arg2, void>(_function));
00271 }
00272
00277 void ReleaseHandler(void* handle, void* function)
00278 {
00279 typename HandlerList::iterator it;
00280 for (it = handlers.begin(); it != handlers.end(); ++it)
00281 {
00282 if ((*it)->Compare(handle, function))
00283 {
00284 delete (*it);
00285 handlers.erase(it);
00286 break;
00287 }
00288 }
00289 }
00290
00294 template <class Class>
00295 void ReleaseHandler(Class* handle, void (Class::*_function)(Arg1, Arg2))
00296 {
00297 void* function = *(void**)(size_t)&_function;
00298 ReleaseHandler((void*) handle, function);
00299 }
00300
00303 void ReleaseHandler(void (*_function)(Arg1, Arg2))
00304 {
00305 void* function = *(void**)(size_t)&_function;
00306 ReleaseHandler(NULL, function);
00307 }
00308
00314 void operator()(Arg1 argument1, Arg2 argument2)
00315 {
00316 intptr_t index = handlers.size() - 1;
00317 for (; index >= 0; --index)
00318 {
00319 (*handlers[index])(argument1, argument2);
00320 }
00321 }
00322 };
00323
00324
00329 template <class Arg1, class Arg2, class Arg3>
00330 class FUEvent3
00331 {
00332 private:
00333 typedef IFunctor3<Arg1, Arg2, Arg3, void> Handler;
00334 typedef fm::pvector<Handler> HandlerList;
00335 HandlerList handlers;
00336
00337 public:
00339 FUEvent3() {}
00340
00342 ~FUEvent3()
00343 {
00344 FUAssert(handlers.empty(), CLEAR_POINTER_VECTOR(handlers));
00345 }
00346
00349 size_t GetHandlerCount() { return handlers.size(); }
00350
00354 template <class Class>
00355 void InsertHandler(Class* handle, void (Class::*_function)(Arg1, Arg2, Arg3))
00356 {
00357 handlers.push_back(new FUFunctor3<Class, Arg1, Arg2, Arg3, void>(handle, _function));
00358 }
00359
00363 void InsertHandler(Handler* functor)
00364 {
00365 handlers.push_back(functor);
00366 }
00367
00370 void InsertHandler(void (*_function)(Arg1, Arg2, Arg3))
00371 {
00372 handlers.push_back(new FUStaticFunctor3<Arg1, Arg2, Arg3, void>(_function));
00373 }
00374
00379 void ReleaseHandler(void* handle, void* function)
00380 {
00381 typename HandlerList::iterator it;
00382 for (it = handlers.begin(); it != handlers.end(); ++it)
00383 {
00384 if ((*it)->Compare(handle, function))
00385 {
00386 delete (*it);
00387 handlers.erase(it);
00388 break;
00389 }
00390 }
00391 }
00392
00396 template <class Class>
00397 void ReleaseHandler(Class* handle, void (Class::*_function)(Arg1, Arg2, Arg3))
00398 {
00399 void* function = *(void**)(size_t)&_function;
00400 ReleaseHandler((void*) handle, function);
00401 }
00402
00405 void ReleaseHandler(void (*_function)(Arg1, Arg2, Arg3))
00406 {
00407 void* function = *(void**)(size_t)&_function;
00408 ReleaseHandler(NULL, function);
00409 }
00410
00417 void operator()(Arg1 argument1, Arg2 argument2, Arg3 argument3)
00418 {
00419 intptr_t index = handlers.size() - 1;
00420 for (; index >= 0; --index)
00421 {
00422 (*handlers[index])(argument1, argument2, argument3);
00423 }
00424 }
00425 };
00426
00427 #endif // _FU_EVENT_H_