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