diff --git a/core/class.c b/core/class.c index 4871c80..c21f954 100644 --- a/core/class.c +++ b/core/class.c @@ -6,7 +6,7 @@ #include #include -void *z__b_class_get_interface(struct _b_class *c, const union b_type *id) +void *b_class_get_interface(const struct _b_class *c, const union b_type *id) { const struct b_type_registration *type_reg = c->c_type; struct b_type_component *comp diff --git a/core/include/blue/core/class.h b/core/include/blue/core/class.h index e09776b..6c9cbd6 100644 --- a/core/include/blue/core/class.h +++ b/core/include/blue/core/class.h @@ -8,10 +8,6 @@ typedef struct _b_class b_class; -#define b_class_get_interface(class, interface_struct, interface_id) \ - ((interface_struct *)z__b_class_get_interface( \ - B_CLASS(class), interface_id)); - -BLUE_API void *z__b_class_get_interface(b_class *c, b_type id); +BLUE_API void *b_class_get_interface(const b_class *c, b_type id); #endif diff --git a/core/include/blue/core/macros.h b/core/include/blue/core/macros.h index 7932822..47a82bc 100644 --- a/core/include/blue/core/macros.h +++ b/core/include/blue/core/macros.h @@ -19,10 +19,10 @@ { #define B_TYPE_CLASS_DEFINITION_END(type_name) } -#define B_TYPE_CLASS_INTERFACE_BEGIN(interface_name, interface_id) \ - interface_name##_class *__B_IFACE_I1(iface, __LINE__) \ - = b_class_get_interface(p, interface_name##_class, interface_id); \ - if (__B_IFACE_I1(iface, __LINE__)) { \ +#define B_TYPE_CLASS_INTERFACE_BEGIN(interface_name, interface_id) \ + interface_name##_class *__B_IFACE_I1(iface, __LINE__) \ + = b_class_get_interface(p, interface_id); \ + if (__B_IFACE_I1(iface, __LINE__)) { \ interface_name##_class *iface = __B_IFACE_I1(iface, __LINE__); #define B_TYPE_CLASS_INTERFACE_END(interface_name, interface_id) } #define B_INTERFACE_ENTRY(slot) iface->slot diff --git a/core/include/blue/core/object.h b/core/include/blue/core/object.h index c8d62d7..f4accba 100644 --- a/core/include/blue/core/object.h +++ b/core/include/blue/core/object.h @@ -15,19 +15,20 @@ struct b_stream; typedef struct _b_object b_object; typedef struct _b_object_class { - void (*to_string)(b_object *, struct b_stream *); + void (*to_string)(const b_object *, struct b_stream *); } b_object_class; BLUE_API b_type b_object_get_type(void); -BLUE_API void *b_object_get_private(b_object *object, b_type type); -BLUE_API void *b_object_get_protected(b_object *object, b_type type); -BLUE_API void *b_object_get_interface(b_object *object, b_type type); +BLUE_API void *b_object_get_private(const b_object *object, b_type type); +BLUE_API void *b_object_get_protected(const b_object *object, b_type type); +BLUE_API void *b_object_get_interface(const b_object *object, b_type type); BLUE_API b_object *b_object_ref(b_object *p); BLUE_API void b_object_unref(b_object *p); BLUE_API b_object *b_object_create(b_type type); -BLUE_API void b_object_to_string(b_object *p, struct b_stream *out); +BLUE_API void b_object_to_string(const b_object *p, struct b_stream *out); +BLUE_API bool b_object_is_type(const b_object *p, b_type type); #endif diff --git a/core/object.c b/core/object.c index 6ebb610..72b82fa 100644 --- a/core/object.c +++ b/core/object.c @@ -77,7 +77,7 @@ void b_object_to_string(struct _b_object *p, struct b_stream *out) b_stream_write_fmt(out, NULL, "<%s@%p>", p->obj_type->r_info->t_name, p); } -void *b_object_get_private(struct _b_object *object, b_type type) +void *b_object_get_private(const struct _b_object *object, b_type type) { if (b_type_id_compare(&object->obj_type->r_info->t_id, type) == 0) { return (char *)object + object->obj_main_priv_offset; @@ -92,7 +92,7 @@ void *b_object_get_private(struct _b_object *object, b_type type) return (char *)object + comp->c_instance_private_data_offset; } -void *b_object_get_protected(struct _b_object *object, b_type type) +void *b_object_get_protected(const struct _b_object *object, b_type type) { struct b_type_component *comp = b_type_get_component(&object->obj_type->r_components, type); @@ -103,9 +103,9 @@ void *b_object_get_protected(struct _b_object *object, b_type type) return (char *)object + comp->c_instance_protected_data_offset; } -void *b_object_get_interface(struct _b_object *object, b_type type) +void *b_object_get_interface(const struct _b_object *object, b_type type) { - return z__b_class_get_interface(object->obj_type->r_class, type); + return b_class_get_interface(object->obj_type->r_class, type); } struct _b_object *b_object_ref(struct _b_object *p)