1 #ifndef DALI_SLOT_DELEGATE_H
2 #define DALI_SLOT_DELEGATE_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/signals/connection-tracker.h>
28 * @addtogroup dali_core_signals
33 * @brief SlotDelegates can be used to connect member functions to signals, without inheriting from SlotDelegateInterface.
35 * Note that the object providing the member function is expected to own the SlotDelegate; therefore when the object
36 * is destroyed, the SlotDelegate destructor will automatically disconnect.
40 * class Example // This does not inherit from SlotDelegateInterface!
45 * : mSlotDelegate( this )
51 * // mSlotDelegate disconnects automatically here
56 * Animation animation = Animation::New( 1.0f );
57 * animation.FinishedSignal().Connect( mSlotDelegate, &Example::OnAnimationFinished );
58 * animation.Play(); // fire & forget
61 * void OnAnimationFinished( Animation& animation )
63 * std::cout << "Animation Finished!" << std::endl;
68 * SlotDelegate<Example> mSlotDelegate;
75 template<typename Slot>
83 * @param[in] slot The object with a callback
85 SlotDelegate(Slot* slot)
91 * @brief Non-virtual destructor.
95 ~SlotDelegate() = default;
98 * @brief Disconnects all signals from this object.
104 mConnectionTracker.DisconnectAll();
108 * @copydoc ConnectionTracker::GetConnectionCount
110 std::size_t GetConnectionCount() const
112 return mConnectionTracker.GetConnectionCount();
116 * @brief Retrieves the slot object.
119 * @return The object with a callback
127 * @brief Retrieves the connection tracker component.
130 * @return The connection tracker component
132 ConnectionTracker* GetConnectionTracker()
134 return &mConnectionTracker;
138 SlotDelegate(const SlotDelegate&) = delete; ///< Deleted copy constructor. @SINCE_1_0.0
139 SlotDelegate(SlotDelegate&&) = delete; ///< Deleted move constructor. @SINCE_1_9.25
140 SlotDelegate& operator=(const SlotDelegate&) = delete; ///< Deleted copy assignment operator. @SINCE_1_0.0
141 SlotDelegate& operator=(SlotDelegate&&) = delete; ///< Deleted move assignment operator. @SINCE_1_9.25
144 Slot* mSlot; ///< The slot object
146 // Use composition instead of inheritance (virtual methods don't mix well with templates)
147 ConnectionTracker mConnectionTracker; ///< A connection tracker
155 #endif // DALI_SLOT_DELEGATE_H