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