1 #ifndef DALI_WEAK_HANDLE_H
2 #define DALI_WEAK_HANDLE_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/actors/custom-actor.h>
23 #include <dali/public-api/object/base-handle.h>
28 * @addtogroup dali_core_object
33 * @brief Base class to store a weak pointer to an internal DALi object.
35 * The handle to the object can be accessed if the object exists, and such access is not reference counted.
36 * When the object is deleted, the weak pointer will be set to NULL, and any further attempt to access to a
37 * deleted object will return an empty handle.
40 class DALI_CORE_API WeakHandleBase
44 * @brief Default constructor which provides an uninitialized Dali::WeakHandleBase.
50 * @brief This constructor creates a weak handle of the DALi object.
53 * @param [in] handle A reference to the handle of the DALi object
55 WeakHandleBase(BaseHandle& handle);
58 * @brief Destructor to free resources.
64 * @brief Copy constructor.
67 * @param [in] handle A reference to the copied WeakHandleBase
69 WeakHandleBase(const WeakHandleBase& handle);
72 * @brief Assignment operator.
74 * It makes this WeakHandleBase point to the same internal DALi object as the copied WeakHandleBase
76 * @param [in] rhs A reference to the copied WeakHandleBase
77 * @return A reference to this WeakHandleBase
79 WeakHandleBase& operator=(const WeakHandleBase& rhs);
82 * @brief Move constructor.
85 * @param[in] rhs A reference to the moved handle
87 WeakHandleBase(WeakHandleBase&& rhs);
90 * @brief Move assignment operator.
93 * @param[in] rhs A reference to the moved handle
94 * @return A reference to this handle
96 WeakHandleBase& operator=(WeakHandleBase&& rhs);
99 * @brief Equality operator overload.
102 * @param [in] rhs A reference to the compared WeakHandleBase
103 * @return true if the handle points to the same DALi resource, or if both are uninitialized
105 bool operator==(const WeakHandleBase& rhs) const;
108 * @brief Inequality operator overload.
111 * @param [in] rhs A reference to the compared WeakHandleBase
112 * @return true if the handle points to the different DALi resources
114 bool operator!=(const WeakHandleBase& rhs) const;
117 * @brief Gets the handle to the DALi object.
120 * @return The handle of the DALi object pointed by this WeakHandleBase or an empty handle if the DALi object doesn't exist
122 BaseHandle GetBaseHandle() const;
125 * @brief Resets this weak handle to not point to any DALi object
138 * @brief Weak handle for the given type of DALi object.
140 * @see WeakHandleBase
143 class WeakHandle : public WeakHandleBase
147 * @copydoc Dali::WeakHandleBase::WeakHandleBase()
155 * @copydoc Dali::WeakHandleBase::WeakHandleBase( BaseHandle& )
157 WeakHandle(T& handle)
158 : WeakHandleBase(handle)
163 * @copydoc Dali::WeakHandleBase::~WeakHandleBase()
165 ~WeakHandle() = default;
168 * @copydoc Dali::WeakHandleBase::WeakHandleBase(const WeakHandleBase&)
170 WeakHandle(const WeakHandle& handle)
171 : WeakHandleBase(handle)
176 * @copydoc Dali::WeakHandleBase::operator=(const WeakHandleBase& rhs)
178 WeakHandle& operator=(const WeakHandle& rhs)
180 WeakHandleBase::operator=(rhs);
185 * @copydoc Dali::WeakHandleBase::WeakHandleBase(WeakHandleBase&& rhs)
187 WeakHandle(WeakHandle&& rhs) = default;
190 * @copydoc Dali::WeakHandleBase::operator=(WeakHandleBase&& rhs)
192 WeakHandle& operator=(WeakHandle&& rhs) = default;
195 * @copydoc Dali::WeakHandleBase::operator==()
197 bool operator==(const WeakHandle& rhs) const
199 return WeakHandleBase::operator==(rhs);
203 * @copydoc Dali::WeakHandleBase::operator!=()
205 bool operator!=(const WeakHandle& rhs) const
207 return WeakHandleBase::operator!=(rhs);
211 * @copydoc Dali::WeakHandleBase::GetBaseHandle()
215 BaseHandle handle(WeakHandleBase::GetBaseHandle());
218 return DownCast<T>(handle);
232 #endif // DALI_WEAK_HANDLE_H