1 #ifndef __DALI_SIGNAL_H__
2 #define __DALI_SIGNAL_H__
5 * Copyright (c) 2015 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.
22 * The class should implement Dali::ConnectionTrackerInterface, or inherit from Dali::ConnectionTracker.
23 * This enforces automatic disconnection when an object is destroyed, so you don't have
24 * to manually disconnect from signals.
26 * Alternatively, you can use a Dali::SlotDelegate if you don't want to inherit.
30 * class MyClass : public ConnectionTracker
33 * void Callback( Actor actor, const TouchEvent& event )
40 * Actor actor = Actor::New();
42 * actor.TouchedSignal().Connect( this, &MyClass::Callback );
47 * // ConnectionTracker base class automatically disconnects
54 #include <dali/public-api/common/dali-common.h>
55 #include <dali/public-api/signals/callback.h>
56 #include <dali/public-api/signals/signal-slot-connections.h>
57 #include <dali/public-api/signals/slot-delegate.h>
58 #include <dali/public-api/signals/base-signal.h>
63 * @addtogroup dali-core-signals
68 * @brief Base Template class to provide signals.
70 * To create a signal for this class, you first have to define a typedef within your handle's scope:
72 * class MyHandle : public Handle
78 * typedef Signal< void ()> VoidSignalType; ///< For signals that require no parameters and no return value
79 * typedef Signal< bool ()> BoolSignalType; ///< For signals that do not need parameters but require a boolean return
80 * typedef Signal< void ( float )> ParamSignalType; ///< For signals that need a float as a parameter but no return value
88 * VoidSignalType& VoidSignal();
89 * BoolSignalType& BoolSignal();
90 * ParamSignalType& ParamSignal();
95 * The methods are required in the handle class so that the application writer can retrieve the Signal in order to connect/disconnect.
97 * In the implementation class, the members should be defined and the methods should be provided to retrieve the signal itself.
98 * These will be called by the equivalent methods in the MyHandle class.
100 * class MyObject : public Object
106 * MyHandle::VoidSignalType& VoidSignal()
108 * return mVoidSignal;
111 * MyHandle::BoolSignalType& BoolSignal()
113 * return mBoolSignal;
116 * MyHandle::ParamSignalType& ParamSignal()
118 * return mParamSignal;
124 * MyHandle::VoidSignalType mVoidSignal;
125 * MyHandle::BoolSignalType mBoolSignal;
126 * MyHandle::ParamSignalType mParamSignal;
132 template< typename _Signature >
138 * @brief A template for Signals with no parameters or return value.
141 class Signal< void () >
146 * @brief Default constructor.
153 * @brief Non-virtual destructor.
160 * @brief Query whether there are any connected slots.
162 * @return True if there are any slots connected to the signal.
166 return mImpl.Empty();
170 * @brief Query the number of slots.
172 * @return The number of slots connected to this signal.
174 std::size_t GetConnectionCount() const
176 return mImpl.GetConnectionCount();
180 * @brief Connect a function.
182 * @param[in] func The function to connect.
184 void Connect( void (*func)() )
186 mImpl.OnConnect( MakeCallback( func ) );
190 * @brief Disconnect a function.
192 * @param[in] func The function to disconnect.
194 void Disconnect( void (*func)() )
196 mImpl.OnDisconnect( MakeCallback( func ) );
200 * @brief Connect a member function.
202 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
203 * @param[in] func The member function to connect.
206 void Connect( X* obj, void (X::*func)() )
208 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
212 * @brief Disconnect a member function.
214 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
215 * @param[in] func The member function to disconnect.
218 void Disconnect( X* obj, void (X::*func)() )
220 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
224 * @brief Connect a member function.
226 * @param[in] delegate A slot delegate.
227 * @param[in] func The member function to connect.
230 void Connect( SlotDelegate<X>& delegate, void (X::*func)() )
232 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
236 * @brief Disconnect a member function.
238 * @param[in] delegate A slot delegate.
239 * @param[in] func The member function to disconnect.
242 void Disconnect( SlotDelegate<X>& delegate, void (X::*func)() )
244 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
248 * @brief Connect a function object.
250 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
251 * @param[in] func The function object to copy.
254 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
256 mImpl.OnConnect( connectionTracker, new CallbackFunctor0< X >( func ) );
260 * @brief Connect a function object using FunctorDelegate.
262 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
263 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
265 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
267 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegate0( delegate ) );
271 * @brief Emit the signal.
280 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
281 Signal& operator=( const Signal& ); ///< undefined assignment operator
285 // Use composition instead of inheritance (virtual methods don't mix well with templates)
286 BaseSignal mImpl; ///< The base signal implementation
290 * @brief A template for Signals with no parameters and a return value.
292 template < typename Ret >
293 class Signal< Ret() >
298 * @brief Default constructor.
305 * @brief Non-virtual destructor.
312 * @brief Query whether there are any connected slots.
314 * @return True if there are any slots connected to the signal.
318 return mImpl.Empty();
322 * @brief Query the number of slots.
324 * @return The number of slots connected to this signal.
326 std::size_t GetConnectionCount() const
328 return mImpl.GetConnectionCount();
331 * @brief Connect a function.
333 * @param[in] func The function to connect.
335 void Connect( Ret (*func)() )
337 mImpl.OnConnect( MakeCallback( func ) );
341 * @brief Disconnect a function.
343 * @param[in] func The function to disconnect.
345 void Disconnect( Ret (*func)() )
347 mImpl.OnDisconnect( MakeCallback( func ) );
351 * @brief Connect a member function.
353 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
354 * @param[in] func The member function to connect.
357 void Connect( X* obj, Ret (X::*func)() )
359 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
363 * @brief Disconnect a member function.
365 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
366 * @param[in] func The member function to disconnect.
369 void Disconnect( X* obj, Ret (X::*func)() )
371 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
375 * @brief Connect a member function.
377 * @param[in] delegate A slot delegate.
378 * @param[in] func The member function to connect.
381 void Connect( SlotDelegate<X>& delegate, Ret (X::*func)() )
383 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
387 * @brief Disconnect a member function.
389 * @param[in] delegate A slot delegate.
390 * @param[in] func The member function to disconnect.
393 void Disconnect( SlotDelegate<X>& delegate, Ret (X::*func)() )
395 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
399 * @brief Connect a function object.
401 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
402 * @param[in] func The function object to copy.
405 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
407 mImpl.OnConnect( connectionTracker, new CallbackFunctorReturn0< X, Ret >( func ) );
411 * @brief Connect a function object using FunctorDelegate.
413 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
414 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
416 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
418 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegateReturn0< Ret >( delegate ) );
422 * @brief Emit the signal.
424 * @return The value returned by the last callback, or a default constructed value if no callbacks are connected.
428 return mImpl.EmitReturn< Ret >();
433 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
434 Signal& operator=( const Signal& ); ///< undefined assignment operator
438 // Use composition instead of inheritance (virtual methods don't mix well with templates)
439 BaseSignal mImpl; ///< Implementation
443 * @brief A template for Signals with 1 parameter.
445 template < typename Arg0 >
446 class Signal< void ( Arg0 ) >
451 * @brief Default constructor.
458 * @brief Non-virtual destructor.
465 * @brief Query whether there are any connected slots.
467 * @return True if there are any slots connected to the signal.
471 return mImpl.Empty();
475 * @brief Query the number of slots.
477 * @return The number of slots connected to this signal.
479 std::size_t GetConnectionCount() const
481 return mImpl.GetConnectionCount();
484 * @brief Connect a function.
486 * @param[in] func The function to connect.
488 void Connect( void (*func)( Arg0 arg0 ) )
490 mImpl.OnConnect( MakeCallback( func ) );
494 * @brief Disconnect a function.
496 * @param[in] func The function to disconnect.
498 void Disconnect( void (*func)( Arg0 arg0 ) )
500 mImpl.OnDisconnect( MakeCallback( func ) );
504 * @brief Connect a member function.
506 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
507 * @param[in] func The member function to connect.
510 void Connect( X* obj, void (X::*func)( Arg0 arg0 ) )
512 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
516 * @brief Disconnect a member function.
518 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
519 * @param[in] func The member function to disconnect.
522 void Disconnect( X* obj, void (X::*func)( Arg0 arg0 ) )
524 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
528 * @brief Connect a member function.
530 * @param[in] delegate A slot delegate.
531 * @param[in] func The member function to connect.
534 void Connect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0 ) )
536 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
540 * @brief Disconnect a member function.
542 * @param[in] delegate A slot delegate.
543 * @param[in] func The member function to disconnect.
546 void Disconnect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0 ) )
548 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
552 * @brief Connect a function object.
554 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
555 * @param[in] func The function object to copy.
558 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
560 mImpl.OnConnect( connectionTracker, new CallbackFunctor1< X, Arg0 >( func ) );
564 * @brief Connect a function object using FunctorDelegate.
566 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
567 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
569 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
571 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegate1< Arg0 >( delegate ) );
575 * @brief Emit the signal.
577 * @param[in] arg0 The first value to pass to callbacks.
579 void Emit( Arg0 arg0 )
581 mImpl.Emit< Arg0 >( arg0 );
586 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
587 Signal& operator=( const Signal& ); ///< undefined assignment operator
591 // Use composition instead of inheritance (virtual methods don't mix well with templates)
592 BaseSignal mImpl; ///< Implementation
596 * @brief A template for Signals with 1 parameter and a return value.
598 template < typename Ret, typename Arg0 >
599 class Signal< Ret( Arg0 ) >
604 * @brief Default constructor.
611 * @brief Non-virtual destructor.
618 * @brief Query whether there are any connected slots.
620 * @return True if there are any slots connected to the signal.
624 return mImpl.Empty();
628 * @brief Query the number of slots.
630 * @return The number of slots connected to this signal.
632 std::size_t GetConnectionCount() const
634 return mImpl.GetConnectionCount();
637 * @brief Connect a function.
639 * @param[in] func The function to connect.
641 void Connect( Ret (*func)( Arg0 arg0 ) )
643 mImpl.OnConnect( MakeCallback( func ) );
647 * @brief Disconnect a function.
649 * @param[in] func The function to disconnect.
651 void Disconnect( Ret (*func)( Arg0 arg0 ) )
653 mImpl.OnDisconnect( MakeCallback( func ) );
657 * @brief Connect a member function.
659 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
660 * @param[in] func The member function to connect.
663 void Connect( X* obj, Ret (X::*func)( Arg0 arg0 ) )
665 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
669 * @brief Disconnect a member function.
671 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
672 * @param[in] func The member function to disconnect.
675 void Disconnect( X* obj, Ret (X::*func)( Arg0 arg0 ) )
677 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
681 * @brief Connect a member function.
683 * @param[in] delegate A slot delegate.
684 * @param[in] func The member function to connect.
687 void Connect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0 ) )
689 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
693 * @brief Disconnect a member function.
695 * @param[in] delegate A slot delegate.
696 * @param[in] func The member function to disconnect.
699 void Disconnect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0 ) )
701 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
705 * @brief Connect a function object.
707 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
708 * @param[in] func The function object to copy.
711 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
713 mImpl.OnConnect( connectionTracker, new CallbackFunctorReturn1< X, Arg0, Ret >( func ) );
717 * @brief Connect a function object using FunctorDelegate.
719 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
720 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
722 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
724 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegateReturn1< Arg0, Ret >( delegate ) );
728 * @brief Emit the signal.
730 * @param[in] arg0 The first value to pass to callbacks.
731 * @return The value returned by the last callback, or a default constructed value if no callbacks are connected.
733 Ret Emit( Arg0 arg0 )
735 return mImpl.EmitReturn< Ret,Arg0 >(arg0);
740 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
741 Signal& operator=( const Signal& ); ///< undefined assignment operator
745 // Use composition instead of inheritance (virtual methods don't mix well with templates)
746 BaseSignal mImpl; ///< Implementation
750 * @brief A template for Signals with 2 parameters.
753 template < typename Arg0, typename Arg1 >
754 class Signal< void ( Arg0, Arg1 ) >
759 * @brief Default constructor.
767 * @brief Non-virtual destructor.
775 * @brief Query whether there are any connected slots.
777 * @return True if there are any slots connected to the signal.
781 return mImpl.Empty();
785 * @brief Query the number of slots.
787 * @return The number of slots connected to this signal.
789 std::size_t GetConnectionCount() const
791 return mImpl.GetConnectionCount();
794 * @brief Connect a function.
796 * @param[in] func The function to connect.
798 void Connect( void (*func)( Arg0 arg0, Arg1 arg1 ) )
800 mImpl.OnConnect( MakeCallback( func ) );
804 * @brief Disconnect a function.
806 * @param[in] func The function to disconnect.
808 void Disconnect( void (*func)( Arg0 arg0, Arg1 arg1 ) )
810 mImpl.OnDisconnect( MakeCallback( func ) );
814 * @brief Connect a member function.
816 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
817 * @param[in] func The member function to connect.
820 void Connect( X* obj, void (X::*func)( Arg0 arg0, Arg1 arg1 ) )
822 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
826 * @brief Disconnect a member function.
828 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
829 * @param[in] func The member function to disconnect.
832 void Disconnect( X* obj, void (X::*func)( Arg0 arg0, Arg1 arg1 ) )
834 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
838 * @brief Connect a member function.
840 * @param[in] delegate A slot delegate.
841 * @param[in] func The member function to connect.
844 void Connect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0, Arg1 arg1 ) )
846 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
850 * @brief Disconnect a member function.
852 * @param[in] delegate A slot delegate.
853 * @param[in] func The member function to disconnect.
856 void Disconnect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0, Arg1 arg1 ) )
858 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
862 * @brief Connect a function object.
864 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
865 * @param[in] func The function object to copy.
868 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
870 mImpl.OnConnect( connectionTracker, new CallbackFunctor2< X, Arg0, Arg1 >( func ) );
874 * @brief Connect a function object using FunctorDelegate.
876 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
877 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
879 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
881 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegate2< Arg0, Arg1 >( delegate ) );
885 * @brief Emit the signal.
887 * @param[in] arg0 The first value to pass to callbacks.
888 * @param[in] arg1 The second value to pass to callbacks.
890 void Emit( Arg0 arg0, Arg1 arg1 )
892 mImpl.Emit< Arg0,Arg1 >( arg0, arg1 );
897 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
898 Signal& operator=( const Signal& ); ///< undefined assignment operator
902 // Use composition instead of inheritance (virtual methods don't mix well with templates)
903 BaseSignal mImpl; ///< Implementation
907 * @brief A template for Signals with 2 parameters and a return value.
909 template < typename Ret, typename Arg0, typename Arg1 >
910 class Signal< Ret( Arg0, Arg1 ) >
915 * @brief Default constructor.
922 * @brief Non-virtual destructor.
929 * @brief Query whether there are any connected slots.
931 * @return True if there are any slots connected to the signal.
935 return mImpl.Empty();
939 * @brief Query the number of slots.
941 * @return The number of slots connected to this signal.
943 std::size_t GetConnectionCount() const
945 return mImpl.GetConnectionCount();
948 * @brief Connect a function.
949 * @param[in] func The function to connect.
951 void Connect( Ret (*func)( Arg0 arg0, Arg1 arg1 ) )
953 mImpl.OnConnect( MakeCallback( func ) );
957 * @brief Disconnect a function.
959 * @param[in] func The function to disconnect.
961 void Disconnect( Ret (*func)( Arg0 arg0, Arg1 arg1 ) )
963 mImpl.OnDisconnect( MakeCallback( func ) );
967 * @brief Connect a member function.
969 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
970 * @param[in] func The member function to connect.
973 void Connect( X* obj, Ret (X::*func)( Arg0 arg0, Arg1 arg1 ) )
975 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
979 * @brief Disconnect a member function.
981 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
982 * @param[in] func The member function to disconnect.
985 void Disconnect( X* obj, Ret (X::*func)( Arg0 arg0, Arg1 arg1 ) )
987 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
991 * @brief Connect a member function.
993 * @param[in] delegate A slot delegate.
994 * @param[in] func The member function to connect.
997 void Connect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0, Arg1 arg1 ) )
999 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1003 * @brief Disconnect a member function.
1005 * @param[in] delegate A slot delegate.
1006 * @param[in] func The member function to disconnect.
1009 void Disconnect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0, Arg1 arg1 ) )
1011 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1015 * @brief Connect a function object.
1017 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
1018 * @param[in] func The function object to copy.
1021 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
1023 mImpl.OnConnect( connectionTracker, new CallbackFunctorReturn2< X, Arg0, Arg1, Ret >( func ) );
1027 * @brief Connect a function object using FunctorDelegate.
1029 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
1030 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
1032 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
1034 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegateReturn2< Arg0, Arg1, Ret >( delegate ) );
1038 * @brief Emit the signal.
1040 * @param[in] arg0 The first value to pass to callbacks.
1041 * @param[in] arg1 The second value to pass to callbacks.
1042 * @return The value returned by the last callback, or a default constructed value if no callbacks are connected.
1044 Ret Emit( Arg0 arg0, Arg1 arg1 )
1046 return mImpl.EmitReturn< Ret,Arg0,Arg1 >( arg0, arg1 );
1051 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
1052 Signal& operator=( const Signal& ); ///< undefined assignment operator
1056 // Use composition instead of inheritance (virtual methods don't mix well with templates)
1057 BaseSignal mImpl; ///< Implementation
1061 * @brief A template for Signals with 3 parameters.
1063 template < typename Arg0, typename Arg1, typename Arg2 >
1064 class Signal< void ( Arg0, Arg1, Arg2 ) >
1069 * @brief Default constructor.
1076 * @brief Non-virtual destructor.
1083 * @brief Query whether there are any connected slots.
1085 * @return True if there are any slots connected to the signal.
1089 return mImpl.Empty();
1093 * @brief Query the number of slots.
1095 * @return The number of slots connected to this signal.
1097 std::size_t GetConnectionCount() const
1099 return mImpl.GetConnectionCount();
1102 * @brief Connect a function.
1104 * @param[in] func The function to connect.
1106 void Connect( void (*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1108 mImpl.OnConnect( MakeCallback( func ) );
1112 * @brief Disconnect a function.
1114 * @param[in] func The function to disconnect.
1116 void Disconnect( void (*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1118 mImpl.OnDisconnect( MakeCallback( func ) );
1122 * @brief Connect a member function.
1124 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
1125 * @param[in] func The member function to connect.
1128 void Connect( X* obj, void (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1130 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
1134 * @brief Disconnect a member function.
1136 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
1137 * @param[in] func The member function to disconnect.
1140 void Disconnect( X* obj, void (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1142 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
1146 * @brief Connect a member function.
1148 * @param[in] delegate A slot delegate.
1149 * @param[in] func The member function to connect.
1152 void Connect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1154 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1158 * @brief Disconnect a member function.
1160 * @param[in] delegate A slot delegate.
1161 * @param[in] func The member function to disconnect.
1164 void Disconnect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1166 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1170 * @brief Connect a function object.
1172 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
1173 * @param[in] func The function object to copy.
1176 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
1178 mImpl.OnConnect( connectionTracker, new CallbackFunctor3< X, Arg0, Arg1, Arg2 >( func ) );
1182 * @brief Connect a function object using FunctorDelegate.
1184 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
1185 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
1187 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
1189 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegate3< Arg0, Arg1, Arg2 >( delegate ) );
1193 * @brief Emit the signal.
1195 * @param[in] arg0 The first value to pass to callbacks.
1196 * @param[in] arg1 The second value to pass to callbacks.
1197 * @param[in] arg2 The third value to pass to callbacks.
1199 void Emit( Arg0 arg0, Arg1 arg1, Arg2 arg2 )
1201 mImpl.Emit< Arg0,Arg1,Arg2 >( arg0, arg1, arg2 );
1206 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
1207 Signal& operator=( const Signal& ); ///< undefined assignment operator
1211 // Use composition instead of inheritance (virtual methods don't mix well with templates)
1212 BaseSignal mImpl; ///< Implementation
1216 * @brief A template for Signals with 2 parameters and a return value.
1218 template < typename Ret, typename Arg0, typename Arg1, typename Arg2 >
1219 class Signal< Ret( Arg0, Arg1, Arg2 ) >
1224 * @brief Default constructor.
1231 * @brief Non-virtual destructor.
1238 * @brief Query whether there are any connected slots.
1240 * @return True if there are any slots connected to the signal.
1244 return mImpl.Empty();
1248 * @brief Query the number of slots.
1250 * @return The number of slots connected to this signal.
1252 std::size_t GetConnectionCount() const
1254 return mImpl.GetConnectionCount();
1258 * @brief Connect a function.
1260 * @param[in] func The function to connect.
1262 void Connect( Ret (*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1264 mImpl.OnConnect( MakeCallback( func ) );
1268 * @brief Disconnect a function.
1270 * @param[in] func The function to disconnect.
1272 void Disconnect( Ret (*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1274 mImpl.OnDisconnect( MakeCallback( func ) );
1278 * @brief Connect a member function.
1280 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
1281 * @param[in] func The member function to connect.
1284 void Connect( X* obj, Ret (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1286 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
1290 * @brief Disconnect a member function.
1292 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
1293 * @param[in] func The member function to disconnect.
1296 void Disconnect( X* obj, Ret (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1298 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
1302 * @brief Connect a member function.
1304 * @param[in] delegate A slot delegate.
1305 * @param[in] func The member function to connect.
1308 void Connect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1310 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1314 * @brief Disconnect a member function.
1316 * @param[in] delegate A slot delegate.
1317 * @param[in] func The member function to disconnect.
1320 void Disconnect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1322 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1326 * @brief Connect a function object.
1328 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
1329 * @param[in] func The function object to copy.
1332 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
1334 mImpl.OnConnect( connectionTracker, new CallbackFunctorReturn3< X, Arg0, Arg1, Arg2, Ret >( func ) );
1338 * @brief Connect a function object using FunctorDelegate.
1340 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
1341 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
1343 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
1345 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegateReturn3< Arg0, Arg1, Arg2, Ret >( delegate ) );
1349 * @brief Emit the signal.
1351 * @param[in] arg0 The first value to pass to callbacks.
1352 * @param[in] arg1 The second value to pass to callbacks.
1353 * @param[in] arg2 The third value to pass to callbacks.
1354 * @return The value returned by the last callback, or a default constructed value if no callbacks are connected.
1356 Ret Emit( Arg0 arg0, Arg1 arg1, Arg2 arg2 )
1358 return mImpl.EmitReturn< Ret,Arg0,Arg1,Arg2 >( arg0, arg1, arg2 );
1363 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
1364 Signal& operator=( const Signal& ); ///< undefined assignment operator
1368 // Use composition instead of inheritance (virtual methods don't mix well with templates)
1369 BaseSignal mImpl; ///< Implementation
1377 #endif // __DALI_SIGNAL_H__