19#define ADTF_IID(_interface, _striid) \
20 typedef _interface interface_type; \
21 template<_interface*> \
22 struct interface_info \
24 static constexpr const char* IID() noexcept \
46 #define UCOM_RESOLVE(...) typedef std::tuple<__VA_ARGS__> hierarchy_type;
77template<
typename T,
typename... TRemaining>
78struct peel_off_first<T, TRemaining...>
88struct is_template : ::std::false_type
97template<
template<
typename...>
class C,
typename... T>
98struct is_template<C<T...>> : ::std::true_type
107class has_interface_expose_type
126 static yes exists(
typename C::interface_expose_type*);
133 static no exists(...);
137 static constexpr bool value =
sizeof(exists<T>(
nullptr)) ==
sizeof(yes);
145class has_hierarchy_type
164 static yes exists(
typename C::hierarchy_type*);
171 static no exists(...);
175 static constexpr bool value =
sizeof(exists<T>(
nullptr)) ==
sizeof(yes);
183template<
typename T,
typename U = T*>
184class has_interface_info_type
203 static yes exists(
typename C::template interface_info<
static_cast<C*
>(
nullptr)>* =
nullptr);
210 static no exists(...);
214 static constexpr bool value =
sizeof(exists<T>(
nullptr)) ==
sizeof(yes);
221template<
typename QueriedInterface,
typename...>
222class find_intermediate : ::std::false_type
226 typedef void* first_type;
228 typedef void* second_type;
230 typedef QueriedInterface query_type;
232 typedef typename ::std::remove_pointer_t<second_type> value_type;
243template<
typename QueriedInterface,
typename... HierarchyTypes>
244class find_intermediate<QueriedInterface, ::std::tuple<HierarchyTypes...>>
247 template<
typename...>
250 typedef void key_type;
251 typedef void value_type;
252 typedef void tuple_type;
261 template<
typename KeyType,
typename ValueType,
typename... TRemaining>
262 struct extract_pair<KeyType, ValueType, TRemaining...>
264 typedef KeyType key_type;
265 typedef ValueType value_type;
266 typedef ::std::tuple<TRemaining...> tuple_type;
270 template<
typename...>
271 struct extract_wrapped_pair;
280 template<
template<
typename,
typename>
class C,
typename KeyType,
typename ValueType,
typename... TRemaining>
281 struct extract_wrapped_pair<C<KeyType, ValueType>, TRemaining...> : extract_pair<KeyType, ValueType, TRemaining...>
286 using current_type =
typename peel_off_first<HierarchyTypes...>::type;
289 using extract_pair_type =
290 typename ::std::conditional_t<is_template<current_type>::value,
292 extract_wrapped_pair<HierarchyTypes...>,
293 extract_pair<HierarchyTypes...>>;
297 using pair_type = typename ::std::conditional_t<
298 ::std::is_same_v<typename ::std::remove_cv_t<QueriedInterface>,
typename extract_pair_type::key_type>,
300 ::std::pair<typename extract_pair_type::key_type*, typename extract_pair_type::value_type*>,
301 find_intermediate<QueriedInterface, typename extract_pair_type::tuple_type>>;
305 typedef typename pair_type::first_type first_type;
306 typedef typename pair_type::second_type second_type;
309 typedef typename ::std::remove_pointer_t<first_type> query_type;
310 typedef typename ::std::remove_pointer_t<second_type> value_type;
313 static constexpr bool value = !::std::is_void_v<query_type>;
317template<
typename InterfaceType,
bool Cond>
318struct ucom_resolve_helper;
328template<
typename InterfaceType,
typename ObjectType>
330 typename ::std::enable_if_t<
331 find_intermediate<InterfaceType, typename ObjectType::hierarchy_type>::value,
332 typename ::std::conditional_t<::std::is_const_v<ObjectType>,
const InterfaceType*, InterfaceType*>
337 ucom_resolve(ObjectType* i_pObject)
noexcept
340 typename find_intermediate<InterfaceType, typename ObjectType::hierarchy_type>::value_type intermediate_type;
342 typedef typename ::std::conditional_t<::std::is_const_v<ObjectType>,
const intermediate_type*, intermediate_type*>
343 intermediate_pointer;
345 intermediate_pointer pIntermediate = i_pObject;
346 return ucom_resolve_helper<InterfaceType, has_hierarchy_type<intermediate_type>::value>::get(pIntermediate);
357template<
typename InterfaceType,
typename ObjectType>
359 typename ::std::enable_if_t<
360 !find_intermediate<InterfaceType, typename ObjectType::hierarchy_type>::value,
361 typename ::std::conditional_t<::std::is_const_v<ObjectType>,
const InterfaceType*, InterfaceType*>
366 ucom_resolve(ObjectType* i_pObject)
noexcept
375template<
typename InterfaceType>
376struct ucom_resolve_helper<InterfaceType, true>
385 template<
typename IntermediateType>
387 typename ::std::conditional_t<::std::is_const_v<IntermediateType>,
const InterfaceType*, InterfaceType*>
388 get(IntermediateType* i_pObject)
noexcept
390 return ucom_resolve<InterfaceType, IntermediateType>(i_pObject);
398template<
typename InterfaceType>
399struct ucom_resolve_helper<InterfaceType, false>
408 template<
typename IntermediateType>
410 typename ::std::conditional_t<::std::is_const_v<IntermediateType>,
const InterfaceType*, InterfaceType*>
411 get(IntermediateType* i_pObject)
noexcept
428template<
typename Interface>
431 typedef typename ::std::remove_const_t<typename ::std::remove_pointer_t<Interface>> value_type;
432 static_assert(::std::is_same<value_type, typename value_type::interface_type>::value,
433 "get_iid<> failed. Check whether your interface correctly defined ADTF_IID()");
435 constexpr typename value_type::interface_type* pNullInstance =
nullptr;
436 (void) (pNullInstance);
437 return value_type::template interface_info<pNullInstance>::IID();
444template<
typename Interface>
445constexpr const char*
get_iid(
const Interface&)
noexcept
454template<
typename Interface>
455constexpr const char*
get_iid(
const Interface*)
noexcept
466template<
typename... Interfaces>
475 template<
typename... InterfacesInner>
486 template<
typename Prov
ider,
typename Vo
idType>
487 static constexpr tResult dispatch(Provider*,
const char*, VoidType*& o_pInterface)
noexcept
489 o_pInterface =
nullptr;
490 return ERR_NO_INTERFACE;
499 template<
typename Interface,
typename... InterfacesInner>
500 struct iid_dispatch<Interface, InterfacesInner...>
510 template<
typename ObjectType,
typename Vo
idType>
511 static constexpr typename ::std::enable_if_t<detail::has_hierarchy_type<ObjectType>::value,
void>
512 resolve(ObjectType* i_pObject, VoidType*& o_pInterface)
noexcept
514 o_pInterface = detail::ucom_resolve<Interface>(i_pObject);
525 template<
typename ObjectType,
typename Vo
idType>
526 static constexpr typename ::std::enable_if_t<!detail::has_hierarchy_type<ObjectType>::value,
void>
527 resolve(ObjectType* i_pObject, VoidType*& o_pInterface)
noexcept
529 typedef typename ::std::conditional_t<::std::is_const_v<ObjectType>,
const Interface*, Interface*>
531 o_pInterface =
static_cast<interface_pointer
>(i_pObject);
549 template<
typename Prov
ider,
typename Vo
idType>
550 static tResult dispatch(Provider* i_pObj,
const char* i_strIID, VoidType*& o_pInterface)
noexcept
554 resolve(i_pObj, o_pInterface);
558 return iid_dispatch<InterfacesInner...>::dispatch(i_pObj, i_strIID, o_pInterface);
584 template<
typename Prov
ider,
typename Vo
idType>
585 static tResult Get(Provider* i_pObj,
const char* i_strIID, VoidType*& o_pInterface)
noexcept
587 static_assert(::std::is_void_v<VoidType>,
"\"VoidType\" must be of type void");
588 return iid_dispatch<Interfaces...>::dispatch(i_pObj, i_strIID, o_pInterface);
637template<
typename Child,
typename... Interfaces,
typename... Parents>
668 static_assert(::std::is_base_of_v<default_object, Child>,
669 "The given Child type must be a child type of this default_object type!");
670 return interface_expose_type::Get(
static_cast<Child*
>(
this), i_strIID, o_pInterface);
691 static_assert(::std::is_base_of_v<default_object, Child>,
692 "The given Child type must be a child type of this default_object type!");
693 return interface_expose_type::Get(
static_cast<const Child*
>(
this), i_strIID, o_pInterface);
699 [[deprecated(
"Use of Destroy results in a mismatched deallocation. Use adtf::ucom::allocate_object_ptr "
700 "instead.")]]
virtual void
725template<
typename BASE_OBJECT,
typename EXTEND_INTERFACE,
typename Child>
754 static_assert(::std::is_base_of_v<extend_object, Child>,
755 "The given Child type must be a child type of this extend_object type!");
756 if (
IS_FAILED(interface_expose<EXTEND_INTERFACE>::Get(
static_cast<Child*
>(
this), i_strIID, o_pInterface)))
758 return BASE_OBJECT::GetInterface(i_strIID, o_pInterface);
780 static_assert(::std::is_base_of_v<extend_object, Child>,
781 "The given Child type must be a child type of this extend_object type!");
782 if (
IS_FAILED(interface_expose<EXTEND_INTERFACE>::Get(
static_cast<const Child*
>(
this), i_strIID, o_pInterface)))
784 return BASE_OBJECT::GetInterface(i_strIID, o_pInterface);
792 [[deprecated(
"Use of Destroy results in a mismatched deallocation. Use adtf::ucom::allocate_object_ptr "
793 "instead.")]]
virtual void
816template<
typename... Interfaces>
820template<
typename... ParentTypes>
824template<
typename... InterfaceTypes>
828template<
typename... Types>
832template<
typename BASE_CLASS,
typename EXTEND_INTERFACE,
typename Child>
#define IS_FAILED(s)
Check if result is failed.
Definition result.h:20
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
virtual ~default_object()
Protected destructor --> Only the final implementation can be destroyed!
Definition adtf_iid.h:646
virtual tResult GetInterface(const char *i_strIID, void *&o_pInterface) noexcept
Default implementation of IObject::GetInterface()
Definition adtf_iid.h:665
virtual void Destroy() const
Default implementation to destroy an object of this type.
Definition adtf_iid.h:701
interface_expose< Interfaces... > interface_expose_type
Enables accessing the exposed interfaces via typedef (e.g. for ucom_cast<> access)
Definition adtf_iid.h:642
virtual tResult GetInterface(const char *i_strIID, const void *&o_pInterface) const noexcept
Default implementation of IObject::GetInterface() provided for const correctness.
Definition adtf_iid.h:688
Used to implement IObject::GetInterface() methods with given interfaces to expose.
Definition adtf_iid.h:727
virtual tResult GetInterface(const char *i_strIID, const void *&o_pInterface) const noexcept
Default implementation of IObject::GetInterface() provided for const correctness.
Definition adtf_iid.h:778
virtual tResult GetInterface(const char *i_strIID, void *&o_pInterface) noexcept
Default implementation of IObject::GetInterface()
Definition adtf_iid.h:752
BASE_OBJECT base_type
base object type
Definition adtf_iid.h:729
virtual void Destroy() const
Default implementation to destroy an object of this type.
Definition adtf_iid.h:794
virtual ~extend_object()
Protected destructor --> Only the final implementation can be destroyed!
Definition adtf_iid.h:733
Definition adtf_iid.h:468
constexpr const char * get_iid() noexcept
Definition adtf_iid.h:429
ant::default_object< Types... > default_object
Alias bringing the latest version of meta struct template ant::default_object into scope.
Definition adtf_iid.h:829
ant::extend_object< BASE_CLASS, EXTEND_INTERFACE, Child > extend_object
Alias bringing the latest version of meta struct template ant::extend_object into scope.
Definition adtf_iid.h:833
ant::inherit_from< ParentTypes... > inherit_from
Alias bringing the latest version of meta struct template ant::inherit_from into scope.
Definition adtf_iid.h:821
ant::interface_expose< Interfaces... > interface_expose
Alias bringing the latest version of meta struct template ant::interface_expose into scope.
Definition adtf_iid.h:817
ant::expose_interfaces< InterfaceTypes... > expose_interfaces
Alias bringing the latest version of meta struct template ant::expose_interfaces into scope.
Definition adtf_iid.h:825
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14
Declares the class to use when implementing IObject::GetInterface() using inheritance.
Definition adtf_iid.h:619
Meta struct template evaluated at compile time when compiling default_object.
Definition adtf_iid.h:611
Meta struct template evaluated at compile time when compiling default_object.
Definition adtf_iid.h:600