1 #ifndef __DALI_SIGNAL_H__
2 #define __DALI_SIGNAL_H__
5 * Copyright (c) 2014 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>
64 * @brief Base Template class to provide signals.
66 * To create a signal for this class, you first have to define a typedef within your handle's scope:
68 * class MyHandle : public Handle
74 * typedef Signal< void ()> VoidSignalType; ///< For signals that require no parameters and no return value
75 * typedef Signal< bool ()> BoolSignalType; ///< For signals that do not need parameters but require a boolean return
76 * typedef Signal< void ( float )> ParamSignalType; ///< For signals that need a float as a parameter but no return value
84 * VoidSignalType& VoidSignal();
85 * BoolSignalType& BoolSignal();
86 * ParamSignalType& ParamSignal();
91 * The methods are required in the handle class so that the application writer can retrieve the Signal in order to connect/disconnect.
93 * In the implementation class, the members should be defined and the methods should be provided to retrieve the signal itself.
94 * These will be called by the equivalent methods in the MyHandle class.
96 * class MyObject : public Object
102 * MyHandle::VoidSignalType& VoidSignal()
104 * return mVoidSignal;
107 * MyHandle::BoolSignalType& BoolSignal()
109 * return mBoolSignal;
112 * MyHandle::ParamSignalType& ParamSignal()
114 * return mParamSignal;
120 * MyHandle::VoidSignalType mVoidSignal;
121 * MyHandle::BoolSignalType mBoolSignal;
122 * MyHandle::ParamSignalType mParamSignal;
128 template< typename _Signature >
134 * @brief A template for Signals with no parameters or return value.
137 class Signal< void () >
142 * @brief Default constructor.
149 * @brief Non-virtual destructor.
156 * @brief Query whether there are any connected slots.
158 * @return True if there are any slots connected to the signal.
162 return mImpl.Empty();
166 * @brief Query the number of slots.
168 * @return The number of slots connected to this signal.
170 std::size_t GetConnectionCount() const
172 return mImpl.GetConnectionCount();
176 * @brief Connect a function.
178 * @param[in] func The function to connect.
180 void Connect( void (*func)() )
182 mImpl.OnConnect( MakeCallback( func ) );
186 * @brief Disconnect a function.
188 * @param[in] func The function to disconnect.
190 void Disconnect( void (*func)() )
192 mImpl.OnDisconnect( MakeCallback( func ) );
196 * @brief Connect a member function.
198 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
199 * @param[in] func The member function to connect.
202 void Connect( X* obj, void (X::*func)() )
204 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
208 * @brief Disconnect a member function.
210 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
211 * @param[in] func The member function to disconnect.
214 void Disconnect( X* obj, void (X::*func)() )
216 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
220 * @brief Connect a member function.
222 * @param[in] delegate A slot delegate.
223 * @param[in] func The member function to connect.
226 void Connect( SlotDelegate<X>& delegate, void (X::*func)() )
228 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
232 * @brief Disconnect a member function.
234 * @param[in] delegate A slot delegate.
235 * @param[in] func The member function to disconnect.
238 void Disconnect( SlotDelegate<X>& delegate, void (X::*func)() )
240 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
244 * @brief Connect a function object.
246 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
247 * @param[in] func The function object to copy.
250 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
252 mImpl.OnConnect( connectionTracker, new CallbackFunctor0< X >( func ) );
256 * @brief Connect a function object using FunctorDelegate.
258 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
259 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
261 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
263 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegate0( delegate ) );
267 * @brief Emit the signal.
276 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
277 Signal& operator=( const Signal& ); ///< undefined assignment operator
281 // Use composition instead of inheritance (virtual methods don't mix well with templates)
282 BaseSignal mImpl; ///< The base signal implementation
286 * @brief A template for Signals with no parameters and a return value.
288 template < typename Ret >
289 class Signal< Ret() >
294 * @brief Default constructor.
301 * @brief Non-virtual destructor.
308 * @brief Query whether there are any connected slots.
310 * @return True if there are any slots connected to the signal.
314 return mImpl.Empty();
318 * @brief Query the number of slots.
320 * @return The number of slots connected to this signal.
322 std::size_t GetConnectionCount() const
324 return mImpl.GetConnectionCount();
327 * @brief Connect a function.
329 * @param[in] func The function to connect.
331 void Connect( Ret (*func)() )
333 mImpl.OnConnect( MakeCallback( func ) );
337 * @brief Disconnect a function.
339 * @param[in] func The function to disconnect.
341 void Disconnect( Ret (*func)() )
343 mImpl.OnDisconnect( MakeCallback( func ) );
347 * @brief Connect a member function.
349 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
350 * @param[in] func The member function to connect.
353 void Connect( X* obj, Ret (X::*func)() )
355 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
359 * @brief Disconnect a member function.
361 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
362 * @param[in] func The member function to disconnect.
365 void Disconnect( X* obj, Ret (X::*func)() )
367 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
371 * @brief Connect a member function.
373 * @param[in] delegate A slot delegate.
374 * @param[in] func The member function to connect.
377 void Connect( SlotDelegate<X>& delegate, Ret (X::*func)() )
379 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
383 * @brief Disconnect a member function.
385 * @param[in] delegate A slot delegate.
386 * @param[in] func The member function to disconnect.
389 void Disconnect( SlotDelegate<X>& delegate, Ret (X::*func)() )
391 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
395 * @brief Connect a function object.
397 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
398 * @param[in] func The function object to copy.
401 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
403 mImpl.OnConnect( connectionTracker, new CallbackFunctorReturn0< X, Ret >( func ) );
407 * @brief Connect a function object using FunctorDelegate.
409 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
410 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
412 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
414 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegateReturn0< Ret >( delegate ) );
418 * @brief Emit the signal.
420 * @return The value returned by the last callback, or a default constructed value if no callbacks are connected.
424 return mImpl.EmitReturn< Ret >();
429 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
430 Signal& operator=( const Signal& ); ///< undefined assignment operator
434 // Use composition instead of inheritance (virtual methods don't mix well with templates)
435 BaseSignal mImpl; ///< Implementation
439 * @brief A template for Signals with 1 parameter.
441 template < typename Arg0 >
442 class Signal< void ( Arg0 ) >
447 * @brief Default constructor.
454 * @brief Non-virtual destructor.
461 * @brief Query whether there are any connected slots.
463 * @return True if there are any slots connected to the signal.
467 return mImpl.Empty();
471 * @brief Query the number of slots.
473 * @return The number of slots connected to this signal.
475 std::size_t GetConnectionCount() const
477 return mImpl.GetConnectionCount();
480 * @brief Connect a function.
482 * @param[in] func The function to connect.
484 void Connect( void (*func)( Arg0 arg0 ) )
486 mImpl.OnConnect( MakeCallback( func ) );
490 * @brief Disconnect a function.
492 * @param[in] func The function to disconnect.
494 void Disconnect( void (*func)( Arg0 arg0 ) )
496 mImpl.OnDisconnect( MakeCallback( func ) );
500 * @brief Connect a member function.
502 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
503 * @param[in] func The member function to connect.
506 void Connect( X* obj, void (X::*func)( Arg0 arg0 ) )
508 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
512 * @brief Disconnect a member function.
514 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
515 * @param[in] func The member function to disconnect.
518 void Disconnect( X* obj, void (X::*func)( Arg0 arg0 ) )
520 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
524 * @brief Connect a member function.
526 * @param[in] delegate A slot delegate.
527 * @param[in] func The member function to connect.
530 void Connect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0 ) )
532 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
536 * @brief Disconnect a member function.
538 * @param[in] delegate A slot delegate.
539 * @param[in] func The member function to disconnect.
542 void Disconnect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0 ) )
544 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
548 * @brief Connect a function object.
550 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
551 * @param[in] func The function object to copy.
554 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
556 mImpl.OnConnect( connectionTracker, new CallbackFunctor1< X, Arg0 >( func ) );
560 * @brief Connect a function object using FunctorDelegate.
562 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
563 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
565 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
567 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegate1< Arg0 >( delegate ) );
571 * @brief Emit the signal.
573 * @param[in] arg0 The first value to pass to callbacks.
575 void Emit( Arg0 arg0 )
577 mImpl.Emit< Arg0 >( arg0 );
582 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
583 Signal& operator=( const Signal& ); ///< undefined assignment operator
587 // Use composition instead of inheritance (virtual methods don't mix well with templates)
588 BaseSignal mImpl; ///< Implementation
592 * @brief A template for Signals with 1 parameter and a return value.
594 template < typename Ret, typename Arg0 >
595 class Signal< Ret( Arg0 ) >
600 * @brief Default constructor.
607 * @brief Non-virtual destructor.
614 * @brief Query whether there are any connected slots.
616 * @return True if there are any slots connected to the signal.
620 return mImpl.Empty();
624 * @brief Query the number of slots.
626 * @return The number of slots connected to this signal.
628 std::size_t GetConnectionCount() const
630 return mImpl.GetConnectionCount();
633 * @brief Connect a function.
635 * @param[in] func The function to connect.
637 void Connect( Ret (*func)( Arg0 arg0 ) )
639 mImpl.OnConnect( MakeCallback( func ) );
643 * @brief Disconnect a function.
645 * @param[in] func The function to disconnect.
647 void Disconnect( Ret (*func)( Arg0 arg0 ) )
649 mImpl.OnDisconnect( MakeCallback( func ) );
653 * @brief Connect a member function.
655 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
656 * @param[in] func The member function to connect.
659 void Connect( X* obj, Ret (X::*func)( Arg0 arg0 ) )
661 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
665 * @brief Disconnect a member function.
667 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
668 * @param[in] func The member function to disconnect.
671 void Disconnect( X* obj, Ret (X::*func)( Arg0 arg0 ) )
673 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
677 * @brief Connect a member function.
679 * @param[in] delegate A slot delegate.
680 * @param[in] func The member function to connect.
683 void Connect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0 ) )
685 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
689 * @brief Disconnect a member function.
691 * @param[in] delegate A slot delegate.
692 * @param[in] func The member function to disconnect.
695 void Disconnect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0 ) )
697 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
701 * @brief Connect a function object.
703 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
704 * @param[in] func The function object to copy.
707 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
709 mImpl.OnConnect( connectionTracker, new CallbackFunctorReturn1< X, Arg0, Ret >( func ) );
713 * @brief Connect a function object using FunctorDelegate.
715 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
716 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
718 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
720 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegateReturn1< Arg0, Ret >( delegate ) );
724 * @brief Emit the signal.
726 * @param[in] arg0 The first value to pass to callbacks.
727 * @return The value returned by the last callback, or a default constructed value if no callbacks are connected.
729 Ret Emit( Arg0 arg0 )
731 return mImpl.EmitReturn< Ret,Arg0 >(arg0);
736 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
737 Signal& operator=( const Signal& ); ///< undefined assignment operator
741 // Use composition instead of inheritance (virtual methods don't mix well with templates)
742 BaseSignal mImpl; ///< Implementation
746 * @brief A template for Signals with 2 parameters.
749 template < typename Arg0, typename Arg1 >
750 class Signal< void ( Arg0, Arg1 ) >
755 * @brief Default constructor.
763 * @brief Non-virtual destructor.
771 * @brief Query whether there are any connected slots.
773 * @return True if there are any slots connected to the signal.
777 return mImpl.Empty();
781 * @brief Query the number of slots.
783 * @return The number of slots connected to this signal.
785 std::size_t GetConnectionCount() const
787 return mImpl.GetConnectionCount();
790 * @brief Connect a function.
792 * @param[in] func The function to connect.
794 void Connect( void (*func)( Arg0 arg0, Arg1 arg1 ) )
796 mImpl.OnConnect( MakeCallback( func ) );
800 * @brief Disconnect a function.
802 * @param[in] func The function to disconnect.
804 void Disconnect( void (*func)( Arg0 arg0, Arg1 arg1 ) )
806 mImpl.OnDisconnect( MakeCallback( func ) );
810 * @brief Connect a member function.
812 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
813 * @param[in] func The member function to connect.
816 void Connect( X* obj, void (X::*func)( Arg0 arg0, Arg1 arg1 ) )
818 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
822 * @brief Disconnect a member function.
824 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
825 * @param[in] func The member function to disconnect.
828 void Disconnect( X* obj, void (X::*func)( Arg0 arg0, Arg1 arg1 ) )
830 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
834 * @brief Connect a member function.
836 * @param[in] delegate A slot delegate.
837 * @param[in] func The member function to connect.
840 void Connect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0, Arg1 arg1 ) )
842 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
846 * @brief Disconnect a member function.
848 * @param[in] delegate A slot delegate.
849 * @param[in] func The member function to disconnect.
852 void Disconnect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0, Arg1 arg1 ) )
854 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
858 * @brief Connect a function object.
860 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
861 * @param[in] func The function object to copy.
864 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
866 mImpl.OnConnect( connectionTracker, new CallbackFunctor2< X, Arg0, Arg1 >( func ) );
870 * @brief Connect a function object using FunctorDelegate.
872 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
873 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
875 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
877 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegate2< Arg0, Arg1 >( delegate ) );
881 * @brief Emit the signal.
883 * @param[in] arg0 The first value to pass to callbacks.
884 * @param[in] arg1 The second value to pass to callbacks.
886 void Emit( Arg0 arg0, Arg1 arg1 )
888 mImpl.Emit< Arg0,Arg1 >( arg0, arg1 );
893 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
894 Signal& operator=( const Signal& ); ///< undefined assignment operator
898 // Use composition instead of inheritance (virtual methods don't mix well with templates)
899 BaseSignal mImpl; ///< Implementation
903 * @brief A template for Signals with 2 parameters and a return value.
905 template < typename Ret, typename Arg0, typename Arg1 >
906 class Signal< Ret( Arg0, Arg1 ) >
911 * @brief Default constructor.
918 * @brief Non-virtual destructor.
925 * @brief Query whether there are any connected slots.
927 * @return True if there are any slots connected to the signal.
931 return mImpl.Empty();
935 * @brief Query the number of slots.
937 * @return The number of slots connected to this signal.
939 std::size_t GetConnectionCount() const
941 return mImpl.GetConnectionCount();
944 * @brief Connect a function.
945 * @param[in] func The function to connect.
947 void Connect( Ret (*func)( Arg0 arg0, Arg1 arg1 ) )
949 mImpl.OnConnect( MakeCallback( func ) );
953 * @brief Disconnect a function.
955 * @param[in] func The function to disconnect.
957 void Disconnect( Ret (*func)( Arg0 arg0, Arg1 arg1 ) )
959 mImpl.OnDisconnect( MakeCallback( func ) );
963 * @brief Connect a member function.
965 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
966 * @param[in] func The member function to connect.
969 void Connect( X* obj, Ret (X::*func)( Arg0 arg0, Arg1 arg1 ) )
971 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
975 * @brief Disconnect a member function.
977 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
978 * @param[in] func The member function to disconnect.
981 void Disconnect( X* obj, Ret (X::*func)( Arg0 arg0, Arg1 arg1 ) )
983 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
987 * @brief Connect a member function.
989 * @param[in] delegate A slot delegate.
990 * @param[in] func The member function to connect.
993 void Connect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0, Arg1 arg1 ) )
995 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
999 * @brief Disconnect a member function.
1001 * @param[in] delegate A slot delegate.
1002 * @param[in] func The member function to disconnect.
1005 void Disconnect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0, Arg1 arg1 ) )
1007 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1011 * @brief Connect a function object.
1013 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
1014 * @param[in] func The function object to copy.
1017 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
1019 mImpl.OnConnect( connectionTracker, new CallbackFunctorReturn2< X, Arg0, Arg1, Ret >( func ) );
1023 * @brief Connect a function object using FunctorDelegate.
1025 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
1026 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
1028 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
1030 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegateReturn2< Arg0, Arg1, Ret >( delegate ) );
1034 * @brief Emit the signal.
1036 * @param[in] arg0 The first value to pass to callbacks.
1037 * @param[in] arg1 The second value to pass to callbacks.
1038 * @return The value returned by the last callback, or a default constructed value if no callbacks are connected.
1040 Ret Emit( Arg0 arg0, Arg1 arg1 )
1042 return mImpl.EmitReturn< Ret,Arg0,Arg1 >( arg0, arg1 );
1047 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
1048 Signal& operator=( const Signal& ); ///< undefined assignment operator
1052 // Use composition instead of inheritance (virtual methods don't mix well with templates)
1053 BaseSignal mImpl; ///< Implementation
1057 * @brief A template for Signals with 3 parameters.
1059 template < typename Arg0, typename Arg1, typename Arg2 >
1060 class Signal< void ( Arg0, Arg1, Arg2 ) >
1065 * @brief Default constructor.
1072 * @brief Non-virtual destructor.
1079 * @brief Query whether there are any connected slots.
1081 * @return True if there are any slots connected to the signal.
1085 return mImpl.Empty();
1089 * @brief Query the number of slots.
1091 * @return The number of slots connected to this signal.
1093 std::size_t GetConnectionCount() const
1095 return mImpl.GetConnectionCount();
1098 * @brief Connect a function.
1100 * @param[in] func The function to connect.
1102 void Connect( void (*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1104 mImpl.OnConnect( MakeCallback( func ) );
1108 * @brief Disconnect a function.
1110 * @param[in] func The function to disconnect.
1112 void Disconnect( void (*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1114 mImpl.OnDisconnect( MakeCallback( func ) );
1118 * @brief Connect a member function.
1120 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
1121 * @param[in] func The member function to connect.
1124 void Connect( X* obj, void (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1126 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
1130 * @brief Disconnect a member function.
1132 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
1133 * @param[in] func The member function to disconnect.
1136 void Disconnect( X* obj, void (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1138 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
1142 * @brief Connect a member function.
1144 * @param[in] delegate A slot delegate.
1145 * @param[in] func The member function to connect.
1148 void Connect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1150 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1154 * @brief Disconnect a member function.
1156 * @param[in] delegate A slot delegate.
1157 * @param[in] func The member function to disconnect.
1160 void Disconnect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1162 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1166 * @brief Connect a function object.
1168 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
1169 * @param[in] func The function object to copy.
1172 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
1174 mImpl.OnConnect( connectionTracker, new CallbackFunctor3< X, Arg0, Arg1, Arg2 >( func ) );
1178 * @brief Connect a function object using FunctorDelegate.
1180 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
1181 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
1183 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
1185 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegate3< Arg0, Arg1, Arg2 >( delegate ) );
1189 * @brief Emit the signal.
1191 * @param[in] arg0 The first value to pass to callbacks.
1192 * @param[in] arg1 The second value to pass to callbacks.
1193 * @param[in] arg2 The third value to pass to callbacks.
1195 void Emit( Arg0 arg0, Arg1 arg1, Arg2 arg2 )
1197 mImpl.Emit< Arg0,Arg1,Arg2 >( arg0, arg1, arg2 );
1202 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
1203 Signal& operator=( const Signal& ); ///< undefined assignment operator
1207 // Use composition instead of inheritance (virtual methods don't mix well with templates)
1208 BaseSignal mImpl; ///< Implementation
1212 * @brief A template for Signals with 2 parameters and a return value.
1214 template < typename Ret, typename Arg0, typename Arg1, typename Arg2 >
1215 class Signal< Ret( Arg0, Arg1, Arg2 ) >
1220 * @brief Default constructor.
1227 * @brief Non-virtual destructor.
1234 * @brief Query whether there are any connected slots.
1236 * @return True if there are any slots connected to the signal.
1240 return mImpl.Empty();
1244 * @brief Query the number of slots.
1246 * @return The number of slots connected to this signal.
1248 std::size_t GetConnectionCount() const
1250 return mImpl.GetConnectionCount();
1254 * @brief Connect a function.
1256 * @param[in] func The function to connect.
1258 void Connect( Ret (*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1260 mImpl.OnConnect( MakeCallback( func ) );
1264 * @brief Disconnect a function.
1266 * @param[in] func The function to disconnect.
1268 void Disconnect( Ret (*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1270 mImpl.OnDisconnect( MakeCallback( func ) );
1274 * @brief Connect a member function.
1276 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
1277 * @param[in] func The member function to connect.
1280 void Connect( X* obj, Ret (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1282 mImpl.OnConnect( obj, MakeCallback( obj, func ) );
1286 * @brief Disconnect a member function.
1288 * @param[in] obj An object which must implement the ConnectionTrackerInterface.
1289 * @param[in] func The member function to disconnect.
1292 void Disconnect( X* obj, Ret (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1294 mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
1298 * @brief Connect a member function.
1300 * @param[in] delegate A slot delegate.
1301 * @param[in] func The member function to connect.
1304 void Connect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1306 mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1310 * @brief Disconnect a member function.
1312 * @param[in] delegate A slot delegate.
1313 * @param[in] func The member function to disconnect.
1316 void Disconnect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1318 mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1322 * @brief Connect a function object.
1324 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
1325 * @param[in] func The function object to copy.
1328 void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
1330 mImpl.OnConnect( connectionTracker, new CallbackFunctorReturn3< X, Arg0, Arg1, Arg2, Ret >( func ) );
1334 * @brief Connect a function object using FunctorDelegate.
1336 * @param[in] connectionTracker A connection tracker which can be used to disconnect.
1337 * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken).
1339 void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
1341 mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegateReturn3< Arg0, Arg1, Arg2, Ret >( delegate ) );
1345 * @brief Emit the signal.
1347 * @param[in] arg0 The first value to pass to callbacks.
1348 * @param[in] arg1 The second value to pass to callbacks.
1349 * @param[in] arg2 The third value to pass to callbacks.
1350 * @return The value returned by the last callback, or a default constructed value if no callbacks are connected.
1352 Ret Emit( Arg0 arg0, Arg1 arg1, Arg2 arg2 )
1354 return mImpl.EmitReturn< Ret,Arg0,Arg1,Arg2 >( arg0, arg1, arg2 );
1359 Signal( const Signal& ); ///< undefined copy constructor, signals don't support copying.
1360 Signal& operator=( const Signal& ); ///< undefined assignment operator
1364 // Use composition instead of inheritance (virtual methods don't mix well with templates)
1365 BaseSignal mImpl; ///< Implementation
1370 #endif // __DALI_SIGNAL_H__