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