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