1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "Object.h"
#include "utils.h"
/* The standard to_string method */
char * _object_standard_to_string (Object * object) {
return string_new_printf ("(Object:%s)", object->name);
}
void object_initialize (Object * object,
char * name,
_pointer klass) {
object->name = name;
object->klass = klass;
object->reserved0 = NULL;
object->reserved1 = NULL;
}
void object_class_initialize (ObjectClass * klass,
NewFunc new_func,
FreeFunc free_func,
ToStringFunc to_string_func) {
assert (new_func != NULL);
assert (free_func != NULL);
if (to_string_func != NULL) {
klass->to_string_func = to_string_func;
} else {
klass->to_string_func = _object_standard_to_string;
}
klass->new_func = new_func;
klass->free_func = free_func;
}
void object_add_private (Object * object, _pointer priv_data) {
object->priv = priv_data;
}
Object * object_new_from_object (Object * self) {
return (Object *) self->klass->new_func (self);
}
char * object_to_string (Object * self) {
return self->klass->to_string_func (self);
}
|