meta: rename to fx
This commit is contained in:
134
core/object.c
134
core/object.c
@@ -3,42 +3,42 @@
|
||||
#include "type.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <blue/core/class.h>
|
||||
#include <blue/core/macros.h>
|
||||
#include <blue/core/object.h>
|
||||
#include <blue/core/stream.h>
|
||||
#include <blue/core/thread.h>
|
||||
#include <fx/core/class.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/object.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/core/thread.h>
|
||||
|
||||
B_TYPE_CLASS_DEFINITION_BEGIN(b_object)
|
||||
B_TYPE_CLASS_INTERFACE_BEGIN(b_object, B_TYPE_OBJECT)
|
||||
B_INTERFACE_ENTRY(to_string) = NULL;
|
||||
B_TYPE_CLASS_INTERFACE_END(b_object, B_TYPE_OBJECT)
|
||||
B_TYPE_CLASS_DEFINITION_END(b_object)
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_object)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_object)
|
||||
|
||||
B_TYPE_DEFINITION_BEGIN(b_object)
|
||||
B_TYPE_ID(0x45f15a2c, 0x6831, 0x4bef, 0xb350, 0x15c650679211);
|
||||
B_TYPE_CLASS(b_object_class);
|
||||
B_TYPE_DEFINITION_END(b_object)
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_object)
|
||||
FX_TYPE_ID(0x45f15a2c, 0x6831, 0x4bef, 0xb350, 0x15c650679211);
|
||||
FX_TYPE_CLASS(fx_object_class);
|
||||
FX_TYPE_DEFINITION_END(fx_object)
|
||||
|
||||
b_result b_object_instantiate(
|
||||
struct b_type_registration *type, struct _b_object **out_object)
|
||||
fx_result fx_object_instantiate(
|
||||
struct fx_type_registration *type, struct _fx_object **out_object)
|
||||
{
|
||||
struct _b_object *out = malloc(type->r_instance_size);
|
||||
struct _fx_object *out = malloc(type->r_instance_size);
|
||||
if (!out) {
|
||||
return B_RESULT_ERR(NO_MEMORY);
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
memset(out, 0x0, type->r_instance_size);
|
||||
|
||||
out->obj_magic = B_OBJECT_MAGIC;
|
||||
out->obj_magic = FX_OBJECT_MAGIC;
|
||||
out->obj_type = type;
|
||||
out->obj_ref = 1;
|
||||
|
||||
struct b_queue_entry *entry = b_queue_first(&type->r_class_hierarchy);
|
||||
struct fx_queue_entry *entry = fx_queue_first(&type->r_class_hierarchy);
|
||||
while (entry) {
|
||||
struct b_type_component *comp
|
||||
= b_unbox(struct b_type_component, entry, c_entry);
|
||||
const struct b_type_info *class_info = comp->c_type->r_info;
|
||||
struct fx_type_component *comp
|
||||
= fx_unbox(struct fx_type_component, entry, c_entry);
|
||||
const struct fx_type_info *class_info = comp->c_type->r_info;
|
||||
void *private_data
|
||||
= (char *)out + comp->c_instance_private_data_offset;
|
||||
|
||||
@@ -51,62 +51,62 @@ b_result b_object_instantiate(
|
||||
= comp->c_instance_private_data_offset;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
*out_object = out;
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
struct _b_object *b_object_create(b_type type)
|
||||
struct _fx_object *fx_object_create(fx_type type)
|
||||
{
|
||||
struct b_type_registration *type_reg = b_type_get_registration(type);
|
||||
struct fx_type_registration *type_reg = fx_type_get_registration(type);
|
||||
if (!type_reg) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct _b_object *out = NULL;
|
||||
b_result result = b_object_instantiate(type_reg, &out);
|
||||
if (b_result_is_error(result)) {
|
||||
b_error_discard(result);
|
||||
struct _fx_object *out = NULL;
|
||||
fx_result result = fx_object_instantiate(type_reg, &out);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_error_discard(result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void b_object_to_string(const struct _b_object *p, b_stream *out)
|
||||
void fx_object_to_string(const struct _fx_object *p, fx_stream *out)
|
||||
{
|
||||
B_CLASS_DISPATCH_VIRTUAL_V(b_object, B_TYPE_OBJECT, to_string, p, out);
|
||||
b_stream_write_fmt(out, NULL, "<%s@%p>", p->obj_type->r_info->t_name, p);
|
||||
FX_CLASS_DISPATCH_VIRTUAL_V(fx_object, FX_TYPE_OBJECT, to_string, p, out);
|
||||
fx_stream_write_fmt(out, NULL, "<%s@%p>", p->obj_type->r_info->t_name, p);
|
||||
}
|
||||
|
||||
bool b_object_is_type(const struct _b_object *p, b_type type)
|
||||
bool fx_object_is_type(const struct _fx_object *p, fx_type type)
|
||||
{
|
||||
if (b_type_id_compare(&p->obj_type->r_info->t_id, type) == 0) {
|
||||
if (fx_type_id_compare(&p->obj_type->r_info->t_id, type) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
struct b_type_component *comp
|
||||
= b_type_get_component(&p->obj_type->r_components, type);
|
||||
struct fx_type_component *comp
|
||||
= fx_type_get_component(&p->obj_type->r_components, type);
|
||||
|
||||
return comp != NULL;
|
||||
}
|
||||
|
||||
void *b_object_get_private(const struct _b_object *object, b_type type)
|
||||
void *fx_object_get_private(const struct _fx_object *object, fx_type type)
|
||||
{
|
||||
if (!object) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
assert(object->obj_magic == B_OBJECT_MAGIC);
|
||||
assert(object->obj_magic == FX_OBJECT_MAGIC);
|
||||
|
||||
if (b_type_id_compare(&object->obj_type->r_info->t_id, type) == 0) {
|
||||
if (fx_type_id_compare(&object->obj_type->r_info->t_id, type) == 0) {
|
||||
return (char *)object + object->obj_main_priv_offset;
|
||||
}
|
||||
|
||||
struct b_type_component *comp
|
||||
= b_type_get_component(&object->obj_type->r_components, type);
|
||||
struct fx_type_component *comp
|
||||
= fx_type_get_component(&object->obj_type->r_components, type);
|
||||
if (!comp) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -114,16 +114,16 @@ void *b_object_get_private(const struct _b_object *object, b_type type)
|
||||
return (char *)object + comp->c_instance_private_data_offset;
|
||||
}
|
||||
|
||||
void *b_object_get_protected(const struct _b_object *object, b_type type)
|
||||
void *fx_object_get_protected(const struct _fx_object *object, fx_type type)
|
||||
{
|
||||
if (!object) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
assert(object->obj_magic == B_OBJECT_MAGIC);
|
||||
assert(object->obj_magic == FX_OBJECT_MAGIC);
|
||||
|
||||
struct b_type_component *comp
|
||||
= b_type_get_component(&object->obj_type->r_components, type);
|
||||
struct fx_type_component *comp
|
||||
= fx_type_get_component(&object->obj_type->r_components, type);
|
||||
if (!comp) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -131,31 +131,31 @@ void *b_object_get_protected(const struct _b_object *object, b_type type)
|
||||
return (char *)object + comp->c_instance_protected_data_offset;
|
||||
}
|
||||
|
||||
void *b_object_get_interface(const struct _b_object *object, b_type type)
|
||||
void *fx_object_get_interface(const struct _fx_object *object, fx_type type)
|
||||
{
|
||||
if (!object) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
assert(object->obj_magic == B_OBJECT_MAGIC);
|
||||
assert(object->obj_magic == FX_OBJECT_MAGIC);
|
||||
|
||||
return b_class_get_interface(object->obj_type->r_class, type);
|
||||
return fx_class_get_interface(object->obj_type->r_class, type);
|
||||
}
|
||||
|
||||
enum b_status b_object_get_data(
|
||||
const struct _b_object *object, b_type type, void **priv, void **prot,
|
||||
enum fx_status fx_object_get_data(
|
||||
const struct _fx_object *object, fx_type type, void **priv, void **prot,
|
||||
void **iface)
|
||||
{
|
||||
if (!object) {
|
||||
return B_ERR_INVALID_ARGUMENT;
|
||||
return FX_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
assert(object->obj_magic == B_OBJECT_MAGIC);
|
||||
assert(object->obj_magic == FX_OBJECT_MAGIC);
|
||||
|
||||
struct b_type_component *comp
|
||||
= b_type_get_component(&object->obj_type->r_components, type);
|
||||
struct fx_type_component *comp
|
||||
= fx_type_get_component(&object->obj_type->r_components, type);
|
||||
if (!comp) {
|
||||
return B_ERR_INVALID_ARGUMENT;
|
||||
return FX_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if (priv) {
|
||||
@@ -171,16 +171,16 @@ enum b_status b_object_get_data(
|
||||
+ comp->c_class_data_offset;
|
||||
}
|
||||
|
||||
return B_SUCCESS;
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
struct _b_object *b_object_ref(struct _b_object *p)
|
||||
struct _fx_object *fx_object_ref(struct _fx_object *p)
|
||||
{
|
||||
p->obj_ref++;
|
||||
return p;
|
||||
}
|
||||
|
||||
void b_object_unref(struct _b_object *p)
|
||||
void fx_object_unref(struct _fx_object *p)
|
||||
{
|
||||
if (p->obj_ref > 1) {
|
||||
p->obj_ref--;
|
||||
@@ -188,14 +188,14 @@ void b_object_unref(struct _b_object *p)
|
||||
}
|
||||
|
||||
p->obj_ref = 0;
|
||||
const struct b_type_registration *type = p->obj_type;
|
||||
const struct fx_type_registration *type = p->obj_type;
|
||||
|
||||
struct b_queue_entry *cur = b_queue_last(&type->r_class_hierarchy);
|
||||
struct fx_queue_entry *cur = fx_queue_last(&type->r_class_hierarchy);
|
||||
while (cur) {
|
||||
struct b_type_component *comp
|
||||
= b_unbox(struct b_type_component, cur, c_entry);
|
||||
struct fx_type_component *comp
|
||||
= fx_unbox(struct fx_type_component, cur, c_entry);
|
||||
|
||||
const struct b_type_info *class_info = comp->c_type->r_info;
|
||||
const struct fx_type_info *class_info = comp->c_type->r_info;
|
||||
void *private_data
|
||||
= (char *)p + comp->c_instance_private_data_offset;
|
||||
|
||||
@@ -203,7 +203,7 @@ void b_object_unref(struct _b_object *p)
|
||||
class_info->t_instance_fini(p, private_data);
|
||||
}
|
||||
|
||||
cur = b_queue_prev(cur);
|
||||
cur = fx_queue_prev(cur);
|
||||
}
|
||||
|
||||
p->obj_magic = 0;
|
||||
@@ -212,7 +212,7 @@ void b_object_unref(struct _b_object *p)
|
||||
free(p);
|
||||
}
|
||||
|
||||
struct _b_object *b_object_make_rvalue(struct _b_object *p)
|
||||
struct _fx_object *fx_object_make_rvalue(struct _fx_object *p)
|
||||
{
|
||||
p->obj_ref = 0;
|
||||
return p;
|
||||
|
||||
Reference in New Issue
Block a user