mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0027104: DownCast() cannot return null for mismatched handle
Method DownCast() is made template, to be available only when argument is actually a pointer or handle to a base class. For compatibility with existing code, method DownCast() that can be used for the same type, derived, or unrelated class (i.e. where there is no actual down casting) is still available, its use shall cause "deprecated" compiler warning. OCCT code is updated to remove meaningless DownCast()s; a few places where DownCast() was used with argument of unrelated type are corrected. DRAW command QAHandleCast is removed (it was useful only during redesign of handles).
This commit is contained in:
@@ -181,16 +181,34 @@ namespace opencascade {
|
||||
return get() < theHandle.get();
|
||||
}
|
||||
|
||||
//! Down casting operator
|
||||
//! Down casting operator from handle to base type
|
||||
template <class T2>
|
||||
static handle DownCast (const handle<T2>& theObject)
|
||||
static typename std::enable_if<is_base_but_not_same<T2, T>::value, handle>::type
|
||||
DownCast (const handle<T2>& theObject)
|
||||
{
|
||||
return handle (dynamic_cast<T*>(const_cast<T2*>(theObject.get())));
|
||||
}
|
||||
|
||||
//! Down casting operator
|
||||
//! Down casting operator from pointer to base type
|
||||
template <class T2>
|
||||
static handle DownCast (const T2* thePtr)
|
||||
static typename std::enable_if<is_base_but_not_same<T2, T>::value, handle>::type
|
||||
DownCast (const T2* thePtr)
|
||||
{
|
||||
return handle (dynamic_cast<T*>(const_cast<T2*>(thePtr)));
|
||||
}
|
||||
|
||||
//! For compatibility, define down casting operator from non-base type, as deprecated
|
||||
template <class T2>
|
||||
Standard_DEPRECATED("down-casting from object of the same or unrelated type is meaningless")
|
||||
static handle DownCast (const handle<T2>& theObject, typename std::enable_if<!is_base_but_not_same<T2, T>::value, void*>::type = 0)
|
||||
{
|
||||
return handle (dynamic_cast<T*>(const_cast<T2*>(theObject.get())));
|
||||
}
|
||||
|
||||
//! For compatibility, define down casting operator from non-base type, as deprecated
|
||||
template <class T2>
|
||||
Standard_DEPRECATED("down-casting from object of the same or unrelated type is meaningless")
|
||||
static handle DownCast (const T2* thePtr, typename std::enable_if<!is_base_but_not_same<T2, T>::value, void*>::type = 0)
|
||||
{
|
||||
return handle (dynamic_cast<T*>(const_cast<T2*>(thePtr)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user