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