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