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