19#define ADTF_IID(_interface, _striid) \
20 typedef _interface interface_type; \
21 template<_interface*> \
22 struct interface_info \
24 static const char* IID() \
19#define ADTF_IID(_interface, _striid) \ …
45 #define UCOM_RESOLVE(...) typedef std::tuple < __VA_ARGS__ > hierarchy_type;
65template<
typename...>
struct peel_off_first {
typedef void type; };
71template<
typename T,
typename... TRemaining>
72struct peel_off_first<T, TRemaining...>
82struct is_template : std::false_type {};
89template<
template<
typename...>
class C,
typename ...T>
90struct is_template<C<T...>> : std::true_type {};
97class has_interface_expose_type
100 struct yes {
char x[1]; };
102 struct no {
char x[2]; };
109 template<
typename C>
static yes exists(
typename C::interface_expose_type*);
115 template<
typename C>
static no exists(...);
119 static const bool value =
sizeof(exists<T>(
nullptr)) ==
sizeof(yes);
127class has_hierarchy_type
130 struct yes {
char x[1]; };
132 struct no {
char x[2]; };
139 template<
typename C>
static yes exists(
typename C::hierarchy_type*);
145 template<
typename C>
static no exists(...);
149 static const bool value =
sizeof(exists<T>(
nullptr)) ==
sizeof(yes);
160class has_interface_info_type
163 struct yes {
char x[1]; };
165 struct no {
char x[2]; };
173 static yes exists(
typename C::template interface_info<
static_cast<C*
>(
nullptr)>* =
nullptr);
179 template<
typename C>
static no exists(...);
183 static const bool value =
sizeof(exists<T>(
nullptr)) ==
sizeof(yes);
190template<
typename QueriedInterface,
typename ...>
191class find_intermediate : std::false_type
195 typedef void* first_type;
197 typedef void* second_type;
199 typedef QueriedInterface query_type;
201 typedef typename std::remove_pointer<second_type>::type value_type;
212template<
typename QueriedInterface,
typename ...HierarchyTypes>
213class find_intermediate<QueriedInterface, std::tuple<HierarchyTypes...>>
216 template<
typename...>
219 typedef void key_type;
220 typedef void value_type;
221 typedef void tuple_type;
230 template<
typename KeyType,
typename ValueType,
typename... TRemaining>
231 struct extract_pair<KeyType, ValueType, TRemaining...>
233 typedef KeyType key_type;
234 typedef ValueType value_type;
235 typedef std::tuple<TRemaining...> tuple_type;
239 template<
typename...>
240 struct extract_wrapped_pair;
249 template<
template<
typename,
typename>
class C,
252 typename ...TRemaining>
253 struct extract_wrapped_pair<C<KeyType, ValueType>, TRemaining...> :
254 extract_pair<KeyType, ValueType, TRemaining...> {};
257 typedef typename peel_off_first<HierarchyTypes...>::type current_type;
263 is_template<current_type>::value,
264 extract_wrapped_pair<HierarchyTypes...>,
265 extract_pair<HierarchyTypes...>
266 >::type extract_pair_type;
275 typename std::remove_cv<QueriedInterface>::type,
276 typename extract_pair_type::key_type
279 std::pair<
typename extract_pair_type::key_type*,
280 typename extract_pair_type::value_type*>,
281 find_intermediate<QueriedInterface, typename extract_pair_type::tuple_type>
286 typedef typename pair_type::first_type first_type;
287 typedef typename pair_type::second_type second_type;
290 typedef typename std::remove_pointer<first_type>::type query_type;
291 typedef typename std::remove_pointer<second_type>::type value_type;
294 static const bool value = !std::is_void<query_type>::value;
298template<
typename InterfaceType,
bool Cond>
299struct ucom_resolve_helper;
309template<
typename InterfaceType,
typename ObjectType>
313 find_intermediate< InterfaceType, typename ObjectType::hierarchy_type >::value,
314 typename std::conditional
316 std::is_const<ObjectType>::value,
317 const InterfaceType*,
321ucom_resolve(ObjectType* i_pObject)
327 typename ObjectType::hierarchy_type
328 >::value_type intermediate_type;
333 std::is_const<ObjectType>::value,
334 const intermediate_type*,
336 >::type intermediate_pointer;
338 intermediate_pointer pIntermediate = i_pObject;
339 return ucom_resolve_helper<InterfaceType,
340 has_hierarchy_type<intermediate_type>::value>::get(pIntermediate);
351template<
typename InterfaceType,
typename ObjectType>
355 !find_intermediate< InterfaceType, typename ObjectType::hierarchy_type >::value,
356 typename std::conditional
358 std::is_const<ObjectType>::value,
359 const InterfaceType*,
363ucom_resolve(ObjectType* i_pObject)
372template<
typename InterfaceType>
373struct ucom_resolve_helper<InterfaceType, true>
382 template<
typename IntermediateType>
383 static typename std::conditional
385 std::is_const<IntermediateType>::value,
386 const InterfaceType*,
389 get(IntermediateType* i_pObject)
391 return ucom_resolve<InterfaceType, IntermediateType>(i_pObject);
399template<
typename InterfaceType>
400struct ucom_resolve_helper<InterfaceType, false>
409 template<
typename IntermediateType>
410 static typename std::conditional
412 std::is_const<IntermediateType>::value,
413 const InterfaceType*,
416 get(IntermediateType* i_pObject)
433template<
typename Interface>
437 typedef typename remove_const<typename remove_pointer<Interface>::type>::type value_type;
438 static_assert(is_same<value_type, typename value_type::interface_type>::value,
439 "get_iid<> failed. Check whether your interface correctly defined ADTF_IID()");
441 constexpr typename value_type::interface_type* pNullInstance =
nullptr;
442 (void)(pNullInstance);
443 return value_type::template interface_info<pNullInstance>::IID();
450template<
typename Interface>
const char*
get_iid(
const Interface&)
450template<
typename Interface>
const char*
get_iid(
const Interface&) {
…}
459template<
typename Interface>
const char*
get_iid(
const Interface*)
459template<
typename Interface>
const char*
get_iid(
const Interface*) {
…}
470template<
typename ...Interfaces>
479 template<
typename ...InterfacesInner>
490 template<
typename Prov
ider,
typename Vo
idType>
491 static tResult dispatch(Provider*,
const char*, VoidType*& o_pInterface)
493 o_pInterface =
nullptr;
494 return ERR_NO_INTERFACE;
503 template<
typename Interface,
typename ...InterfacesInner>
504 struct iid_dispatch<Interface, InterfacesInner...>
514 template<
typename ObjectType,
typename Vo
idType>
515 static typename std::enable_if<detail::has_hierarchy_type<ObjectType>::value,
void>::type
516 resolve(ObjectType* i_pObject, VoidType*& o_pInterface)
518 o_pInterface = detail::ucom_resolve<Interface>(i_pObject);
529 template<
typename ObjectType,
typename Vo
idType>
530 static typename std::enable_if<!detail::has_hierarchy_type<ObjectType>::value,
void>::type
531 resolve(ObjectType* i_pObject, VoidType*& o_pInterface)
533 typedef typename std::conditional
535 std::is_const<ObjectType>::value,
538 >::type interface_pointer;
539 o_pInterface =
static_cast<interface_pointer
>(i_pObject);
557 template<
typename Prov
ider,
typename Vo
idType>
558 static tResult dispatch(Provider* i_pObj,
const char* i_strIID, VoidType*& o_pInterface)
563 resolve(i_pObj, o_pInterface);
567 return iid_dispatch<InterfacesInner...>::dispatch(i_pObj, i_strIID, o_pInterface);
593 template<
typename Prov
ider,
typename Vo
idType>
594 static tResult Get(Provider* i_pObj,
const char* i_strIID, VoidType*& o_pInterface)
596 static_assert(std::is_void<VoidType>::value,
"\"VoidType\" must be of type void");
597 return iid_dispatch<Interfaces...>::dispatch(i_pObj, i_strIID, o_pInterface);
594 static tResult Get(Provider* i_pObj,
const char* i_strIID, VoidType*& o_pInterface) {
…}
616template<
typename ...>
642template<
typename Child,
typename ...Interfaces,
typename ...Parents>
674 static_assert(std::is_base_of<default_object, Child>::value,
675 "The given Child type must be a child type of this default_object type!");
697 static_assert(std::is_base_of<default_object, Child>::value,
698 "The given Child type must be a child type of this default_object type!");
705 [[deprecated(
"Use of Destroy results in a mismatched deallocation. Use adtf::ucom::allocate_object_ptr "
706 "instead.")]]
virtual void
731template<
typename BASE_OBJECT,
typename EXTEND_INTERFACE,
typename Child>
758 static_assert(std::is_base_of<extend_object, Child>::value,
759 "The given Child type must be a child type of this extend_object type!");
764 return BASE_OBJECT::GetInterface(i_strIID, o_pInterface);
786 static_assert(std::is_base_of<extend_object, Child>::value,
787 "The given Child type must be a child type of this extend_object type!");
792 return BASE_OBJECT::GetInterface(i_strIID, o_pInterface);
800 [[deprecated(
"Use of Destroy results in a mismatched deallocation. Use adtf::ucom::allocate_object_ptr "
801 "instead.")]]
virtual void
824template<
typename ...Interfaces>
828template<
typename ...ParentTypes>
832template<
typename ...InterfaceTypes>
836template<
typename ...Types>
840template<
typename BASE_CLASS,
typename EXTEND_INTERFACE,
typename Child>
Copyright © Audi Electronics Venture GmbH.
#define IS_FAILED(s)
Check if result is failed.
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
interface_expose< Interfaces... > interface_expose_type
Enables accessing the exposed interfaces via typedef (e.g. for ucom_cast<> access)
virtual void Destroy() const
Default implementation to destroy an object of this type.
virtual tResult GetInterface(const char *i_strIID, const void *&o_pInterface) const
Default implementation of IObject::GetInterface() provided for const correctness.
virtual tResult GetInterface(const char *i_strIID, void *&o_pInterface)
Default implementation of IObject::GetInterface()
virtual ~default_object()
Protected destructor --> Only the final implementation can be destroyed!
Used to implement IObject::GetInterface() methods with given interfaces to expose.
virtual ~extend_object()
Protected destructor --> Only the final implementation can be destroyed!
virtual void Destroy() const
Default implementation to destroy an object of this type.
virtual tResult GetInterface(const char *i_strIID, const void *&o_pInterface) const
Default implementation of IObject::GetInterface() provided for const correctness.
virtual tResult GetInterface(const char *i_strIID, void *&o_pInterface)
Default implementation of IObject::GetInterface()
BASE_OBJECT base_type
base object type
Meta template struct used to expose all interfaces.
static tResult Get(Provider *i_pObj, const char *i_strIID, VoidType *&o_pInterface)
Get the interface with IID i_strIID exposed from i_pObj.
const char * get_iid()
Get the interface id (IID) of the Interface type.
ant::interface_expose< Interfaces... > interface_expose
Alias bringing the latest version of meta struct template interface_expose into scope.
ant::extend_object< BASE_CLASS, EXTEND_INTERFACE, Child > extend_object
Alias bringing the latest version of meta struct template extend_object into scope.
ant::inherit_from< ParentTypes... > inherit_from
Alias bringing the latest version of meta struct template inherit_from into scope.
ant::default_object< Types... > default_object
Alias bringing the latest version of meta struct template default_object into scope.
ant::expose_interfaces< InterfaceTypes... > expose_interfaces
Alias bringing the latest version of meta struct template expose_interfaces into scope.
Namespace for entire ADTF SDK.
Declares the class to use when implementing GetInterface using inheritance.
Meta struct template evaluated at compile time when compiling default_object.
Meta struct template evaluated at compile time when compiling default_object.