1 #ifndef DALI_CALLBACK_H
2 #define DALI_CALLBACK_H
5 * Copyright (c) 2020 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
143 * @brief Member function.
146 using MemberFunction = void (CallbackBase::*)();
149 * @brief Used to call the correct member function.
152 using Dispatcher = void (*)(CallbackBase&);
155 * @brief Used to destroy mObjectPointer (NULL if not mObjectPointer is not owned).
158 using Destructor = void (*)(void*);
161 * @brief Copy constructor operator not declared.
163 * @param[in] rhs Handle to an object
165 CallbackBase(const CallbackBase& rhs);
168 * @brief Assignment operator not declared.
170 * @param[in] rhs Handle to an object
171 * @return A reference to this
173 CallbackBase& operator=(const CallbackBase& rhs);
176 * @brief Constructor for member function.
179 * @param[in] object The object to call (not owned)
180 * @param[in] function The member function of the object
181 * @param[in] dispatcher Used to call the actual object
183 CallbackBase(void* object, MemberFunction function, Dispatcher dispatcher);
186 * @brief Constructor for member function.
189 * @param[in] object The object to call (owned)
190 * @param[in] function The member function of the object
191 * @param dispatcher Used to call the actual object
192 * @param destructor Used to delete the owned object
194 CallbackBase(void* object, MemberFunction function, Dispatcher dispatcher, Destructor destructor);
196 public: // Data for deriving classes & Dispatchers
198 * @brief Struct to hold the extra data needed for member functions.
203 void* mObjectPointer{nullptr}; ///< Object whose member function will be called. Not owned if mDestructorDispatcher is NULL.
204 Dispatcher mMemberFunctionDispatcher{nullptr}; ///< Dispatcher for member functions
205 Destructor mDestructorDispatcher{nullptr}; ///< Destructor for owned objects. NULL if mDestructorDispatcher is not owned.
211 MemberFunction mMemberFunction; ///< Pointer to member function
212 Function mFunction; ///< Static function
217 * @brief Non-member equality operator.
219 * @param[in] lhs A reference to compare
220 * @param[in] rhs A reference to compare to
221 * @return True if lhs is same as rhs
223 inline bool operator==(const CallbackBase& lhs, const CallbackBase& rhs)
225 if (lhs.mFunction == rhs.mFunction &&
226 lhs.mImpl.mObjectPointer == rhs.mImpl.mObjectPointer)
234 * @brief Dispatcher to delete an object.
241 * @brief Dispatcher to delete an object.
243 * @param[in] object An object to delete
245 static void Delete(void* object)
247 // CallbackBase owns the object but we're the only one who knows the real type so need
248 // to delete by "downcasting" from void* to the correct type
249 delete reinterpret_cast<T*>(object);
254 * @brief Dispatcher to call the actual member function.
261 * @brief Calls an actual member function.
264 * @param[in] callback The callback information
266 static void Dispatch(CallbackBase& callback)
268 // "downcast" the object and function type back to the correct ones
269 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
270 using MemberFunction = void (T::*)();
271 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
272 (object->*function)();
277 * @brief Dispatcher to call the actual member function.
280 template<class T, typename P1>
284 * @brief Calls an actual member function.
287 * @param[in] callback The callback information
288 * @param[in] param1 The first parameter to pass to the real member function
290 static void Dispatch(CallbackBase& callback, P1 param1)
292 // "downcast" the object and function type back to the correct ones
293 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
294 using MemberFunction = void (T::*)(P1);
295 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
296 (object->*function)(param1);
301 * @brief Dispatcher to call the actual member function.
304 template<class T, typename P1, typename P2>
308 * @brief Call an actual member function.
311 * @param[in] callback The callback information
312 * @param[in] param1 The first parameter to pass to the real member function
313 * @param[in] param2 The second parameter to pass to the real member function
315 static void Dispatch(CallbackBase& callback, P1 param1, P2 param2)
317 // "downcast" the object and function type back to the correct ones
318 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
319 using MemberFunction = void (T::*)(P1, P2);
320 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
321 (object->*function)(param1, param2);
326 * @brief Dispatcher to call the actual member function.
329 template<class T, typename P1, typename P2, typename P3>
333 * @brief Call an actual member function.
336 * @param[in] callback The callback information
337 * @param[in] param1 The first parameter to pass to the real member function
338 * @param[in] param2 The second parameter to pass to the real member function
339 * @param[in] param3 The third parameter to pass to the real member function
341 static void Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
343 // "downcast" the object and function type back to the correct ones
344 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
345 using MemberFunction = void (T::*)(P1, P2, P3);
346 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
347 (object->*function)(param1, param2, param3);
352 * @brief Dispatcher to call the actual member function.
355 template<class T, typename R>
356 struct DispatcherReturn0
359 * @brief Calls an actual member function.
362 * @param[in] callback The callback information
365 static R Dispatch(CallbackBase& callback)
367 // "downcast" the object and function type back to the correct ones
368 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
369 using MemberFunction = R (T::*)();
370 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
371 return (object->*function)();
376 * @brief Dispatcher to call the actual member function.
379 template<class T, typename R, typename P1>
380 struct DispatcherReturn1
383 * @brief Calls an actual member function.
386 * @param[in] callback The callback information
387 * @param[in] param1 The first parameter to pass to the real member function
388 * @return The return value from the function
390 static R Dispatch(CallbackBase& callback, P1 param1)
392 // "downcast" the object and function type back to the correct ones
393 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
394 using MemberFunction = R (T::*)(P1);
395 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
396 return (object->*function)(param1);
401 * @brief Dispatcher to call the actual member function.
404 template<class T, typename R, typename P1, typename P2>
405 struct DispatcherReturn2
408 * @brief Calls an actual member function.
411 * @param[in] callback The callback information
412 * @param[in] param1 The first parameter to pass to the real member function
413 * @param[in] param2 The second parameter to pass to the real member function
414 * @return The return value from the function
416 static R Dispatch(CallbackBase& callback, P1 param1, P2 param2)
418 // "downcast" the object and function type back to the correct ones
419 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
420 using MemberFunction = R (T::*)(P1, P2);
421 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
422 return (object->*function)(param1, param2);
427 * @brief Dispatcher to call the actual member function.
430 template<class T, typename R, typename P1, typename P2, typename P3>
431 struct DispatcherReturn3
434 * @brief Calls an actual member function.
437 * @param[in] callback The callback information
438 * @param[in] param1 The first parameter to pass to the real member function
439 * @param[in] param2 The second parameter to pass to the real member function
440 * @param[in] param3 The third parameter to pass to the real member function
441 * @return The return value from the function
443 static R Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
445 // "downcast" the object and function type back to the correct ones
446 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
447 using MemberFunction = R (T::*)(P1, P2, P3);
448 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
449 return (object->*function)(param1, param2, param3);
454 * @brief Dispatcher to call a functor.
458 struct FunctorDispatcher0
461 * @brief Calls a function object.
464 * @param[in] callback The callback information
466 static void Dispatch(CallbackBase& callback)
468 // "downcast" the object and function type back to the correct ones
469 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
475 * @brief Dispatcher to call a functor.
478 template<class T, typename P1>
479 struct FunctorDispatcher1
482 * @brief Calls a function object.
485 * @param[in] callback The callback information
486 * @param[in] param1 The first parameter to pass to the real member function.
488 static void Dispatch(CallbackBase& callback, P1 param1)
490 // "downcast" the object and function type back to the correct ones
491 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
497 * @brief Dispatcher to call a functor.
500 template<class T, typename P1, typename P2>
501 struct FunctorDispatcher2
504 * @brief Calls a function object.
507 * @param[in] callback The callback information
508 * @param[in] param1 The first parameter to pass to the real member function
509 * @param[in] param2 The second parameter to pass to the real member function
511 static void Dispatch(CallbackBase& callback, P1 param1, P2 param2)
513 // "downcast" the object and function type back to the correct ones
514 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
515 (*object)(param1, param2);
520 * @brief Dispatcher to call a functor.
523 template<class T, typename P1, typename P2, typename P3>
524 struct FunctorDispatcher3
527 * @brief Calls a function object.
530 * @param[in] callback The callback information
531 * @param[in] param1 The first parameter to pass to the real member function
532 * @param[in] param2 The second parameter to pass to the real member function
533 * @param[in] param3 The third parameter to pass to the real member function
535 static void Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
537 // "downcast" the object and function type back to the correct ones
538 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
539 (*object)(param1, param2, param3);
544 * @brief Dispatcher to call a functor.
547 template<class T, typename R>
548 struct FunctorDispatcherReturn0
551 * @brief Calls a function object.
554 * @param[in] callback The callback information
557 static R Dispatch(CallbackBase& callback)
559 // "downcast" the object and function type back to the correct ones
560 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
566 * @brief Dispatcher to call a functor.
569 template<class T, typename R, typename P1>
570 struct FunctorDispatcherReturn1
573 * @brief Calls a function object.
576 * @param[in] callback The callback information
577 * @param[in] param1 The first parameter to pass to the real member function
578 * @return The return value from the function
580 static R Dispatch(CallbackBase& callback, P1 param1)
582 // "downcast" the object and function type back to the correct ones
583 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
584 return (*object)(param1);
589 * @brief Dispatcher to call a functor.
592 template<class T, typename R, typename P1, typename P2>
593 struct FunctorDispatcherReturn2
596 * @brief Calls a function object.
599 * @param[in] callback The callback information
600 * @param[in] param1 The first parameter to pass to the real member function
601 * @param[in] param2 The second parameter to pass to the real member function
602 * @return The return value from the function
604 static R Dispatch(CallbackBase& callback, P1 param1, P2 param2)
606 // "downcast" the object and function type back to the correct ones
607 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
608 return (*object)(param1, param2);
613 * @brief Dispatcher to call a functor.
616 template<class T, typename R, typename P1, typename P2, typename P3>
617 struct FunctorDispatcherReturn3
620 * @brief Calls a function object.
623 * @param[in] callback The callback information
624 * @param[in] param1 The first parameter to pass to the real member function
625 * @param[in] param2 The second parameter to pass to the real member function
626 * @param[in] param3 The third parameter to pass to the real member function
627 * @return The return value from the function
629 static R Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
631 // "downcast" the object and function type back to the correct ones
632 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
633 return (*object)(param1, param2, param3);
638 * @brief Dispatcher to call a functor.
640 * This variant calls a specific void() member function.
644 struct VoidFunctorDispatcher0
647 * @brief Calls a function object.
650 * @param[in] callback The callback information
652 static void Dispatch(CallbackBase& callback)
654 // "downcast" the object and function type back to the correct ones
655 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
656 using MemberFunction = void (T::*)();
657 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
658 (object->*function)();
663 * @brief Dispatcher to call a functor.
665 * This variant calls a void() member, ignoring any signal parameters.
668 template<class T, typename P1>
669 struct VoidFunctorDispatcher1
672 * @brief Calls a function object.
675 * @param[in] callback The callback information
676 * @param[in] param1 The first parameter to pass to the real member function
678 static void Dispatch(CallbackBase& callback, P1 param1)
680 // "downcast" the object and function type back to the correct ones
681 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
682 using MemberFunction = void (T::*)();
683 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
684 (object->*function)(/*ignore params*/);
689 * @brief Dispatcher to call a functor.
691 * This variant calls a void() member, ignoring any signal parameters.
694 template<class T, typename P1, typename P2>
695 struct VoidFunctorDispatcher2
698 * @brief Calls a function object.
701 * @param[in] callback The callback information
702 * @param[in] param1 The first parameter to pass to the real member function
703 * @param[in] param2 The second parameter to pass to the real member function
705 static void Dispatch(CallbackBase& callback, P1 param1, P2 param2)
707 // "downcast" the object and function type back to the correct ones
708 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
709 using MemberFunction = void (T::*)();
710 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
711 (object->*function)(/*ignore params*/);
716 * @brief Dispatcher to call a functor.
718 * This variant calls a void() member, ignoring any signal parameters.
721 template<class T, typename P1, typename P2, typename P3>
722 struct VoidFunctorDispatcher3
725 * @brief Calls a function object.
728 * @param[in] callback The callback information
729 * @param[in] param1 The first parameter to pass to the real member function
730 * @param[in] param2 The second parameter to pass to the real member function
731 * @param[in] param3 The third parameter to pass to the real member function
733 static void Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
735 // "downcast" the object and function type back to the correct ones
736 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
737 using MemberFunction = void (T::*)();
738 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
739 (object->*function)(/*ignore params*/);
744 * @brief Dispatcher to call a functor.
746 * This variant calls a void() member, and returns a default-constructed value.
749 template<class T, typename R>
750 struct VoidFunctorDispatcherReturn0
753 * @brief Calls a function object.
756 * @param[in] callback The callback information
759 static R Dispatch(CallbackBase& callback)
761 // "downcast" the object and function type back to the correct ones
762 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
763 using MemberFunction = void (T::*)();
764 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
765 (object->*function)(/*ignore params*/);
771 * @brief Dispatcher to call a functor.
773 * This variant calls a void() member, and returns a default-constructed value.
776 template<class T, typename R, typename P1>
777 struct VoidFunctorDispatcherReturn1
780 * @brief Calls a function object.
783 * @param[in] callback The callback information
784 * @param[in] param1 The first parameter to pass to the real member function
785 * @return The return value from the function
787 static R Dispatch(CallbackBase& callback, P1 param1)
789 // "downcast" the object and function type back to the correct ones
790 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
791 using MemberFunction = void (T::*)();
792 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
793 (object->*function)(/*ignore params*/);
799 * @brief Dispatcher to call a functor.
801 * This variant calls a void() member, and returns a default-constructed value.
804 template<class T, typename R, typename P1, typename P2>
805 struct VoidFunctorDispatcherReturn2
808 * @brief Calls a function object.
811 * @param[in] callback The callback information
812 * @param[in] param1 The first parameter to pass to the real member function
813 * @param[in] param2 The second parameter to pass to the real member function
814 * @return The return value from the function
816 static R Dispatch(CallbackBase& callback, P1 param1, P2 param2)
818 // "downcast" the object and function type back to the correct ones
819 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
820 using MemberFunction = void (T::*)();
821 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
822 (object->*function)(/*ignore params*/);
828 * @brief Dispatcher to call a functor.
830 * This variant calls a void() member, and returns a default-constructed value.
833 template<class T, typename R, typename P1, typename P2, typename P3>
834 struct VoidFunctorDispatcherReturn3
837 * @brief Calls a function object.
840 * @param[in] callback The callback information
841 * @param[in] param1 The first parameter to pass to the real member function
842 * @param[in] param2 The second parameter to pass to the real member function
843 * @param[in] param3 The third parameter to pass to the real member function
844 * @return The return value from the function
846 static R Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
848 // "downcast" the object and function type back to the correct ones
849 T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
850 using MemberFunction = void (T::*)();
851 MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
852 (object->*function)(/*ignore params*/);
858 * @brief Thin template to provide type safety for member function callbacks.
860 * Version with two parameters and return value.
864 class Callback : public CallbackBase
868 * @brief Default constructor.
878 * @brief Constructor for member function.
880 * Copies the function object.
882 * @param[in] object The object to call
883 * @param[in] memberFunction The member function of the object
885 Callback(T* object, void (T::*memberFunction)(void))
886 : CallbackBase(object,
887 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
888 reinterpret_cast<CallbackBase::Dispatcher>(&Dispatcher0<T>::Dispatch))
891 template<typename P1>
892 Callback(T* object, void (T::*memberFunction)(P1))
893 : CallbackBase(object,
894 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
895 reinterpret_cast<CallbackBase::Dispatcher>(&Dispatcher1<T, P1>::Dispatch))
898 template<typename P1, typename P2>
899 Callback(T* object, void (T::*memberFunction)(P1, P2))
900 : CallbackBase(object,
901 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
902 reinterpret_cast<CallbackBase::Dispatcher>(&Dispatcher2<T, P1, P2>::Dispatch))
905 template<typename P1, typename P2, typename P3>
906 Callback(T* object, void (T::*memberFunction)(P1, P2, P3))
907 : CallbackBase(object,
908 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
909 reinterpret_cast<CallbackBase::Dispatcher>(&Dispatcher3<T, P1, P2, P3>::Dispatch))
913 Callback(T* object, R (T::*memberFunction)(void))
914 : CallbackBase(object,
915 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
916 reinterpret_cast<CallbackBase::Dispatcher>(&DispatcherReturn0<T, R>::Dispatch))
919 template<typename R, typename P1>
920 Callback(T* object, R (T::*memberFunction)(P1))
921 : CallbackBase(object,
922 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
923 reinterpret_cast<CallbackBase::Dispatcher>(&DispatcherReturn1<T, R, P1>::Dispatch))
926 template<typename R, typename P1, typename P2>
927 Callback(T* object, R (T::*memberFunction)(P1, P2))
928 : CallbackBase(object,
929 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
930 reinterpret_cast<CallbackBase::Dispatcher>(&DispatcherReturn2<T, R, P1, P2>::Dispatch))
933 template<typename R, typename P1, typename P2, typename P3>
934 Callback(T* object, R (T::*memberFunction)(P1, P2, P3))
935 : CallbackBase(object,
936 reinterpret_cast<CallbackBase::MemberFunction>(memberFunction),
937 reinterpret_cast<CallbackBase::Dispatcher>(&DispatcherReturn3<T, R, P1, P2, P3>::Dispatch))
943 * @brief Specializations for function object callbacks.
947 class CallbackFunctor0 : public CallbackBase
951 * @brief Constructor which copies a function object.
954 * @param[in] object The object to copy
956 CallbackFunctor0(const T& object)
957 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
958 NULL, // uses operator() instead of member function
959 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcher0<T>::Dispatch),
960 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
966 * @brief Function object callback for connecting void() methods.
969 class CallbackFunctorDelegate0 : public CallbackBase
973 * @brief Constructor which copies a function object.
975 * This variant calls a void() member, ignoring any signal parameters.
977 * @param[in] object A newly allocated object (ownership is transferred)
979 CallbackFunctorDelegate0(FunctorDelegate* object)
980 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
981 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
982 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcher0<FunctorDelegate>::Dispatch),
983 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
989 * @brief Function object callback for matching callbacks to signal signature.
992 template<class T, typename P1>
993 class CallbackFunctor1 : public CallbackBase
997 * @brief Constructor which copies a function object.
1000 * @param[in] object The object to copy
1002 CallbackFunctor1(const T& object)
1003 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
1004 NULL, // uses operator() instead of member function
1005 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcher1<T, P1>::Dispatch),
1006 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
1012 * @brief Function object callback for connecting void() methods.
1015 template<typename P1>
1016 class CallbackFunctorDelegate1 : public CallbackBase
1020 * @brief Constructor which copies a function object.
1022 * This variant calls a void() member, ignoring any signal parameters.
1024 * @param[in] object The object to copy
1026 CallbackFunctorDelegate1(FunctorDelegate* object)
1027 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
1028 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
1029 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcher1<FunctorDelegate, P1>::Dispatch),
1030 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
1036 * @brief Function object callback for matching callbacks to signal signature.
1039 template<class T, typename P1, typename P2>
1040 class CallbackFunctor2 : public CallbackBase
1044 * @brief Constructor which copies a function object.
1047 * @param[in] object The object to copy
1049 CallbackFunctor2(const T& object)
1050 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
1051 NULL, // uses operator() instead of member function
1052 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcher2<T, P1, P2>::Dispatch),
1053 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
1059 * @brief Function object callback for connecting void() methods.
1062 template<typename P1, typename P2>
1063 class CallbackFunctorDelegate2 : public CallbackBase
1067 * @brief Constructor which copies a function object.
1069 * This variant calls a void() member, ignoring any signal parameters.
1071 * @param[in] object The object to copy
1073 CallbackFunctorDelegate2(FunctorDelegate* object)
1074 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
1075 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
1076 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcher2<FunctorDelegate, P1, P2>::Dispatch),
1077 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
1083 * @brief Function object callback for matching callbacks to signal signature.
1086 template<class T, typename P1, typename P2, typename P3>
1087 class CallbackFunctor3 : public CallbackBase
1091 * @brief Constructor which copies a function object.
1094 * @param[in] object The object to copy
1096 CallbackFunctor3(const T& object)
1097 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
1098 NULL, // uses operator() instead of member function
1099 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcher3<T, P1, P2, P3>::Dispatch),
1100 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
1106 * @brief Function object callback for connecting void() methods.
1109 template<typename P1, typename P2, typename P3>
1110 class CallbackFunctorDelegate3 : public CallbackBase
1114 * @brief Constructor which copies a function object.
1116 * This variant calls a void() member, ignoring any signal parameters.
1118 * @param[in] object The object to copy
1120 CallbackFunctorDelegate3(FunctorDelegate* object)
1121 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
1122 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
1123 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcher3<FunctorDelegate, P1, P2, P3>::Dispatch),
1124 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
1130 * @brief Function object callback for matching callbacks to signal signature.
1133 template<class T, typename R>
1134 class CallbackFunctorReturn0 : public CallbackBase
1138 * @brief Constructor which copies a function object.
1141 * @param[in] object The object to copy
1143 CallbackFunctorReturn0(const T& object)
1144 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
1145 NULL, // uses operator() instead of member function
1146 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcherReturn0<T, R>::Dispatch),
1147 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
1153 * @brief Function object callback for connecting void() methods.
1156 template<typename R>
1157 class CallbackFunctorDelegateReturn0 : public CallbackBase
1161 * @brief Constructor which copies a function object.
1163 * This variant calls a void() member, ignoring any signal parameters.
1165 * @param[in] object The object to copy
1167 CallbackFunctorDelegateReturn0(FunctorDelegate* object)
1168 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
1169 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
1170 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcherReturn0<FunctorDelegate, R>::Dispatch),
1171 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
1177 * @brief Function object callback for matching callbacks to signal signature.
1180 template<class T, typename P1, typename R>
1181 class CallbackFunctorReturn1 : public CallbackBase
1185 * @brief Constructor which copies a function object.
1188 * @param[in] object The object to copy
1190 CallbackFunctorReturn1(const T& object)
1191 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
1192 NULL, // uses operator() instead of member function
1193 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcherReturn1<T, R, P1>::Dispatch),
1194 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
1200 * @brief Function object callback for connecting void() methods.
1203 template<typename P1, typename R>
1204 class CallbackFunctorDelegateReturn1 : public CallbackBase
1208 * @brief Constructor which copies a function object.
1210 * This variant calls a void() member, ignoring any signal parameters.
1212 * @param[in] object The object to copy
1214 CallbackFunctorDelegateReturn1(FunctorDelegate* object)
1215 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
1216 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
1217 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcherReturn1<FunctorDelegate, R, P1>::Dispatch),
1218 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
1224 * @brief Function object callback for matching callbacks to signal signature.
1227 template<class T, typename P1, typename P2, typename R>
1228 class CallbackFunctorReturn2 : public CallbackBase
1232 * @brief Constructor which copies a function object.
1235 * @param[in] object The object to copy
1237 CallbackFunctorReturn2(const T& object)
1238 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
1239 NULL, // uses operator() instead of member function
1240 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcherReturn2<T, R, P1, P2>::Dispatch),
1241 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
1247 * @brief Function object callback for connecting void() methods.
1250 template<typename P1, typename P2, typename R>
1251 class CallbackFunctorDelegateReturn2 : public CallbackBase
1255 * @brief Constructor which copies a function object.
1257 * This variant calls a void() member, ignoring any signal parameters.
1259 * @param[in] object The object to copy
1261 CallbackFunctorDelegateReturn2(FunctorDelegate* object)
1262 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
1263 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
1264 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcherReturn2<FunctorDelegate, R, P1, P2>::Dispatch),
1265 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
1271 * @brief Function object callback for matching callbacks to signal signature.
1274 template<class T, typename P1, typename P2, typename P3, typename R>
1275 class CallbackFunctorReturn3 : public CallbackBase
1279 * @brief Constructor which copies a function object.
1282 * @param[in] object The object to copy
1284 CallbackFunctorReturn3(const T& object)
1285 : CallbackBase(reinterpret_cast<void*>(new T(object)), // copy the object
1286 NULL, // uses operator() instead of member function
1287 reinterpret_cast<CallbackBase::Dispatcher>(&FunctorDispatcherReturn3<T, R, P1, P2, P3>::Dispatch),
1288 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<T>::Delete))
1294 * @brief Function object callback for connecting void() methods.
1297 template<typename P1, typename P2, typename P3, typename R>
1298 class CallbackFunctorDelegateReturn3 : public CallbackBase
1302 * @brief Constructor which copies a function object.
1304 * This variant calls a void() member, ignoring any signal parameters.
1306 * @param[in] object The object to copy
1308 CallbackFunctorDelegateReturn3(FunctorDelegate* object)
1309 : CallbackBase(reinterpret_cast<void*>(object), // transfer ownership
1310 reinterpret_cast<CallbackBase::MemberFunction>(&FunctorDelegate::Execute),
1311 reinterpret_cast<CallbackBase::Dispatcher>(&VoidFunctorDispatcherReturn3<FunctorDelegate, R, P1, P2, P3>::Dispatch),
1312 reinterpret_cast<CallbackBase::Destructor>(&Destroyer<FunctorDelegate>::Delete))
1317 // Callback creation thin templates
1320 * @brief Creates a callback from a free function with parameter pack.
1323 * @param[in] function The function to call
1324 * @return A newly allocated Callback object, ownership transferred to caller
1326 template<typename R, typename... Args>
1327 inline CallbackBase* MakeCallback(R (*function)(Args... args))
1329 return new CallbackBase(reinterpret_cast<CallbackBase::Function>(function));
1333 * @brief Creates a callback from a class member function with no parameters.
1335 * Requires the function to be member of the same class.
1337 * @param[in] object The object to call
1338 * @param[in] function The member function to call
1339 * @return A newly allocated Callback object, ownership transferred to caller
1342 inline CallbackBase* MakeCallback(T* object, void (T::*function)(void))
1344 return new Callback<T>(object, function);
1348 * @brief Creates a callback from a class member function with one parameter.
1350 * Requires the function to be member of the same class.
1352 * @param[in] object The object to call
1353 * @param[in] function The member function to call
1354 * @return A newly allocated Callback object, ownership transferred to caller
1356 template<class T, typename P1>
1357 inline CallbackBase* MakeCallback(T* object, void (T::*function)(P1))
1359 return new Callback<T>(object, function);
1363 * @brief Creates a callback from a class member function with two parameters.
1365 * Requires the function to be member of the same class.
1367 * @param[in] object The object to call
1368 * @param[in] function The member function to call
1369 * @return A newly allocated Callback object, ownership transferred to caller
1371 template<class T, typename P1, typename P2>
1372 inline CallbackBase* MakeCallback(T* object, void (T::*function)(P1, P2))
1374 return new Callback<T>(object, function);
1378 * @brief Creates a callback from a class member function with three parameters.
1380 * Requires the function to be member of the same class.
1382 * @param[in] object The object to call
1383 * @param[in] function The member function to call
1384 * @return A newly allocated Callback object, ownership transferred to caller
1386 template<class T, typename P1, typename P2, typename P3>
1387 inline CallbackBase* MakeCallback(T* object, void (T::*function)(P1, P2, P3))
1389 return new Callback<T>(object, function);
1393 * @brief Creates a callback from a class member function with no parameters and a return type.
1395 * Requires the function to be member of the same class.
1397 * @param[in] object The object to call
1398 * @param[in] function The member function to call
1399 * @return A newly allocated Callback object, ownership transferred to caller
1401 template<class T, typename R>
1402 inline CallbackBase* MakeCallback(T* object, R (T::*function)())
1404 return new Callback<T>(object, function);
1408 * @brief Creates a callback from a class member function with one parameter and a return type.
1410 * Requires the function to be member of the same class.
1412 * @param[in] object The object to call
1413 * @param[in] function The member function to call
1414 * @return A newly allocated Callback object, ownership transferred to caller
1416 template<class T, typename P1, typename R>
1417 inline CallbackBase* MakeCallback(T* object, R (T::*function)(P1))
1419 return new Callback<T>(object, function);
1423 * @brief Creates a callback from a class member function with two parameters and a return type.
1425 * Requires the function to be member of the same class.
1427 * @param[in] object The object to call
1428 * @param[in] function The member function to call
1429 * @return A newly allocated Callback object, ownership transferred to caller
1431 template<class T, typename P1, typename P2, typename R>
1432 inline CallbackBase* MakeCallback(T* object, R (T::*function)(P1, P2))
1434 return new Callback<T>(object, function);
1438 * @brief Creates a callback from a class member function with three parameters and a return type.
1440 * Requires the function to be member of the same class.
1442 * @param[in] object The object to call
1443 * @param[in] function The member function to call
1444 * @return A newly allocated Callback object, ownership transferred to caller
1446 template<class T, typename P1, typename P2, typename P3, typename R>
1447 inline CallbackBase* MakeCallback(T* object, R (T::*function)(P1, P2, P3))
1449 return new Callback<T>(object, function);
1453 * @brief Creates a callback from a class's parent member function with no parameters.
1455 * Requires the function to be member of the same class.
1457 * @param[in] object The object to call
1458 * @param[in] function The member function to call
1459 * @return A newly allocated Callback object, ownership transferred to caller
1461 template<class T, class Base>
1462 inline CallbackBase* MakeCallback(T* object, void (Base::*function)(void))
1464 return new Callback<T>(object, function);
1467 * @brief Creates a callback from a class's parent member function with no parameters.
1469 * Requires the function to be member of the same class.
1471 * @param[in] object The object to call
1472 * @param[in] function The member function to call
1473 * @return A newly allocated Callback object, ownership transferred to caller
1475 template<class T, class Base>
1476 inline CallbackBase* MakeCallback(T& object, void (Base::*function)(void))
1478 return new Callback<T>(object, function);
1486 #endif // DALI_CALLBACK_H