1 #ifndef DALI_CALLBACK_H
2 #define DALI_CALLBACK_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/signals/functor-delegate.h>
31 * @addtogroup dali_core_signals
38 * @brief Callback base class to hold the data for callback function and member function calls.
41 class DALI_CORE_API CallbackBase
45 * @brief Default constructor.
57 * @brief Resets the object pointer so that we know not to call methods of this object any more.
63 * @brief Function to call the function or member function dispatcher.
65 * This function template gets instantiated at the call site.
67 * @param[in] callback The callback to call
68 * @param[in] args parameter pack to pass into the function
69 * @return The value from the function
71 template<typename R, typename... Args>
72 static R ExecuteReturn(CallbackBase& callback, Args... args)
75 // if we point to a function, we can call it directly
76 // otherwise call the dispatcher function that knows the real type of the object
77 // Note that this template dispatcher lives in client code (where the callback was created)
78 // so the library containing the code has to be loaded, otherwise we crash boom bang
79 if(callback.mImpl.mObjectPointer)
81 using Dispatcher = R (*)(CallbackBase&, Args...);
82 Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl.mMemberFunctionDispatcher);
83 returnVal = (*dispatcher)(callback, args...);
85 else if(callback.mFunction)
87 // convert function type
88 using Function = R (*)(Args...);
89 returnVal = (*(reinterpret_cast<Function>(callback.mFunction)))(args...);
96 * @brief Function to call the function or member function dispatcher.
98 * This function template gets instantiated at the call site.
100 * @param[in] callback The callback to call
101 * @param[in] args parameter pack to pass into the function
103 template<typename... Args>
104 static void Execute(CallbackBase& callback, Args... args)
106 // if we point to a function, we can call it directly
107 // otherwise call the dispatcher function that knows the real type of the object
108 // Note that this template dispatcher lives in client code (where the callback was created)
109 // so the library containing the code has to be loaded, otherwise we crash boom bang
110 if(callback.mImpl.mObjectPointer)
112 using Dispatcher = void (*)(CallbackBase&, Args...);
113 Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl.mMemberFunctionDispatcher);
114 (*dispatcher)(callback, args...);
116 else if(callback.mFunction)
118 // convert function type
119 using Function = void (*)(Args...);
120 (*(reinterpret_cast<Function>(callback.mFunction)))(args...);
126 * @brief Function with static linkage.
129 using Function = void (*)();
132 * @brief Constructor for function with static linkage.
135 * @param[in] function The function to call
137 CallbackBase(Function function);
139 protected: // Constructors for deriving classes
141 * @brief Member function.
144 using MemberFunction = void (CallbackBase::*)();
147 * @brief Used to call the correct member function.
150 using Dispatcher = void (*)(CallbackBase&);
153 * @brief Used to destroy mObjectPointer (NULL if not mObjectPointer is not owned).
156 using Destructor = void (*)(void*);
159 * @brief Copy constructor operator not declared.
161 * @param[in] rhs Handle to an object
163 CallbackBase(const CallbackBase& rhs);
166 * @brief Assignment operator not declared.
168 * @param[in] rhs Handle to an object
169 * @return A reference to this
171 CallbackBase& operator=(const CallbackBase& rhs);
174 * @brief Constructor for member function.
177 * @param[in] object The object to call (not owned)
178 * @param[in] function The member function of the object
179 * @param[in] dispatcher Used to call the actual object
181 CallbackBase(void* object, MemberFunction function, Dispatcher dispatcher);
184 * @brief Constructor for member function.
187 * @param[in] object The object to call (owned)
188 * @param[in] function The member function of the object
189 * @param dispatcher Used to call the actual object
190 * @param destructor Used to delete the owned object
192 CallbackBase(void* object, MemberFunction function, Dispatcher dispatcher, Destructor destructor);
194 public: // Data for deriving classes & Dispatchers
196 * @brief Struct to hold the extra data needed for member functions.
201 void* mObjectPointer{nullptr}; ///< Object whose member function will be called. Not owned if mDestructorDispatcher is NULL.
202 Dispatcher mMemberFunctionDispatcher{nullptr}; ///< Dispatcher for member functions
203 Destructor mDestructorDispatcher{nullptr}; ///< Destructor for owned objects. NULL if mDestructorDispatcher is not owned.
209 MemberFunction mMemberFunction; ///< Pointer to member function
210 Function mFunction; ///< Static function
215 * @brief Non-member equality operator.
217 * @param[in] lhs A reference to compare
218 * @param[in] rhs A reference to compare to
219 * @return True if lhs is same as rhs
221 inline bool operator==(const CallbackBase& lhs, const CallbackBase& rhs)
223 if(lhs.mFunction == rhs.mFunction &&
224 lhs.mImpl.mObjectPointer == rhs.mImpl.mObjectPointer)
232 * @brief Dispatcher to delete an object.
239 * @brief Dispatcher to delete an object.
241 * @param[in] object An object to delete
243 static void Delete(void* object)
245 // CallbackBase owns the object but we're the only one who knows the real type so need
246 // to delete by "downcasting" from void* to the correct type
247 delete reinterpret_cast<T*>(object);
252 * @brief Dispatcher to call the actual member function.
259 * @brief Calls an actual member function.
262 * @param[in] callback The callback information
264 static void Dispatch(CallbackBase& callback)
266 // "downcast" the object and function type back to the correct ones
267 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
268 using MemberFunction = void (T::*)();
269 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
270 (object->*function)();
275 * @brief Dispatcher to call the actual member function.
278 template<class T, typename P1>
282 * @brief Calls an actual member function.
285 * @param[in] callback The callback information
286 * @param[in] param1 The first parameter to pass to the real member function
288 static void Dispatch(CallbackBase& callback, P1 param1)
290 // "downcast" the object and function type back to the correct ones
291 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
292 using MemberFunction = void (T::*)(P1);
293 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
294 (object->*function)(param1);
299 * @brief Dispatcher to call the actual member function.
302 template<class T, typename P1, typename P2>
306 * @brief Call an actual member function.
309 * @param[in] callback The callback information
310 * @param[in] param1 The first parameter to pass to the real member function
311 * @param[in] param2 The second parameter to pass to the real member function
313 static void Dispatch(CallbackBase& callback, P1 param1, P2 param2)
315 // "downcast" the object and function type back to the correct ones
316 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
317 using MemberFunction = void (T::*)(P1, P2);
318 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
319 (object->*function)(param1, param2);
324 * @brief Dispatcher to call the actual member function.
327 template<class T, typename P1, typename P2, typename P3>
331 * @brief Call an actual member function.
334 * @param[in] callback The callback information
335 * @param[in] param1 The first parameter to pass to the real member function
336 * @param[in] param2 The second parameter to pass to the real member function
337 * @param[in] param3 The third parameter to pass to the real member function
339 static void Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
341 // "downcast" the object and function type back to the correct ones
342 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
343 using MemberFunction = void (T::*)(P1, P2, P3);
344 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
345 (object->*function)(param1, param2, param3);
350 * @brief Dispatcher to call the actual member function.
353 template<class T, typename R>
354 struct DispatcherReturn0
357 * @brief Calls an actual member function.
360 * @param[in] callback The callback information
363 static R Dispatch(CallbackBase& callback)
365 // "downcast" the object and function type back to the correct ones
366 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
367 using MemberFunction = R (T::*)();
368 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
369 return (object->*function)();
374 * @brief Dispatcher to call the actual member function.
377 template<class T, typename R, typename P1>
378 struct DispatcherReturn1
381 * @brief Calls an actual member function.
384 * @param[in] callback The callback information
385 * @param[in] param1 The first parameter to pass to the real member function
386 * @return The return value from the function
388 static R Dispatch(CallbackBase& callback, P1 param1)
390 // "downcast" the object and function type back to the correct ones
391 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
392 using MemberFunction = R (T::*)(P1);
393 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
394 return (object->*function)(param1);
399 * @brief Dispatcher to call the actual member function.
402 template<class T, typename R, typename P1, typename P2>
403 struct DispatcherReturn2
406 * @brief Calls an actual member function.
409 * @param[in] callback The callback information
410 * @param[in] param1 The first parameter to pass to the real member function
411 * @param[in] param2 The second parameter to pass to the real member function
412 * @return The return value from the function
414 static R Dispatch(CallbackBase& callback, P1 param1, P2 param2)
416 // "downcast" the object and function type back to the correct ones
417 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
418 using MemberFunction = R (T::*)(P1, P2);
419 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
420 return (object->*function)(param1, param2);
425 * @brief Dispatcher to call the actual member function.
428 template<class T, typename R, typename P1, typename P2, typename P3>
429 struct DispatcherReturn3
432 * @brief Calls an actual member function.
435 * @param[in] callback The callback information
436 * @param[in] param1 The first parameter to pass to the real member function
437 * @param[in] param2 The second parameter to pass to the real member function
438 * @param[in] param3 The third parameter to pass to the real member function
439 * @return The return value from the function
441 static R Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
443 // "downcast" the object and function type back to the correct ones
444 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
445 using MemberFunction = R (T::*)(P1, P2, P3);
446 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
447 return (object->*function)(param1, param2, param3);
452 * @brief Dispatcher to call a functor.
456 struct FunctorDispatcher0
459 * @brief Calls a function object.
462 * @param[in] callback The callback information
464 static void Dispatch(CallbackBase& callback)
466 // "downcast" the object and function type back to the correct ones
467 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
473 * @brief Dispatcher to call a functor.
476 template<class T, typename P1>
477 struct FunctorDispatcher1
480 * @brief Calls a function object.
483 * @param[in] callback The callback information
484 * @param[in] param1 The first parameter to pass to the real member function.
486 static void Dispatch(CallbackBase& callback, P1 param1)
488 // "downcast" the object and function type back to the correct ones
489 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
495 * @brief Dispatcher to call a functor.
498 template<class T, typename P1, typename P2>
499 struct FunctorDispatcher2
502 * @brief Calls a function object.
505 * @param[in] callback The callback information
506 * @param[in] param1 The first parameter to pass to the real member function
507 * @param[in] param2 The second parameter to pass to the real member function
509 static void Dispatch(CallbackBase& callback, P1 param1, P2 param2)
511 // "downcast" the object and function type back to the correct ones
512 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
513 (*object)(param1, param2);
518 * @brief Dispatcher to call a functor.
521 template<class T, typename P1, typename P2, typename P3>
522 struct FunctorDispatcher3
525 * @brief Calls a function object.
528 * @param[in] callback The callback information
529 * @param[in] param1 The first parameter to pass to the real member function
530 * @param[in] param2 The second parameter to pass to the real member function
531 * @param[in] param3 The third parameter to pass to the real member function
533 static void Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
535 // "downcast" the object and function type back to the correct ones
536 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
537 (*object)(param1, param2, param3);
542 * @brief Dispatcher to call a functor.
545 template<class T, typename R>
546 struct FunctorDispatcherReturn0
549 * @brief Calls a function object.
552 * @param[in] callback The callback information
555 static R Dispatch(CallbackBase& callback)
557 // "downcast" the object and function type back to the correct ones
558 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
564 * @brief Dispatcher to call a functor.
567 template<class T, typename R, typename P1>
568 struct FunctorDispatcherReturn1
571 * @brief Calls a function object.
574 * @param[in] callback The callback information
575 * @param[in] param1 The first parameter to pass to the real member function
576 * @return The return value from the function
578 static R Dispatch(CallbackBase& callback, P1 param1)
580 // "downcast" the object and function type back to the correct ones
581 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
582 return (*object)(param1);
587 * @brief Dispatcher to call a functor.
590 template<class T, typename R, typename P1, typename P2>
591 struct FunctorDispatcherReturn2
594 * @brief Calls a function object.
597 * @param[in] callback The callback information
598 * @param[in] param1 The first parameter to pass to the real member function
599 * @param[in] param2 The second parameter to pass to the real member function
600 * @return The return value from the function
602 static R Dispatch(CallbackBase& callback, P1 param1, P2 param2)
604 // "downcast" the object and function type back to the correct ones
605 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
606 return (*object)(param1, param2);
611 * @brief Dispatcher to call a functor.
614 template<class T, typename R, typename P1, typename P2, typename P3>
615 struct FunctorDispatcherReturn3
618 * @brief Calls a function object.
621 * @param[in] callback The callback information
622 * @param[in] param1 The first parameter to pass to the real member function
623 * @param[in] param2 The second parameter to pass to the real member function
624 * @param[in] param3 The third parameter to pass to the real member function
625 * @return The return value from the function
627 static R Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
629 // "downcast" the object and function type back to the correct ones
630 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
631 return (*object)(param1, param2, param3);
636 * @brief Dispatcher to call a functor.
638 * This variant calls a specific void() member function.
642 struct VoidFunctorDispatcher0
645 * @brief Calls a function object.
648 * @param[in] callback The callback information
650 static void Dispatch(CallbackBase& callback)
652 // "downcast" the object and function type back to the correct ones
653 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
654 using MemberFunction = void (T::*)();
655 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
656 (object->*function)();
661 * @brief Dispatcher to call a functor.
663 * This variant calls a void() member, ignoring any signal parameters.
666 template<class T, typename P1>
667 struct VoidFunctorDispatcher1
670 * @brief Calls a function object.
673 * @param[in] callback The callback information
674 * @param[in] param1 The first parameter to pass to the real member function
676 static void Dispatch(CallbackBase& callback, P1 param1)
678 // "downcast" the object and function type back to the correct ones
679 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
680 using MemberFunction = void (T::*)();
681 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
682 (object->*function)(/*ignore params*/);
687 * @brief Dispatcher to call a functor.
689 * This variant calls a void() member, ignoring any signal parameters.
692 template<class T, typename P1, typename P2>
693 struct VoidFunctorDispatcher2
696 * @brief Calls a function object.
699 * @param[in] callback The callback information
700 * @param[in] param1 The first parameter to pass to the real member function
701 * @param[in] param2 The second parameter to pass to the real member function
703 static void Dispatch(CallbackBase& callback, P1 param1, P2 param2)
705 // "downcast" the object and function type back to the correct ones
706 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
707 using MemberFunction = void (T::*)();
708 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
709 (object->*function)(/*ignore params*/);
714 * @brief Dispatcher to call a functor.
716 * This variant calls a void() member, ignoring any signal parameters.
719 template<class T, typename P1, typename P2, typename P3>
720 struct VoidFunctorDispatcher3
723 * @brief Calls a function object.
726 * @param[in] callback The callback information
727 * @param[in] param1 The first parameter to pass to the real member function
728 * @param[in] param2 The second parameter to pass to the real member function
729 * @param[in] param3 The third parameter to pass to the real member function
731 static void Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
733 // "downcast" the object and function type back to the correct ones
734 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
735 using MemberFunction = void (T::*)();
736 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
737 (object->*function)(/*ignore params*/);
742 * @brief Dispatcher to call a functor.
744 * This variant calls a void() member, and returns a default-constructed value.
747 template<class T, typename R>
748 struct VoidFunctorDispatcherReturn0
751 * @brief Calls a function object.
754 * @param[in] callback The callback information
757 static R Dispatch(CallbackBase& callback)
759 // "downcast" the object and function type back to the correct ones
760 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
761 using MemberFunction = void (T::*)();
762 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
763 (object->*function)(/*ignore params*/);
769 * @brief Dispatcher to call a functor.
771 * This variant calls a void() member, and returns a default-constructed value.
774 template<class T, typename R, typename P1>
775 struct VoidFunctorDispatcherReturn1
778 * @brief Calls a function object.
781 * @param[in] callback The callback information
782 * @param[in] param1 The first parameter to pass to the real member function
783 * @return The return value from the function
785 static R Dispatch(CallbackBase& callback, P1 param1)
787 // "downcast" the object and function type back to the correct ones
788 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
789 using MemberFunction = void (T::*)();
790 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
791 (object->*function)(/*ignore params*/);
797 * @brief Dispatcher to call a functor.
799 * This variant calls a void() member, and returns a default-constructed value.
802 template<class T, typename R, typename P1, typename P2>
803 struct VoidFunctorDispatcherReturn2
806 * @brief Calls a function object.
809 * @param[in] callback The callback information
810 * @param[in] param1 The first parameter to pass to the real member function
811 * @param[in] param2 The second parameter to pass to the real member function
812 * @return The return value from the function
814 static R Dispatch(CallbackBase& callback, P1 param1, P2 param2)
816 // "downcast" the object and function type back to the correct ones
817 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
818 using MemberFunction = void (T::*)();
819 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
820 (object->*function)(/*ignore params*/);
826 * @brief Dispatcher to call a functor.
828 * This variant calls a void() member, and returns a default-constructed value.
831 template<class T, typename R, typename P1, typename P2, typename P3>
832 struct VoidFunctorDispatcherReturn3
835 * @brief Calls a function object.
838 * @param[in] callback The callback information
839 * @param[in] param1 The first parameter to pass to the real member function
840 * @param[in] param2 The second parameter to pass to the real member function
841 * @param[in] param3 The third parameter to pass to the real member function
842 * @return The return value from the function
844 static R Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
846 // "downcast" the object and function type back to the correct ones
847 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
848 using MemberFunction = void (T::*)();
849 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
850 (object->*function)(/*ignore params*/);
856 * @brief Thin template to provide type safety for member function callbacks.
858 * Version with two parameters and return value.
862 class Callback : public CallbackBase
866 * @brief Default constructor.
876 * @brief Constructor for member function.
878 * Copies the function object.
880 * @param[in] object The object to call
881 * @param[in] memberFunction The member function of the object
883 Callback(T* object, void (T::*memberFunction)(void))
884 : CallbackBase(object,
885 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
886 reinterpret_cast<CallbackBase::Dispatcher>(&Dispatcher0<T>::Dispatch))
889 template<typename P1>
890 Callback(T* object, void (T::*memberFunction)(P1))
891 : CallbackBase(object,
892 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
893 reinterpret_cast<CallbackBase::Dispatcher>(&Dispatcher1<T, P1>::Dispatch))
896 template<typename P1, typename P2>
897 Callback(T* object, void (T::*memberFunction)(P1, P2))
898 : CallbackBase(object,
899 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
900 reinterpret_cast<CallbackBase::Dispatcher>(&Dispatcher2<T, P1, P2>::Dispatch))
903 template<typename P1, typename P2, typename P3>
904 Callback(T* object, void (T::*memberFunction)(P1, P2, P3))
905 : CallbackBase(object,
906 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
907 reinterpret_cast<CallbackBase::Dispatcher>(&Dispatcher3<T, P1, P2, P3>::Dispatch))
911 Callback(T* object, R (T::*memberFunction)(void))
912 : CallbackBase(object,
913 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
914 reinterpret_cast<CallbackBase::Dispatcher>(&DispatcherReturn0<T, R>::Dispatch))
917 template<typename R, typename P1>
918 Callback(T* object, R (T::*memberFunction)(P1))
919 : CallbackBase(object,
920 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
921 reinterpret_cast<CallbackBase::Dispatcher>(&DispatcherReturn1<T, R, P1>::Dispatch))
924 template<typename R, typename P1, typename P2>
925 Callback(T* object, R (T::*memberFunction)(P1, P2))
926 : CallbackBase(object,
927 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
928 reinterpret_cast<CallbackBase::Dispatcher>(&DispatcherReturn2<T, R, P1, P2>::Dispatch))
931 template<typename R, typename P1, typename P2, typename P3>
932 Callback(T* object, R (T::*memberFunction)(P1, P2, P3))
933 : CallbackBase(object,
934 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
935 reinterpret_cast<CallbackBase::Dispatcher>(&DispatcherReturn3<T, R, P1, P2, P3>::Dispatch))
941 * @brief Specializations for function object callbacks.
945 class CallbackFunctor0 : public CallbackBase
949 * @brief Constructor which copies a function object.
952 * @param[in] object The object to copy
954 CallbackFunctor0(const T& object)
955 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
956 NULL, // uses operator() instead of member function
957 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcher0<T>::Dispatch),
958 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
964 * @brief Function object callback for connecting void() methods.
967 class CallbackFunctorDelegate0 : public CallbackBase
971 * @brief Constructor which copies a function object.
973 * This variant calls a void() member, ignoring any signal parameters.
975 * @param[in] object A newly allocated object (ownership is transferred)
977 CallbackFunctorDelegate0(FunctorDelegate* object)
978 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
979 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
980 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcher0<FunctorDelegate>::Dispatch),
981 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
987 * @brief Function object callback for matching callbacks to signal signature.
990 template<class T, typename P1>
991 class CallbackFunctor1 : public CallbackBase
995 * @brief Constructor which copies a function object.
998 * @param[in] object The object to copy
1000 CallbackFunctor1(const T& object)
1001 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
1002 NULL, // uses operator() instead of member function
1003 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcher1<T, P1>::Dispatch),
1004 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
1010 * @brief Function object callback for connecting void() methods.
1013 template<typename P1>
1014 class CallbackFunctorDelegate1 : public CallbackBase
1018 * @brief Constructor which copies a function object.
1020 * This variant calls a void() member, ignoring any signal parameters.
1022 * @param[in] object The object to copy
1024 CallbackFunctorDelegate1(FunctorDelegate* object)
1025 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
1026 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
1027 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcher1<FunctorDelegate, P1>::Dispatch),
1028 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
1034 * @brief Function object callback for matching callbacks to signal signature.
1037 template<class T, typename P1, typename P2>
1038 class CallbackFunctor2 : public CallbackBase
1042 * @brief Constructor which copies a function object.
1045 * @param[in] object The object to copy
1047 CallbackFunctor2(const T& object)
1048 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
1049 NULL, // uses operator() instead of member function
1050 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcher2<T, P1, P2>::Dispatch),
1051 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
1057 * @brief Function object callback for connecting void() methods.
1060 template<typename P1, typename P2>
1061 class CallbackFunctorDelegate2 : public CallbackBase
1065 * @brief Constructor which copies a function object.
1067 * This variant calls a void() member, ignoring any signal parameters.
1069 * @param[in] object The object to copy
1071 CallbackFunctorDelegate2(FunctorDelegate* object)
1072 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
1073 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
1074 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcher2<FunctorDelegate, P1, P2>::Dispatch),
1075 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
1081 * @brief Function object callback for matching callbacks to signal signature.
1084 template<class T, typename P1, typename P2, typename P3>
1085 class CallbackFunctor3 : public CallbackBase
1089 * @brief Constructor which copies a function object.
1092 * @param[in] object The object to copy
1094 CallbackFunctor3(const T& object)
1095 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
1096 NULL, // uses operator() instead of member function
1097 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcher3<T, P1, P2, P3>::Dispatch),
1098 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
1104 * @brief Function object callback for connecting void() methods.
1107 template<typename P1, typename P2, typename P3>
1108 class CallbackFunctorDelegate3 : public CallbackBase
1112 * @brief Constructor which copies a function object.
1114 * This variant calls a void() member, ignoring any signal parameters.
1116 * @param[in] object The object to copy
1118 CallbackFunctorDelegate3(FunctorDelegate* object)
1119 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
1120 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
1121 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcher3<FunctorDelegate, P1, P2, P3>::Dispatch),
1122 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
1128 * @brief Function object callback for matching callbacks to signal signature.
1131 template<class T, typename R>
1132 class CallbackFunctorReturn0 : public CallbackBase
1136 * @brief Constructor which copies a function object.
1139 * @param[in] object The object to copy
1141 CallbackFunctorReturn0(const T& object)
1142 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
1143 NULL, // uses operator() instead of member function
1144 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcherReturn0<T, R>::Dispatch),
1145 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
1151 * @brief Function object callback for connecting void() methods.
1154 template<typename R>
1155 class CallbackFunctorDelegateReturn0 : public CallbackBase
1159 * @brief Constructor which copies a function object.
1161 * This variant calls a void() member, ignoring any signal parameters.
1163 * @param[in] object The object to copy
1165 CallbackFunctorDelegateReturn0(FunctorDelegate* object)
1166 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
1167 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
1168 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcherReturn0<FunctorDelegate, R>::Dispatch),
1169 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
1175 * @brief Function object callback for matching callbacks to signal signature.
1178 template<class T, typename P1, typename R>
1179 class CallbackFunctorReturn1 : public CallbackBase
1183 * @brief Constructor which copies a function object.
1186 * @param[in] object The object to copy
1188 CallbackFunctorReturn1(const T& object)
1189 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
1190 NULL, // uses operator() instead of member function
1191 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcherReturn1<T, R, P1>::Dispatch),
1192 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
1198 * @brief Function object callback for connecting void() methods.
1201 template<typename P1, typename R>
1202 class CallbackFunctorDelegateReturn1 : public CallbackBase
1206 * @brief Constructor which copies a function object.
1208 * This variant calls a void() member, ignoring any signal parameters.
1210 * @param[in] object The object to copy
1212 CallbackFunctorDelegateReturn1(FunctorDelegate* object)
1213 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
1214 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
1215 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcherReturn1<FunctorDelegate, R, P1>::Dispatch),
1216 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
1222 * @brief Function object callback for matching callbacks to signal signature.
1225 template<class T, typename P1, typename P2, typename R>
1226 class CallbackFunctorReturn2 : public CallbackBase
1230 * @brief Constructor which copies a function object.
1233 * @param[in] object The object to copy
1235 CallbackFunctorReturn2(const T& object)
1236 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
1237 NULL, // uses operator() instead of member function
1238 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcherReturn2<T, R, P1, P2>::Dispatch),
1239 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
1245 * @brief Function object callback for connecting void() methods.
1248 template<typename P1, typename P2, typename R>
1249 class CallbackFunctorDelegateReturn2 : public CallbackBase
1253 * @brief Constructor which copies a function object.
1255 * This variant calls a void() member, ignoring any signal parameters.
1257 * @param[in] object The object to copy
1259 CallbackFunctorDelegateReturn2(FunctorDelegate* object)
1260 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
1261 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
1262 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcherReturn2<FunctorDelegate, R, P1, P2>::Dispatch),
1263 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
1269 * @brief Function object callback for matching callbacks to signal signature.
1272 template<class T, typename P1, typename P2, typename P3, typename R>
1273 class CallbackFunctorReturn3 : public CallbackBase
1277 * @brief Constructor which copies a function object.
1280 * @param[in] object The object to copy
1282 CallbackFunctorReturn3(const T& object)
1283 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
1284 NULL, // uses operator() instead of member function
1285 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcherReturn3<T, R, P1, P2, P3>::Dispatch),
1286 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
1292 * @brief Function object callback for connecting void() methods.
1295 template<typename P1, typename P2, typename P3, typename R>
1296 class CallbackFunctorDelegateReturn3 : public CallbackBase
1300 * @brief Constructor which copies a function object.
1302 * This variant calls a void() member, ignoring any signal parameters.
1304 * @param[in] object The object to copy
1306 CallbackFunctorDelegateReturn3(FunctorDelegate* object)
1307 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
1308 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
1309 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcherReturn3<FunctorDelegate, R, P1, P2, P3>::Dispatch),
1310 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
1315 // Callback creation thin templates
1318 * @brief Creates a callback from a free function with parameter pack.
1321 * @param[in] function The function to call
1322 * @return A newly allocated Callback object, ownership transferred to caller
1324 template<typename R, typename... Args>
1325 inline CallbackBase* MakeCallback(R (*function)(Args... args))
1327 return new CallbackBase(reinterpret_cast<CallbackBase::Function>(function));
1331 * @brief Creates a callback from a class member function with no parameters.
1333 * Requires the function to be member of the same class.
1335 * @param[in] object The object to call
1336 * @param[in] function The member function to call
1337 * @return A newly allocated Callback object, ownership transferred to caller
1340 inline CallbackBase* MakeCallback(T* object, void (T::*function)(void))
1342 return new Callback<T>(object, function);
1346 * @brief Creates a callback from a class member function with one parameter.
1348 * Requires the function to be member of the same class.
1350 * @param[in] object The object to call
1351 * @param[in] function The member function to call
1352 * @return A newly allocated Callback object, ownership transferred to caller
1354 template<class T, typename P1>
1355 inline CallbackBase* MakeCallback(T* object, void (T::*function)(P1))
1357 return new Callback<T>(object, function);
1361 * @brief Creates a callback from a class member function with two parameters.
1363 * Requires the function to be member of the same class.
1365 * @param[in] object The object to call
1366 * @param[in] function The member function to call
1367 * @return A newly allocated Callback object, ownership transferred to caller
1369 template<class T, typename P1, typename P2>
1370 inline CallbackBase* MakeCallback(T* object, void (T::*function)(P1, P2))
1372 return new Callback<T>(object, function);
1376 * @brief Creates a callback from a class member function with three parameters.
1378 * Requires the function to be member of the same class.
1380 * @param[in] object The object to call
1381 * @param[in] function The member function to call
1382 * @return A newly allocated Callback object, ownership transferred to caller
1384 template<class T, typename P1, typename P2, typename P3>
1385 inline CallbackBase* MakeCallback(T* object, void (T::*function)(P1, P2, P3))
1387 return new Callback<T>(object, function);
1391 * @brief Creates a callback from a class member function with no parameters and a return type.
1393 * Requires the function to be member of the same class.
1395 * @param[in] object The object to call
1396 * @param[in] function The member function to call
1397 * @return A newly allocated Callback object, ownership transferred to caller
1399 template<class T, typename R>
1400 inline CallbackBase* MakeCallback(T* object, R (T::*function)())
1402 return new Callback<T>(object, function);
1406 * @brief Creates a callback from a class member function with one parameter and a return type.
1408 * Requires the function to be member of the same class.
1410 * @param[in] object The object to call
1411 * @param[in] function The member function to call
1412 * @return A newly allocated Callback object, ownership transferred to caller
1414 template<class T, typename P1, typename R>
1415 inline CallbackBase* MakeCallback(T* object, R (T::*function)(P1))
1417 return new Callback<T>(object, function);
1421 * @brief Creates a callback from a class member function with two parameters and a return type.
1423 * Requires the function to be member of the same class.
1425 * @param[in] object The object to call
1426 * @param[in] function The member function to call
1427 * @return A newly allocated Callback object, ownership transferred to caller
1429 template<class T, typename P1, typename P2, typename R>
1430 inline CallbackBase* MakeCallback(T* object, R (T::*function)(P1, P2))
1432 return new Callback<T>(object, function);
1436 * @brief Creates a callback from a class member function with three parameters and a return type.
1438 * Requires the function to be member of the same class.
1440 * @param[in] object The object to call
1441 * @param[in] function The member function to call
1442 * @return A newly allocated Callback object, ownership transferred to caller
1444 template<class T, typename P1, typename P2, typename P3, typename R>
1445 inline CallbackBase* MakeCallback(T* object, R (T::*function)(P1, P2, P3))
1447 return new Callback<T>(object, function);
1451 * @brief Creates a callback from a class's parent member function with no parameters.
1453 * Requires the function to be member of the same class.
1455 * @param[in] object The object to call
1456 * @param[in] function The member function to call
1457 * @return A newly allocated Callback object, ownership transferred to caller
1459 template<class T, class Base>
1460 inline CallbackBase* MakeCallback(T* object, void (Base::*function)(void))
1462 return new Callback<T>(object, function);
1465 * @brief Creates a callback from a class's parent member function with no parameters.
1467 * Requires the function to be member of the same class.
1469 * @param[in] object The object to call
1470 * @param[in] function The member function to call
1471 * @return A newly allocated Callback object, ownership transferred to caller
1473 template<class T, class Base>
1474 inline CallbackBase* MakeCallback(T& object, void (Base::*function)(void))
1476 return new Callback<T>(object, function);
1484 #endif // DALI_CALLBACK_H