type: add subclass check

This commit is contained in:
Wim Taymans 2017-03-24 13:25:43 +01:00
parent 25b7ede0bc
commit 141202b1fd
2 changed files with 12 additions and 0 deletions

View file

@ -39,6 +39,12 @@ typedef uint32_t SpaType;
#define SPA_TYPE__Object SPA_TYPE_BASE "Object"
#define SPA_TYPE_OBJECT_BASE SPA_TYPE__Object ":"
static inline bool
spa_type_is_a (const char *type, const char *parent)
{
return type != NULL && parent != NULL && strstr (type, parent) == type;
}
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -269,5 +269,11 @@ main (int argc, char *argv[])
do_static_struct ();
printf ("%d\n", spa_type_is_a (SPA_TYPE__MediaType, SPA_TYPE_ENUM_BASE));
printf ("%d\n", spa_type_is_a (SPA_TYPE__MediaSubtype, SPA_TYPE_ENUM_BASE));
printf ("%d\n", spa_type_is_a (SPA_TYPE__Format, SPA_TYPE_ENUM_BASE));
printf ("%d\n", spa_type_is_a (SPA_TYPE__Format, SPA_TYPE_POD_BASE));
printf ("%d\n", spa_type_is_a (SPA_TYPE__Format, SPA_TYPE_POD_OBJECT_BASE));
return 0;
}