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