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