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 |
||
|
62
by Gustav Hartvigsson
* General documentation clean up. |
23 |
|
24 |
||
|
1
by Gustav Hartvigsson
Initial Code. |
25 |
#ifndef __H_BASE_OBJECT__
|
26 |
#define __H_BASE_OBJECT__
|
|
27 |
||
|
45
by Gustav Hartvigsson
* Fixed indirect dependency in baseobject.h |
28 |
#include "defs.h" |
29 |
#include "utils.h" |
|
|
47
by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h |
30 |
#include "Map.h" |
|
45
by Gustav Hartvigsson
* Fixed indirect dependency in baseobject.h |
31 |
|
32 |
BEGIN_DECLS
|
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
33 |
|
|
5.1.4
by Gustav Hartvigsson
* Added a comment to baseoject.h describing what the file does. |
34 |
/** @file
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
35 |
* @defgroup SObject SObject
|
36 |
* @addtogroup SObject SObject
|
|
37 |
* @{
|
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
38 |
* An SObject represents the base of the Super Simple Type System.
|
|
5.1.4
by Gustav Hartvigsson
* Added a comment to baseoject.h describing what the file does. |
39 |
*
|
40 |
* Almost all other data structures in this library are children to this object
|
|
41 |
* type.
|
|
42 |
*
|
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
43 |
* All objects that inherent from SObject get the ability to have
|
|
5.1.4
by Gustav Hartvigsson
* Added a comment to baseoject.h describing what the file does. |
44 |
* reference counting of objects via built in functions.
|
|
62
by Gustav Hartvigsson
* General documentation clean up. |
45 |
*
|
46 |
* @section Signals/Callbacks
|
|
47 |
* @par @c notify
|
|
48 |
* This signal is envoked when a propertiy is changed in an SObject.
|
|
49 |
* @endpar
|
|
|
5.1.4
by Gustav Hartvigsson
* Added a comment to baseoject.h describing what the file does. |
50 |
*/
|
51 |
||
|
1
by Gustav Hartvigsson
Initial Code. |
52 |
/* ---------------------------------------------------
|
53 |
* This is just a test of creating a small typesystem.
|
|
54 |
* It will include refrence counting.
|
|
55 |
* ---------------------------------------------------
|
|
56 |
*/
|
|
57 |
||
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
58 |
/**
|
59 |
* The class holds all the "virtual" functions, also knows as methods
|
|
60 |
* that are to be used with the object.
|
|
61 |
*
|
|
62 |
*/
|
|
63 |
typedef struct SObjectClass SObjectClass; |
|
64 |
||
65 |
/**
|
|
66 |
* The instance holds the data that is associated with the object.
|
|
67 |
* it also holds a pointer to the class of the object.
|
|
68 |
*
|
|
69 |
*/
|
|
70 |
typedef struct SObject SObject; |
|
71 |
||
|
32
by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt |
72 |
/**
|
73 |
*
|
|
74 |
*/
|
|
75 |
typedef void (* FreeMethod)(SObject *); |
|
76 |
||
77 |
/**
|
|
78 |
*
|
|
79 |
*/
|
|
80 |
typedef char * (* ToStringFunc)(SObject *); |
|
81 |
||
82 |
/**
|
|
83 |
*
|
|
84 |
*/
|
|
85 |
typedef void (* MethodFunc)(SObject *); |
|
86 |
||
87 |
/**
|
|
88 |
*
|
|
89 |
*/
|
|
90 |
typedef int (* MethodFuncInt)(SObject *); |
|
91 |
||
|
45
by Gustav Hartvigsson
* Fixed indirect dependency in baseobject.h |
92 |
#define FREE_METHOD(k) (FreeMethod)k
|
93 |
#define TO_STRING_FUNC(k) (ToStringFunc)k
|
|
94 |
#define METHOD_FUNC(k) (MethodFunc)k
|
|
95 |
#define METHOD_FUNC_INT(k) (MethodFuncInt)k
|
|
|
32
by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt |
96 |
|
|
23
by Gustav Hartvigsson
* Fixed some of the build warnings. |
97 |
#define S_OBJECT(k) (SObject *)k
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
98 |
#define S_OBJECT_CLASS(k) (SObjectClass *)k
|
|
23
by Gustav Hartvigsson
* Fixed some of the build warnings. |
99 |
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
100 |
struct
|
101 |
SObjectClass { |
|
|
32
by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt |
102 |
MethodFunc initialize; |
103 |
MethodFunc deinitialize; |
|
104 |
FreeMethod free; |
|
105 |
MethodFuncInt ref; |
|
106 |
MethodFuncInt unref; |
|
107 |
MethodFuncInt get_refcount; |
|
108 |
ToStringFunc to_string; |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
109 |
};
|
110 |
||
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
111 |
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
112 |
struct
|
113 |
SObject { |
|
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
114 |
schar * name; /*< The name of the class.*/ |
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
115 |
SObjectClass * base_class; /*< holds the reference to the class. */ |
116 |
SMap * callbacks; /*< This is what holds the callbacks. */ |
|
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
117 |
suint refcount; /*< The reference count. */ |
|
3
by Gustav Hartvigsson
Fixed a few things... |
118 |
};
|
119 |
||
|
1
by Gustav Hartvigsson
Initial Code. |
120 |
|
121 |
/* -----------------
|
|
122 |
* Helper functions...
|
|
123 |
* -----------------
|
|
124 |
*/
|
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
125 |
|
126 |
/** @deprecated This function was never used.
|
|
127 |
* This function is used to set the method to initialize a new instance of an
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
128 |
* object.
|
|
32
by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt |
129 |
*
|
130 |
*
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
131 |
*/
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
132 |
DEPRECATED
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
133 |
void
|
134 |
s_object_set_initialize_method (SObject * self, MethodFunc method); |
|
|
1
by Gustav Hartvigsson
Initial Code. |
135 |
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
136 |
/** @deprecated This was never used
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
137 |
* This function is used to set the method to deinitialize an object.
|
|
1
by Gustav Hartvigsson
Initial Code. |
138 |
*
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
139 |
* set it to a method that deinitialize your object.
|
|
1
by Gustav Hartvigsson
Initial Code. |
140 |
*/
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
141 |
DEPRECATED
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
142 |
void
|
143 |
s_object_set_deinitialize_method (SObject * self, MethodFunc method); |
|
|
1
by Gustav Hartvigsson
Initial Code. |
144 |
|
145 |
/**
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
146 |
* This function is used to set the ref method.
|
|
1
by Gustav Hartvigsson
Initial Code. |
147 |
*
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
148 |
* @warning DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
|
|
1
by Gustav Hartvigsson
Initial Code. |
149 |
*/
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
150 |
void
|
151 |
s_object_set_ref_method (SObject * self, MethodFuncInt method); |
|
|
1
by Gustav Hartvigsson
Initial Code. |
152 |
|
153 |
/**
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
154 |
* This function is used to set the unref method.
|
|
1
by Gustav Hartvigsson
Initial Code. |
155 |
*
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
156 |
* @warning DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
|
|
1
by Gustav Hartvigsson
Initial Code. |
157 |
*/
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
158 |
void
|
159 |
s_object_set_unref_method (SObject * self, MethodFuncInt method); |
|
|
1
by Gustav Hartvigsson
Initial Code. |
160 |
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
161 |
/**
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
162 |
* This function is used to set the get_refcount method.
|
|
1
by Gustav Hartvigsson
Initial Code. |
163 |
*
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
164 |
* @warning DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
|
|
1
by Gustav Hartvigsson
Initial Code. |
165 |
*/
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
166 |
void
|
167 |
s_object_set_get_refcount_method (SObject * self, MethodFuncInt method); |
|
|
1
by Gustav Hartvigsson
Initial Code. |
168 |
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
169 |
/**
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
170 |
* This function is used to set the to_string method.
|
|
1
by Gustav Hartvigsson
Initial Code. |
171 |
*/
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
172 |
void
|
173 |
s_object_set_to_string_method (SObject * self, ToStringFunc method); |
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
174 |
|
|
22
by Gustav Hartvigsson
* Made code compile |
175 |
/**
|
176 |
*
|
|
177 |
*/
|
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
178 |
void
|
179 |
s_object_set_free_method (SObject * self, MethodFunc method); |
|
|
22
by Gustav Hartvigsson
* Made code compile |
180 |
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
181 |
|
182 |
/* concrete functions are defined in the C file.
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
183 |
*/
|
184 |
||
185 |
/* ----------------------
|
|
186 |
* Base object functions.
|
|
187 |
* ----------------------
|
|
188 |
*/
|
|
189 |
||
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
190 |
/**
|
191 |
* @brief
|
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
192 |
* Initializes an SObject
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
193 |
*
|
194 |
* @param self The object to initialize.
|
|
195 |
*
|
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
196 |
* This function initializes an instance of the SObject, it also sets
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
197 |
* the methods to be used with the object and sets the reference count to one.
|
|
1
by Gustav Hartvigsson
Initial Code. |
198 |
*/
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
199 |
void
|
200 |
s_object_initialize (SObject * self, const char * name); |
|
|
1
by Gustav Hartvigsson
Initial Code. |
201 |
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
202 |
/** @brief
|
|
1
by Gustav Hartvigsson
Initial Code. |
203 |
* This function creates a new base object.
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
204 |
*
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
205 |
* @return a new SObject
|
|
1
by Gustav Hartvigsson
Initial Code. |
206 |
*/
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
207 |
SObject * |
208 |
s_object_new (); |
|
|
1
by Gustav Hartvigsson
Initial Code. |
209 |
|
210 |
/**
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
211 |
* This function desensitizes/frees an object even if it is still referenced.
|
|
5.2.9
by Gustav Hartvigsson
* Added license to files |
212 |
* This is usually a bad idea, use s_object_unref () instead.
|
|
1
by Gustav Hartvigsson
Initial Code. |
213 |
*/
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
214 |
void
|
215 |
s_object_free (SObject * self); |
|
|
1
by Gustav Hartvigsson
Initial Code. |
216 |
|
217 |
/**
|
|
218 |
* This function gets the class (which hold the object methods).
|
|
219 |
*/
|
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
220 |
SObjectClass * |
221 |
s_object_get_class (SObject * self); |
|
|
1
by Gustav Hartvigsson
Initial Code. |
222 |
|
223 |
/**
|
|
224 |
* This function sets the instance class of an object.
|
|
225 |
*/
|
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
226 |
void
|
227 |
s_object_set_class (SObject * self, SObjectClass * klass); |
|
|
1
by Gustav Hartvigsson
Initial Code. |
228 |
|
229 |
/**
|
|
230 |
* This function is used to decrese the reference count of an object.
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
231 |
* When an object reaches zero, it will deinitialize the object using the
|
232 |
* objects deinitialize method.
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
233 |
*
|
234 |
* It returns the current (after change) reference count.
|
|
235 |
*/
|
|
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
236 |
sint
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
237 |
s_object_unref (SObject * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
238 |
|
239 |
/**
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
240 |
* This function is used to increase the reference count of an object.
|
|
1
by Gustav Hartvigsson
Initial Code. |
241 |
*
|
242 |
* Returns the current (after change) reference count.
|
|
243 |
*/
|
|
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
244 |
sint
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
245 |
s_object_ref (SObject * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
246 |
|
247 |
/**
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
248 |
* This function returns the current reference count without changing it.
|
|
1
by Gustav Hartvigsson
Initial Code. |
249 |
*/
|
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
250 |
sint
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
251 |
s_object_get_refcount (SObject * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
252 |
|
253 |
/**
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
254 |
* This function returns a textual (string) that represents the object.
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
255 |
* The method can be set using s_object_set_to_string_method().
|
|
1
by Gustav Hartvigsson
Initial Code. |
256 |
*
|
257 |
* Note: The string that is returned must be freed.
|
|
258 |
*/
|
|
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
259 |
schar * |
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
260 |
s_object_to_string (SObject * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
261 |
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
262 |
/**
|
263 |
* @}
|
|
264 |
*/
|
|
265 |
||
|
22
by Gustav Hartvigsson
* Made code compile |
266 |
END_DECLS
|
|
1
by Gustav Hartvigsson
Initial Code. |
267 |
|
268 |
#endif
|