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