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