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;
103 * @brief Type CustomActors support
105 template <typename Type>
109 * This flag tells Dali if a class is derived from CustomActor.
111 enum { IS_CUSTOM_ACTOR = __is_base_of(Dali::CustomActor, Type) };
114 template <typename Type>
115 struct TypeCustomActors : public CustomActors< Type >
119 template < bool CustomActorType >
120 class InternalTypeName
124 typedef Dali::Internal::CustomActor InternalObjectType;
128 class InternalTypeName< false >
132 typedef Dali::Internal::Actor InternalObjectType;
136 * @brief Weak handle for the given type of Dali object.
139 class WeakHandle : public WeakHandleBase
143 typedef typename InternalTypeName< TypeCustomActors<T>::IS_CUSTOM_ACTOR >::InternalObjectType InternalObjectType;
148 * @copydoc Dali::WeakHandleBase::WeakHandleBase()
156 * @copydoc Dali::WeakHandleBase::WeakHandleBase(Handle&)
158 WeakHandle( T& handle )
159 : WeakHandleBase( handle )
164 * @copydoc Dali::WeakHandleBase::~WeakHandleBase()
169 * @copydoc Dali::WeakHandleBase::WeakHandleBase(const WeakHandleBase&)
171 WeakHandle(const WeakHandle& handle)
172 : WeakHandleBase( handle )
177 * @copydoc Dali::WeakHandleBase::operator=()
179 WeakHandle& operator=( const WeakHandle& rhs )
181 WeakHandleBase::operator=(rhs);
186 * @copydoc Dali::WeakHandleBase::operator==()
188 bool operator==(const WeakHandle& rhs) const
190 return WeakHandleBase::operator==(rhs);
194 * @copydoc Dali::WeakHandleBase::operator!=()
196 bool operator!=(const WeakHandle& rhs) const
198 return WeakHandleBase::operator!=(rhs);
202 * @copydoc Dali::WeakHandleBase::GetHandle()
206 Handle handle( GetBaseHandle() );
209 return T( reinterpret_cast< InternalObjectType* >( handle.GetObjectPtr() ) );
220 #endif // __DALI_WEAK_HANDLE_H__