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