2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/public-api/object/weak-handle.h>
22 #include <dali/internal/event/common/base-object-impl.h>
27 struct WeakHandleBase::Impl : public BaseObject::Impl::Observer
36 Impl( BaseHandle& handle )
41 mObject = static_cast<Dali::BaseObject*>( handle.GetObjectPtr() );
44 BaseObject::Impl::Get( *mObject ).AddObserver( *this );
59 BaseObject::Impl::Get( *mObject ).RemoveObserver( *this );
65 * From BaseObject::Impl::Observer
67 void ObjectDestroyed( BaseObject& object ) override
73 Dali::BaseObject* mObject;
76 WeakHandleBase::WeakHandleBase()
81 WeakHandleBase::WeakHandleBase( BaseHandle& handle )
82 : mImpl( new Impl( handle ) )
86 WeakHandleBase::~WeakHandleBase()
92 WeakHandleBase::WeakHandleBase(const WeakHandleBase& handle)
95 BaseHandle object = handle.GetBaseHandle();
96 mImpl = new Impl(object);
99 WeakHandleBase& WeakHandleBase::operator=( const WeakHandleBase& rhs )
105 BaseHandle handle = rhs.GetBaseHandle();
106 mImpl = new Impl(handle);
112 WeakHandleBase::WeakHandleBase( WeakHandleBase&& rhs )
118 WeakHandleBase& WeakHandleBase::operator=( WeakHandleBase&& rhs )
131 bool WeakHandleBase::operator==( const WeakHandleBase& rhs ) const
133 return this->mImpl->mObject == rhs.mImpl->mObject;
136 bool WeakHandleBase::operator!=( const WeakHandleBase& rhs ) const
138 return !( *this == rhs );
141 BaseHandle WeakHandleBase::GetBaseHandle() const
143 return mImpl ? BaseHandle( mImpl->mObject ) : BaseHandle();
146 void WeakHandleBase::Reset()