/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/object/weak-handle.h>
// INTERNAL INCLUDES
-#include <dali/internal/event/common/object-impl.h>
+#include <dali/internal/event/common/base-object-impl.h>
namespace Dali
{
-
-struct WeakHandleBase::Impl : public Internal::Object::Observer
+struct WeakHandleBase::Impl : public BaseObject::Impl::Observer
{
// Construction
Impl()
- : mObject( NULL )
+ : mObject(nullptr)
{
}
// Construction
- Impl( Handle& handle )
- : mObject( NULL )
+ Impl(BaseHandle& handle)
+ : mObject(nullptr)
{
if(handle)
{
- mObject = static_cast<Internal::Object*>( handle.GetObjectPtr() );
+ mObject = static_cast<Dali::BaseObject*>(handle.GetObjectPtr());
if(mObject)
{
- mObject->AddObserver( *this );
+ BaseObject::Impl::Get(*mObject).AddObserver(*this);
}
}
}
// Destruction
- ~Impl()
+ ~Impl() override
{
Reset();
}
void Reset()
{
- if( mObject )
+ if(mObject)
{
- mObject->RemoveObserver( *this );
- mObject = NULL;
+ BaseObject::Impl::Get(*mObject).RemoveObserver(*this);
+ mObject = nullptr;
}
}
/**
- * From Object::Observer
- */
- virtual void SceneObjectAdded( Internal::Object& object )
- {
- }
-
- /**
- * From Object::Observer
+ * From BaseObject::Impl::Observer
*/
- virtual void SceneObjectRemoved( Internal::Object& object )
+ void ObjectDestroyed(BaseObject& object) override
{
- }
-
- /**
- * From Object::Observer
- */
- virtual void ObjectDestroyed( Internal::Object& object )
- {
- mObject = NULL;
+ mObject = nullptr;
}
// Data
- Internal::Object* mObject;
+ Dali::BaseObject* mObject;
};
WeakHandleBase::WeakHandleBase()
-: mImpl( new Impl() )
+: mImpl(new Impl())
{
}
-WeakHandleBase::WeakHandleBase( Handle& handle )
-: mImpl( new Impl( handle ) )
+WeakHandleBase::WeakHandleBase(BaseHandle& handle)
+: mImpl(new Impl(handle))
{
}
WeakHandleBase::~WeakHandleBase()
{
delete mImpl;
- mImpl = NULL;
+ mImpl = nullptr;
}
WeakHandleBase::WeakHandleBase(const WeakHandleBase& handle)
-: mImpl( NULL )
+: mImpl(nullptr)
+{
+ BaseHandle object = handle.GetBaseHandle();
+ mImpl = new Impl(object);
+}
+
+WeakHandleBase& WeakHandleBase::operator=(const WeakHandleBase& rhs)
+{
+ if(this != &rhs)
+ {
+ delete mImpl;
+
+ BaseHandle handle = rhs.GetBaseHandle();
+ mImpl = new Impl(handle);
+ }
+
+ return *this;
+}
+
+WeakHandleBase::WeakHandleBase(WeakHandleBase&& rhs) noexcept
+: mImpl(rhs.mImpl)
{
- Handle object = handle.GetBaseHandle();
- mImpl = new Impl(object);
+ rhs.mImpl = nullptr;
}
-WeakHandleBase& WeakHandleBase::operator=( const WeakHandleBase& rhs )
+WeakHandleBase& WeakHandleBase::operator=(WeakHandleBase&& rhs) noexcept
{
- if( this != &rhs )
+ if(this != &rhs)
{
delete mImpl;
- Handle handle = rhs.GetBaseHandle();
- mImpl = new Impl(handle);
+ mImpl = rhs.mImpl;
+ rhs.mImpl = nullptr;
}
return *this;
}
-bool WeakHandleBase::operator==( const WeakHandleBase& rhs ) const
+bool WeakHandleBase::operator==(const WeakHandleBase& rhs) const
{
return this->mImpl->mObject == rhs.mImpl->mObject;
}
-bool WeakHandleBase::operator!=( const WeakHandleBase& rhs ) const
+bool WeakHandleBase::operator!=(const WeakHandleBase& rhs) const
{
- return !( *this == rhs );
+ return !(*this == rhs);
}
-Handle WeakHandleBase::GetBaseHandle() const
+BaseHandle WeakHandleBase::GetBaseHandle() const
{
- return Handle( mImpl->mObject );
+ return mImpl ? BaseHandle(mImpl->mObject) : BaseHandle();
}
void WeakHandleBase::Reset()
mImpl->Reset();
}
-
-} // Dali
+} // namespace Dali