1 #ifndef DALI_WEAK_HANDLE_H
2 #define DALI_WEAK_HANDLE_H
5 * Copyright (c) 2018 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/object/handle.h>
23 #include <dali/public-api/actors/custom-actor.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
46 * @brief Default constructor which provides an uninitialized Dali::WeakHandleBase.
52 * @brief This constructor creates a weak handle of the DALi object.
55 * @param [in] handle A reference to the handle of the DALi object
57 WeakHandleBase( Handle& handle );
60 * @brief Destructor to free resources.
66 * @brief Copy constructor.
69 * @param [in] handle A reference to the copied WeakHandleBase
71 WeakHandleBase(const WeakHandleBase& handle);
74 * @brief Assignment operator.
76 * It makes this WeakHandleBase point to the same internal DALi object as the copied WeakHandleBase
78 * @param [in] rhs A reference to the copied WeakHandleBase
79 * @return A reference to this WeakHandleBase
81 WeakHandleBase& operator=( const WeakHandleBase& rhs );
84 * @brief Equality operator overload.
87 * @param [in] rhs A reference to the compared WeakHandleBase
88 * @return true if the handle points to the same DALi resource, or if both are uninitialized
90 bool operator==(const WeakHandleBase& rhs) const;
93 * @brief Inequality operator overload.
96 * @param [in] rhs A reference to the compared WeakHandleBase
97 * @return true if the handle points to the different DALi resources
99 bool operator!=(const WeakHandleBase& rhs) const;
102 * @brief Gets the handle to the DALi object.
105 * @return The handle of the DALi object pointed by this WeakHandleBase or an empty handle if the DALi object doesn't exist
107 Handle GetBaseHandle() const;
110 * @brief Resets this weak handle to not point to any DALi object
126 * @brief Weak handle for the given type of DALi object.
128 * @see WeakHandleBase
131 class WeakHandle : public WeakHandleBase
136 * @copydoc Dali::WeakHandleBase::WeakHandleBase()
144 * @copydoc Dali::WeakHandleBase::WeakHandleBase(Handle&)
146 WeakHandle( T& handle )
147 : WeakHandleBase( handle )
152 * @copydoc Dali::WeakHandleBase::~WeakHandleBase()
157 * @copydoc Dali::WeakHandleBase::WeakHandleBase(const WeakHandleBase&)
159 WeakHandle(const WeakHandle& handle)
160 : WeakHandleBase( handle )
165 * @copydoc Dali::WeakHandleBase::operator=()
167 WeakHandle& operator=( const WeakHandle& rhs )
169 WeakHandleBase::operator=(rhs);
174 * @copydoc Dali::WeakHandleBase::operator==()
176 bool operator==(const WeakHandle& rhs) const
178 return WeakHandleBase::operator==(rhs);
182 * @copydoc Dali::WeakHandleBase::operator!=()
184 bool operator!=(const WeakHandle& rhs) const
186 return WeakHandleBase::operator!=(rhs);
190 * @copydoc Dali::WeakHandleBase::GetBaseHandle()
194 Handle handle( GetBaseHandle() );
197 return DownCast< T >( handle );
211 #endif // DALI_WEAK_HANDLE_H