/*
- * 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.
END_TEST;
}
-int UtcDaliWeakHandleBaseConstructorWithHandle(void)
+int UtcDaliWeakHandleBaseConstructorWithBaseHandle(void)
{
TestApplication application;
- tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase(Handle)");
+ tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase(BaseHandle)");
- Handle emptyHandle;
+ BaseHandle emptyHandle;
WeakHandleBase emptyObject(emptyHandle);
DALI_TEST_CHECK(!emptyObject.GetBaseHandle());
WeakHandleBase object(actor);
DALI_TEST_CHECK(object.GetBaseHandle() == actor);
+ Animation animation = Animation::New( 1.0f );
+ WeakHandleBase animationObject( animation );
+ DALI_TEST_CHECK( animationObject.GetBaseHandle() == animation );
+
END_TEST;
}
WeakHandleBase aDifferentWeakHandleBase(differentActor);
DALI_TEST_CHECK(object.GetBaseHandle() != aDifferentWeakHandleBase.GetBaseHandle());
+ Animation animation = Animation::New( 1.0f );
+ WeakHandleBase animationObject( animation );
+ DALI_TEST_CHECK( animationObject.GetBaseHandle() == animation );
+
+ WeakHandleBase theSameAnimationObject = WeakHandleBase( animation );
+ DALI_TEST_CHECK( animationObject.GetBaseHandle() == theSameAnimationObject.GetBaseHandle() );
+
+ Animation differentAnimation = Animation::New( 1.0f );
+ WeakHandleBase aDifferentAnimationObject( differentAnimation );
+ DALI_TEST_CHECK( animationObject.GetBaseHandle() != aDifferentAnimationObject.GetBaseHandle() );
+
END_TEST;
}
DALI_TEST_CHECK(object.GetHandle() != customObject.GetHandle());
+ Animation animation = Animation::New( 1.0f );
+ WeakHandle<Animation> animationObject( animation );
+ DALI_TEST_CHECK( animationObject.GetHandle() == animation );
+
+ animation.Reset();
+ DALI_TEST_CHECK( animationObject.GetHandle() == Animation() );
+
END_TEST;
}
-
--- /dev/null
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali/internal/event/common/base-object-impl.h>
+
+namespace Dali
+{
+
+BaseObject::Impl::Impl( BaseObject& baseObject )
+: mBaseObject( baseObject )
+{
+}
+
+BaseObject::Impl::~Impl()
+{
+ // Notification for observers
+ for( auto&& item : mObservers )
+ {
+ item->ObjectDestroyed( mBaseObject );
+ }
+}
+
+BaseObject::Impl& BaseObject::Impl::Get( BaseObject& baseObject )
+{
+ return *baseObject.mImpl;
+}
+
+const BaseObject::Impl& BaseObject::Impl::Get( const BaseObject& baseObject )
+{
+ return *baseObject.mImpl;
+}
+
+void BaseObject::Impl::AddObserver( Observer& observer )
+{
+ // make sure an observer doesn't observe the same object twice
+ // otherwise it will get multiple calls to ObjectDestroyed()
+ DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer) );
+
+ mObservers.PushBack( &observer );
+}
+
+void BaseObject::Impl::RemoveObserver( Observer& observer )
+{
+ // Find the observer...
+ const auto endIter = mObservers.End();
+ for( auto iter = mObservers.Begin(); iter != endIter; ++iter )
+ {
+ if( ( *iter ) == &observer)
+ {
+ mObservers.Erase( iter );
+ break;
+ }
+ }
+ DALI_ASSERT_DEBUG( endIter != mObservers.End() );
+}
+
+} // namespace Dali
--- /dev/null
+#ifndef DALI_BASE_OBJECT_IMPL_H
+#define DALI_BASE_OBJECT_IMPL_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/object/base-object.h>
+
+namespace Dali
+{
+
+/**
+ * @brief Holds the Implementation for the BaseObject class
+ */
+class BaseObject::Impl
+{
+
+public:
+
+ /**
+ * @brief Retrieves the implementation of the internal BaseObject class.
+ * @param[in] internalBaseObject A ref to the BaseObject whose internal implementation is required
+ * @return The internal implementation
+ */
+ static BaseObject::Impl& Get( BaseObject& baseObject );
+
+ /**
+ * @copydoc Get( BaseObject& )
+ */
+ static const BaseObject::Impl& Get( const BaseObject& baseObject );
+
+ /**
+ * @brief Constructor.
+ * @param[in] baseObject The base object which owns this implementation
+ */
+ Impl( BaseObject& baseObject );
+
+ /**
+ * @brief Destructor.
+ */
+ ~Impl();
+
+ class Observer
+ {
+ public:
+
+ /**
+ * Called shortly before the object itself is destroyed; no further callbacks will be received.
+ * @param[in] object The base object.
+ */
+ virtual void ObjectDestroyed( BaseObject& object ) = 0;
+
+ protected:
+
+ /**
+ * Virtual destructor
+ */
+ virtual ~Observer() {}
+ };
+
+ /**
+ * Add an observer to the object.
+ * @param[in] observer The observer to add.
+ */
+ void AddObserver( Observer& observer );
+
+ /**
+ * Remove an observer from the object
+ * @pre The observer has already been added.
+ * @param[in] observer The observer to remove.
+ */
+ void RemoveObserver( Observer& observer );
+
+private:
+
+ BaseObject& mBaseObject;
+ Dali::Vector<Observer*> mObservers;
+};
+
+} // namespace Dali
+
+#endif // DALI_BASE_OBJECT_IMPL_H
${internal_src_dir}/event/animation/linear-constrainer-impl.cpp
${internal_src_dir}/event/animation/path-impl.cpp
${internal_src_dir}/event/animation/path-constrainer-impl.cpp
+ ${internal_src_dir}/event/common/base-object-impl.cpp
${internal_src_dir}/event/common/event-thread-services.cpp
${internal_src_dir}/event/common/notification-manager.cpp
${internal_src_dir}/event/common/object-impl.cpp
/*
- * Copyright (c) 2015 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/internal/event/common/stage-impl.h>
#include <dali/internal/event/common/type-registry-impl.h>
#include <dali/internal/event/common/thread-local-storage.h>
+#include <dali/internal/event/common/base-object-impl.h>
namespace Dali
{
BaseObject::BaseObject()
+: mImpl( new Impl( *this ) )
{
}
#define DALI_BASE_OBJECT_H
/*
- * Copyright (c) 2019 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.
*
*/
+// EXTERNAL INCLUDES
+#include <memory>
+
// INTERNAL INCLUDES
#include <dali/public-api/object/ref-object.h>
#include <dali/public-api/object/base-handle.h>
// Not implemented
DALI_INTERNAL BaseObject& operator=(const BaseObject& rhs);
+
+public:
+
+ class DALI_INTERNAL Impl;
+
+private:
+
+ std::unique_ptr<Impl> mImpl;
};
// Helpers for public-api forwarding methods
/*
- * 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)
+ if( handle )
{
- mObject = static_cast<Internal::Object*>( handle.GetObjectPtr() );
- if(mObject)
+ mObject = static_cast<Dali::BaseObject*>( handle.GetObjectPtr() );
+ if( mObject )
{
- mObject->AddObserver( *this );
+ BaseObject::Impl::Get( *mObject ).AddObserver( *this );
}
}
}
{
if( mObject )
{
- mObject->RemoveObserver( *this );
- mObject = NULL;
+ BaseObject::Impl::Get( *mObject ).RemoveObserver( *this );
+ mObject = nullptr;
}
}
/**
- * From Object::Observer
+ * From BaseObject::Impl::Observer
*/
- virtual void SceneObjectAdded( Internal::Object& object )
+ virtual void ObjectDestroyed( BaseObject& object )
{
- }
-
- /**
- * From Object::Observer
- */
- virtual void SceneObjectRemoved( Internal::Object& object )
- {
- }
-
- /**
- * From Object::Observer
- */
- virtual void ObjectDestroyed( Internal::Object& object )
- {
- mObject = NULL;
+ mObject = nullptr;
}
// Data
- Internal::Object* mObject;
+ Dali::BaseObject* mObject;
};
WeakHandleBase::WeakHandleBase()
{
}
-WeakHandleBase::WeakHandleBase( Handle& 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 )
{
- Handle object = handle.GetBaseHandle();
+ BaseHandle object = handle.GetBaseHandle();
mImpl = new Impl(object);
}
{
delete mImpl;
- Handle handle = rhs.GetBaseHandle();
+ BaseHandle handle = rhs.GetBaseHandle();
mImpl = new Impl(handle);
}
return !( *this == rhs );
}
-Handle WeakHandleBase::GetBaseHandle() const
+BaseHandle WeakHandleBase::GetBaseHandle() const
{
- return Handle( mImpl->mObject );
+ return BaseHandle( mImpl->mObject );
}
void WeakHandleBase::Reset()
#define DALI_WEAK_HANDLE_H
/*
- * Copyright (c) 2018 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.
*/
// INTERNAL INCLUDES
-#include <dali/public-api/object/handle.h>
+#include <dali/public-api/object/base-handle.h>
#include <dali/public-api/actors/custom-actor.h>
namespace Dali
* @SINCE_1_2.60
* @param [in] handle A reference to the handle of the DALi object
*/
- WeakHandleBase( Handle& handle );
+ WeakHandleBase( BaseHandle& handle );
/**
* @brief Destructor to free resources.
* @SINCE_1_2.60
* @return The handle of the DALi object pointed by this WeakHandleBase or an empty handle if the DALi object doesn't exist
*/
- Handle GetBaseHandle() const;
+ BaseHandle GetBaseHandle() const;
/**
* @brief Resets this weak handle to not point to any DALi object
}
/**
- * @copydoc Dali::WeakHandleBase::WeakHandleBase(Handle&)
+ * @copydoc Dali::WeakHandleBase::WeakHandleBase( BaseHandle& )
*/
WeakHandle( T& handle )
: WeakHandleBase( handle )
*/
T GetHandle() const
{
- Handle handle( GetBaseHandle() );
+ BaseHandle handle( WeakHandleBase::GetBaseHandle() );
if( handle )
{
return DownCast< T >( handle );