From 141202b1fd6eb96c5259341b234bb695aa0c4c68 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 24 Mar 2017 13:25:43 +0100 Subject: [PATCH] type: add subclass check --- spa/include/spa/type.h | 6 ++++++ spa/tests/test-props.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/spa/include/spa/type.h b/spa/include/spa/type.h index 27d5976cf..1f1a0adcc 100644 --- a/spa/include/spa/type.h +++ b/spa/include/spa/type.h @@ -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 diff --git a/spa/tests/test-props.c b/spa/tests/test-props.c index 565e69603..ed4afbaa7 100644 --- a/spa/tests/test-props.c +++ b/spa/tests/test-props.c @@ -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; }