|
@@ -384,31 +384,27 @@ inline bool IsKindOf(const Ref<Type> &inObject, const RTTI *inRTTI)
|
|
|
}
|
|
|
|
|
|
/// Cast inObject to DstType, asserts on failure
|
|
|
-template <class DstType, class SrcType>
|
|
|
+template <class DstType, class SrcType, std::enable_if_t<std::is_base_of_v<DstType, SrcType> || std::is_base_of_v<SrcType, DstType>, bool> = true>
|
|
|
inline const DstType *StaticCast(const SrcType *inObject)
|
|
|
{
|
|
|
- JPH_ASSERT(IsKindOf(inObject, JPH_RTTI(DstType)), "Invalid cast");
|
|
|
return static_cast<const DstType *>(inObject);
|
|
|
}
|
|
|
|
|
|
-template <class DstType, class SrcType>
|
|
|
+template <class DstType, class SrcType, std::enable_if_t<std::is_base_of_v<DstType, SrcType> || std::is_base_of_v<SrcType, DstType>, bool> = true>
|
|
|
inline DstType *StaticCast(SrcType *inObject)
|
|
|
{
|
|
|
- JPH_ASSERT(IsKindOf(inObject, JPH_RTTI(DstType)), "Invalid cast");
|
|
|
return static_cast<DstType *>(inObject);
|
|
|
}
|
|
|
|
|
|
-template <class DstType, class SrcType>
|
|
|
-inline RefConst<DstType> StaticCast(RefConst<SrcType> &inObject)
|
|
|
+template <class DstType, class SrcType, std::enable_if_t<std::is_base_of_v<DstType, SrcType> || std::is_base_of_v<SrcType, DstType>, bool> = true>
|
|
|
+inline const DstType *StaticCast(const RefConst<SrcType> &inObject)
|
|
|
{
|
|
|
- JPH_ASSERT(IsKindOf(inObject, JPH_RTTI(DstType)), "Invalid cast");
|
|
|
return static_cast<const DstType *>(inObject.GetPtr());
|
|
|
}
|
|
|
|
|
|
-template <class DstType, class SrcType>
|
|
|
-inline Ref<DstType> StaticCast(Ref<SrcType> &inObject)
|
|
|
+template <class DstType, class SrcType, std::enable_if_t<std::is_base_of_v<DstType, SrcType> || std::is_base_of_v<SrcType, DstType>, bool> = true>
|
|
|
+inline DstType *StaticCast(const Ref<SrcType> &inObject)
|
|
|
{
|
|
|
- JPH_ASSERT(IsKindOf(inObject, JPH_RTTI(DstType)), "Invalid cast");
|
|
|
return static_cast<DstType *>(inObject.GetPtr());
|
|
|
}
|
|
|
|
|
@@ -426,13 +422,13 @@ inline DstType *DynamicCast(SrcType *inObject)
|
|
|
}
|
|
|
|
|
|
template <class DstType, class SrcType>
|
|
|
-inline RefConst<DstType> DynamicCast(RefConst<SrcType> &inObject)
|
|
|
+inline const DstType *DynamicCast(const RefConst<SrcType> &inObject)
|
|
|
{
|
|
|
return inObject != nullptr? reinterpret_cast<const DstType *>(inObject->CastTo(JPH_RTTI(DstType))) : nullptr;
|
|
|
}
|
|
|
|
|
|
template <class DstType, class SrcType>
|
|
|
-inline Ref<DstType> DynamicCast(Ref<SrcType> &inObject)
|
|
|
+inline DstType *DynamicCast(const Ref<SrcType> &inObject)
|
|
|
{
|
|
|
return inObject != nullptr? const_cast<DstType *>(reinterpret_cast<const DstType *>(inObject->CastTo(JPH_RTTI(DstType)))) : nullptr;
|
|
|
}
|