From 7f65f68f7fc73f55c6e88809a344a930e8574bcf Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Thu, 3 Mar 2022 14:39:28 +0900 Subject: [PATCH] [Tizen] Make Dali::InstrusivePtr able to compare with nullptr After explicit operation bool() patch, Dali::InstrusivePtr == nullptr make compile error. This patch fix that situation, so keep codes legacy Change-Id: I6fbdee55203a1a0e9b5d3a90125497957dddeced Signed-off-by: Eunki, Hong --- automated-tests/src/dali/utc-Dali-BaseHandle.cpp | 26 ++++++++- automated-tests/src/dali/utc-Dali-IntrusivePtr.cpp | 26 ++++++++- dali/public-api/common/intrusive-ptr.h | 61 +++++++++++++++++++++- 3 files changed, 110 insertions(+), 3 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-BaseHandle.cpp b/automated-tests/src/dali/utc-Dali-BaseHandle.cpp index b55478a..5b2061b 100644 --- a/automated-tests/src/dali/utc-Dali-BaseHandle.cpp +++ b/automated-tests/src/dali/utc-Dali-BaseHandle.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -308,6 +308,30 @@ int UtcDaliBaseHandleInequalityOperator02(void) END_TEST; } +int UtcDaliBaseHandleInequalityWithNullptr(void) +{ + TestApplication application; + tet_infoline("Test for Dali::BaseHandle::operator == nullptr"); + + BaseHandle object; + + // object is nullptr. + DALI_TEST_CHECK(object == nullptr); + DALI_TEST_CHECK(nullptr == object); + DALI_TEST_CHECK(!(object != nullptr)); + DALI_TEST_CHECK(!(nullptr != object)); + + object = Actor::New(); + + // object is not nullptr. + DALI_TEST_CHECK(!(object == nullptr)); + DALI_TEST_CHECK(!(nullptr == object)); + DALI_TEST_CHECK(object != nullptr); + DALI_TEST_CHECK(nullptr != object); + + END_TEST; +} + int UtcDaliBaseHandleStlVector(void) { TestApplication application; diff --git a/automated-tests/src/dali/utc-Dali-IntrusivePtr.cpp b/automated-tests/src/dali/utc-Dali-IntrusivePtr.cpp index 77454af..9e838a7 100644 --- a/automated-tests/src/dali/utc-Dali-IntrusivePtr.cpp +++ b/automated-tests/src/dali/utc-Dali-IntrusivePtr.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -608,3 +608,27 @@ int UtcDaliIntrusivePtrMoveAssignment(void) END_TEST; } + +/** Equality with nullptr */ +int UtcDaliIntrusivePtrOperatorEqualWithNullptr(void) +{ + tet_infoline("Test for Dali::IntrusivePtr::operator == nullptr"); + + IntrusivePtr counted1(new Counted); + + // counted1 is not nullptr. + DALI_TEST_CHECK(!(counted1 == nullptr)); + DALI_TEST_CHECK(!(nullptr == counted1)); + DALI_TEST_CHECK(counted1 != nullptr); + DALI_TEST_CHECK(nullptr != counted1); + + counted1 = nullptr; + + // counted1 is nullptr. + DALI_TEST_CHECK(counted1 == nullptr); + DALI_TEST_CHECK(nullptr == counted1); + DALI_TEST_CHECK(!(counted1 != nullptr)); + DALI_TEST_CHECK(!(nullptr != counted1)); + + END_TEST; +} diff --git a/dali/public-api/common/intrusive-ptr.h b/dali/public-api/common/intrusive-ptr.h index 9397d14..30ee989 100644 --- a/dali/public-api/common/intrusive-ptr.h +++ b/dali/public-api/common/intrusive-ptr.h @@ -2,7 +2,7 @@ #define DALI_INTRUSIVE_PTR_H /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -18,6 +18,9 @@ * */ +// EXTERNAL INCLUDES +#include // for std::nullptr_t + // INTERNAL INCLUDES #include @@ -378,6 +381,62 @@ inline bool operator!=(T* lhs, IntrusivePtr const& rhs) } /** + * @brief Comparison overrides of objects with nullptr_t. + * + * @SINCE_2_1.11 + * @param[in] lhs Intrusive pointer to compare with + * @param[in] rhs nullptr + * @return True if the pointers is nullptr + */ +template +inline bool operator==(IntrusivePtr const& lhs, std::nullptr_t rhs) +{ + return lhs.Get() == nullptr; +} + +/** + * @brief Comparison overrides of objects with nullptr_t. + * + * @SINCE_2_1.11 + * @param[in] lhs Intrusive pointer to compare with + * @param[in] rhs nullptr + * @return True if the pointers is not nullptr + */ +template +inline bool operator!=(IntrusivePtr const& lhs, std::nullptr_t rhs) +{ + return lhs.Get() != nullptr; +} + +/** + * @brief Comparison overrides of objects with nullptr_t. + * + * @SINCE_2_1.11 + * @param[in] lhs nullptr + * @param[in] rhs Intrusive pointer to compare against + * @return True if the pointers is nullptr + */ +template +inline bool operator==(std::nullptr_t lhs, IntrusivePtr const& rhs) +{ + return nullptr == rhs.Get(); +} + +/** + * @brief Comparison overrides of objects with nullptr_t. + * + * @SINCE_2_1.11 + * @param[in] lhs nullptr + * @param[in] rhs Intrusive pointer to compare against + * @return True if the pointers is not nullptr + */ +template +inline bool operator!=(std::nullptr_t lhs, IntrusivePtr const& rhs) +{ + return nullptr != rhs.Get(); +} + +/** * @} */ } // namespace Dali -- 2.7.4