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