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