meta: rename legacy object module to 'ds'
This commit is contained in:
66
ds/object.c
Normal file
66
ds/object.c
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "object.h"
|
||||
|
||||
#include <blue/core/stream.h>
|
||||
#include <blue/ds/object.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <blue/ds/type.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void b_dsref_init(struct b_dsref *obj, struct b_dsref_type *type)
|
||||
{
|
||||
obj->ob_ref = 1;
|
||||
obj->ob_type = type;
|
||||
}
|
||||
|
||||
struct b_dsref *b_make_rvalue(struct b_dsref *obj)
|
||||
{
|
||||
obj->ob_ref = 0;
|
||||
return obj;
|
||||
}
|
||||
|
||||
struct b_dsref *b_retain(struct b_dsref *obj)
|
||||
{
|
||||
obj->ob_ref++;
|
||||
return obj;
|
||||
}
|
||||
|
||||
void b_release(struct b_dsref *obj)
|
||||
{
|
||||
if (obj->ob_ref > 1) {
|
||||
obj->ob_ref--;
|
||||
return;
|
||||
}
|
||||
|
||||
obj->ob_ref = 0;
|
||||
|
||||
if (obj->ob_type && obj->ob_type->t_release) {
|
||||
obj->ob_type->t_release(obj);
|
||||
}
|
||||
|
||||
free(obj);
|
||||
}
|
||||
|
||||
void b_to_string(struct b_dsref *obj, struct b_stream *out)
|
||||
{
|
||||
if (obj->ob_type->t_to_string) {
|
||||
obj->ob_type->t_to_string(obj, out);
|
||||
return;
|
||||
}
|
||||
|
||||
const char *name = "corelib::object";
|
||||
if (obj->ob_type) {
|
||||
name = obj->ob_type->t_name;
|
||||
}
|
||||
|
||||
b_stream_write_fmt(out, NULL, "<%s@%p>", name, obj);
|
||||
}
|
||||
|
||||
b_dsref_type_id b_typeid(const struct b_dsref *obj)
|
||||
{
|
||||
if (obj->ob_type->t_flags & B_DSREF_FUNDAMENTAL) {
|
||||
return obj->ob_type->t_id;
|
||||
}
|
||||
|
||||
return (b_dsref_type_id)obj->ob_type;
|
||||
}
|
||||
Reference in New Issue
Block a user