return ostream;
}
+std::ostream& operator<<(std::ostream& ostream, BaseHandle handle)
+{
+ return ostream << static_cast<void*>(handle.GetObjectPtr());
+}
+
void DALI_TEST_EQUALS(const BaseHandle& baseHandle1, const BaseHandle& baseHandle2, const char* location)
{
DALI_TEST_EQUALS<const BaseHandle&>(baseHandle1, baseHandle2, location);
std::ostream& operator<<(std::ostream& ostream, TimePeriod value);
std::ostream& operator<<(std::ostream& ostream, Radian angle);
std::ostream& operator<<(std::ostream& ostream, Degree angle);
+std::ostream& operator<<(std::ostream& ostream, BaseHandle handle);
/**
* Test whether two values are equal.
<< " usageFlags:" << std::hex << createInfo.usageFlags
<< " data:" << std::hex << createInfo.data
<< " dataSize:" << std::dec << createInfo.dataSize
- << " nativeImagePtr:" << std::hex << createInfo.nativeImagePtr;
+ << " nativeImagePtr:" << std::hex << createInfo.nativeImagePtr.Get();
return o;
}
class FakeObject : public BaseObject
{
};
-// used for testing ThisIsSaferThanReturningVoidStar
-class FakeHandle : public BaseHandle
-{
-public:
- void RunTest()
- {
- return ThisIsSaferThanReturningVoidStar();
- }
-};
} // namespace
int UtcDaliBaseHandleConstructorVoid(void)
END_TEST;
}
-int UtcDaliBaseHandleThisIsSaferThanReturningVoidStar(void)
-{
- TestApplication application;
- tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
- FakeHandle handle;
- handle.RunTest();
- tet_result(TET_PASS);
- END_TEST;
-}
-
int UtcDaliBaseHandleGetTypeInfoN(void)
{
TestApplication application;
int UtcDaliBaseHandleBooleanCast(void)
{
TestApplication application;
- tet_infoline("Testing Dali::BaseHandle::BooleanType");
+ tet_infoline("Testing Dali::BaseHandle::operator bool");
// get the root layer
BaseHandle handle = Actor::New();
- DALI_TEST_CHECK(static_cast<BaseHandle::BooleanType>(handle));
+ DALI_TEST_CHECK(static_cast<bool>(handle));
END_TEST;
}
END_TEST;
}
-int UtcDaliIntrusivePtrOperatorBooleanTypeP(void)
+int UtcDaliIntrusivePtrOperatorBoolP(void)
{
- tet_infoline("Positive Test for Dali::IntrusivePtr::operator Booleantype()");
+ tet_infoline("Positive Test for Dali::IntrusivePtr::operator bool()");
IntrusivePtr<Counted> counted(new Counted);
- DALI_TEST_CHECK(counted.operator BooleanType() != 0);
+ DALI_TEST_CHECK(counted.operator bool() == true);
DALI_TEST_CHECK(counted);
- typedef void (IntrusivePtr<Counted>::*BoolIdiomFunc)() const;
- BoolIdiomFunc func = static_cast<BoolIdiomFunc>(counted.operator BooleanType());
- ((counted).*func)(); // purely for test coverage
-
counted.Reset();
- DALI_TEST_CHECK(counted.operator BooleanType() == 0);
+ DALI_TEST_CHECK(counted.operator bool() == false);
END_TEST;
}
-int UtcDaliIntrusivePtrOperatorBooleanTypeN(void)
+int UtcDaliIntrusivePtrOperatorBoolN(void)
{
- tet_infoline("Negative Test for Dali::IntrusivePtr::operator Booleantype()");
+ tet_infoline("Negative Test for Dali::IntrusivePtr::operator bool()");
IntrusivePtr<Counted> counted;
- DALI_TEST_CHECK(counted.operator BooleanType() == 0);
+ DALI_TEST_CHECK(counted.operator bool() == false);
DALI_TEST_CHECK(!counted);
END_TEST;
}
}
}
- // Handle comparisons - This is a variation of the safe bool idiom
+ // Handle comparisons
/**
- * Pointer-to-member type. Objects can be implicitly converted to this for validity checks.
- */
- using BooleanType = void (OwnerPointer<T>::*)() const;
-
- /**
- * Converts an object handle to a BooleanType.
+ * Converts an object handle to a bool.
* This is useful for checking whether the handle is NULL.
*/
- operator BooleanType() const
+ explicit operator bool() const
{
- return (mObject != nullptr) ? &OwnerPointer::ThisIsSaferThanReturningVoidStar : nullptr;
+ return mObject != nullptr;
}
private:
- /**
- * Used by the safe bool idiom.
- */
- void ThisIsSaferThanReturningVoidStar() const
- {
- }
-
// data
T* mObject; ///< Raw pointer to the object
};
bool Texture::IsNative() const
{
- return mNativeImage != nullptr;
+ return static_cast<bool>(mNativeImage);
}
bool Texture::ApplyNativeFragmentShader(std::string& shader)
{
bool modified = false;
- if(mNativeImage != nullptr && !shader.empty())
+ if(mNativeImage && !shader.empty())
{
modified = mNativeImage->ApplyNativeFragmentShader(shader);
}
void Texture::Upload(PixelDataPtr pixelData, const Internal::Texture::UploadParams& params)
{
- DALI_ASSERT_ALWAYS(mNativeImage == nullptr);
+ DALI_ASSERT_ALWAYS(!mNativeImage);
if(!mGraphicsTexture)
{
*/
[[nodiscard]] bool IsNativeImage() const
{
- return mNativeImage;
+ return static_cast<bool>(mNativeImage);
}
private:
void RenderTaskList::AddTask(OwnerPointer<RenderTask>& newTask)
{
- DALI_ASSERT_DEBUG(newTask != NULL && "SceneGraph RenderTask is null");
+ DALI_ASSERT_DEBUG(newTask && "SceneGraph RenderTask is null");
DALI_ASSERT_DEBUG(mRenderMessageDispatcher != NULL && "RenderMessageDispatcher is null");
newTask->Initialize(*mRenderMessageDispatcher);
IntrusivePtr(rhs).Swap(*this);
}
- // IntrusivePtr comparisons - This is a variation of the safe bool idiom
+ // IntrusivePtr comparisons
/**
- * @brief Pointer-to-member type.
- *
- * Objects can be implicitly converted to this for validity checks.
- */
- using BooleanType = void (IntrusivePtr<T>::*)() const;
-
- /**
- * @brief Converts an object handle to a BooleanType.
+ * @brief Converts an object handle to a bool.
*
* This is useful for checking whether the handle is NULL.
* @SINCE_1_0.0
*/
- operator BooleanType() const
+ explicit operator bool() const
{
- return mPtr ? &IntrusivePtr::ThisIsSaferThanReturningVoidStar : nullptr;
+ return mPtr != nullptr;
}
/**
private:
/**
- * @brief Used by the safe bool idiom.
- * @SINCE_1_0.0
- */
- void ThisIsSaferThanReturningVoidStar() const
- {
- }
-
- /**
* @brief Internal swap function.
* @SINCE_1_0.0
*/
mObjectHandle = nullptr;
}
-BaseHandle::operator BaseHandle::BooleanType() const
+BaseHandle::operator bool() const
{
- return mObjectHandle ? &BaseHandle::ThisIsSaferThanReturningVoidStar : nullptr;
+ return static_cast<bool>(mObjectHandle);
}
bool BaseHandle::operator==(const BaseHandle& rhs) const
*/
void Reset();
- // BaseHandle comparisons - This is a variation of the safe bool idiom
+ // BaseHandle comparisons
/**
- * @brief Pointer-to-member type.
- * Objects can be implicitly converted to this for validity checks.
- */
- using BooleanType = void (BaseHandle::*)() const;
-
- /**
- * @brief Converts an handle to a BooleanType.
+ * @brief Converts an handle to a bool.
*
* This is useful for checking whether the handle is empty.
* @SINCE_1_0.0
*/
- operator BooleanType() const;
+ explicit operator bool() const;
/**
* @brief Equality operator overload.
*/
bool DoConnectSignal(ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functorDelegate);
-protected:
- /**
- * @brief Used by the safe bool idiom.
- *
- * The safe bool idiom basically provides a Boolean test for classes. It validates objects
- * in a boolean context without the usual harmful side effects.
- * @SINCE_1_0.0
- */
- void ThisIsSaferThanReturningVoidStar() const
- {
- }
-
private:
IntrusivePtr<Dali::RefObject> mObjectHandle; ///< Object this handle points at.
};
return T::DownCast(handle);
}
-// See also BaseHandle::BooleanType() conversion
-
/**
* @brief Equality operator.
* @SINCE_1_0.0
template<typename T>
inline bool operator==(const BaseHandle& lhs, const T& rhs)
{
- // We depart from the safe bool idiom to allow Dali::BaseHandle derived classes to be compared
return lhs == static_cast<const BaseHandle&>(rhs);
}
template<typename T>
inline bool operator!=(const BaseHandle& lhs, const T& rhs)
{
- // We depart from the safe bool idiom to allow Dali::BaseHandle derived classes to be compared
return lhs != static_cast<const BaseHandle&>(rhs);
}