Renamed TouchSignal to TouchedSignal
[platform/core/uifw/dali-core.git] / dali / public-api / signals / dali-signal.h
1 #ifndef DALI_SIGNAL_H
2 #define DALI_SIGNAL_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 /**
22  * @brief The class should implement Dali::ConnectionTrackerInterface, or inherit from Dali::ConnectionTracker.
23  *
24  * This enforces automatic disconnection when an object is destroyed, so you don't have
25  * to manually disconnect from signals.
26  *
27  * Alternatively, you can use a Dali::SlotDelegate if you don't want to inherit.
28  *
29  * E.g:
30  * @code
31  * class MyClass : public ConnectionTracker
32  * {
33  *
34  *   void Callback( Actor actor, const TouchEvent& event )
35  *   {
36  *     ...
37  *   }
38  *
39  *   void Init()
40  *   {
41  *     Actor actor = Actor::New();
42  *
43  *     actor.TouchedSignal().Connect( this, &MyClass::Callback );
44  *   }
45  *
46  *   ~MyClass()
47  *   {
48  *     // ConnectionTracker base class automatically disconnects
49  *   }
50  * }
51  * @endcode
52  * @SINCE_1_0.0
53  */
54
55 // INTERNAL INCLUDES
56 #include <dali/public-api/common/dali-common.h>
57 #include <dali/public-api/signals/callback.h>
58 #include <dali/public-api/signals/signal-slot-connections.h>
59 #include <dali/public-api/signals/slot-delegate.h>
60 #include <dali/public-api/signals/base-signal.h>
61
62 namespace Dali
63 {
64 /**
65  * @addtogroup dali_core_signals
66  * @{
67  */
68
69 /**
70  * @brief Base Template class to provide signals.
71  *
72  * To create a signal for this class, you first have to define a typedef within your handle's scope:
73  * @code
74  * class MyHandle : public Handle
75  * {
76  * public:
77  *
78  *   // Typedefs
79  *
80  *   typedef Signal< void ()> VoidSignalType;         ///< For signals that require no parameters and no return value
81  *   typedef Signal< bool ()> BoolSignalType;         ///< For signals that do not need parameters but require a boolean return
82  *   typedef Signal< void ( float )> ParamSignalType; ///< For signals that need a float as a parameter but no return value
83  *
84  *   ...
85  *
86  * public:
87  *
88  *   // Signals
89  *
90  *   VoidSignalType&  VoidSignal();
91  *   BoolSignalType&  BoolSignal();
92  *   ParamSignalType& ParamSignal();
93  *
94  *   ...
95  * };
96  * @endcode
97  * The methods are required in the handle class so that the application writer can retrieve the Signal in order to connect/disconnect.
98  *
99  * In the implementation class, the members should be defined and the methods should be provided to retrieve the signal itself.
100  * These will be called by the equivalent methods in the MyHandle class.
101  * @code
102  * class MyObject : public Object
103  * {
104  *   ...
105  *
106  * public:
107  *
108  *   MyHandle::VoidSignalType&  VoidSignal()
109  *   {
110  *     return mVoidSignal;
111  *   }
112  *
113  *   MyHandle::BoolSignalType&  BoolSignal()
114  *   {
115  *     return mBoolSignal;
116  *   }
117  *
118  *   MyHandle::ParamSignalType& ParamSignal()
119  *   {
120  *     return mParamSignal;
121  *   }
122  *
123  * private:
124  *
125  *   // Signals
126  *   MyHandle::VoidSignalType   mVoidSignal;
127  *   MyHandle::BoolSignalType   mBoolSignal;
128  *   MyHandle::ParamSignalType  mParamSignal;
129  *
130  *   ...
131  * };
132  * @endcode
133  * @SINCE_1_0.0
134  */
135 template< typename _Signature >
136 class Signal
137 {
138 };
139
140 /**
141  * @brief A template for Signals with no parameters or return value.
142  * @SINCE_1_0.0
143  */
144 template <>
145 class Signal< void () >
146 {
147 public:
148
149   /**
150    * @brief Default constructor.
151    * @SINCE_1_0.0
152    */
153   Signal()
154   {
155   }
156
157   /**
158    * @brief Non-virtual destructor.
159    * @SINCE_1_0.0
160    */
161   ~Signal()
162   {
163   }
164
165   /**
166    * @brief Queries whether there are any connected slots.
167    *
168    * @SINCE_1_0.0
169    * @return True if there are any slots connected to the signal
170    */
171   bool Empty() const
172   {
173     return mImpl.Empty();
174   }
175
176   /**
177    * @brief Queries the number of slots.
178    *
179    * @SINCE_1_0.0
180    * @return The number of slots connected to this signal
181    */
182   std::size_t GetConnectionCount() const
183   {
184     return mImpl.GetConnectionCount();
185   }
186
187   /**
188    * @brief Connects a function.
189    *
190    * @SINCE_1_0.0
191    * @param[in] func The function to connect
192    */
193   void Connect( void (*func)() )
194   {
195     mImpl.OnConnect( MakeCallback( func ) );
196   }
197
198   /**
199    * @brief Disconnects a function.
200    *
201    * @SINCE_1_0.0
202    * @param[in] func The function to disconnect
203    */
204   void Disconnect( void (*func)() )
205   {
206     mImpl.OnDisconnect( MakeCallback( func ) );
207   }
208
209   /**
210    * @brief Connects a member function.
211    *
212    * @SINCE_1_0.0
213    * @param[in] obj An object which must implement the ConnectionTrackerInterface
214    * @param[in] func The member function to connect
215    */
216   template<class X>
217   void Connect( X* obj, void (X::*func)() )
218   {
219     mImpl.OnConnect( obj, MakeCallback( obj, func ) );
220   }
221
222   /**
223    * @brief Disconnects a member function.
224    *
225    * @SINCE_1_0.0
226    * @param[in] obj An object which must implement the ConnectionTrackerInterface
227    * @param[in] func The member function to disconnect
228    */
229   template<class X>
230   void Disconnect( X* obj, void (X::*func)() )
231   {
232     mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
233   }
234
235   /**
236    * @brief Connects a member function.
237    *
238    * @SINCE_1_0.0
239    * @param[in] delegate A slot delegate
240    * @param[in] func The member function to connect
241    */
242   template<class X>
243   void Connect( SlotDelegate<X>& delegate, void (X::*func)() )
244   {
245     mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
246   }
247
248   /**
249    * @brief Disconnects a member function.
250    *
251    * @SINCE_1_0.0
252    * @param[in] delegate A slot delegate
253    * @param[in] func The member function to disconnect
254    */
255   template<class X>
256   void Disconnect( SlotDelegate<X>& delegate, void (X::*func)() )
257   {
258     mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
259   }
260
261   /**
262    * @brief Connects a function object.
263    *
264    * @SINCE_1_0.0
265    * @param[in] connectionTracker A connection tracker which can be used to disconnect
266    * @param[in] func The function object to copy
267    */
268   template<class X>
269   void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
270   {
271     mImpl.OnConnect( connectionTracker, new CallbackFunctor0< X >( func ) );
272   }
273
274   /**
275    * @brief Connects a function object using FunctorDelegate.
276    *
277    * @SINCE_1_0.0
278    * @param[in] connectionTracker A connection tracker which can be used to disconnect
279    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
280    */
281   void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
282   {
283     mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegate0( delegate ) );
284   }
285
286   /**
287    * @brief Emits the signal.
288    * @SINCE_1_0.0
289    */
290   void Emit()
291   {
292     mImpl.Emit();
293   }
294
295 private:
296
297   Signal( const Signal& ) = delete; ///< Deleted copy constructor, signals don't support copying. @SINCE_1_0.0
298   Signal( Signal&& ) = delete; ///< Deleted move constructor, signals don't support moving. @SINCE_1_9.25
299   Signal& operator=( const Signal& ) = delete; ///< Deleted copy assignment operator @SINCE_1_0.0
300   Signal& operator=( Signal&& ) = delete; ///< Deleted move assignment operator @SINCE_1_9.25
301
302 private:
303
304   // Use composition instead of inheritance (virtual methods don't mix well with templates)
305   BaseSignal mImpl; ///< The base signal implementation
306 };
307
308 /**
309  * @brief A template for Signals with no parameters and a return value.
310  * @SINCE_1_0.0
311  */
312 template < typename Ret >
313 class Signal< Ret() >
314 {
315 public:
316
317   /**
318    * @brief Default constructor.
319    * @SINCE_1_0.0
320    */
321   Signal()
322   {
323   }
324
325   /**
326    * @brief Non-virtual destructor.
327    * @SINCE_1_0.0
328    */
329   ~Signal()
330   {
331   }
332
333   /**
334    * @brief Queries whether there are any connected slots.
335    *
336    * @SINCE_1_0.0
337    * @return True if there are any slots connected to the signal
338    */
339   bool Empty() const
340   {
341     return mImpl.Empty();
342   }
343
344   /**
345    * @brief Queries the number of slots.
346    *
347    * @SINCE_1_0.0
348    * @return The number of slots connected to this signal
349    */
350   std::size_t GetConnectionCount() const
351   {
352     return mImpl.GetConnectionCount();
353   }
354   /**
355    * @brief Connects a function.
356    *
357    * @SINCE_1_0.0
358    * @param[in] func The function to connect
359    */
360   void Connect( Ret (*func)() )
361   {
362     mImpl.OnConnect( MakeCallback( func ) );
363   }
364
365   /**
366    * @brief Disconnects a function.
367    *
368    * @SINCE_1_0.0
369    * @param[in] func The function to disconnect
370    */
371   void Disconnect( Ret (*func)() )
372   {
373     mImpl.OnDisconnect( MakeCallback( func ) );
374   }
375
376   /**
377    * @brief Connects a member function.
378    *
379    * @SINCE_1_0.0
380    * @param[in] obj An object which must implement the ConnectionTrackerInterface
381    * @param[in] func The member function to connect
382    */
383   template<class X>
384   void Connect( X* obj, Ret (X::*func)() )
385   {
386     mImpl.OnConnect( obj, MakeCallback( obj, func ) );
387   }
388
389   /**
390    * @brief Disconnects a member function.
391    *
392    * @SINCE_1_0.0
393    * @param[in] obj An object which must implement the ConnectionTrackerInterface
394    * @param[in] func The member function to disconnect
395    */
396   template<class X>
397   void Disconnect( X* obj, Ret (X::*func)() )
398   {
399     mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
400   }
401
402   /**
403    * @brief Connects a member function.
404    *
405    * @SINCE_1_0.0
406    * @param[in] delegate A slot delegate
407    * @param[in] func The member function to connect
408    */
409   template<class X>
410   void Connect( SlotDelegate<X>& delegate, Ret (X::*func)() )
411   {
412     mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
413   }
414
415   /**
416    * @brief Disconnects a member function.
417    *
418    * @SINCE_1_0.0
419    * @param[in] delegate A slot delegate
420    * @param[in] func The member function to disconnect
421    */
422   template<class X>
423   void Disconnect( SlotDelegate<X>& delegate, Ret (X::*func)() )
424   {
425     mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
426   }
427
428   /**
429    * @brief Connects a function object.
430    *
431    * @SINCE_1_0.0
432    * @param[in] connectionTracker A connection tracker which can be used to disconnect
433    * @param[in] func The function object to copy
434    */
435   template<class X>
436   void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
437   {
438     mImpl.OnConnect( connectionTracker, new CallbackFunctorReturn0< X, Ret >( func ) );
439   }
440
441   /**
442    * @brief Connects a function object using FunctorDelegate.
443    *
444    * @SINCE_1_0.0
445    * @param[in] connectionTracker A connection tracker which can be used to disconnect
446    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
447    */
448   void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
449   {
450     mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegateReturn0< Ret >( delegate ) );
451   }
452
453   /**
454    * @brief Emits the signal.
455    *
456    * @SINCE_1_0.0
457    * @return The value returned by the last callback, or a default constructed value if no callbacks are connected
458    */
459   Ret Emit()
460   {
461     return mImpl.EmitReturn< Ret >();
462   }
463
464 private:
465
466   Signal( const Signal& ) = delete; ///< Deleted copy constructor, signals don't support copying. @SINCE_1_0.0
467   Signal( Signal&& ) = delete; ///< Deleted move constructor, signals don't support moving. @SINCE_1_9.25
468   Signal& operator=( const Signal& ) = delete; ///< Deleted copy assignment operator @SINCE_1_0.0
469   Signal& operator=( Signal&& ) = delete; ///< Deleted move assignment operator @SINCE_1_9.25
470
471 private:
472
473   // Use composition instead of inheritance (virtual methods don't mix well with templates)
474   BaseSignal mImpl; ///< Implementation
475 };
476
477 /**
478  * @brief A template for Signals with 1 parameter.
479  * @SINCE_1_0.0
480  */
481 template < typename Arg0 >
482 class Signal< void ( Arg0 ) >
483 {
484 public:
485
486   /**
487    * @brief Default constructor.
488    * @SINCE_1_0.0
489    */
490   Signal()
491   {
492   }
493
494   /**
495    * @brief Non-virtual destructor.
496    * @SINCE_1_0.0
497    */
498   ~Signal()
499   {
500   }
501
502   /**
503    * @brief Queries whether there are any connected slots.
504    *
505    * @SINCE_1_0.0
506    * @return True if there are any slots connected to the signal
507    */
508   bool Empty() const
509   {
510     return mImpl.Empty();
511   }
512
513   /**
514    * @brief Queries the number of slots.
515    *
516    * @SINCE_1_0.0
517    * @return The number of slots connected to this signal
518    */
519   std::size_t GetConnectionCount() const
520   {
521     return mImpl.GetConnectionCount();
522   }
523   /**
524    * @brief Connects a function.
525    *
526    * @SINCE_1_0.0
527    * @param[in] func The function to connect
528    */
529   void Connect( void (*func)( Arg0 arg0 ) )
530   {
531     mImpl.OnConnect( MakeCallback( func ) );
532   }
533
534   /**
535    * @brief Disconnects a function.
536    *
537    * @SINCE_1_0.0
538    * @param[in] func The function to disconnect
539    */
540   void Disconnect( void (*func)( Arg0 arg0 ) )
541   {
542     mImpl.OnDisconnect( MakeCallback( func ) );
543   }
544
545   /**
546    * @brief Connects a member function.
547    *
548    * @SINCE_1_0.0
549    * @param[in] obj An object which must implement the ConnectionTrackerInterface
550    * @param[in] func The member function to connect
551    */
552   template<class X>
553   void Connect( X* obj, void (X::*func)( Arg0 arg0 ) )
554   {
555     mImpl.OnConnect( obj, MakeCallback( obj, func ) );
556   }
557
558   /**
559    * @brief Disconnects a member function.
560    *
561    * @SINCE_1_0.0
562    * @param[in] obj An object which must implement the ConnectionTrackerInterface
563    * @param[in] func The member function to disconnect
564    */
565   template<class X>
566   void Disconnect( X* obj, void (X::*func)( Arg0 arg0 ) )
567   {
568     mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
569   }
570
571   /**
572    * @brief Connects a member function.
573    *
574    * @SINCE_1_0.0
575    * @param[in] delegate A slot delegate
576    * @param[in] func The member function to connect
577    */
578   template<class X>
579   void Connect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0 ) )
580   {
581     mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
582   }
583
584   /**
585    * @brief Disconnects a member function.
586    *
587    * @SINCE_1_0.0
588    * @param[in] delegate A slot delegate
589    * @param[in] func The member function to disconnect
590    */
591   template<class X>
592   void Disconnect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0 ) )
593   {
594     mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
595   }
596
597   /**
598    * @brief Connects a function object.
599    *
600    * @SINCE_1_0.0
601    * @param[in] connectionTracker A connection tracker which can be used to disconnect
602    * @param[in] func The function object to copy
603    */
604   template<class X>
605   void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
606   {
607     mImpl.OnConnect( connectionTracker, new CallbackFunctor1< X, Arg0 >( func ) );
608   }
609
610   /**
611    * @brief Connects a function object using FunctorDelegate.
612    *
613    * @SINCE_1_0.0
614    * @param[in] connectionTracker A connection tracker which can be used to disconnect
615    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
616    */
617   void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
618   {
619     mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegate1< Arg0 >( delegate ) );
620   }
621
622   /**
623    * @brief Emits the signal.
624    *
625    * @SINCE_1_0.0
626    * @param[in] arg0 The first value to pass to callbacks
627    */
628   void Emit( Arg0 arg0 )
629   {
630     mImpl.Emit< Arg0 >( arg0 );
631   }
632
633 private:
634
635   Signal( const Signal& ) = delete; ///< Deleted copy constructor, signals don't support copying. @SINCE_1_0.0
636   Signal( Signal&& ) = delete; ///< Deleted move constructor, signals don't support moving. @SINCE_1_9.25
637   Signal& operator=( const Signal& ) = delete; ///< Deleted copy assignment operator @SINCE_1_0.0
638   Signal& operator=( Signal&& ) = delete; ///< Deleted move assignment operator @SINCE_1_9.25
639
640 private:
641
642   // Use composition instead of inheritance (virtual methods don't mix well with templates)
643   BaseSignal mImpl; ///< Implementation
644 };
645
646 /**
647  * @brief A template for Signals with 1 parameter and a return value.
648  * @SINCE_1_0.0
649  */
650 template < typename Ret, typename Arg0 >
651 class Signal< Ret( Arg0 ) >
652 {
653 public:
654
655   /**
656    * @brief Default constructor.
657    * @SINCE_1_0.0
658    */
659   Signal()
660   {
661   }
662
663   /**
664    * @brief Non-virtual destructor.
665    * @SINCE_1_0.0
666    */
667   ~Signal()
668   {
669   }
670
671   /**
672    * @brief Queries whether there are any connected slots.
673    *
674    * @SINCE_1_0.0
675    * @return True if there are any slots connected to the signal
676    */
677   bool Empty() const
678   {
679     return mImpl.Empty();
680   }
681
682   /**
683    * @brief Queries the number of slots.
684    *
685    * @SINCE_1_0.0
686    * @return The number of slots connected to this signal
687    */
688   std::size_t GetConnectionCount() const
689   {
690     return mImpl.GetConnectionCount();
691   }
692   /**
693    * @brief Connects a function.
694    *
695    * @SINCE_1_0.0
696    * @param[in] func The function to connect
697    */
698   void Connect( Ret (*func)( Arg0 arg0 ) )
699   {
700     mImpl.OnConnect( MakeCallback( func ) );
701   }
702
703   /**
704    * @brief Disconnects a function.
705    *
706    * @SINCE_1_0.0
707    * @param[in] func The function to disconnect
708    */
709   void Disconnect( Ret (*func)( Arg0 arg0 ) )
710   {
711     mImpl.OnDisconnect( MakeCallback( func ) );
712   }
713
714   /**
715    * @brief Connects a member function.
716    *
717    * @SINCE_1_0.0
718    * @param[in] obj An object which must implement the ConnectionTrackerInterface
719    * @param[in] func The member function to connect
720    */
721   template<class X>
722   void Connect( X* obj, Ret (X::*func)( Arg0 arg0 ) )
723   {
724     mImpl.OnConnect( obj, MakeCallback( obj, func ) );
725   }
726
727   /**
728    * @brief Disconnects a member function.
729    *
730    * @SINCE_1_0.0
731    * @param[in] obj An object which must implement the ConnectionTrackerInterface
732    * @param[in] func The member function to disconnect
733    */
734   template<class X>
735   void Disconnect( X* obj, Ret (X::*func)( Arg0 arg0 ) )
736   {
737     mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
738   }
739
740   /**
741    * @brief Connects a member function.
742    *
743    * @SINCE_1_0.0
744    * @param[in] delegate A slot delegate
745    * @param[in] func The member function to connect
746    */
747   template<class X>
748   void Connect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0 ) )
749   {
750     mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
751   }
752
753   /**
754    * @brief Disconnects a member function.
755    *
756    * @SINCE_1_0.0
757    * @param[in] delegate A slot delegate
758    * @param[in] func The member function to disconnect
759    */
760   template<class X>
761   void Disconnect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0 ) )
762   {
763     mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
764   }
765
766   /**
767    * @brief Connects a function object.
768    *
769    * @SINCE_1_0.0
770    * @param[in] connectionTracker A connection tracker which can be used to disconnect
771    * @param[in] func The function object to copy
772    */
773   template<class X>
774   void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
775   {
776     mImpl.OnConnect( connectionTracker, new CallbackFunctorReturn1< X, Arg0, Ret >( func ) );
777   }
778
779   /**
780    * @brief Connects a function object using FunctorDelegate.
781    *
782    * @SINCE_1_0.0
783    * @param[in] connectionTracker A connection tracker which can be used to disconnect
784    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
785    */
786   void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
787   {
788     mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegateReturn1< Arg0, Ret >( delegate ) );
789   }
790
791   /**
792    * @brief Emits the signal.
793    *
794    * @SINCE_1_0.0
795    * @param[in] arg0 The first value to pass to callbacks
796    * @return The value returned by the last callback, or a default constructed value if no callbacks are connected
797    */
798   Ret Emit( Arg0 arg0 )
799   {
800     return mImpl.EmitReturn< Ret,Arg0 >(arg0);
801   }
802
803 private:
804
805   Signal( const Signal& ) = delete; ///< Deleted copy constructor, signals don't support copying. @SINCE_1_0.0
806   Signal( Signal&& ) = delete; ///< Deleted move constructor, signals don't support moving. @SINCE_1_9.25
807   Signal& operator=( const Signal& ) = delete; ///< Deleted copy assignment operator @SINCE_1_0.0
808   Signal& operator=( Signal&& ) = delete; ///< Deleted move assignment operator @SINCE_1_9.25
809
810 private:
811
812   // Use composition instead of inheritance (virtual methods don't mix well with templates)
813   BaseSignal mImpl; ///< Implementation
814 };
815
816 /**
817  * @brief A template for Signals with 2 parameters.
818  *
819  * @SINCE_1_0.0
820  */
821 template < typename Arg0, typename Arg1 >
822 class Signal< void ( Arg0, Arg1 ) >
823 {
824 public:
825
826   /**
827    * @brief Default constructor.
828    *
829    * @SINCE_1_0.0
830    */
831   Signal()
832   {
833   }
834
835   /**
836    * @brief Non-virtual destructor.
837    *
838    * @SINCE_1_0.0
839    */
840   ~Signal()
841   {
842   }
843
844   /**
845    * @brief Queries whether there are any connected slots.
846    *
847    * @SINCE_1_0.0
848    * @return True if there are any slots connected to the signal
849    */
850   bool Empty() const
851   {
852     return mImpl.Empty();
853   }
854
855   /**
856    * @brief Queries the number of slots.
857    *
858    * @SINCE_1_0.0
859    * @return The number of slots connected to this signal
860    */
861   std::size_t GetConnectionCount() const
862   {
863     return mImpl.GetConnectionCount();
864   }
865   /**
866    * @brief Connects a function.
867    *
868    * @SINCE_1_0.0
869    * @param[in] func The function to connect
870    */
871   void Connect( void (*func)( Arg0 arg0, Arg1 arg1 ) )
872   {
873     mImpl.OnConnect( MakeCallback( func ) );
874   }
875
876   /**
877    * @brief Disconnects a function.
878    *
879    * @SINCE_1_0.0
880    * @param[in] func The function to disconnect
881    */
882   void Disconnect( void (*func)( Arg0 arg0, Arg1 arg1 ) )
883   {
884     mImpl.OnDisconnect( MakeCallback( func ) );
885   }
886
887   /**
888    * @brief Connects a member function.
889    *
890    * @SINCE_1_0.0
891    * @param[in] obj An object which must implement the ConnectionTrackerInterface
892    * @param[in] func The member function to connect
893    */
894   template<class X>
895   void Connect( X* obj, void (X::*func)( Arg0 arg0, Arg1 arg1 ) )
896   {
897     mImpl.OnConnect( obj, MakeCallback( obj, func ) );
898   }
899
900   /**
901    * @brief Disconnects a member function.
902    *
903    * @SINCE_1_0.0
904    * @param[in] obj An object which must implement the ConnectionTrackerInterface
905    * @param[in] func The member function to disconnect
906    */
907   template<class X>
908   void Disconnect( X* obj, void (X::*func)( Arg0 arg0, Arg1 arg1 ) )
909   {
910     mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
911   }
912
913   /**
914    * @brief Connects a member function.
915    *
916    * @SINCE_1_0.0
917    * @param[in] delegate A slot delegate
918    * @param[in] func The member function to connect
919    */
920   template<class X>
921   void Connect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0, Arg1 arg1 ) )
922   {
923     mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
924   }
925
926   /**
927    * @brief Disconnects a member function.
928    *
929    * @SINCE_1_0.0
930    * @param[in] delegate A slot delegate
931    * @param[in] func The member function to disconnect
932    */
933   template<class X>
934   void Disconnect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0, Arg1 arg1 ) )
935   {
936     mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
937   }
938
939   /**
940    * @brief Connects a function object.
941    *
942    * @SINCE_1_0.0
943    * @param[in] connectionTracker A connection tracker which can be used to disconnect
944    * @param[in] func The function object to copy
945    */
946   template<class X>
947   void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
948   {
949     mImpl.OnConnect( connectionTracker, new CallbackFunctor2< X, Arg0, Arg1 >( func ) );
950   }
951
952   /**
953    * @brief Connects a function object using FunctorDelegate.
954    *
955    * @SINCE_1_0.0
956    * @param[in] connectionTracker A connection tracker which can be used to disconnect
957    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
958    */
959   void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
960   {
961     mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegate2< Arg0, Arg1 >( delegate ) );
962   }
963
964   /**
965    * @brief Emits the signal.
966    *
967    * @SINCE_1_0.0
968    * @param[in] arg0 The first value to pass to callbacks
969    * @param[in] arg1 The second value to pass to callbacks
970    */
971   void Emit( Arg0 arg0, Arg1 arg1 )
972   {
973     mImpl.Emit< Arg0,Arg1 >( arg0, arg1 );
974   }
975
976 private:
977
978   Signal( const Signal& ) = delete; ///< Deleted copy constructor, signals don't support copying. @SINCE_1_0.0
979   Signal( Signal&& ) = delete; ///< Deleted move constructor, signals don't support moving. @SINCE_1_9.25
980   Signal& operator=( const Signal& ) = delete; ///< Deleted copy assignment operator @SINCE_1_0.0
981   Signal& operator=( Signal&& ) = delete; ///< Deleted move assignment operator @SINCE_1_9.25
982
983 private:
984
985   // Use composition instead of inheritance (virtual methods don't mix well with templates)
986   BaseSignal mImpl; ///< Implementation
987 };
988
989 /**
990  * @brief A template for Signals with 2 parameters and a return value.
991  * @SINCE_1_0.0
992  */
993 template < typename Ret, typename Arg0, typename Arg1 >
994 class Signal< Ret( Arg0, Arg1 ) >
995 {
996 public:
997
998   /**
999    * @brief Default constructor.
1000    * @SINCE_1_0.0
1001    */
1002   Signal()
1003   {
1004   }
1005
1006   /**
1007    * @brief Non-virtual destructor.
1008    * @SINCE_1_0.0
1009    */
1010   ~Signal()
1011   {
1012   }
1013
1014   /**
1015    * @brief Queries whether there are any connected slots.
1016    *
1017    * @SINCE_1_0.0
1018    * @return True if there are any slots connected to the signal
1019    */
1020   bool Empty() const
1021   {
1022     return mImpl.Empty();
1023   }
1024
1025   /**
1026    * @brief Queries the number of slots.
1027    *
1028    * @SINCE_1_0.0
1029    * @return The number of slots connected to this signal
1030    */
1031   std::size_t GetConnectionCount() const
1032   {
1033     return mImpl.GetConnectionCount();
1034   }
1035   /**
1036    * @brief Connects a function.
1037    * @SINCE_1_0.0
1038    * @param[in] func The function to connect
1039    */
1040   void Connect( Ret (*func)( Arg0 arg0, Arg1 arg1 ) )
1041   {
1042     mImpl.OnConnect( MakeCallback( func ) );
1043   }
1044
1045   /**
1046    * @brief Disconnects a function.
1047    *
1048    * @SINCE_1_0.0
1049    * @param[in] func The function to disconnect
1050    */
1051   void Disconnect( Ret (*func)( Arg0 arg0, Arg1 arg1 ) )
1052   {
1053     mImpl.OnDisconnect( MakeCallback( func ) );
1054   }
1055
1056   /**
1057    * @brief Connects a member function.
1058    *
1059    * @SINCE_1_0.0
1060    * @param[in] obj An object which must implement the ConnectionTrackerInterface
1061    * @param[in] func The member function to connect
1062    */
1063   template<class X>
1064   void Connect( X* obj, Ret (X::*func)( Arg0 arg0, Arg1 arg1 ) )
1065   {
1066     mImpl.OnConnect( obj, MakeCallback( obj, func ) );
1067   }
1068
1069   /**
1070    * @brief Disconnects a member function.
1071    *
1072    * @SINCE_1_0.0
1073    * @param[in] obj An object which must implement the ConnectionTrackerInterface
1074    * @param[in] func The member function to disconnect
1075    */
1076   template<class X>
1077   void Disconnect( X* obj, Ret (X::*func)( Arg0 arg0, Arg1 arg1 ) )
1078   {
1079     mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
1080   }
1081
1082   /**
1083    * @brief Connects a member function.
1084    *
1085    * @SINCE_1_0.0
1086    * @param[in] delegate A slot delegate
1087    * @param[in] func The member function to connect
1088    */
1089   template<class X>
1090   void Connect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0, Arg1 arg1 ) )
1091   {
1092     mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1093   }
1094
1095   /**
1096    * @brief Disconnects a member function.
1097    *
1098    * @SINCE_1_0.0
1099    * @param[in] delegate A slot delegate
1100    * @param[in] func The member function to disconnect
1101    */
1102   template<class X>
1103   void Disconnect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0, Arg1 arg1 ) )
1104   {
1105     mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1106   }
1107
1108   /**
1109    * @brief Connects a function object.
1110    *
1111    * @SINCE_1_0.0
1112    * @param[in] connectionTracker A connection tracker which can be used to disconnect
1113    * @param[in] func The function object to copy
1114    */
1115   template<class X>
1116   void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
1117   {
1118     mImpl.OnConnect( connectionTracker, new CallbackFunctorReturn2< X, Arg0, Arg1, Ret >( func ) );
1119   }
1120
1121   /**
1122    * @brief Connects a function object using FunctorDelegate.
1123    *
1124    * @SINCE_1_0.0
1125    * @param[in] connectionTracker A connection tracker which can be used to disconnect
1126    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
1127    */
1128   void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
1129   {
1130     mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegateReturn2< Arg0, Arg1, Ret >( delegate ) );
1131   }
1132
1133   /**
1134    * @brief Emits the signal.
1135    *
1136    * @SINCE_1_0.0
1137    * @param[in] arg0 The first value to pass to callbacks
1138    * @param[in] arg1 The second value to pass to callbacks
1139    * @return The value returned by the last callback, or a default constructed value if no callbacks are connected
1140    */
1141   Ret Emit( Arg0 arg0, Arg1 arg1 )
1142   {
1143     return mImpl.EmitReturn< Ret,Arg0,Arg1 >( arg0, arg1 );
1144   }
1145
1146 private:
1147
1148   Signal( const Signal& ) = delete; ///< Deleted copy constructor, signals don't support copying. @SINCE_1_0.0
1149   Signal( Signal&& ) = delete; ///< Deleted move constructor, signals don't support moving. @SINCE_1_9.25
1150   Signal& operator=( const Signal& ) = delete; ///< Deleted copy assignment operator @SINCE_1_0.0
1151   Signal& operator=( Signal&& ) = delete; ///< Deleted move assignment operator @SINCE_1_9.25
1152
1153 private:
1154
1155   // Use composition instead of inheritance (virtual methods don't mix well with templates)
1156   BaseSignal mImpl; ///< Implementation
1157 };
1158
1159 /**
1160  * @brief A template for Signals with 3 parameters.
1161  * @SINCE_1_0.0
1162  */
1163 template < typename Arg0, typename Arg1, typename Arg2 >
1164 class Signal< void ( Arg0, Arg1, Arg2 ) >
1165 {
1166 public:
1167
1168   /**
1169    * @brief Default constructor.
1170    * @SINCE_1_0.0
1171    */
1172   Signal()
1173   {
1174   }
1175
1176   /**
1177    * @brief Non-virtual destructor.
1178    * @SINCE_1_0.0
1179    */
1180   ~Signal()
1181   {
1182   }
1183
1184   /**
1185    * @brief Queries whether there are any connected slots.
1186    *
1187    * @SINCE_1_0.0
1188    * @return True if there are any slots connected to the signal
1189    */
1190   bool Empty() const
1191   {
1192     return mImpl.Empty();
1193   }
1194
1195   /**
1196    * @brief Queries the number of slots.
1197    *
1198    * @SINCE_1_0.0
1199    * @return The number of slots connected to this signal
1200    */
1201   std::size_t GetConnectionCount() const
1202   {
1203     return mImpl.GetConnectionCount();
1204   }
1205   /**
1206    * @brief Connects a function.
1207    *
1208    * @SINCE_1_0.0
1209    * @param[in] func The function to connect
1210    */
1211   void Connect( void (*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1212   {
1213     mImpl.OnConnect( MakeCallback( func ) );
1214   }
1215
1216   /**
1217    * @brief Disconnects a function.
1218    *
1219    * @SINCE_1_0.0
1220    * @param[in] func The function to disconnect
1221    */
1222   void Disconnect( void (*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1223   {
1224     mImpl.OnDisconnect( MakeCallback( func ) );
1225   }
1226
1227   /**
1228    * @brief Connects a member function.
1229    *
1230    * @SINCE_1_0.0
1231    * @param[in] obj An object which must implement the ConnectionTrackerInterface
1232    * @param[in] func The member function to connect
1233    */
1234   template<class X>
1235   void Connect( X* obj, void (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1236   {
1237     mImpl.OnConnect( obj, MakeCallback( obj, func ) );
1238   }
1239
1240   /**
1241    * @brief Disconnects a member function.
1242    *
1243    * @SINCE_1_0.0
1244    * @param[in] obj An object which must implement the ConnectionTrackerInterface
1245    * @param[in] func The member function to disconnect
1246    */
1247   template<class X>
1248   void Disconnect( X* obj, void (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1249   {
1250     mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
1251   }
1252
1253   /**
1254    * @brief Connects a member function.
1255    *
1256    * @SINCE_1_0.0
1257    * @param[in] delegate A slot delegate
1258    * @param[in] func The member function to connect
1259    */
1260   template<class X>
1261   void Connect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1262   {
1263     mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1264   }
1265
1266   /**
1267    * @brief Disconnects a member function.
1268    *
1269    * @SINCE_1_0.0
1270    * @param[in] delegate A slot delegate
1271    * @param[in] func The member function to disconnect
1272    */
1273   template<class X>
1274   void Disconnect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1275   {
1276     mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1277   }
1278
1279   /**
1280    * @brief Connects a function object.
1281    *
1282    * @SINCE_1_0.0
1283    * @param[in] connectionTracker A connection tracker which can be used to disconnect
1284    * @param[in] func The function object to copy
1285    */
1286   template<class X>
1287   void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
1288   {
1289     mImpl.OnConnect( connectionTracker, new CallbackFunctor3< X, Arg0, Arg1, Arg2 >( func ) );
1290   }
1291
1292   /**
1293    * @brief Connects a function object using FunctorDelegate.
1294    *
1295    * @SINCE_1_0.0
1296    * @param[in] connectionTracker A connection tracker which can be used to disconnect
1297    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
1298    */
1299   void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
1300   {
1301     mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegate3< Arg0, Arg1, Arg2 >( delegate ) );
1302   }
1303
1304   /**
1305    * @brief Emits the signal.
1306    *
1307    * @SINCE_1_0.0
1308    * @param[in] arg0 The first value to pass to callbacks
1309    * @param[in] arg1 The second value to pass to callbacks
1310    * @param[in] arg2 The third value to pass to callbacks
1311    */
1312   void Emit( Arg0 arg0, Arg1 arg1, Arg2 arg2 )
1313   {
1314     mImpl.Emit< Arg0,Arg1,Arg2 >( arg0, arg1, arg2 );
1315   }
1316
1317 private:
1318
1319   Signal( const Signal& ) = delete; ///< Deleted copy constructor, signals don't support copying. @SINCE_1_0.0
1320   Signal( Signal&& ) = delete; ///< Deleted move constructor, signals don't support moving. @SINCE_1_9.25
1321   Signal& operator=( const Signal& ) = delete; ///< Deleted copy assignment operator @SINCE_1_0.0
1322   Signal& operator=( Signal&& ) = delete; ///< Deleted move assignment operator @SINCE_1_9.25
1323
1324 private:
1325
1326   // Use composition instead of inheritance (virtual methods don't mix well with templates)
1327   BaseSignal mImpl; ///< Implementation
1328 };
1329
1330 /**
1331  * @brief A template for Signals with 2 parameters and a return value.
1332  * @SINCE_1_0.0
1333  */
1334 template < typename Ret, typename Arg0, typename Arg1, typename Arg2 >
1335 class Signal< Ret( Arg0, Arg1, Arg2 ) >
1336 {
1337 public:
1338
1339   /**
1340    * @brief Default constructor.
1341    * @SINCE_1_0.0
1342    */
1343   Signal()
1344   {
1345   }
1346
1347   /**
1348    * @brief Non-virtual destructor.
1349    * @SINCE_1_0.0
1350    */
1351   ~Signal()
1352   {
1353   }
1354
1355   /**
1356    * @brief Queries whether there are any connected slots.
1357    *
1358    * @SINCE_1_0.0
1359    * @return True if there are any slots connected to the signal
1360    */
1361   bool Empty() const
1362   {
1363     return mImpl.Empty();
1364   }
1365
1366   /**
1367    * @brief Queries the number of slots.
1368    *
1369    * @SINCE_1_0.0
1370    * @return The number of slots connected to this signal
1371    */
1372   std::size_t GetConnectionCount() const
1373   {
1374     return mImpl.GetConnectionCount();
1375   }
1376
1377   /**
1378    * @brief Connects a function.
1379    *
1380    * @SINCE_1_0.0
1381    * @param[in] func The function to connect
1382    */
1383   void Connect( Ret (*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1384   {
1385     mImpl.OnConnect( MakeCallback( func ) );
1386   }
1387
1388   /**
1389    * @brief Disconnects a function.
1390    *
1391    * @SINCE_1_0.0
1392    * @param[in] func The function to disconnect
1393    */
1394   void Disconnect( Ret (*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1395   {
1396     mImpl.OnDisconnect( MakeCallback( func ) );
1397   }
1398
1399   /**
1400    * @brief Connects a member function.
1401    *
1402    * @SINCE_1_0.0
1403    * @param[in] obj An object which must implement the ConnectionTrackerInterface
1404    * @param[in] func The member function to connect
1405    */
1406   template<class X>
1407   void Connect( X* obj, Ret (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1408   {
1409     mImpl.OnConnect( obj, MakeCallback( obj, func ) );
1410   }
1411
1412   /**
1413    * @brief Disconnects a member function.
1414    *
1415    * @SINCE_1_0.0
1416    * @param[in] obj An object which must implement the ConnectionTrackerInterface
1417    * @param[in] func The member function to disconnect
1418    */
1419   template<class X>
1420   void Disconnect( X* obj, Ret (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1421   {
1422     mImpl.OnDisconnect( obj, MakeCallback( obj, func ) );
1423   }
1424
1425   /**
1426    * @brief Connects a member function.
1427    *
1428    * @SINCE_1_0.0
1429    * @param[in] delegate A slot delegate
1430    * @param[in] func The member function to connect
1431    */
1432   template<class X>
1433   void Connect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1434   {
1435     mImpl.OnConnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1436   }
1437
1438   /**
1439    * @brief Disconnects a member function.
1440    *
1441    * @SINCE_1_0.0
1442    * @param[in] delegate A slot delegate
1443    * @param[in] func The member function to disconnect
1444    */
1445   template<class X>
1446   void Disconnect( SlotDelegate<X>& delegate, Ret (X::*func)( Arg0 arg0, Arg1 arg1, Arg2 arg2 ) )
1447   {
1448     mImpl.OnDisconnect( delegate.GetConnectionTracker(), MakeCallback( delegate.GetSlot(), func ) );
1449   }
1450
1451   /**
1452    * @brief Connects a function object.
1453    *
1454    * @SINCE_1_0.0
1455    * @param[in] connectionTracker A connection tracker which can be used to disconnect
1456    * @param[in] func The function object to copy
1457    */
1458   template<class X>
1459   void Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
1460   {
1461     mImpl.OnConnect( connectionTracker, new CallbackFunctorReturn3< X, Arg0, Arg1, Arg2, Ret >( func ) );
1462   }
1463
1464   /**
1465    * @brief Connects a function object using FunctorDelegate.
1466    *
1467    * @SINCE_1_0.0
1468    * @param[in] connectionTracker A connection tracker which can be used to disconnect
1469    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
1470    */
1471   void Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
1472   {
1473     mImpl.OnConnect( connectionTracker, new CallbackFunctorDelegateReturn3< Arg0, Arg1, Arg2, Ret >( delegate ) );
1474   }
1475
1476   /**
1477    * @brief Emits the signal.
1478    *
1479    * @SINCE_1_0.0
1480    * @param[in] arg0 The first value to pass to callbacks
1481    * @param[in] arg1 The second value to pass to callbacks
1482    * @param[in] arg2 The third value to pass to callbacks
1483    * @return The value returned by the last callback, or a default constructed value if no callbacks are connected
1484    */
1485   Ret Emit( Arg0 arg0, Arg1 arg1, Arg2 arg2 )
1486   {
1487     return mImpl.EmitReturn< Ret,Arg0,Arg1,Arg2 >( arg0, arg1, arg2 );
1488   }
1489
1490 private:
1491
1492   Signal( const Signal& ) = delete; ///< Deleted copy constructor, signals don't support copying. @SINCE_1_0.0
1493   Signal( Signal&& ) = delete; ///< Deleted move constructor, signals don't support moving. @SINCE_1_9.25
1494   Signal& operator=( const Signal& ) = delete; ///< Deleted copy assignment operator @SINCE_1_0.0
1495   Signal& operator=( Signal&& ) = delete; ///< Deleted move assignment operator @SINCE_1_9.25
1496
1497 private:
1498
1499   // Use composition instead of inheritance (virtual methods don't mix well with templates)
1500   BaseSignal mImpl; ///< Implementation
1501 };
1502
1503 /**
1504  * @}
1505  */
1506 } // namespace Dali
1507
1508 #endif // DALI_SIGNAL_H