Merge "Remove unnecessary stream operators from radian and degree as well as unnecess...
[platform/core/uifw/dali-core.git] / dali / public-api / signals / slot-delegate.h
1 #ifndef __DALI_SLOT_DELEGATE_H__
2 #define __DALI_SLOT_DELEGATE_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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/signals/connection-tracker.h>
24
25 namespace Dali
26 {
27
28 /**
29  * @brief SlotDelegates can be used to connect member functions to signals, without inheriting from SlotDelegateInterface.
30  *
31  * Note that the object providing the member function is expected to own the SlotDelegate; therefore when the object
32  * is destroyed, the SlotDelegate destructor will automatically disconnect.
33  *
34  * @code
35  *
36  * class Example // This does not inherit from SlotDelegateInterface!
37  * {
38  * public:
39  *
40  *   Example()
41  *   : mSlotDelegate( this )
42  *   {
43  *   }
44  *
45  *   ~Example()
46  *   {
47  *     // mSlotDelegate disconnects automatically here
48  *   }
49  *
50  *   void Animate()
51  *   {
52  *     Animation animation = Animation::New( 1.0f );
53  *     animation.FinishedSignal().Connect( mSlotDelegate, &Example::OnAnimationFinished );
54  *     animation.Play(); // fire & forget
55  *   }
56  *
57  *   void OnAnimationFinished( Animation& animation )
58  *   {
59  *     std::cout << "Animation Finished!" << std::endl;
60  *   }
61  *
62  * private:
63  *
64  *  SlotDelegate<Example> mSlotDelegate;
65  *
66  * };
67  *
68  * @endcode
69  */
70 template <typename Slot>
71 class SlotDelegate
72 {
73 public:
74
75   /**
76    * @brief Constructor.
77    *
78    * @param[in] slot The object with a callback.
79    */
80   SlotDelegate( Slot* slot )
81   : mSlot( slot )
82   {
83   }
84
85   /**
86    * @brief Non-virtual destructor.
87    *
88    */
89   ~SlotDelegate()
90   {
91   }
92
93   /**
94    * @brief Disconnect all signals from this object.
95    *
96    */
97   void DisconnectAll()
98   {
99     mConnectionTracker.DisconnectAll();
100   }
101
102   /**
103    * @copydoc ConnectionTracker::GetConnectionCount
104    */
105   std::size_t GetConnectionCount() const
106   {
107     return mConnectionTracker.GetConnectionCount();
108   }
109
110   /**
111    * @brief Retrieve the slot object.
112    *
113    * @return The object with a callback.
114    */
115   Slot* GetSlot()
116   {
117     return mSlot;
118   }
119
120   /**
121    * @brief Retrieve the connection tracker component.
122    *
123    * @return The connection tracker component.
124    */
125   ConnectionTracker* GetConnectionTracker()
126   {
127     return &mConnectionTracker;
128   }
129
130 private:
131
132   SlotDelegate( const SlotDelegate& );            ///< undefined copy constructor
133   SlotDelegate& operator=( const SlotDelegate& ); ///< undefined assignment operator
134
135 private:
136
137   Slot* mSlot; ///< The slot object
138
139   // Use composition instead of inheritance (virtual methods don't mix well with templates)
140   ConnectionTracker mConnectionTracker; ///< A connection tracker
141 };
142
143 } // namespace Dali
144
145 #endif // __DALI_SLOT_DELEGATE_H__