core: object: add functions to retrieve multiple parts of an object at once
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#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>
|
||||
|
||||
B_TYPE_CLASS_DEFINITION_BEGIN(b_object)
|
||||
@@ -71,9 +72,9 @@ struct _b_object *b_object_create(b_type type)
|
||||
return out;
|
||||
}
|
||||
|
||||
void b_object_to_string(const struct _b_object *p, struct b_stream *out)
|
||||
void b_object_to_string(const struct _b_object *p, b_stream *out)
|
||||
{
|
||||
B_CLASS_DISPATCH_VIRTUAL_V(b_object, B_TYPE_OBJECT, p, to_string, p, 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);
|
||||
}
|
||||
|
||||
@@ -120,6 +121,32 @@ void *b_object_get_interface(const struct _b_object *object, b_type type)
|
||||
return b_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,
|
||||
void **iface)
|
||||
{
|
||||
struct b_type_component *comp
|
||||
= b_type_get_component(&object->obj_type->r_components, type);
|
||||
if (!comp) {
|
||||
return B_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if (priv) {
|
||||
*priv = (char *)object + comp->c_instance_private_data_offset;
|
||||
}
|
||||
|
||||
if (prot) {
|
||||
*prot = (char *)object + comp->c_instance_protected_data_offset;
|
||||
}
|
||||
|
||||
if (iface) {
|
||||
*iface = (char *)object->obj_type->r_class
|
||||
+ comp->c_class_data_offset;
|
||||
}
|
||||
|
||||
return B_SUCCESS;
|
||||
}
|
||||
|
||||
struct _b_object *b_object_ref(struct _b_object *p)
|
||||
{
|
||||
p->obj_ref++;
|
||||
|
||||
Reference in New Issue
Block a user