1 #ifndef __DALI_WEAK_HANDLE_H__
2 #define __DALI_WEAK_HANDLE_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/object/handle.h>
23 #include <dali/public-api/actors/custom-actor.h>
29 * @brief Base class to store a weak pointer to an internal Dali object. The handle to the object
30 * can be accessed if the object exists, and such access is not reference counted. When the object
31 * is deleted, the weak pointer will be set to NULL, and any further attmpt to access to a deleted
32 * object will return an empty handle.
35 class DALI_IMPORT_API WeakHandleBase
41 * @brief Default constructor which provides an uninitialized Dali::WeakHandleBase.
46 * @brief This constructor creates a weak handle of the Dali object.
48 * @param [in] handle A reference to the handle of the Dali object.
50 WeakHandleBase( Handle& handle );
53 * @brief Destructor to free resources.
58 * @brief Copy constructor.
60 * @param [in] handle A reference to the copied WeakHandleBase
62 WeakHandleBase(const WeakHandleBase& handle);
65 * @brief Assignment operator.
67 * It makes this WeakHandleBase point to the same internal Dali object as the copied WeakHandleBase
68 * @param [in] rhs A reference to the copied WeakHandleBase
69 * @return A reference to this WeakHandleBase
71 WeakHandleBase& operator=( const WeakHandleBase& rhs );
74 * @brief Equality operator overload.
76 * @param [in] rhs A reference to the compared WeakHandleBase.
77 * @return true if the handle points to the same Dali resource, or if both are uninitialized.
79 bool operator==(const WeakHandleBase& rhs) const;
82 * @brief Inequality operator overload.
84 * @param [in] rhs A reference to the compared WeakHandleBase.
85 * @return true if the handle points to the different Dali resources.
87 bool operator!=(const WeakHandleBase& rhs) const;
90 * @brief Gets the handle to the Dali object.
92 * @return The handle of the Dali object pointed by this WeakHandleBase or an empty handle if the Dali object doesn't exist.
94 Handle GetBaseHandle() const;
97 * @brief Resets this weak handle to not point to any Dali object
110 * @brief Weak handle for the given type of Dali object.
113 class WeakHandle : public WeakHandleBase
118 * @copydoc Dali::WeakHandleBase::WeakHandleBase()
126 * @copydoc Dali::WeakHandleBase::WeakHandleBase(Handle&)
128 WeakHandle( T& handle )
129 : WeakHandleBase( handle )
134 * @copydoc Dali::WeakHandleBase::~WeakHandleBase()
139 * @copydoc Dali::WeakHandleBase::WeakHandleBase(const WeakHandleBase&)
141 WeakHandle(const WeakHandle& handle)
142 : WeakHandleBase( handle )
147 * @copydoc Dali::WeakHandleBase::operator=()
149 WeakHandle& operator=( const WeakHandle& rhs )
151 WeakHandleBase::operator=(rhs);
156 * @copydoc Dali::WeakHandleBase::operator==()
158 bool operator==(const WeakHandle& rhs) const
160 return WeakHandleBase::operator==(rhs);
164 * @copydoc Dali::WeakHandleBase::operator!=()
166 bool operator!=(const WeakHandle& rhs) const
168 return WeakHandleBase::operator!=(rhs);
172 * @copydoc Dali::WeakHandleBase::GetBaseHandle()
176 Handle handle( GetBaseHandle() );
179 return DownCast< T >( handle );
190 #endif // __DALI_WEAK_HANDLE_H__