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