1 #ifndef __DALI_SLOT_DELEGATE_H__
2 #define __DALI_SLOT_DELEGATE_H__
5 * Copyright (c) 2015 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>
29 * @brief SlotDelegates can be used to connect member functions to signals, without inheriting from SlotDelegateInterface.
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.
36 * class Example // This does not inherit from SlotDelegateInterface!
41 * : mSlotDelegate( this )
47 * // mSlotDelegate disconnects automatically here
52 * Animation animation = Animation::New( 1.0f );
53 * animation.FinishedSignal().Connect( mSlotDelegate, &Example::OnAnimationFinished );
54 * animation.Play(); // fire & forget
57 * void OnAnimationFinished( Animation& animation )
59 * std::cout << "Animation Finished!" << std::endl;
64 * SlotDelegate<Example> mSlotDelegate;
70 template <typename Slot>
78 * @param[in] slot The object with a callback.
80 SlotDelegate( Slot* slot )
86 * @brief Non-virtual destructor.
94 * @brief Disconnect all signals from this object.
99 mConnectionTracker.DisconnectAll();
103 * @copydoc ConnectionTracker::GetConnectionCount
105 std::size_t GetConnectionCount() const
107 return mConnectionTracker.GetConnectionCount();
111 * @brief Retrieve the slot object.
113 * @return The object with a callback.
121 * @brief Retrieve the connection tracker component.
123 * @return The connection tracker component.
125 ConnectionTracker* GetConnectionTracker()
127 return &mConnectionTracker;
132 SlotDelegate( const SlotDelegate& ); ///< undefined copy constructor
133 SlotDelegate& operator=( const SlotDelegate& ); ///< undefined assignment operator
137 Slot* mSlot; ///< The slot object
139 // Use composition instead of inheritance (virtual methods don't mix well with templates)
140 ConnectionTracker mConnectionTracker; ///< A connection tracker
145 #endif // __DALI_SLOT_DELEGATE_H__