Use <cstddef> for NULL
[platform/core/uifw/dali-core.git] / dali / public-api / signals / callback.h
1 #ifndef __DALI_CALLBACK_H__
2 #define __DALI_CALLBACK_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <cstddef>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/signals/functor-delegate.h>
27
28 namespace Dali
29 {
30
31 class CallbackBase;
32
33 /**
34  * @brief Callback base class to hold the data for callback function and member function calls.
35  */
36 class DALI_IMPORT_API CallbackBase
37 {
38 public:
39
40   /**
41    * @brief Default constructor
42    */
43   CallbackBase();
44
45   /**
46    * @brief Destructor
47    */
48   ~CallbackBase();
49
50   /**
51    * @brief Resets the object pointer so that we know not to call methods of this object any more.
52    */
53   void Reset();
54
55   /**
56    * @brief Function to call the function or member function dispatcher
57    *
58    * @param[in] callback The callback to call.
59    */
60   static void Execute( CallbackBase& callback )
61   {
62     // if we point to a function, we can call it directly
63     // otherwise call the dispatcher function that knows the real type of the object
64     // Note that this template dispatcher lives in client code so the library containing
65     // the code has to be loaded, otherwise we crash boom bang
66     if( callback.mImpl && callback.mImpl->mObjectPointer )
67     {
68       Dispatcher dispatcher = callback.mImpl->mMemberFunctionDispatcher;
69       (*dispatcher)( callback );
70     }
71     // its also possible to have a member function pointer to a CallbackProvider
72     // that has been deleted, so check if we have impl still
73     else if( !callback.mImpl && callback.mFunction )
74     {
75       (*(callback.mFunction))();
76     }
77   }
78
79   /**
80    * @brief Function to call the function or member function dispatcher.
81    *
82    * @param[in] callback The callback to call.
83    * @return value from the function
84    */
85   template< typename R >
86   static R ExecuteReturn( CallbackBase& callback )
87   {
88     R returnVal = R();
89     // if we point to a function, we can call it directly
90     // otherwise call the dispatcher function that knows the real type of the object
91     // Note that this template dispatcher lives in client code so the library containing
92     // the code has to be loaded, otherwise we crash boom bang
93     if( callback.mImpl && callback.mImpl->mObjectPointer )
94     {
95       typedef R(*Dispatcher)(CallbackBase& base);
96       Dispatcher dispatcher = reinterpret_cast< Dispatcher >( callback.mImpl->mMemberFunctionDispatcher );
97       returnVal = (*dispatcher)( callback );
98     }
99     else if( !callback.mImpl && callback.mFunction )
100     {
101       typedef R(*Function1)();
102       returnVal = (*(reinterpret_cast< Function1 >( callback.mFunction )))();
103     }
104
105     return returnVal;
106   }
107
108   /**
109    * @brief Function to call the function or member function dispatcher.
110    *
111    * This function template gets instantiated at the call site
112    * @param[in] callback The callback to call.
113    * @param[in] param1 The first parameter to pass into the function.
114    */
115   template< typename P1 >
116   static void Execute( CallbackBase& callback, P1 param1 )
117   {
118     // if we point to a function, we can call it directly
119     // otherwise call the dispatcher function that knows the real type of the object
120     // Note that this template dispatcher lives in client code (where the callback was created)
121     // so the library containing the code has to be loaded, otherwise we crash boom bang
122     if( callback.mImpl && callback.mImpl->mObjectPointer )
123     {
124       typedef void(*Dispatcher)(CallbackBase& base,P1);
125       Dispatcher dispatcher = reinterpret_cast< Dispatcher >( callback.mImpl->mMemberFunctionDispatcher );
126       (*dispatcher)( callback, param1 );
127     }
128     else if( !callback.mImpl && callback.mFunction )
129     {
130       // convert function type
131       typedef void(*Function1)(P1);
132       (*(reinterpret_cast< Function1 >( callback.mFunction )))( param1 );
133     }
134   }
135
136   /**
137    * @brief Function to call the function or member function dispatcher.
138    *
139    * This function template gets instantiated at the call site
140    * @param[in] callback The callback to call.
141    * @param[in] param1 The first parameter to pass into the function.
142    * @return the value from the function
143    */
144   template< typename R, typename P1 >
145   static R ExecuteReturn( CallbackBase& callback, P1 param1 )
146   {
147     R returnVal =  R();
148     // if we point to a function, we can call it directly
149     // otherwise call the dispatcher function that knows the real type of the object
150     // Note that this template dispatcher lives in client code (where the callback was created)
151     // so the library containing the code has to be loaded, otherwise we crash boom bang
152     if( callback.mImpl && callback.mImpl->mObjectPointer )
153     {
154       typedef R(*Dispatcher)(CallbackBase& base,P1);
155       Dispatcher dispatcher = reinterpret_cast< Dispatcher >( callback.mImpl->mMemberFunctionDispatcher );
156       returnVal = (*dispatcher)( callback, param1 );
157     }
158     else if( !callback.mImpl && callback.mFunction )
159     {
160       // convert function type
161       typedef R(*Function1)(P1);
162       returnVal = (*(reinterpret_cast< Function1 >( callback.mFunction )))( param1 );
163     }
164
165     return returnVal;
166   }
167
168   /**
169    * @brief Function to call the function or member function dispatcher.
170    *
171    * This function template gets instantiated at the call site.
172    * @param[in] callback The callback to call.
173    * @param[in] param1 The first parameter to pass into the function.
174    * @param[in] param2 The second parameter to pass into the function.
175    */
176   template< typename P1, typename P2 >
177   static void Execute( CallbackBase& callback, P1 param1, P2 param2 )
178   {
179     // if we point to a function, we can call it directly
180     // otherwise call the dispatcher function that knows the real type of the object
181     // Note that this template dispatcher lives in client code (where the callback was created)
182     // so the library containing the code has to be loaded, otherwise we crash boom bang
183     if( callback.mImpl && callback.mImpl->mObjectPointer )
184     {
185       typedef void(*Dispatcher)(CallbackBase& base,P1,P2);
186       Dispatcher dispatcher = reinterpret_cast< Dispatcher >( callback.mImpl->mMemberFunctionDispatcher );
187       (*dispatcher)( callback, param1, param2 );
188     }
189     else if( !callback.mImpl && callback.mFunction )
190     {
191       // convert function type
192       typedef void(*Function2)(P1,P2);
193       (*(reinterpret_cast< Function2 >( callback.mFunction )))( param1, param2 );
194     }
195   }
196
197   /**
198    * @brief Function to call the function or member function dispatcher.
199    *
200    * This function template gets instantiated at the call site
201    * @param[in] callback The callback to call.
202    * @param[in] param1 The first parameter to pass into the function.
203    * @param[in] param2 The second parameter to pass into the function.
204    * @return The return value from the function
205    */
206   template< typename R, typename P1, typename P2 >
207   static R ExecuteReturn( CallbackBase& callback, P1 param1, P2 param2 )
208   {
209     R returnVal= R();
210     // if we point to a function, we can call it directly
211     // otherwise call the dispatcher function that knows the real type of the object
212     // Note that this template dispatcher lives in client code (where the callback was created)
213     // so the library containing the code has to be loaded, otherwise we crash boom bang
214     if( callback.mImpl && callback.mImpl->mObjectPointer )
215     {
216       typedef R(*Dispatcher)(CallbackBase& base,P1,P2);
217       Dispatcher dispatcher = reinterpret_cast< Dispatcher >( callback.mImpl->mMemberFunctionDispatcher );
218       returnVal = (*dispatcher)( callback, param1, param2 );
219     }
220     else if( !callback.mImpl && callback.mFunction )
221     {
222       // convert function type
223       typedef R(*Function2)(P1,P2);
224       returnVal = (*(reinterpret_cast< Function2 >( callback.mFunction )))( param1, param2 );
225     }
226
227     return returnVal;
228   }
229
230   /**
231    * @brief Function to call the function or member function dispatcher.
232    *
233    * This function template gets instantiated at the call site.
234    * @param[in] callback The callback to call.
235    * @param[in] param1 The first parameter to pass into the function.
236    * @param[in] param2 The second parameter to pass into the function.
237    * @param[in] param3 The third parameter to pass into the function.
238    */
239   template< typename P1, typename P2, typename P3 >
240   static void Execute( CallbackBase& callback, P1 param1, P2 param2, P3 param3 )
241   {
242     // if we point to a function, we can call it directly
243     // otherwise call the dispatcher function that knows the real type of the object
244     // Note that this template dispatcher lives in client code (where the callback was created)
245     // so the library containing the code has to be loaded, otherwise we crash boom bang
246     if( callback.mImpl && callback.mImpl->mObjectPointer )
247     {
248       typedef void(*Dispatcher)(CallbackBase& base,P1,P2,P3);
249       Dispatcher dispatcher = reinterpret_cast< Dispatcher >( callback.mImpl->mMemberFunctionDispatcher );
250       (*dispatcher)( callback, param1, param2, param3 );
251     }
252     else if( !callback.mImpl && callback.mFunction )
253     {
254       // convert function type
255       typedef void(*Function2)(P1,P2,P3);
256       (*(reinterpret_cast< Function2 >( callback.mFunction )))( param1, param2, param3 );
257     }
258   }
259
260   /**
261    * @brief Function to call the function or member function dispatcher.
262    *
263    * This function template gets instantiated at the call site
264    * @param[in] callback The callback to call.
265    * @param[in] param1 The first parameter to pass into the function.
266    * @param[in] param2 The second parameter to pass into the function.
267    * @param[in] param3 The third parameter to pass into the function.
268    * @return The return value from the function
269    */
270   template< typename R, typename P1, typename P2, typename P3 >
271   static R ExecuteReturn( CallbackBase& callback, P1 param1, P2 param2, P3 param3 )
272   {
273     R returnVal= R();
274     // if we point to a function, we can call it directly
275     // otherwise call the dispatcher function that knows the real type of the object
276     // Note that this template dispatcher lives in client code (where the callback was created)
277     // so the library containing the code has to be loaded, otherwise we crash boom bang
278     if( callback.mImpl && callback.mImpl->mObjectPointer )
279     {
280       typedef R(*Dispatcher)(CallbackBase& base,P1,P2,P3);
281       Dispatcher dispatcher = reinterpret_cast< Dispatcher >( callback.mImpl->mMemberFunctionDispatcher );
282       returnVal = (*dispatcher)( callback, param1, param2, param3 );
283     }
284     else if( !callback.mImpl && callback.mFunction )
285     {
286       // convert function type
287       typedef R(*Function2)(P1,P2,P3);
288       returnVal = (*(reinterpret_cast< Function2 >( callback.mFunction )))( param1, param2, param3 );
289     }
290
291     return returnVal;
292   }
293
294 protected: // Constructors for deriving classes
295
296   /**
297    * @brief Function with static linkage
298    */
299   typedef void(*Function)(void);
300
301   /**
302    * @brief Member function
303    */
304   typedef void (CallbackBase::*MemberFunction)( void );
305
306   /**
307    * @brief Used to call the correct member function
308    */
309   typedef void (*Dispatcher)( CallbackBase& base );
310
311   /**
312    * @brief Used to destroy mObjectPointer (NULL if not mObjectPointer is not owned)
313    */
314   typedef void(*Destructor)(void* object);
315
316   /**
317    * @brief Copy constructor operator not declared.
318    */
319   CallbackBase( const CallbackBase& rhs );
320   /**
321    * @brief assignment operator not declared.
322    */
323   const CallbackBase& operator=( const CallbackBase& rhs );
324
325   /**
326    * @brief Constructor for function with static linkage.
327    *
328    * @param[in] function The function to call.
329    */
330   CallbackBase( Function function );
331
332   /**
333    * @brief Constructor for member function.
334    *
335    * @param[in] object The object to call (not owned).
336    * @param[in] function The member function of the object.
337    * @param[in] dispatcher Used to call the actual object.
338    */
339   CallbackBase( void* object, MemberFunction function, Dispatcher dispatcher );
340
341   /**
342    * @brief Constructor for member function.
343    *
344    * @param[in] object The object to call (owned).
345    * @param[in] function The member function of the object.
346    * @param dispatcher Used to call the actual object.
347    * @param destructor Used to delete the owned object.
348    */
349   CallbackBase( void* object, MemberFunction function, Dispatcher dispatcher, Destructor destructor );
350
351 public: // Data for deriving classes & Dispatchers
352
353   /**
354    * @brief struct to hold the extra data needed for member functions.
355    */
356   struct Impl
357   {
358     Impl();                               ///< Default constructor
359
360     void* mObjectPointer;                 ///< Object whose member function will be called. Not owned if mDestructorDispatcher is NULL.
361     Dispatcher mMemberFunctionDispatcher; ///< Dispatcher for member functions
362     Destructor mDestructorDispatcher;     ///< Destructor for owned objects. NULL if mDestructorDispatcher is not owned.
363   };
364   Impl* mImpl;                            ///< Implementation pointer
365
366   union
367   {
368     MemberFunction mMemberFunction;       ///< Pointer to member function
369     Function mFunction;                   ///< Static function
370   };
371 };
372
373 /**
374  * @brief Non-member equality operator
375  */
376 bool operator==( const CallbackBase& lhs, const CallbackBase& rhs );
377
378 /**
379  * @brief Dispatcher to delete an object.
380  */
381 template< class T >
382 struct Destroyer
383 {
384   /**
385    * @brief Dispatcher to delete an object.
386    */
387   static void Delete( void* object )
388   {
389     // CallbackBase owns the object but we're the only one who knows the real type so need
390     // to delete by "downcasting" from void* to the correct type
391     delete reinterpret_cast< T* >( object );
392   }
393 };
394
395 /**
396  * @brief Dispatcher to call the actual member function.
397  */
398 template< class T >
399 struct Dispatcher0
400 {
401   /**
402    * @brief Call an actual member function.
403    *
404    * @param[in] callback The callback information.
405    */
406   static void Dispatch( CallbackBase& callback )
407   {
408     // "downcast" the object and function type back to the correct ones
409     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
410     typedef void(T::*MemberFunction)(void);
411     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
412     (object->*function)();
413   }
414 };
415
416 /**
417  * @brief Dispatcher to call the actual member function.
418  */
419 template< class T, typename P1 >
420 struct Dispatcher1
421 {
422   /**
423    * @brief Call an actual member function.
424    *
425    * @param[in] callback The callback information.
426    * @param[in] param1 The first parameter to pass to the real member function.
427    */
428   static void Dispatch( CallbackBase& callback, P1 param1 )
429   {
430     // "downcast" the object and function type back to the correct ones
431     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
432     typedef void(T::*MemberFunction)(P1);
433     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
434     (object->*function)( param1 );
435   }
436 };
437
438 /**
439  * @brief Dispatcher to call the actual member function.
440  */
441 template< class T, typename P1, typename P2 >
442 struct Dispatcher2
443 {
444   /**
445    * @brief Call an actual member function.
446    *
447    * @param[in] callback The callback information.
448    * @param[in] param1 The first parameter to pass to the real member function.
449    * @param[in] param2 The second parameter to pass to the real member function.
450    */
451   static void Dispatch( CallbackBase& callback, P1 param1, P2 param2 )
452   {
453     // "downcast" the object and function type back to the correct ones
454     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
455     typedef void(T::*MemberFunction)(P1, P2);
456     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
457     (object->*function)( param1, param2 );
458   }
459 };
460
461 /**
462  * @brief Dispatcher to call the actual member function.
463  */
464 template< class T, typename P1, typename P2, typename P3 >
465 struct Dispatcher3
466 {
467   /**
468    * @brief Call an actual member function.
469    *
470    * @param[in] callback The callback information.
471    * @param[in] param1 The first parameter to pass to the real member function.
472    * @param[in] param2 The second parameter to pass to the real member function.
473    * @param[in] param3 The third parameter to pass to the real member function.
474    */
475   static void Dispatch( CallbackBase& callback, P1 param1, P2 param2, P3 param3 )
476   {
477     // "downcast" the object and function type back to the correct ones
478     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
479     typedef void(T::*MemberFunction)(P1, P2, P3);
480     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
481     (object->*function)( param1, param2, param3 );
482   }
483 };
484
485 /**
486  * @brief Dispatcher to call the actual member function.
487  */
488 template< class T, typename R >
489 struct DispatcherReturn0
490 {
491   /**
492    * @brief Call an actual member function.
493    *
494    * @param[in] callback The callback information.
495    * @return the value.
496    */
497   static R Dispatch( CallbackBase& callback )
498   {
499     // "downcast" the object and function type back to the correct ones
500     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
501     typedef R(T::*MemberFunction)(void);
502     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
503     return (object->*function)();
504   }
505 };
506
507 /**
508  * @brief Dispatcher to call the actual member function.
509  */
510 template< class T, typename R, typename P1 >
511 struct DispatcherReturn1
512 {
513   /**
514    * @brief Call an actual member function.
515    *
516    * @param[in] callback The callback information.
517    * @param[in] param1 The first parameter to pass to the real member function.
518    * @return The return value from the function
519    */
520   static R Dispatch( CallbackBase& callback, P1 param1 )
521   {
522     // "downcast" the object and function type back to the correct ones
523     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
524     typedef R(T::*MemberFunction)(P1);
525     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
526     return (object->*function)( param1 );
527   }
528 };
529
530 /**
531  * @brief Dispatcher to call the actual member function.
532  */
533 template< class T, typename R, typename P1, typename P2 >
534 struct DispatcherReturn2
535 {
536   /**
537    * @brief Call an actual member function.
538    *
539    * @param[in] callback The callback information.
540    * @param[in] param1 The first parameter to pass to the real member function.
541    * @param[in] param2 The second parameter to pass to the real member function.
542    * @return The return value from the function
543    */
544   static R Dispatch( CallbackBase& callback, P1 param1, P2 param2 )
545   {
546     // "downcast" the object and function type back to the correct ones
547     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
548     typedef R(T::*MemberFunction)(P1, P2);
549     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
550     return (object->*function)( param1, param2 );
551   }
552 };
553
554 /**
555  * @brief Dispatcher to call the actual member function.
556  */
557 template< class T, typename R, typename P1, typename P2, typename P3 >
558 struct DispatcherReturn3
559 {
560   /**
561    * @brief Call an actual member function.
562    *
563    * @param[in] callback The callback information.
564    * @param[in] param1 The first parameter to pass to the real member function.
565    * @param[in] param2 The second parameter to pass to the real member function.
566    * @param[in] param3 The third parameter to pass to the real member function.
567    * @return The return value from the function
568    */
569   static R Dispatch( CallbackBase& callback, P1 param1, P2 param2, P3 param3 )
570   {
571     // "downcast" the object and function type back to the correct ones
572     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
573     typedef R(T::*MemberFunction)(P1, P2, P3);
574     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
575     return (object->*function)( param1, param2, param3 );
576   }
577 };
578
579 /**
580  * @brief Dispatcher to call a functor.
581  */
582 template< class T >
583 struct FunctorDispatcher0
584 {
585   /**
586    * @brief Call a function object.
587    *
588    * @param[in] callback The callback information.
589    */
590   static void Dispatch( CallbackBase& callback )
591   {
592     // "downcast" the object and function type back to the correct ones
593     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
594     (*object)();
595   }
596 };
597
598 /**
599  * @brief Dispatcher to call a functor.
600  */
601 template< class T, typename P1 >
602 struct FunctorDispatcher1
603 {
604   /**
605    * @brief Call a function object.
606    *
607    * @param[in] callback The callback information.
608    * @param[in] param1 The first parameter to pass to the real member function.
609    */
610   static void Dispatch( CallbackBase& callback, P1 param1 )
611   {
612     // "downcast" the object and function type back to the correct ones
613     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
614     (*object)( param1 );
615   }
616 };
617
618 /**
619  * @brief Dispatcher to call a functor.
620  */
621 template< class T, typename P1, typename P2 >
622 struct FunctorDispatcher2
623 {
624   /**
625    * @brief Call a function object.
626    *
627    * @param[in] callback The callback information.
628    * @param[in] param1 The first parameter to pass to the real member function.
629    * @param[in] param2 The second parameter to pass to the real member function.
630    */
631   static void Dispatch( CallbackBase& callback, P1 param1, P2 param2 )
632   {
633     // "downcast" the object and function type back to the correct ones
634     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
635     (*object)( param1, param2 );
636   }
637 };
638
639 /**
640  * @brief Dispatcher to call a functor.
641  */
642 template< class T, typename P1, typename P2, typename P3 >
643 struct FunctorDispatcher3
644 {
645   /**
646    * @brief Call a function object.
647    *
648    * @param[in] callback The callback information.
649    * @param[in] param1 The first parameter to pass to the real member function.
650    * @param[in] param2 The second parameter to pass to the real member function.
651    * @param[in] param3 The third parameter to pass to the real member function.
652    */
653   static void Dispatch( CallbackBase& callback, P1 param1, P2 param2, P3 param3 )
654   {
655     // "downcast" the object and function type back to the correct ones
656     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
657     (*object)( param1, param2, param3 );
658   }
659 };
660
661 /**
662  * @brief Dispatcher to call a functor.
663  */
664 template< class T, typename R >
665 struct FunctorDispatcherReturn0
666 {
667   /**
668    * @brief Call a function object.
669    *
670    * @param[in] callback The callback information.
671    * @return the value.
672    */
673   static R Dispatch( CallbackBase& callback )
674   {
675     // "downcast" the object and function type back to the correct ones
676     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
677     return (*object)();
678   }
679 };
680
681 /**
682  * @brief Dispatcher to call a functor.
683  */
684 template< class T, typename R, typename P1 >
685 struct FunctorDispatcherReturn1
686 {
687   /**
688    * @brief Call a function object.
689    *
690    * @param[in] callback The callback information.
691    * @param[in] param1 The first parameter to pass to the real member function.
692    * @return The return value from the function
693    */
694   static R Dispatch( CallbackBase& callback, P1 param1 )
695   {
696     // "downcast" the object and function type back to the correct ones
697     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
698     return (*object)( param1 );
699   }
700 };
701
702 /**
703  * @brief Dispatcher to call a functor.
704  */
705 template< class T, typename R, typename P1, typename P2 >
706 struct FunctorDispatcherReturn2
707 {
708   /**
709    * @brief Call a function object.
710    *
711    * @param[in] callback The callback information.
712    * @param[in] param1 The first parameter to pass to the real member function.
713    * @param[in] param2 The second parameter to pass to the real member function.
714    * @return The return value from the function
715    */
716   static R Dispatch( CallbackBase& callback, P1 param1, P2 param2 )
717   {
718     // "downcast" the object and function type back to the correct ones
719     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
720     return (*object)( param1, param2 );
721   }
722 };
723
724 /**
725  * @brief Dispatcher to call a functor.
726  */
727 template< class T, typename R, typename P1, typename P2, typename P3 >
728 struct FunctorDispatcherReturn3
729 {
730   /**
731    * @brief Call a function object.
732    *
733    * @param[in] callback The callback information.
734    * @param[in] param1 The first parameter to pass to the real member function.
735    * @param[in] param2 The second parameter to pass to the real member function.
736    * @param[in] param3 The third parameter to pass to the real member function.
737    * @return The return value from the function
738    */
739   static R Dispatch( CallbackBase& callback, P1 param1, P2 param2, P3 param3 )
740   {
741     // "downcast" the object and function type back to the correct ones
742     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
743     return (*object)( param1, param2, param3 );
744   }
745 };
746
747 /**
748  * @brief Dispatcher to call a functor.
749  * This variant calls a specific void() member function.
750  */
751 template< class T >
752 struct VoidFunctorDispatcher0
753 {
754   /**
755    * @brief Call a function object.
756    *
757    * @param[in] callback The callback information.
758    */
759   static void Dispatch( CallbackBase& callback )
760   {
761     // "downcast" the object and function type back to the correct ones
762     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
763     typedef void(T::*MemberFunction)(void);
764     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
765     (object->*function)();
766   }
767 };
768
769 /**
770  * @brief Dispatcher to call a functor.
771  *
772  * This variant calls a void() member, ignoring any signal parameters
773  */
774 template< class T, typename P1 >
775 struct VoidFunctorDispatcher1
776 {
777   /**
778    * @brief Call a function object.
779    *
780    * @param[in] callback The callback information.
781    * @param[in] param1 The first parameter to pass to the real member function.
782    */
783   static void Dispatch( CallbackBase& callback, P1 param1 )
784   {
785     // "downcast" the object and function type back to the correct ones
786     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
787     typedef void(T::*MemberFunction)(void);
788     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
789     (object->*function)(/*ignore params*/);
790   }
791 };
792
793 /**
794  * @brief Dispatcher to call a functor.
795  *
796  * This variant calls a void() member, ignoring any signal parameters
797  */
798 template< class T, typename P1, typename P2 >
799 struct VoidFunctorDispatcher2
800 {
801   /**
802    * @brief Call a function object.
803    *
804    * @param[in] callback The callback information.
805    * @param[in] param1 The first parameter to pass to the real member function.
806    * @param[in] param2 The second parameter to pass to the real member function.
807    */
808   static void Dispatch( CallbackBase& callback, P1 param1, P2 param2 )
809   {
810     // "downcast" the object and function type back to the correct ones
811     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
812     typedef void(T::*MemberFunction)(void);
813     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
814     (object->*function)(/*ignore params*/);
815   }
816 };
817
818 /**
819  * @brief Dispatcher to call a functor.
820  *
821  * This variant calls a void() member, ignoring any signal parameters
822  */
823 template< class T, typename P1, typename P2, typename P3 >
824 struct VoidFunctorDispatcher3
825 {
826   /**
827    * @brief Call a function object.
828    *
829    * @param[in] callback The callback information.
830    * @param[in] param1 The first parameter to pass to the real member function.
831    * @param[in] param2 The second parameter to pass to the real member function.
832    * @param[in] param3 The third parameter to pass to the real member function.
833    */
834   static void Dispatch( CallbackBase& callback, P1 param1, P2 param2, P3 param3 )
835   {
836     // "downcast" the object and function type back to the correct ones
837     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
838     typedef void(T::*MemberFunction)(void);
839     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
840     (object->*function)(/*ignore params*/);
841   }
842 };
843
844 /**
845  * @brief Dispatcher to call a functor.
846  *
847  * This variant calls a void() member, and returns a default-constructed value
848  */
849 template< class T, typename R >
850 struct VoidFunctorDispatcherReturn0
851 {
852   /**
853    * @brief Call a function object.
854    *
855    * @param[in] callback The callback information.
856    * @return the value.
857    */
858   static R Dispatch( CallbackBase& callback )
859   {
860     // "downcast" the object and function type back to the correct ones
861     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
862     typedef void(T::*MemberFunction)(void);
863     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
864     (object->*function)(/*ignore params*/);
865     return R();
866   }
867 };
868
869 /**
870  * @brief Dispatcher to call a functor.
871  *
872  * This variant calls a void() member, and returns a default-constructed value
873  */
874 template< class T, typename R, typename P1 >
875 struct VoidFunctorDispatcherReturn1
876 {
877   /**
878    * @brief Call a function object.
879    *
880    * @param[in] callback The callback information.
881    * @param[in] param1 The first parameter to pass to the real member function.
882    * @return The return value from the function
883    */
884   static R Dispatch( CallbackBase& callback, P1 param1 )
885   {
886     // "downcast" the object and function type back to the correct ones
887     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
888     typedef void(T::*MemberFunction)(void);
889     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
890     (object->*function)(/*ignore params*/);
891     return R();
892   }
893 };
894
895 /**
896  * @brief Dispatcher to call a functor.
897  *
898  * This variant calls a void() member, and returns a default-constructed value
899  */
900 template< class T, typename R, typename P1, typename P2 >
901 struct VoidFunctorDispatcherReturn2
902 {
903   /**
904    * @brief Call a function object.
905    *
906    * @param[in] callback The callback information.
907    * @param[in] param1 The first parameter to pass to the real member function.
908    * @param[in] param2 The second parameter to pass to the real member function.
909    * @return The return value from the function
910    */
911   static R Dispatch( CallbackBase& callback, P1 param1, P2 param2 )
912   {
913     // "downcast" the object and function type back to the correct ones
914     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
915     typedef void(T::*MemberFunction)(void);
916     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
917     (object->*function)(/*ignore params*/);
918     return R();
919   }
920 };
921
922 /**
923  * @brief Dispatcher to call a functor.
924  *
925  * This variant calls a void() member, and returns a default-constructed value
926  */
927 template< class T, typename R, typename P1, typename P2, typename P3 >
928 struct VoidFunctorDispatcherReturn3
929 {
930   /**
931    * @brief Call a function object.
932    *
933    * @param[in] callback The callback information.
934    * @param[in] param1 The first parameter to pass to the real member function.
935    * @param[in] param2 The second parameter to pass to the real member function.
936    * @param[in] param3 The third parameter to pass to the real member function.
937    * @return The return value from the function
938    */
939   static R Dispatch( CallbackBase& callback, P1 param1, P2 param2, P3 param3 )
940   {
941     // "downcast" the object and function type back to the correct ones
942     T* object = reinterpret_cast< T* >( callback.mImpl->mObjectPointer );
943     typedef void(T::*MemberFunction)(void);
944     MemberFunction function = reinterpret_cast< MemberFunction >( callback.mMemberFunction );
945     (object->*function)(/*ignore params*/);
946     return R();
947   }
948 };
949
950 /**
951  * @brief Thin template to provide type safety for member function callbacks.
952  *
953  * version with two parameters and return value
954  */
955 template< class T >
956 class Callback : public CallbackBase
957 {
958 public:
959
960   /**
961    * @brief Default constructor.
962    *
963    */
964   Callback()
965   : CallbackBase()
966   {
967   }
968
969   /**
970    * @brief Constructor for member function.
971    *
972    * Copies the function object.
973    * @param[in] object The object to call.
974    * @param[in] memberFunction The member function of the object.
975    */
976   Callback( T* object, void(T::*memberFunction)(void) )
977   : CallbackBase( object,
978                   reinterpret_cast< CallbackBase::MemberFunction >( memberFunction ),
979                   reinterpret_cast< CallbackBase::Dispatcher >( &Dispatcher0<T>::Dispatch ) ) { }
980   template< typename P1 >
981   Callback( T* object, void(T::*memberFunction)(P1) )
982   : CallbackBase( object,
983                   reinterpret_cast< CallbackBase::MemberFunction >( memberFunction ),
984                   reinterpret_cast< CallbackBase::Dispatcher >( &Dispatcher1<T,P1>::Dispatch ) ) { }
985   template< typename P1, typename P2 >
986   Callback( T* object, void(T::*memberFunction)(P1, P2) )
987   : CallbackBase( object,
988                   reinterpret_cast< CallbackBase::MemberFunction >( memberFunction ),
989                   reinterpret_cast< CallbackBase::Dispatcher >( &Dispatcher2<T,P1,P2>::Dispatch ) ) { }
990   template< typename P1, typename P2, typename P3 >
991   Callback( T* object, void(T::*memberFunction)(P1, P2, P3) )
992   : CallbackBase( object,
993                   reinterpret_cast< CallbackBase::MemberFunction >( memberFunction ),
994                   reinterpret_cast< CallbackBase::Dispatcher >( &Dispatcher3<T,P1,P2,P3>::Dispatch ) ) { }
995   template< typename R >
996   Callback( T* object, R(T::*memberFunction)(void) )
997   : CallbackBase( object,
998                   reinterpret_cast< CallbackBase::MemberFunction >( memberFunction ),
999                   reinterpret_cast< CallbackBase::Dispatcher >( &DispatcherReturn0<T,R>::Dispatch ) ) { }
1000   template< typename R, typename P1 >
1001   Callback( T* object, R(T::*memberFunction)(P1) )
1002   : CallbackBase( object,
1003                   reinterpret_cast< CallbackBase::MemberFunction >( memberFunction ),
1004                   reinterpret_cast< CallbackBase::Dispatcher >( &DispatcherReturn1<T,R,P1>::Dispatch ) ) { }
1005   template< typename R, typename P1, typename P2 >
1006   Callback( T* object, R(T::*memberFunction)(P1, P2) )
1007   : CallbackBase( object,
1008                   reinterpret_cast< CallbackBase::MemberFunction >( memberFunction ),
1009                   reinterpret_cast< CallbackBase::Dispatcher >( &DispatcherReturn2<T,R,P1,P2>::Dispatch ) ) { }
1010   template< typename R, typename P1, typename P2, typename P3 >
1011   Callback( T* object, R(T::*memberFunction)(P1, P2, P3) )
1012   : CallbackBase( object,
1013                   reinterpret_cast< CallbackBase::MemberFunction >( memberFunction ),
1014                   reinterpret_cast< CallbackBase::Dispatcher >( &DispatcherReturn3<T,R,P1,P2,P3>::Dispatch ) ) { }
1015
1016 };
1017
1018 /**
1019  * @brief Specializations for static function callbacks.
1020  */
1021 class CallbackFunction : public CallbackBase
1022 {
1023 public:
1024
1025   /**
1026    * @brief Default constructor.
1027    */
1028   CallbackFunction()
1029   : CallbackBase()
1030   {
1031   }
1032
1033   /**
1034    * @brief Constructors for functions with static linkage.
1035    *
1036    * @param[in] function The function to call.
1037    */
1038   CallbackFunction( void(*function)() )
1039   : CallbackBase( reinterpret_cast< CallbackBase::Function >( function ) )
1040   { }
1041   template< typename R >
1042   CallbackFunction( R(*function)() )
1043   : CallbackBase( reinterpret_cast< CallbackBase::Function >( function ) )
1044   { }
1045   template< typename P1 >
1046   CallbackFunction( void(*function)(P1) )
1047   : CallbackBase( reinterpret_cast< CallbackBase::Function >( function ) )
1048   { }
1049   template< typename P1, typename R >
1050   CallbackFunction( R(*function)(P1)  )
1051   : CallbackBase( reinterpret_cast< CallbackBase::Function >( function ) )
1052   { }
1053   template< typename P1, typename P2 >
1054   CallbackFunction( void(*function)(P1,P2)  )
1055   : CallbackBase( reinterpret_cast< CallbackBase::Function >( function ) )
1056   { }
1057   template< typename P1, typename P2, typename R >
1058   CallbackFunction( R(*function)(P1,P2) )
1059   : CallbackBase( reinterpret_cast< CallbackBase::Function >( function ) )
1060   { }
1061   template< typename P1, typename P2, typename P3 >
1062   CallbackFunction( void(*function)(P1,P2,P3)  )
1063   : CallbackBase( reinterpret_cast< CallbackBase::Function >( function ) )
1064   { }
1065   template< typename P1, typename P2, typename P3, typename R >
1066   CallbackFunction( R(*function)(P1,P2,P3) )
1067   : CallbackBase( reinterpret_cast< CallbackBase::Function >( function ) )
1068   { }
1069
1070 };
1071
1072 /**
1073  * @brief Specializations for function object callbacks.
1074  */
1075 template< class T >
1076 class CallbackFunctor0 : public CallbackBase
1077 {
1078 public:
1079
1080   /**
1081    * @brief Constructor which copies a function object.
1082    *
1083    * @param[in] object The object to copy.
1084    */
1085   CallbackFunctor0( const T& object )
1086   : CallbackBase( reinterpret_cast< void* >( new T( object ) ), // copy the object
1087                   NULL, // uses operator() instead of member function
1088                   reinterpret_cast< CallbackBase::Dispatcher >( &FunctorDispatcher0<T>::Dispatch ),
1089                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<T>::Delete ) ) { }
1090 };
1091
1092 /**
1093  * @brief Function object callback for connecting void() methods
1094  */
1095 class CallbackFunctorDelegate0 : public CallbackBase
1096 {
1097 public:
1098
1099   /**
1100    * @brief Constructor which copies a function object.
1101    *
1102    * This variant calls a void() member, ignoring any signal parameters.
1103    * @param[in] object A newly allocated object (ownership is transferred).
1104    */
1105   CallbackFunctorDelegate0( FunctorDelegate* object )
1106   : CallbackBase( reinterpret_cast< void* >( object ), // transfer ownership
1107                   reinterpret_cast< CallbackBase::MemberFunction >( &FunctorDelegate::Execute ),
1108                   reinterpret_cast< CallbackBase::Dispatcher >( &VoidFunctorDispatcher0<FunctorDelegate>::Dispatch ),
1109                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<FunctorDelegate>::Delete ) ) { }
1110 };
1111
1112 /**
1113  * @brief Function object callback for matching callbacks to signal signature.
1114  */
1115 template< class T, typename P1 >
1116 class CallbackFunctor1 : public CallbackBase
1117 {
1118 public:
1119
1120   /**
1121    * @brief Constructor which copies a function object.
1122    *
1123    * @param[in] object The object to copy.
1124    */
1125   CallbackFunctor1( const T& object )
1126   : CallbackBase( reinterpret_cast< void* >( new T( object ) ), // copy the object
1127                   NULL, // uses operator() instead of member function
1128                   reinterpret_cast< CallbackBase::Dispatcher >( &FunctorDispatcher1<T,P1>::Dispatch ),
1129                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<T>::Delete ) ) { }
1130 };
1131
1132 /**
1133  * @brief Function object callback for connecting void() methods.
1134  */
1135 template< typename P1 >
1136 class CallbackFunctorDelegate1 : public CallbackBase
1137 {
1138 public:
1139
1140   /**
1141    * @brief Constructor which copies a function object.
1142    *
1143    * This variant calls a void() member, ignoring any signal parameters.
1144    * @param[in] object The object to copy.
1145    */
1146   CallbackFunctorDelegate1( FunctorDelegate* object )
1147   : CallbackBase( reinterpret_cast< void* >( object ), // transfer ownership
1148                   reinterpret_cast< CallbackBase::MemberFunction >( &FunctorDelegate::Execute ),
1149                   reinterpret_cast< CallbackBase::Dispatcher >( &VoidFunctorDispatcher1<FunctorDelegate,P1>::Dispatch ),
1150                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<FunctorDelegate>::Delete ) ) { }
1151 };
1152
1153 /**
1154  * @brief Function object callback for matching callbacks to signal signature
1155  */
1156 template< class T, typename P1, typename P2 >
1157 class CallbackFunctor2 : public CallbackBase
1158 {
1159 public:
1160
1161   /**
1162    * @brief Constructor which copies a function object.
1163    *
1164    * @param[in] object The object to copy.
1165    */
1166   CallbackFunctor2( const T& object )
1167   : CallbackBase( reinterpret_cast< void* >( new T( object ) ), // copy the object
1168                   NULL, // uses operator() instead of member function
1169                   reinterpret_cast< CallbackBase::Dispatcher >( &FunctorDispatcher2<T,P1,P2>::Dispatch ),
1170                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<T>::Delete ) ) { }
1171 };
1172
1173 /**
1174  * @brief Function object callback for connecting void() methods
1175  */
1176 template< typename P1, typename P2 >
1177 class CallbackFunctorDelegate2 : public CallbackBase
1178 {
1179 public:
1180
1181   /**
1182    * @brief Constructor which copies a function object.
1183    *
1184    * This variant calls a void() member, ignoring any signal parameters.
1185    * @param[in] object The object to copy.
1186    */
1187   CallbackFunctorDelegate2( FunctorDelegate* object )
1188   : CallbackBase( reinterpret_cast< void* >( object ), // transfer ownership
1189                   reinterpret_cast< CallbackBase::MemberFunction >( &FunctorDelegate::Execute ),
1190                   reinterpret_cast< CallbackBase::Dispatcher >( &VoidFunctorDispatcher2<FunctorDelegate,P1,P2>::Dispatch ),
1191                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<FunctorDelegate>::Delete ) ) { }
1192 };
1193
1194 /**
1195  * @brief Function object callback for matching callbacks to signal signature
1196  */
1197 template< class T, typename P1, typename P2, typename P3 >
1198 class CallbackFunctor3 : public CallbackBase
1199 {
1200 public:
1201
1202   /**
1203    * @brief Constructor which copies a function object.
1204    *
1205    * @param[in] object The object to copy.
1206    */
1207   CallbackFunctor3( const T& object )
1208   : CallbackBase( reinterpret_cast< void* >( new T( object ) ), // copy the object
1209                   NULL, // uses operator() instead of member function
1210                   reinterpret_cast< CallbackBase::Dispatcher >( &FunctorDispatcher3<T,P1,P2,P3>::Dispatch ),
1211                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<T>::Delete ) ) { }
1212 };
1213
1214 /**
1215  * @brief Function object callback for connecting void() methods
1216  */
1217 template< typename P1, typename P2, typename P3 >
1218 class CallbackFunctorDelegate3 : public CallbackBase
1219 {
1220 public:
1221
1222
1223   /**
1224    * @brief Constructor which copies a function object.
1225    *
1226    * This variant calls a void() member, ignoring any signal parameters.
1227    * @param[in] object The object to copy.
1228    */
1229   CallbackFunctorDelegate3( FunctorDelegate* object )
1230   : CallbackBase( reinterpret_cast< void* >( object ), // transfer ownership
1231                   reinterpret_cast< CallbackBase::MemberFunction >( &FunctorDelegate::Execute ),
1232                   reinterpret_cast< CallbackBase::Dispatcher >( &VoidFunctorDispatcher3<FunctorDelegate,P1,P2,P3>::Dispatch ),
1233                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<FunctorDelegate>::Delete ) ) { }
1234 };
1235
1236 /**
1237  * @brief Function object callback for matching callbacks to signal signature
1238  */
1239 template< class T, typename R >
1240 class CallbackFunctorReturn0 : public CallbackBase
1241 {
1242 public:
1243
1244   /**
1245    * @brief Constructor which copies a function object.
1246    *
1247    * @param[in] object The object to copy.
1248    */
1249   CallbackFunctorReturn0( const T& object )
1250   : CallbackBase( reinterpret_cast< void* >( new T( object ) ), // copy the object
1251                   NULL, // uses operator() instead of member function
1252                   reinterpret_cast< CallbackBase::Dispatcher >( &FunctorDispatcherReturn0<T,R>::Dispatch ),
1253                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<T>::Delete ) ) { }
1254 };
1255
1256 /**
1257  * @brief Function object callback for connecting void() methods
1258  */
1259 template< typename R >
1260 class CallbackFunctorDelegateReturn0 : public CallbackBase
1261 {
1262 public:
1263
1264   /**
1265    * @brief Constructor which copies a function object.
1266    *
1267    * This variant calls a void() member, ignoring any signal parameters.
1268    * @param[in] object The object to copy.
1269    */
1270   CallbackFunctorDelegateReturn0( FunctorDelegate* object )
1271   : CallbackBase( reinterpret_cast< void* >( object ), // transfer ownership
1272                   reinterpret_cast< CallbackBase::MemberFunction >( &FunctorDelegate::Execute ),
1273                   reinterpret_cast< CallbackBase::Dispatcher >( &VoidFunctorDispatcherReturn0<FunctorDelegate,R>::Dispatch ),
1274                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<FunctorDelegate>::Delete ) ) { }
1275 };
1276
1277 /**
1278  * @brief Function object callback for matching callbacks to signal signature
1279  */
1280 template< class T, typename P1, typename R >
1281 class CallbackFunctorReturn1 : public CallbackBase
1282 {
1283 public:
1284
1285   /**
1286    * @brief Constructor which copies a function object.
1287    *
1288    * @param[in] object The object to copy.
1289    */
1290   CallbackFunctorReturn1( const T& object )
1291   : CallbackBase( reinterpret_cast< void* >( new T( object ) ), // copy the object
1292                   NULL, // uses operator() instead of member function
1293                   reinterpret_cast< CallbackBase::Dispatcher >( &FunctorDispatcherReturn1<T,R,P1>::Dispatch ),
1294                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<T>::Delete ) ) { }
1295 };
1296
1297 /**
1298  * @brief Function object callback for connecting void() methods
1299  */
1300 template< typename P1, typename R >
1301 class CallbackFunctorDelegateReturn1 : public CallbackBase
1302 {
1303 public:
1304
1305   /**
1306    * @brief Constructor which copies a function object.
1307    *
1308    * This variant calls a void() member, ignoring any signal parameters.
1309    * @param[in] object The object to copy.
1310    */
1311   CallbackFunctorDelegateReturn1( FunctorDelegate* object )
1312   : CallbackBase( reinterpret_cast< void* >( object ), // transfer ownership
1313                   reinterpret_cast< CallbackBase::MemberFunction >( &FunctorDelegate::Execute ),
1314                   reinterpret_cast< CallbackBase::Dispatcher >( &VoidFunctorDispatcherReturn1<FunctorDelegate,R,P1>::Dispatch ),
1315                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<FunctorDelegate>::Delete ) ) { }
1316 };
1317
1318 /**
1319  * @brief Function object callback for matching callbacks to signal signature
1320  */
1321 template< class T, typename P1, typename P2, typename R >
1322 class CallbackFunctorReturn2 : public CallbackBase
1323 {
1324 public:
1325
1326   /**
1327    * @brief Constructor which copies a function object.
1328    *
1329    * @param[in] object The object to copy.
1330    */
1331   CallbackFunctorReturn2( const T& object )
1332   : CallbackBase( reinterpret_cast< void* >( new T( object ) ), // copy the object
1333                   NULL, // uses operator() instead of member function
1334                   reinterpret_cast< CallbackBase::Dispatcher >( &FunctorDispatcherReturn2<T,R,P1,P2>::Dispatch ),
1335                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<T>::Delete ) ) { }
1336 };
1337
1338 /**
1339  * @brief Function object callback for connecting void() methods
1340  */
1341 template< typename P1, typename P2, typename R >
1342 class CallbackFunctorDelegateReturn2 : public CallbackBase
1343 {
1344 public:
1345
1346   /**
1347    * @brief Constructor which copies a function object.
1348    *
1349    * This variant calls a void() member, ignoring any signal parameters.
1350    * @param[in] object The object to copy.
1351    */
1352   CallbackFunctorDelegateReturn2( FunctorDelegate* object )
1353   : CallbackBase( reinterpret_cast< void* >( object ), // transfer ownership
1354                   reinterpret_cast< CallbackBase::MemberFunction >( &FunctorDelegate::Execute ),
1355                   reinterpret_cast< CallbackBase::Dispatcher >( &VoidFunctorDispatcherReturn2<FunctorDelegate,R,P1,P2>::Dispatch ),
1356                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<FunctorDelegate>::Delete ) ) { }
1357 };
1358
1359 /**
1360  * @brief Function object callback for matching callbacks to signal signature
1361  */
1362 template< class T, typename P1, typename P2, typename P3, typename R >
1363 class CallbackFunctorReturn3 : public CallbackBase
1364 {
1365 public:
1366
1367   /**
1368    * @brief Constructor which copies a function object.
1369    *
1370    * @param[in] object The object to copy.
1371    */
1372   CallbackFunctorReturn3( const T& object )
1373   : CallbackBase( reinterpret_cast< void* >( new T( object ) ), // copy the object
1374                   NULL, // uses operator() instead of member function
1375                   reinterpret_cast< CallbackBase::Dispatcher >( &FunctorDispatcherReturn3<T,R,P1,P2,P3>::Dispatch ),
1376                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<T>::Delete ) ) { }
1377 };
1378
1379 /**
1380  * @brief Function object callback for connecting void() methods
1381  */
1382 template< typename P1, typename P2, typename P3, typename R >
1383 class CallbackFunctorDelegateReturn3 : public CallbackBase
1384 {
1385 public:
1386
1387   /**
1388    * @brief Constructor which copies a function object.
1389    *
1390    * This variant calls a void() member, ignoring any signal parameters.
1391    * @param[in] object The object to copy.
1392    */
1393   CallbackFunctorDelegateReturn3( FunctorDelegate* object )
1394   : CallbackBase( reinterpret_cast< void* >( object ), // transfer ownership
1395                   reinterpret_cast< CallbackBase::MemberFunction >( &FunctorDelegate::Execute ),
1396                   reinterpret_cast< CallbackBase::Dispatcher >( &VoidFunctorDispatcherReturn3<FunctorDelegate,R,P1,P2,P3>::Dispatch ),
1397                   reinterpret_cast< CallbackBase::Destructor >( &Destroyer<FunctorDelegate>::Delete ) ) { }
1398 };
1399
1400 // Callback creation thin templates
1401
1402 /**
1403  * @brief Creates a callback from a C function or static member function with no parameters.
1404  *
1405  * @param[in] function The function to call.
1406  * @return a newly allocated Callback object, ownership transferred to caller
1407  */
1408 inline CallbackBase* MakeCallback( void(*function)(void) )
1409 {
1410   return new CallbackFunction( function );
1411 }
1412
1413 /**
1414  * @brief Creates a callback from a C function or static member function with one parameter.
1415  *
1416  * @param[in] function The function to call.
1417  * @return a newly allocated Callback object, ownership transferred to caller
1418  */
1419 template< typename P1 >
1420 inline CallbackBase* MakeCallback( void(*function)(P1) )
1421 {
1422   return new CallbackFunction( function );
1423 }
1424
1425 /**
1426  * @brief Creates a callback from a C function or static member function with no parameters and a return type.
1427  *
1428  * @param[in] function The function to call.
1429  * @return a newly allocated Callback object, ownership transferred to caller
1430  */
1431 template< typename R >
1432 inline CallbackBase* MakeCallback( R(*function)(void) )
1433 {
1434   return new CallbackFunction( function );
1435 }
1436
1437 /**
1438  * @brief Creates a callback from a C function or static member function with one parameter and a return type.
1439  *
1440  * @param[in] function The function to call.
1441  * @return a newly allocated Callback object, ownership transferred to caller
1442  */
1443 template< typename R, typename P1 >
1444 inline CallbackBase* MakeCallback( R(*function)(P1) )
1445 {
1446   return new CallbackFunction( function );
1447 }
1448
1449 /**
1450  * @brief Creates a callback from a C function or static member function with two parameters.
1451  *
1452  * @param[in] function The function to call.
1453  * @return a newly allocated Callback object, ownership transferred to caller
1454  */
1455 template< typename P1, typename P2 >
1456 inline CallbackBase* MakeCallback( void(*function)(P1,P2) )
1457 {
1458   return new CallbackFunction( function );
1459 }
1460
1461 /**
1462  * @brief Creates a callback from a C function or static member function with two parameters and a return type.
1463  *
1464  * @param[in] function The function to call.
1465  * @return a newly allocated Callback object, ownership transferred to caller
1466  */
1467 template< typename R, typename P1, typename P2 >
1468 inline CallbackBase* MakeCallback( R(*function)(P1,P2) )
1469 {
1470   return new CallbackFunction( function );
1471 }
1472
1473 /**
1474  * @brief Creates a callback from a C function or static member function with three parameters.
1475  *
1476  * @param[in] function The function to call.
1477  * @return a newly allocated Callback object, ownership transferred to caller
1478  */
1479 template< typename P1, typename P2, typename P3 >
1480 inline CallbackBase* MakeCallback( void(*function)(P1,P2,P3) )
1481 {
1482   return new CallbackFunction( function );
1483 }
1484
1485 /**
1486  * @brief Creates a callback from a C function or static member function with three parameters and a return type.
1487  *
1488  * @param[in] function The function to call.
1489  * @return a newly allocated Callback object, ownership transferred to caller
1490  */
1491 template< typename R, typename P1, typename P2, typename P3 >
1492 inline CallbackBase* MakeCallback( R(*function)(P1,P2,P3) )
1493 {
1494   return new CallbackFunction( function );
1495 }
1496
1497 /**
1498  * @brief Creates a callback from a class member function with no parameters.
1499  *
1500  * requires the function to be member of the same class
1501  * @param[in] object The object to call.
1502  * @param[in] function The member function to call.
1503  * @return a newly allocated Callback object, ownership transferred to caller
1504  */
1505 template< class T >
1506 inline CallbackBase* MakeCallback( T* object, void(T::*function)(void) )
1507 {
1508   return new Callback< T >( object, function );
1509 }
1510
1511 /**
1512  * @brief Creates a callback from a class member function with one parameter.
1513  *
1514  * requires the function to be member of the same class
1515  * @param[in] object The object to call.
1516  * @param[in] function The member function to call.
1517  * @return a newly allocated Callback object, ownership transferred to caller
1518  */
1519 template< class T, typename P1 >
1520 inline CallbackBase* MakeCallback( T* object, void(T::*function)(P1) )
1521 {
1522   return new Callback< T >( object, function );
1523 }
1524
1525 /**
1526  * @brief Creates a callback from a class member function with two parameters.
1527  *
1528  * requires the function to be member of the same class
1529  * @param[in] object The object to call.
1530  * @param[in] function The member function to call.
1531  * @return a newly allocated Callback object, ownership transferred to caller
1532  */
1533 template< class T, typename P1, typename P2 >
1534 inline CallbackBase* MakeCallback( T* object, void(T::*function)(P1,P2) )
1535 {
1536   return new Callback< T >( object, function );
1537 }
1538
1539 /**
1540  * @brief Creates a callback from a class member function with three parameters.
1541  *
1542  * requires the function to be member of the same class
1543  * @param[in] object The object to call.
1544  * @param[in] function The member function to call.
1545  * @return a newly allocated Callback object, ownership transferred to caller
1546  */
1547 template< class T, typename P1, typename P2, typename P3 >
1548 inline CallbackBase* MakeCallback( T* object, void(T::*function)(P1,P2,P3) )
1549 {
1550   return new Callback< T >( object, function );
1551 }
1552
1553 /**
1554  * @brief Creates a callback from a class member function with no parameters and a return type.
1555  *
1556  * requires the function to be member of the same class
1557  * @param[in] object The object to call.
1558  * @param[in] function The member function to call.
1559  * @return a newly allocated Callback object, ownership transferred to caller
1560  */
1561 template< class T, typename R >
1562 inline CallbackBase* MakeCallback( T* object, R(T::*function)() )
1563 {
1564   return new Callback< T >( object, function );
1565 }
1566
1567 /**
1568  * @brief Creates a callback from a class member function with one parameter and a return type.
1569  *
1570  * requires the function to be member of the same class
1571  * @param[in] object The object to call.
1572  * @param[in] function The member function to call.
1573  * @return a newly allocated Callback object, ownership transferred to caller
1574  */
1575 template< class T, typename P1, typename R >
1576 inline CallbackBase* MakeCallback( T* object, R(T::*function)(P1) )
1577 {
1578   return new Callback< T >( object, function );
1579 }
1580
1581 /**
1582  * @brief Creates a callback from a class member function with two parameters and a return type.
1583  *
1584  * requires the function to be member of the same class
1585  * @param[in] object The object to call.
1586  * @param[in] function The member function to call.
1587  * @return a newly allocated Callback object, ownership transferred to caller
1588  */
1589 template< class T, typename P1, typename P2, typename R >
1590 inline CallbackBase* MakeCallback( T* object, R(T::*function)(P1,P2) )
1591 {
1592   return new Callback< T >( object, function );
1593 }
1594
1595 /**
1596  * @brief Creates a callback from a class member function with three parameters and a return type.
1597  *
1598  * requires the function to be member of the same class
1599  * @param[in] object The object to call.
1600  * @param[in] function The member function to call.
1601  * @return a newly allocated Callback object, ownership transferred to caller
1602  */
1603 template< class T, typename P1, typename P2, typename P3, typename R >
1604 inline CallbackBase* MakeCallback( T* object, R(T::*function)(P1,P2,P3) )
1605 {
1606   return new Callback< T >( object, function );
1607 }
1608
1609 /**
1610  * @brief Creates a callback from a class's parent member function with no parameters.
1611  *
1612  * requires the function to be member of the same class
1613  * @param[in] object The object to call.
1614  * @param[in] function The member function to call.
1615  * @return a newly allocated Callback object, ownership transferred to caller
1616  */
1617 template< class T, class Base >
1618 inline CallbackBase* MakeCallback( T* object, void(Base::*function)(void) )
1619 {
1620   return new Callback< T >( object, function );
1621 }
1622 /**
1623  * @brief Creates a callback from a class's parent member function with no parameters.
1624  *
1625  * requires the function to be member of the same class
1626  * @param[in] object The object to call.
1627  * @param[in] function The member function to call.
1628  * @return a newly allocated Callback object, ownership transferred to caller
1629  */
1630 template< class T, class Base >
1631 inline CallbackBase* MakeCallback( T& object, void(Base::*function)(void) )
1632 {
1633   return new Callback< T >( object, function );
1634 }
1635
1636 } // namespace DALI
1637
1638 #endif // __DALI_CALLBACK_H__