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