1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-12-04 14:46:31 -05:00

Feature: Added support to actually define types

This commit is contained in:
Philipp Schafft 2018-11-01 08:09:07 +00:00
parent 2bee2ee3a4
commit 2b6b718568
3 changed files with 30 additions and 3 deletions

View File

@ -61,7 +61,6 @@ struct igloo_ro_type_tag {
/* Size of this control structure */ /* Size of this control structure */
size_t control_length; size_t control_length;
/* ABI version of this structure */ /* ABI version of this structure */
#define igloo_RO__CONTROL_VERSION 1
int control_version; int control_version;
/* Total length of the objects to be created */ /* Total length of the objects to be created */

View File

@ -28,8 +28,25 @@ extern "C" {
* This header must be included before "types.h" and "ro.h" if used. * This header must be included before "types.h" and "ro.h" if used.
*/ */
#define igloo_RO_TYPE(type) type * subtype__ ## type; #define igloo_RO_TYPE(type) type * subtype__ ## type;
#define igloo_RO_FORWARD_TYPE(type) extern const igloo_ro_type_t *igloo_ro__type__ ## type
#define igloo_RO__CONTROL_VERSION 1
#define igloo_RO__DEFINE_TYPE(type, suffix, ...) \
static const igloo_ro_type_t igloo_ro__typedef__ ## type = \
{ \
.control_length = sizeof(igloo_ro_type_t), \
.control_version = igloo_RO__CONTROL_VERSION, \
.type_length = sizeof(type), \
.type_name = # type suffix \
, ## __VA_ARGS__ \
}
#define igloo_RO_FORWARD_TYPE(type) extern const igloo_ro_type_t *igloo_ro__type__ ## type
#define igloo_RO_PUBLIC_TYPE(type, ...) igloo_RO__DEFINE_TYPE(type, "", ## __VA_ARGS__); const igloo_ro_type_t * igloo_ro__type__ ## type = &igloo_ro__typedef__ ## type
#define igloo_RO_PRIVATE_TYPE(type, ...) igloo_RO__DEFINE_TYPE(type, " (private)", ## __VA_ARGS__); static const igloo_ro_type_t * igloo_ro__type__ ## type = &igloo_ro__typedef__ ## type
#define igloo_RO_TYPEDECL_FREE(cb) .type_freecb = (cb)
#define igloo_RO_TYPEDECL_NEW(cb) .type_newcb = (cb)
#define igloo_RO_TYPEDECL_NEW_NOOP() .type_newcb = igloo_ro_new__return_zero
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -26,6 +26,17 @@
#include <igloo/ro.h> #include <igloo/ro.h>
/* This is not static as it is used by igloo_RO_TYPEDECL_NEW_NOOP() */
int igloo_ro_new__return_zero(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap)
{
(void)self, (void)type, (void)ap;
return 0;
}
igloo_RO_PUBLIC_TYPE(igloo_ro_base_t,
igloo_RO_TYPEDECL_NEW_NOOP()
);
static inline int check_type(const igloo_ro_type_t *type) static inline int check_type(const igloo_ro_type_t *type)
{ {
return type->control_length == sizeof(igloo_ro_type_t) && type->control_version == igloo_RO__CONTROL_VERSION && return type->control_length == sizeof(igloo_ro_type_t) && type->control_version == igloo_RO__CONTROL_VERSION &&