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