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>
26 struct WeakHandleBase::Impl : public BaseObject::Impl::Observer
35 Impl(BaseHandle& handle)
40 mObject = static_cast<Dali::BaseObject*>(handle.GetObjectPtr());
43 BaseObject::Impl::Get(*mObject).AddObserver(*this);
58 BaseObject::Impl::Get(*mObject).RemoveObserver(*this);
64 * From BaseObject::Impl::Observer
66 void ObjectDestroyed(BaseObject& object) override
72 Dali::BaseObject* mObject;
75 WeakHandleBase::WeakHandleBase()
80 WeakHandleBase::WeakHandleBase(BaseHandle& handle)
81 : mImpl(new Impl(handle))
85 WeakHandleBase::~WeakHandleBase()
91 WeakHandleBase::WeakHandleBase(const WeakHandleBase& handle)
94 BaseHandle object = handle.GetBaseHandle();
95 mImpl = new Impl(object);
98 WeakHandleBase& WeakHandleBase::operator=(const WeakHandleBase& rhs)
104 BaseHandle handle = rhs.GetBaseHandle();
105 mImpl = new Impl(handle);
111 WeakHandleBase::WeakHandleBase(WeakHandleBase&& rhs)
117 WeakHandleBase& WeakHandleBase::operator=(WeakHandleBase&& rhs)
130 bool WeakHandleBase::operator==(const WeakHandleBase& rhs) const
132 return this->mImpl->mObject == rhs.mImpl->mObject;
135 bool WeakHandleBase::operator!=(const WeakHandleBase& rhs) const
137 return !(*this == rhs);
140 BaseHandle WeakHandleBase::GetBaseHandle() const
142 return mImpl ? BaseHandle(mImpl->mObject) : BaseHandle();
145 void WeakHandleBase::Reset()