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