32
32
* ---------------------------
35
void method_base_initialize (SObject * self);
37
void method_base_deinitialize (SObject * self);
39
void method_base_free (SObject * self);
41
int method_base_ref (SObject * self);
43
int method_base_unref (SObject * self);
45
int method_base_get_refcount (SObject * self);
47
char * method_base_to_string (SObject * self);
36
method_base_initialize (SObject * self);
39
method_base_deinitialize (SObject * self);
42
method_base_free (SObject * self);
45
method_base_ref (SObject * self);
48
method_base_unref (SObject * self);
51
method_base_get_refcount (SObject * self);
54
method_base_to_string (SObject * self);
49
56
/* -----------------
50
57
* Helper functions...
51
58
* -----------------
53
void s_object_set_initialize_method (SObject * self, MethodFunc method) {
61
s_object_set_initialize_method (SObject * self, MethodFunc method) {
54
62
SObjectClass * klass = s_object_get_class (self);
55
63
klass->initialize = method;
58
void s_object_set_free_method (SObject * self, MethodFunc method) {
67
s_object_set_free_method (SObject * self, MethodFunc method) {
59
68
SObjectClass * klass = s_object_get_class (self);
60
69
klass->free = method;
64
void s_object_set_ref_method (SObject * self, MethodFuncInt method) {
74
s_object_set_ref_method (SObject * self, MethodFuncInt method) {
65
75
SObjectClass * klass = s_object_get_class (self);
66
76
klass->ref = method;
70
void s_object_set_unref_method (SObject * self, MethodFuncInt method) {
81
s_object_set_unref_method (SObject * self, MethodFuncInt method) {
71
82
SObjectClass * klass = s_object_get_class (self);
72
83
klass->unref = method;
76
void s_object_set_get_refcount_method (SObject * self, MethodFuncInt method) {
88
s_object_set_get_refcount_method (SObject * self, MethodFuncInt method) {
77
89
SObjectClass * klass = s_object_get_class (self);
78
90
klass->get_refcount = method;
82
void s_object_set_to_string_method (SObject * self, ToStringFunc method) {
95
s_object_set_to_string_method (SObject * self, ToStringFunc method) {
83
96
SObjectClass * klass = s_object_get_class (self);
84
97
klass->to_string = method;
87
void s_object_set_deinitialize_method (SObject * self, MethodFunc method) {
101
s_object_set_deinitialize_method (SObject * self, MethodFunc method) {
88
102
SObjectClass * klass = s_object_get_class (self);
89
103
klass->deinitialize = method;
92
void s_object_initialize (SObject * self, const char * name) {
107
s_object_initialize (SObject * self, const char * name) {
93
108
self->name = s_string_new (name);
95
110
self->refcount = 1;
117
void s_object_free (SObject * self) {
134
s_object_free (SObject * self) {
118
135
free (self->name);
119
136
SObjectClass * klass = s_object_get_class (self);
120
137
klass->free (self);
123
SObjectClass * s_object_get_class (SObject * self) {
141
s_object_get_class (SObject * self) {
124
142
return self->base_class;
127
void s_object_set_class (SObject * self, SObjectClass * klass) {
146
s_object_set_class (SObject * self, SObjectClass * klass) {
128
147
self->base_class = klass;
131
int s_object_unref (SObject * self) {
151
s_object_unref (SObject * self) {
132
152
unsigned int ret = self->base_class->unref (self);
136
int s_object_ref (SObject * self) {
157
s_object_ref (SObject * self) {
137
158
unsigned int ret = self->base_class->ref (self);
142
163
* This function returns the current reference count without chaning it.
144
int s_object_get_refcount (SObject * self) {
166
s_object_get_refcount (SObject * self) {
145
167
unsigned int ret = self->base_class->get_refcount (self);
149
char * s_object_to_string (SObject * self) {
172
s_object_to_string (SObject * self) {
150
173
return self->base_class->to_string (self);
159
void method_base_deinitialize (SObject * self) { }
161
void method_base_initialize (SObject * self) { }
163
void method_base_free (SObject * self) {
183
method_base_deinitialize (SObject * self) { }
186
method_base_initialize (SObject * self) { }
189
method_base_free (SObject * self) {
164
190
free (self->base_class);
168
int method_base_ref (SObject * self) {
195
method_base_ref (SObject * self) {
169
196
self->refcount = self->refcount + 1;
170
197
return self->refcount;
173
int method_base_unref (SObject * self) {
201
method_base_unref (SObject * self) {
174
202
self->refcount = self->refcount - 1;
175
203
if (self->refcount == 0) {
176
204
s_object_free (self);