From fd5885926204dd0969d292a2452e22e6c66c5622 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Tue, 1 Sep 2020 19:00:23 +0100 Subject: [PATCH] Added move semantics to TouchEvent & fixed some other internal event classes Change-Id: Iaff0eb50d4cdb9b7e481cfe5def5ad850c58eb92 --- automated-tests/src/dali/CMakeLists.txt | 1 + automated-tests/src/dali/utc-Dali-TouchEvent.cpp | 116 +++++++++++++++++++++++ dali/internal/event/events/hover-event-impl.cpp | 4 - dali/internal/event/events/hover-event-impl.h | 12 ++- dali/internal/event/events/key-event-impl.cpp | 4 - dali/internal/event/events/key-event-impl.h | 12 ++- dali/internal/event/events/touch-event-impl.cpp | 36 +------ dali/internal/event/events/touch-event-impl.h | 53 ++++++----- dali/internal/event/events/wheel-event-impl.cpp | 4 - dali/internal/event/events/wheel-event-impl.h | 12 ++- dali/public-api/events/touch-event.cpp | 24 ++--- dali/public-api/events/touch-event.h | 17 ++++ 12 files changed, 199 insertions(+), 96 deletions(-) create mode 100644 automated-tests/src/dali/utc-Dali-TouchEvent.cpp diff --git a/automated-tests/src/dali/CMakeLists.txt b/automated-tests/src/dali/CMakeLists.txt index cb569e3..bab6fb6 100644 --- a/automated-tests/src/dali/CMakeLists.txt +++ b/automated-tests/src/dali/CMakeLists.txt @@ -86,6 +86,7 @@ SET(TC_SOURCES utc-Dali-TextureSet.cpp utc-Dali-Thread.cpp utc-Dali-ThreadPool.cpp + utc-Dali-TouchEvent.cpp utc-Dali-TouchEventCombiner.cpp utc-Dali-TouchProcessing.cpp utc-Dali-TypeRegistry.cpp diff --git a/automated-tests/src/dali/utc-Dali-TouchEvent.cpp b/automated-tests/src/dali/utc-Dali-TouchEvent.cpp new file mode 100644 index 0000000..dbd663b --- /dev/null +++ b/automated-tests/src/dali/utc-Dali-TouchEvent.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2014 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. + * + */ + +#include +#include + +#include +#include +#include + +void utc_dali_touch_event_startup(void) +{ + test_return_value = TET_UNDEF; +} + +void utc_dali_touch_event_cleanup(void) +{ + test_return_value = TET_PASS; +} + +namespace +{ +TouchPoint GenerateTouchPoint() +{ + return TouchPoint(1, PointState::STARTED, 100.0f, 200.0f); +} +} + +int UtcDaliTouchEventConstructorP(void) +{ + TouchEvent touchEvent; + DALI_TEST_CHECK( !touchEvent ); + END_TEST; +} + +int UtcDaliTouchEventCopyConstructorP(void) +{ + TouchEvent touchEvent = Integration::NewTouchEvent(123u, GenerateTouchPoint()); + DALI_TEST_CHECK( touchEvent ); + + const auto refCount = touchEvent.GetBaseObject().ReferenceCount(); + + TouchEvent touchEvent2( touchEvent ); + DALI_TEST_CHECK( touchEvent ); + DALI_TEST_CHECK( touchEvent2 ); + DALI_TEST_EQUALS( touchEvent, touchEvent2, TEST_LOCATION ); + DALI_TEST_EQUALS( refCount + 1, touchEvent.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTouchEventMoveConstructorP(void) +{ + TouchEvent touchEvent = Integration::NewTouchEvent(123u, GenerateTouchPoint()); + DALI_TEST_CHECK( touchEvent ); + + const auto refCount = touchEvent.GetBaseObject().ReferenceCount(); + + TouchEvent touchEvent2( std::move(touchEvent) ); + DALI_TEST_CHECK( !touchEvent ); + DALI_TEST_CHECK( touchEvent2 ); + DALI_TEST_EQUALS( refCount, touchEvent2.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTouchEventCopyAssignmentP(void) +{ + TouchEvent touchEvent = Integration::NewTouchEvent(123u, GenerateTouchPoint()); + DALI_TEST_CHECK( touchEvent ); + + const auto refCount = touchEvent.GetBaseObject().ReferenceCount(); + + TouchEvent touchEvent2; + DALI_TEST_CHECK( !touchEvent2 ); + + touchEvent2 = touchEvent; + DALI_TEST_CHECK( touchEvent ); + DALI_TEST_CHECK( touchEvent2 ); + DALI_TEST_EQUALS( touchEvent, touchEvent2, TEST_LOCATION ); + DALI_TEST_EQUALS( refCount + 1, touchEvent.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTouchEventMoveAssignmentP(void) +{ + TouchEvent touchEvent = Integration::NewTouchEvent(123u, GenerateTouchPoint()); + DALI_TEST_CHECK( touchEvent ); + + const auto refCount = touchEvent.GetBaseObject().ReferenceCount(); + + TouchEvent touchEvent2; + DALI_TEST_CHECK( !touchEvent2 ); + + touchEvent2 = std::move(touchEvent); + DALI_TEST_CHECK( !touchEvent ); + DALI_TEST_CHECK( touchEvent2 ); + DALI_TEST_EQUALS( refCount, touchEvent2.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + + END_TEST; +} diff --git a/dali/internal/event/events/hover-event-impl.cpp b/dali/internal/event/events/hover-event-impl.cpp index 5f6f191..3c200c7 100755 --- a/dali/internal/event/events/hover-event-impl.cpp +++ b/dali/internal/event/events/hover-event-impl.cpp @@ -44,10 +44,6 @@ HoverEventPtr HoverEvent::Clone( const HoverEvent& rhs ) return hoverEvent; } -HoverEvent::~HoverEvent() -{ -} - unsigned long HoverEvent::GetTime() const { return mTime; diff --git a/dali/internal/event/events/hover-event-impl.h b/dali/internal/event/events/hover-event-impl.h index 31c7392..bf105b3 100755 --- a/dali/internal/event/events/hover-event-impl.h +++ b/dali/internal/event/events/hover-event-impl.h @@ -63,11 +63,6 @@ public: */ static HoverEventPtr Clone( const HoverEvent& rhs ); - /** - * @brief Destructor - */ - ~HoverEvent(); - // Getters /** @@ -137,6 +132,13 @@ public: private: + /** + * @brief Destructor + * + * A reference counted object may only be deleted by calling Unreference() + */ + virtual ~HoverEvent() = default; + // Not copyable or movable HoverEvent( const HoverEvent& rhs ) = delete; ///< Deleted copy constructor diff --git a/dali/internal/event/events/key-event-impl.cpp b/dali/internal/event/events/key-event-impl.cpp index f8c1fa8..452379b 100755 --- a/dali/internal/event/events/key-event-impl.cpp +++ b/dali/internal/event/events/key-event-impl.cpp @@ -75,10 +75,6 @@ KeyEvent::KeyEvent( const std::string& keyName, { } -KeyEvent::~KeyEvent() -{ -} - KeyEventPtr KeyEvent::New( const std::string& keyName, const std::string& logicalKey, const std::string& keyString, diff --git a/dali/internal/event/events/key-event-impl.h b/dali/internal/event/events/key-event-impl.h index 8b8f7d4..863e244 100755 --- a/dali/internal/event/events/key-event-impl.h +++ b/dali/internal/event/events/key-event-impl.h @@ -71,11 +71,6 @@ public: const Device::Subclass::Type deviceSubclass ); /** - * @brief Destructor. - */ - ~KeyEvent(); - - /** * Create a new KeyEvent. * * @param[in] keyName The name of the key pressed or command from the IMF, if later then the some following parameters will be needed. @@ -217,6 +212,13 @@ public: private: + /** + * @brief Destructor. + * + * A reference counted object may only be deleted by calling Unreference() + */ + virtual ~KeyEvent() = default; + // Not copyable or movable KeyEvent( const KeyEvent& rhs ) = delete; ///< Deleted copy constructor diff --git a/dali/internal/event/events/touch-event-impl.cpp b/dali/internal/event/events/touch-event-impl.cpp index 12e21bf..d7bfe4c 100644 --- a/dali/internal/event/events/touch-event-impl.cpp +++ b/dali/internal/event/events/touch-event-impl.cpp @@ -27,18 +27,6 @@ namespace Dali namespace Internal { -TouchEvent::TouchEvent() -: mPoints(), - mTime( 0 ) -{ -} - -TouchEvent::TouchEvent( unsigned long time ) -: mPoints(), - mTime( time ) -{ -} - TouchEventPtr TouchEvent::Clone( const TouchEvent& other ) { TouchEventPtr touchEvent( new TouchEvent ); @@ -47,20 +35,6 @@ TouchEventPtr TouchEvent::Clone( const TouchEvent& other ) return touchEvent; } -TouchEvent::~TouchEvent() -{ -} - -unsigned long TouchEvent::GetTime() const -{ - return mTime; -} - -std::size_t TouchEvent::GetPointCount() const -{ - return mPoints.size(); -} - int32_t TouchEvent::GetDeviceId( std::size_t point ) const { if( point < mPoints.size() ) @@ -154,11 +128,6 @@ Integration::Point& TouchEvent::GetPoint( std::size_t point ) return mPoints[ point ]; } -void TouchEvent::AddPoint( const Integration::Point& point ) -{ - mPoints.push_back( point ); -} - Device::Class::Type TouchEvent::GetDeviceClass( std::size_t point ) const { if( point < mPoints.size() ) @@ -186,6 +155,11 @@ MouseButton::Type TouchEvent::GetMouseButton( std::size_t point ) const return MouseButton::INVALID; } +void TouchEvent::AddPoint( const Integration::Point& point ) +{ + mPoints.push_back( point ); +} + } // namsespace Internal } // namespace Dali diff --git a/dali/internal/event/events/touch-event-impl.h b/dali/internal/event/events/touch-event-impl.h index 3018763..01bdb7c 100644 --- a/dali/internal/event/events/touch-event-impl.h +++ b/dali/internal/event/events/touch-event-impl.h @@ -49,13 +49,16 @@ public: /** * @brief Default constructor */ - TouchEvent(); + TouchEvent() = default; /** * @brief Constructor * @param[in] time The time the event occurred */ - TouchEvent( unsigned long time ); + TouchEvent( unsigned long time ) + : mTime( time ) + { + } /** * @brief Clones the TouchEvent object. @@ -66,22 +69,28 @@ public: */ static TouchEventPtr Clone( const TouchEvent& other ); - /** - * @brief Destructor - */ - ~TouchEvent(); + TouchEvent( const TouchEvent& other ) = delete; ///< Deleted copy constructor. + TouchEvent( TouchEvent&& other ) = delete; ///< Deleted move constructor. + TouchEvent& operator=( const TouchEvent& other ) = delete; ///< Deleted copy assignment operator. + TouchEvent& operator=( TouchEvent&& other ) = delete; ///< Deleted move assignment operator. // Getters /** * @copydoc Dali::TouchEvent::GetTime() */ - unsigned long GetTime() const; + inline unsigned long GetTime() const + { + return mTime; + } /** * @copydoc Dali::TouchEvent::GetPointCount() */ - std::size_t GetPointCount() const; + inline std::size_t GetPointCount() const + { + return mPoints.size(); + } /** * @copydoc Dali::TouchEvent::GetDeviceId() @@ -150,14 +159,6 @@ public: */ Integration::Point& GetPoint( std::size_t point ); - // Setters - - /** - * @brief Adds a point to this touch event handler. - * @param[in] point The point to add to the touch event handler. - */ - void AddPoint( const Integration::Point& point ); - /** * @brief Get the device class the mouse/touch event originated from * @@ -179,19 +180,27 @@ public: */ MouseButton::Type GetMouseButton( std::size_t point ) const; + // Setters -private: + /** + * @brief Adds a point to this touch event handler. + * @param[in] point The point to add to the touch event handler. + */ + void AddPoint( const Integration::Point& point ); - /// Undefined Copy constructor - TouchEvent( const TouchEvent& other ); +private: - /// Undefined - TouchEvent& operator=( const TouchEvent& other ); + /** + * @brief Virtual Destructor + * + * A reference counted object may only be deleted by calling Unreference() + */ + virtual ~TouchEvent() = default; private: std::vector< Integration::Point > mPoints; ///< Container of the points for this touch event. - unsigned long mTime; ///< The time (in ms) that the touch event occurred. + unsigned long mTime{0u}; ///< The time (in ms) that the touch event occurred. }; } // namespace Internal diff --git a/dali/internal/event/events/wheel-event-impl.cpp b/dali/internal/event/events/wheel-event-impl.cpp index 2508796..6cc3d62 100755 --- a/dali/internal/event/events/wheel-event-impl.cpp +++ b/dali/internal/event/events/wheel-event-impl.cpp @@ -51,10 +51,6 @@ WheelEvent::WheelEvent( Dali::WheelEvent::Type type, int32_t direction, uint32_t { } -WheelEvent::~WheelEvent() -{ -} - WheelEventPtr WheelEvent::New( Dali::WheelEvent::Type type, int32_t direction, uint32_t modifiers, Vector2 point, int32_t delta, uint32_t timeStamp ) { WheelEventPtr wheelEvent = new WheelEvent( type, direction, modifiers, point, delta, timeStamp ); diff --git a/dali/internal/event/events/wheel-event-impl.h b/dali/internal/event/events/wheel-event-impl.h index 91c8152..17fcb35 100755 --- a/dali/internal/event/events/wheel-event-impl.h +++ b/dali/internal/event/events/wheel-event-impl.h @@ -58,11 +58,6 @@ public: WheelEvent( Dali::WheelEvent::Type type, int32_t direction, uint32_t modifiers, Vector2 point, int32_t delta, uint32_t timeStamp ); /** - * @brief Destructor - */ - ~WheelEvent(); - - /** * Create a new WheelEvent. * * @param[in] type The type of the wheel event @@ -124,6 +119,13 @@ public: private: + /** + * @brief Destructor + * + * A reference counted object may only be deleted by calling Unreference() + */ + virtual ~WheelEvent() = default; + // Not copyable or movable WheelEvent( const WheelEvent& rhs ) = delete; ///< Deleted copy constructor diff --git a/dali/public-api/events/touch-event.cpp b/dali/public-api/events/touch-event.cpp index 8239d79..d5cc27b 100755 --- a/dali/public-api/events/touch-event.cpp +++ b/dali/public-api/events/touch-event.cpp @@ -27,25 +27,17 @@ namespace Dali { -TouchEvent::TouchEvent() -: BaseHandle() -{ -} +TouchEvent::TouchEvent() = default; -TouchEvent::TouchEvent( const TouchEvent& other ) -: BaseHandle( other ) -{ -} +TouchEvent::TouchEvent( const TouchEvent& other ) = default; -TouchEvent::~TouchEvent() -{ -} +TouchEvent::TouchEvent( TouchEvent&& other ) = default; -TouchEvent& TouchEvent::operator=( const TouchEvent& other ) -{ - BaseHandle::operator=( other ); - return *this; -} +TouchEvent::~TouchEvent() = default; + +TouchEvent& TouchEvent::operator=( const TouchEvent& other ) = default; + +TouchEvent& TouchEvent::operator=( TouchEvent&& other ) = default; unsigned long TouchEvent::GetTime() const { diff --git a/dali/public-api/events/touch-event.h b/dali/public-api/events/touch-event.h index 64ae48f..59ee042 100644 --- a/dali/public-api/events/touch-event.h +++ b/dali/public-api/events/touch-event.h @@ -82,6 +82,14 @@ public: TouchEvent( const TouchEvent& other ); /** + * @brief Move constructor. + * + * @SINCE_1_9.28 + * @param[in] other The TouchEvent to move + */ + TouchEvent( TouchEvent&& other ); + + /** * @brief Destructor. * * @SINCE_1_9.26 @@ -99,6 +107,15 @@ public: */ TouchEvent& operator=( const TouchEvent& other ); + /** + * @brief Move assignment Operator. + * + * @SINCE_1_9.28 + * @param[in] other The TouchEvent to move + * @return A reference to this + */ + TouchEvent& operator=( TouchEvent&& other ); + // Getters /** -- 2.7.4