#include #include #include struct fx_type_registration; struct fx_type_p { struct fx_type_info *ty_info; }; /*** PRIVATE FUNCTIONS ********************************************************/ extern struct fx_type_info *fx_type_info_get_by_id(const union fx_type_id *key); extern struct fx_type_info *fx_type_info_get_by_name(const char *name); extern fx_function *fx_type_info_get_function_by_name( const struct fx_type_info *ty, const char *name); static const char *type_get_name(const struct fx_type_p *ty) { return ty->ty_info->ty_name; } const fx_function *type_get_function( const struct fx_type_p *ty, const char *name) { return fx_type_info_get_function_by_name(ty->ty_info, name); } /*** PUBLIC FUNCTIONS *********************************************************/ fx_type *__fx_type_create(struct fx_type_info *type_info) { fx_type *out = fx_object_create(FX_REFLECTION_TYPE_TYPE); if (!out) { return NULL; } struct fx_type_p *p = fx_object_get_private( out, FX_REFLECTION_TYPE_TYPE); p->ty_info = type_info; return out; } const char *fx_type_get_name(const fx_type *ty) { FX_CLASS_DISPATCH_STATIC_0(FX_REFLECTION_TYPE_TYPE, type_get_name, ty); } const fx_function *fx_type_get_function(const fx_type *ty, const char *name) { FX_CLASS_DISPATCH_STATIC( FX_REFLECTION_TYPE_TYPE, type_get_function, ty, name); } const fx_type *fx_type_get_by_id(fx_type_id id) { struct fx_type_info *ty = fx_type_info_get_by_id(id); return ty ? ty->ty_metatype : NULL; } const fx_type *fx_type_get_by_name(const char *name) { struct fx_type_info *ty = fx_type_info_get_by_name(name); return ty ? ty->ty_metatype : NULL; } /*** VIRTUAL FUNCTIONS ********************************************************/ static void type_init(fx_object *obj, void *priv) { } static void type_fini(fx_object *obj, void *priv) { } /*** CLASS DEFINITION *********************************************************/ FX_TYPE_CLASS_BEGIN(fx_type) FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT) FX_INTERFACE_ENTRY(to_string) = NULL; FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT) FX_TYPE_CLASS_END(fx_type) FX_TYPE_DEFINITION_BEGIN(fx_type) FX_TYPE_ID(0xec8b2679, 0x5c73, 0x4ec9, 0xa04e, 0x3f72881b5b5a); FX_TYPE_NAME("fx.reflection.type"); FX_TYPE_CLASS(fx_type_class); FX_TYPE_INSTANCE_PRIVATE(struct fx_type_p); FX_TYPE_INSTANCE_INIT(type_init); FX_TYPE_INSTANCE_FINI(type_fini); FX_TYPE_DEFINITION_END(fx_type)