bzr branch
http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
|
1
by Gustav Hartvigsson
Initial Code. |
1 |
/*
|
|
5.2.7
by Gustav Hartvigsson
* Switched licence to a more permisive one. |
2 |
Copyright (c) 2013-2014 Gustav Hartvigsson
|
3 |
||
4 |
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5 |
of this software and associated documentation files (the "Software"), to deal
|
|
6 |
in the Software without restriction, including without limitation the rights
|
|
7 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8 |
copies of the Software, and to permit persons to whom the Software is
|
|
9 |
furnished to do so, subject to the following conditions:
|
|
10 |
||
11 |
The above copyright notice and this permission notice shall be included in
|
|
12 |
all copies or substantial portions of the Software.
|
|
13 |
||
14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20 |
THE SOFTWARE.
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
21 |
*/
|
22 |
||
23 |
#include "baseobject.h" |
|
|
62
by Gustav Hartvigsson
* General documentation clean up. |
24 |
#include "Callback.h" |
|
2
by Gustav Hartvigsson
Made the code compile. |
25 |
#include <stdlib.h> |
|
3
by Gustav Hartvigsson
Fixed a few things... |
26 |
#include <string.h> |
27 |
#include <stdio.h> |
|
28 |
||
|
1
by Gustav Hartvigsson
Initial Code. |
29 |
|
30 |
/* ---------------------------
|
|
31 |
* Concrete method definitions
|
|
32 |
* These are implemented towards the end of this file.
|
|
33 |
* ---------------------------
|
|
34 |
*/
|
|
35 |
||
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
36 |
void
|
37 |
method_base_initialize (SObject * self); |
|
38 |
||
39 |
void
|
|
40 |
method_base_deinitialize (SObject * self); |
|
41 |
||
42 |
void
|
|
43 |
method_base_free (SObject * self); |
|
44 |
||
45 |
int
|
|
46 |
method_base_ref (SObject * self); |
|
47 |
||
48 |
int
|
|
49 |
method_base_unref (SObject * self); |
|
50 |
||
51 |
int
|
|
52 |
method_base_get_refcount (SObject * self); |
|
53 |
||
54 |
char * |
|
55 |
method_base_to_string (SObject * self); |
|
|
1
by Gustav Hartvigsson
Initial Code. |
56 |
|
57 |
/* -----------------
|
|
58 |
* Helper functions...
|
|
59 |
* -----------------
|
|
60 |
*/
|
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
61 |
void
|
62 |
s_object_set_initialize_method (SObject * self, MethodFunc method) { |
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
63 |
SObjectClass * klass = s_object_get_class (self); |
|
22
by Gustav Hartvigsson
* Made code compile |
64 |
klass->initialize = method; |
|
1
by Gustav Hartvigsson
Initial Code. |
65 |
}
|
|
5.2.7
by Gustav Hartvigsson
* Switched licence to a more permisive one. |
66 |
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
67 |
void
|
68 |
s_object_set_free_method (SObject * self, MethodFunc method) { |
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
69 |
SObjectClass * klass = s_object_get_class (self); |
70 |
klass->free = method; |
|
|
1
by Gustav Hartvigsson
Initial Code. |
71 |
} |
72 |
||
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
73 |
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
74 |
void
|
75 |
s_object_set_ref_method (SObject * self, MethodFuncInt method) { |
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
76 |
SObjectClass * klass = s_object_get_class (self); |
|
1
by Gustav Hartvigsson
Initial Code. |
77 |
klass->ref = method; |
78 |
}
|
|
79 |
||
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
80 |
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
81 |
void
|
82 |
s_object_set_unref_method (SObject * self, MethodFuncInt method) { |
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
83 |
SObjectClass * klass = s_object_get_class (self); |
|
1
by Gustav Hartvigsson
Initial Code. |
84 |
klass->unref = method; |
85 |
}
|
|
86 |
||
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
87 |
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
88 |
void
|
89 |
s_object_set_get_refcount_method (SObject * self, MethodFuncInt method) { |
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
90 |
SObjectClass * klass = s_object_get_class (self); |
|
4
by Gustav Hartvigsson
Fixed a few problems. |
91 |
klass->get_refcount = method; |
92 |
}
|
|
93 |
||
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
94 |
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
95 |
void
|
96 |
s_object_set_to_string_method (SObject * self, ToStringFunc method) { |
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
97 |
SObjectClass * klass = s_object_get_class (self); |
|
1
by Gustav Hartvigsson
Initial Code. |
98 |
klass->to_string = method; |
99 |
}
|
|
100 |
||
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
101 |
void
|
102 |
s_object_set_deinitialize_method (SObject * self, MethodFunc method) { |
|
|
32
by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt |
103 |
SObjectClass * klass = s_object_get_class (self); |
104 |
klass->deinitialize = method; |
|
105 |
}
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
106 |
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
107 |
void
|
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
108 |
s_object_initialize (SObject * self, const schar * name) { |
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
109 |
self->name = s_string_new (name); |
110 |
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
111 |
self->refcount = 1; |
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
112 |
|
|
22
by Gustav Hartvigsson
* Made code compile |
113 |
s_object_set_free_method (self, method_base_free); |
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
114 |
s_object_set_ref_method (self, method_base_ref); |
115 |
s_object_set_unref_method (self, method_base_unref); |
|
116 |
s_object_set_get_refcount_method (self, method_base_get_refcount); |
|
117 |
s_object_set_to_string_method (self, method_base_to_string); |
|
|
1
by Gustav Hartvigsson
Initial Code. |
118 |
}
|
119 |
||
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
120 |
SObject * |
121 |
s_object_new () { |
|
|
32
by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt |
122 |
s_warn_print ("s_object_new () should never be used in production code"); |
|
22
by Gustav Hartvigsson
* Made code compile |
123 |
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
124 |
SObject * self = malloc (sizeof (SObject)); |
|
1
by Gustav Hartvigsson
Initial Code. |
125 |
//allocate the class definition of the object. |
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
126 |
self->base_class = malloc (sizeof(SObjectClass)); |
|
22
by Gustav Hartvigsson
* Made code compile |
127 |
//initialize it. |
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
128 |
s_object_initialize (self, "SObject"); |
|
1
by Gustav Hartvigsson
Initial Code. |
129 |
return self; |
130 |
}
|
|
131 |
||
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
132 |
void
|
133 |
s_object_free (SObject * self) { |
|
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
134 |
free (self->name); |
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
135 |
SObjectClass * klass = s_object_get_class (self); |
136 |
klass->free (self); |
|
|
1
by Gustav Hartvigsson
Initial Code. |
137 |
}
|
138 |
||
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
139 |
SObjectClass * |
140 |
s_object_get_class (SObject * self) { |
|
|
1
by Gustav Hartvigsson
Initial Code. |
141 |
return self->base_class; |
142 |
}
|
|
143 |
||
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
144 |
void
|
145 |
s_object_set_class (SObject * self, SObjectClass * klass) { |
|
|
1
by Gustav Hartvigsson
Initial Code. |
146 |
self->base_class = klass; |
147 |
}
|
|
148 |
||
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
149 |
sint
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
150 |
s_object_unref (SObject * self) { |
|
4
by Gustav Hartvigsson
Fixed a few problems. |
151 |
unsigned int ret = self->base_class->unref (self); |
152 |
return ret; |
|
|
1
by Gustav Hartvigsson
Initial Code. |
153 |
}
|
154 |
||
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
155 |
int
|
156 |
s_object_ref (SObject * self) { |
|
|
4
by Gustav Hartvigsson
Fixed a few problems. |
157 |
unsigned int ret = self->base_class->ref (self); |
158 |
return ret; |
|
|
1
by Gustav Hartvigsson
Initial Code. |
159 |
}
|
160 |
||
161 |
/**
|
|
162 |
* This function returns the current reference count without chaning it.
|
|
163 |
*/
|
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
164 |
int
|
165 |
s_object_get_refcount (SObject * self) { |
|
|
4
by Gustav Hartvigsson
Fixed a few problems. |
166 |
unsigned int ret = self->base_class->get_refcount (self); |
167 |
return ret; |
|
|
1
by Gustav Hartvigsson
Initial Code. |
168 |
}
|
169 |
||
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
170 |
char * |
171 |
s_object_to_string (SObject * self) { |
|
|
39
by Gustav Hartvigsson
* Added "check" target for testing. |
172 |
return self->base_class->to_string (self); |
|
1
by Gustav Hartvigsson
Initial Code. |
173 |
}
|
174 |
||
175 |
/* -----------------
|
|
176 |
* Contrete methods.
|
|
177 |
* -----------------
|
|
178 |
*/
|
|
|
22
by Gustav Hartvigsson
* Made code compile |
179 |
|
|
78
by Gustav Hartvigsson
* Fixed a deprecated warning in base object. |
180 |
DEPRECATED
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
181 |
void
|
182 |
method_base_deinitialize (SObject * self) { } |
|
183 |
||
|
78
by Gustav Hartvigsson
* Fixed a deprecated warning in base object. |
184 |
DEPRECATED
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
185 |
void
|
186 |
method_base_initialize (SObject * self) { } |
|
187 |
||
188 |
void
|
|
189 |
method_base_free (SObject * self) { |
|
|
32
by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt |
190 |
free (self->base_class); |
191 |
free (self); |
|
|
1
by Gustav Hartvigsson
Initial Code. |
192 |
}
|
193 |
||
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
194 |
int
|
195 |
method_base_ref (SObject * self) { |
|
|
1
by Gustav Hartvigsson
Initial Code. |
196 |
self->refcount = self->refcount + 1; |
197 |
return self->refcount; |
|
198 |
}
|
|
199 |
||
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
200 |
int
|
201 |
method_base_unref (SObject * self) { |
|
|
1
by Gustav Hartvigsson
Initial Code. |
202 |
self->refcount = self->refcount - 1; |
|
4
by Gustav Hartvigsson
Fixed a few problems. |
203 |
if (self->refcount == 0) { |
|
32
by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt |
204 |
s_object_free (self); |
|
1
by Gustav Hartvigsson
Initial Code. |
205 |
return 0; |
206 |
} |
|
207 |
return self->refcount; |
|
208 |
}
|
|
209 |
||
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
210 |
int
|
211 |
method_base_get_refcount (SObject * self) { |
|
|
1
by Gustav Hartvigsson
Initial Code. |
212 |
return self->refcount; |
213 |
}
|
|
214 |
||
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
215 |
char * |
216 |
method_base_to_string (SObject * self) { |
|
|
68
by Gustav Hartvigsson
* Hid internals of SDynamicArray. |
217 |
char * ret_string = s_string_new_fmt ("(SObject, References: %d)", self->base_class->get_refcount(self)); |
|
1
by Gustav Hartvigsson
Initial Code. |
218 |
return ret_string; |
219 |
}
|
|
220 |
||
221 |