8#ifndef _ADTF_UCOM_ANT_UCOM_CAST_INCLUDES_HEADER_
9#define _ADTF_UCOM_ANT_UCOM_CAST_INCLUDES_HEADER_
30struct ucom_cast_cache final
32 static constexpr auto cache_miss = (::std::numeric_limits<::std::ptrdiff_t>::lowest)();
33 static constexpr auto interface_not_found = (::std::numeric_limits<::std::ptrdiff_t>::max)();
42 static ::std::ptrdiff_t& open_cache_line(
const IObject* pBase, const ::std::type_info* pTargetType)
noexcept;
50template<
typename QueriedInterfaceType,
bool>
51struct ucom_cast_to_implicit_cast final
60 template<
typename ObjectType>
61 static QueriedInterfaceType* perform_cast(ObjectType* i_pObject)
noexcept
64 using interface_type =
65 typename ::std::conditional_t<::std::is_const_v<QueriedInterfaceType>,
const IObject,
IObject>;
67 typename ::std::conditional_t<::std::is_const_v<QueriedInterfaceType>,
const IObject*,
IObject*>;
68 using void_pointer = typename ::std::conditional_t<::std::is_const_v<QueriedInterfaceType>,
const void*,
void*>;
69 using memory_type = typename ::std::conditional_t<::std::is_const_v<QueriedInterfaceType>,
const char*,
char*>;
72 if (
nullptr != i_pObject)
74 base_pointer
const pBase = ucom_cast_to_implicit_cast<interface_type, true>::perform_cast(i_pObject);
75 auto& nCachedOffset = ucom_cast_cache::open_cache_line(pBase, &
typeid(::std::remove_cv_t<QueriedInterfaceType>));
76 if (ucom_cast_cache::cache_miss == nCachedOffset)
80 QueriedInterfaceType* nRet =
nullptr;
81 const char*
const strIID = get_iid<QueriedInterfaceType*>();
82 if (pBase->GetInterface(strIID,
reinterpret_cast<void_pointer&
>(nRet)).IsOk())
84 nCachedOffset =
reinterpret_cast<memory_type
>(nRet) -
reinterpret_cast<memory_type
>(pBase);
89 nCachedOffset = ucom_cast_cache::interface_not_found;
92 else if (ucom_cast_cache::interface_not_found != nCachedOffset)
94 return reinterpret_cast<QueriedInterfaceType*
>(
reinterpret_cast<memory_type
>(pBase) + nCachedOffset);
106template<
typename QueriedInterfaceType>
107struct ucom_cast_to_implicit_cast<QueriedInterfaceType, true> final
118 template<
typename ObjectType>
119 static constexpr typename ::std::enable_if_t<detail::has_hierarchy_type<ObjectType>::value, QueriedInterfaceType>*
120 perform_cast(ObjectType* i_pObject)
noexcept
123 return ucom_resolve<QueriedInterfaceType>(i_pObject);
134 template<
typename ObjectType>
135 static constexpr typename ::std::enable_if_t<!detail::has_hierarchy_type<ObjectType>::value, QueriedInterfaceType>*
136 perform_cast(ObjectType* i_pObject)
noexcept
156template<
typename InterfacePo
interType,
typename ObjectPo
interType>
157InterfacePointerType
ucom_cast(ObjectPointerType i_pObject)
noexcept
159 using object_type = typename ::std::remove_pointer_t<ObjectPointerType>;
160 using interface_type = typename ::std::remove_pointer_t<InterfacePointerType>;
163 static_assert(::std::is_pointer_v<ObjectPointerType>,
"ucom_cast<> failed. \"i_pObject\" is not a pointer");
164 static_assert(::std::is_base_of_v<IObject, typename ::std::remove_const_t<object_type>>,
165 "ucom_cast<> failed. \"i_pObject\" does not point to a type derived from IObject");
168 return detail::ucom_cast_to_implicit_cast<
169 typename ::std::conditional_t<::std::is_const_v<object_type>,
const interface_type, interface_type>,
170 ::std::is_base_of_v<interface_type, object_type>>::perform_cast(i_pObject);
Definition object_intf.h:33
Namespace for all internally used functionality implemented.
Definition class_info.h:17
Namespace for all functionality of the ADTF UCOM SDK provided since v3.0.
Definition test_runtime.h:14
InterfacePointerType ucom_cast(ObjectPointerType i_pObject) noexcept
Definition ucom_cast.h:157
Namespace for the ADTF uCOM SDK.
Definition adtf_system.h:324
ant::IObject IObject
Alias always bringing the latest version of ant::IObject into scope.
Definition object_intf.h:109
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14