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