8 #ifndef _ADTF_UCOM_ANT_ADTF_IID_HEADER_
9 #define _ADTF_UCOM_ANT_ADTF_IID_HEADER_
17 #define ADTF_IID(_interface, _striid) \
18 typedef _interface interface_type; \
19 template<_interface*> struct interface_info \
21 static const char* IID() { return _striid; } \
40 #define UCOM_RESOLVE(...) typedef std::tuple < __VA_ARGS__ > hierarchy_type;
60 template<
typename...>
struct peel_off_first {
typedef void type; };
66 template<
typename T,
typename... TRemaining>
67 struct peel_off_first<T, TRemaining...>
77 struct is_template : std::false_type {};
84 template<
template<
typename...>
class C,
typename ...T>
85 struct is_template<C<T...>> : std::true_type {};
92 class has_interface_expose_type
95 struct yes {
char x[1]; };
97 struct no {
char x[2]; };
104 template<
typename C>
static yes
exists(
typename C::interface_expose_type*);
110 template<
typename C>
static no
exists(...);
114 static const bool value =
sizeof(exists<T>(
nullptr)) ==
sizeof(yes);
122 class has_hierarchy_type
125 struct yes {
char x[1]; };
127 struct no {
char x[2]; };
134 template<
typename C>
static yes
exists(
typename C::hierarchy_type*);
140 template<
typename C>
static no
exists(...);
144 static const bool value =
sizeof(exists<T>(
nullptr)) ==
sizeof(yes);
155 class has_interface_info_type
158 struct yes {
char x[1]; };
160 struct no {
char x[2]; };
168 static yes
exists(
typename C::template interface_info<
static_cast<C*
>(
nullptr)>* =
nullptr);
174 template<
typename C>
static no
exists(...);
178 static const bool value =
sizeof(exists<T>(
nullptr)) ==
sizeof(yes);
185 template<
typename QueriedInterface,
typename ...>
186 class find_intermediate : std::false_type
190 typedef void* first_type;
192 typedef void* second_type;
194 typedef QueriedInterface query_type;
196 typedef typename std::remove_pointer<second_type>::type value_type;
207 template<
typename QueriedInterface,
typename ...HierarchyTypes>
208 class find_intermediate<QueriedInterface, std::tuple<HierarchyTypes...>>
211 template<
typename...>
214 typedef void key_type;
215 typedef void value_type;
216 typedef void tuple_type;
225 template<
typename KeyType,
typename ValueType,
typename... TRemaining>
226 struct extract_pair<KeyType, ValueType, TRemaining...>
228 typedef KeyType key_type;
229 typedef ValueType value_type;
230 typedef std::tuple<TRemaining...> tuple_type;
234 template<
typename...>
235 struct extract_wrapped_pair;
244 template<
template<
typename,
typename>
class C,
247 typename ...TRemaining>
248 struct extract_wrapped_pair<C<KeyType, ValueType>, TRemaining...> :
249 extract_pair<KeyType, ValueType, TRemaining...> {};
252 typedef typename peel_off_first<HierarchyTypes...>::type current_type;
258 is_template<current_type>::value,
259 extract_wrapped_pair<HierarchyTypes...>,
260 extract_pair<HierarchyTypes...>
261 >::type extract_pair_type;
270 typename std::remove_cv<QueriedInterface>::type,
271 typename extract_pair_type::key_type
274 std::pair<
typename extract_pair_type::key_type*,
275 typename extract_pair_type::value_type*>,
276 find_intermediate<QueriedInterface, typename extract_pair_type::tuple_type>
281 typedef typename pair_type::first_type first_type;
282 typedef typename pair_type::second_type second_type;
285 typedef typename std::remove_pointer<first_type>::type query_type;
286 typedef typename std::remove_pointer<second_type>::type value_type;
289 static const bool value = !std::is_void<query_type>::value;
293 template<
typename InterfaceType,
bool Cond>
294 struct ucom_resolve_helper;
304 template<
typename InterfaceType,
typename ObjectType>
308 find_intermediate< InterfaceType, typename ObjectType::hierarchy_type >::value,
309 typename std::conditional
311 std::is_const<ObjectType>::value,
312 const InterfaceType*,
316 ucom_resolve(ObjectType* i_pObject)
322 typename ObjectType::hierarchy_type
323 >::value_type intermediate_type;
328 std::is_const<ObjectType>::value,
329 const intermediate_type*,
331 >::type intermediate_pointer;
333 intermediate_pointer pIntermediate = i_pObject;
334 return ucom_resolve_helper<InterfaceType,
335 has_hierarchy_type<intermediate_type>::value>::get(pIntermediate);
346 template<
typename InterfaceType,
typename ObjectType>
350 !find_intermediate< InterfaceType, typename ObjectType::hierarchy_type >::value,
351 typename std::conditional
353 std::is_const<ObjectType>::value,
354 const InterfaceType*,
358 ucom_resolve(ObjectType* i_pObject)
367 template<
typename InterfaceType>
368 struct ucom_resolve_helper<InterfaceType, true>
377 template<
typename IntermediateType>
378 static typename std::conditional
380 std::is_const<IntermediateType>::value,
381 const InterfaceType*,
384 get(IntermediateType* i_pObject)
386 return ucom_resolve<InterfaceType, IntermediateType>(i_pObject);
394 template<
typename InterfaceType>
395 struct ucom_resolve_helper<InterfaceType, false>
404 template<
typename IntermediateType>
405 static typename std::conditional
407 std::is_const<IntermediateType>::value,
408 const InterfaceType*,
411 get(IntermediateType* i_pObject)
428 template<
typename Interface>
432 typedef typename remove_const<typename remove_pointer<Interface>::type>::type value_type;
433 static_assert(is_same<value_type, typename value_type::interface_type>::value,
434 "get_iid<> failed. Check whether your interface correctly defined ADTF_IID()");
436 constexpr
typename value_type::interface_type* pNullInstance =
nullptr;
437 (void)(pNullInstance);
438 return value_type::template interface_info<pNullInstance>::IID();
445 template<
typename Interface>
const char*
get_iid(
const Interface&)
447 return get_iid<Interface>();
454 template<
typename Interface>
const char*
get_iid(
const Interface*)
456 return get_iid<Interface>();
465 template<
typename ...Interfaces>
474 template<
typename ...InterfacesInner>
485 template<
typename Prov
ider,
typename Vo
idType>
486 static tResult dispatch(Provider*,
const char*, VoidType*& o_pInterface)
488 o_pInterface =
nullptr;
489 return ERR_NO_INTERFACE;
498 template<
typename Interface,
typename ...InterfacesInner>
499 struct iid_dispatch<Interface, InterfacesInner...>
509 template<
typename ObjectType,
typename Vo
idType>
510 static typename std::enable_if<detail::has_hierarchy_type<ObjectType>::value,
void>::type
511 resolve(ObjectType* i_pObject, VoidType*& o_pInterface)
513 o_pInterface = detail::ucom_resolve<Interface>(i_pObject);
524 template<
typename ObjectType,
typename Vo
idType>
525 static typename std::enable_if<!detail::has_hierarchy_type<ObjectType>::value,
void>::type
526 resolve(ObjectType* i_pObject, VoidType*& o_pInterface)
528 typedef typename std::conditional
530 std::is_const<ObjectType>::value,
533 >::type interface_pointer;
534 o_pInterface =
static_cast<interface_pointer
>(i_pObject);
552 template<
typename Prov
ider,
typename Vo
idType>
553 static tResult dispatch(Provider* i_pObj,
const char* i_strIID, VoidType*& o_pInterface)
556 if (adtf_util::cStringUtil::IsEqual(get_iid<Interface>(), i_strIID))
558 resolve(i_pObj, o_pInterface);
562 return iid_dispatch<InterfacesInner...>::dispatch(i_pObj, i_strIID, o_pInterface);
588 template<
typename Prov
ider,
typename Vo
idType>
589 static tResult Get(Provider* i_pObj,
const char* i_strIID, VoidType*& o_pInterface)
591 static_assert(std::is_void<VoidType>::value,
"\"VoidType\" must be of type void");
592 return iid_dispatch<Interfaces...>::dispatch(i_pObj, i_strIID, o_pInterface);
602 template<
typename...>
611 template<
typename ...>
618 template<
typename...>
637 template<
typename Child,
typename ...Interfaces,
typename ...Parents>
671 static_assert(std::is_base_of<default_object, Child>::value,
672 "The given Child type must be a child type of this default_object type!");
673 return interface_expose_type::Get(
static_cast<Child*
>(
this), i_strIID, o_pInterface);
694 static_assert(std::is_base_of<default_object, Child>::value,
695 "The given Child type must be a child type of this default_object type!");
696 return interface_expose_type::Get(
static_cast<const Child*
>(
this), i_strIID, o_pInterface);
726 template<
typename BASE_OBJECT,
typename EXTEND_INTERFACE,
typename Child>
755 static_assert(std::is_base_of<extend_object, Child>::value,
756 "The given Child type must be a child type of this extend_object type!");
761 return BASE_OBJECT::GetInterface(i_strIID, o_pInterface);
783 static_assert(std::is_base_of<extend_object, Child>::value,
784 "The given Child type must be a child type of this extend_object type!");
789 return BASE_OBJECT::GetInterface(i_strIID, o_pInterface);
819 template<
typename ...Interfaces>
823 template<
typename ...ParentTypes>
827 template<
typename ...InterfaceTypes>
831 template<
typename ...Types>
835 template<
typename BASE_CLASS,
typename EXTEND_INTERFACE,
typename Child>
#define IS_FAILED(s)
Check if result is failed.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
A common result class usable as return value throughout.
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()
Virtual destructor needed for call to this->Destroy()
Used to implement IObject::GetInterface() methods with given interfaces to expose.
virtual ~extend_object()
Virtual destructor needed for call to this->Destroy()
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.
bool exists(const Path &path)
Check whether the file or directory exists on the filesystem.
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 ant::interface_expose into scope.
ant::default_object< Types... > default_object
Alias bringing the latest version of meta struct template ant::default_object into scope.
Namespace for entire ADTF SDK.
Declares the class to use when implementing IObject::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.