bzr branch
http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
|
1
by Gustav Hartvigsson
Initial Code. |
1 |
/*
|
2 |
(C) Gustav Hartvigsson, 2013.
|
|
3 |
|
|
4 |
This program is free software: you can redistribute it and/or modify
|
|
5 |
it under the terms of the GNU Lesser General Public License as
|
|
6 |
published by the Free Software Foundation, either version 3 of the
|
|
7 |
License.
|
|
8 |
||
9 |
This program is distributed in the hope that it will be useful,
|
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
GNU General Public License for more details.
|
|
13 |
||
14 |
You should have received a copy of the GNU General Public License
|
|
15 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
*/
|
|
17 |
||
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
18 |
/** @file */
|
19 |
||
|
1
by Gustav Hartvigsson
Initial Code. |
20 |
#ifndef __H_BASE_OBJECT__
|
21 |
#define __H_BASE_OBJECT__
|
|
22 |
||
|
5.1.4
by Gustav Hartvigsson
* Added a comment to baseoject.h describing what the file does. |
23 |
/** @file
|
24 |
* An SBaseObjectInstance represents the base of the Super Simple Type System.
|
|
25 |
*
|
|
26 |
* Almost all other data structures in this library are children to this object
|
|
27 |
* type.
|
|
28 |
*
|
|
29 |
* All objects that inherent from SBaseObjectInstance get the ability to have
|
|
30 |
* reference counting of objects via built in functions.
|
|
31 |
*/
|
|
32 |
||
|
1
by Gustav Hartvigsson
Initial Code. |
33 |
/* ---------------------------------------------------
|
34 |
* This is just a test of creating a small typesystem.
|
|
35 |
* It will include refrence counting.
|
|
36 |
* ---------------------------------------------------
|
|
37 |
*/
|
|
38 |
||
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
39 |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
40 |
typedef struct _SBaseObjectClass SBaseObjectClass; |
|
1
by Gustav Hartvigsson
Initial Code. |
41 |
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
42 |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
43 |
typedef struct _SBaseObjectInstance SBaseObjectInstance; |
44 |
||
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
45 |
/**
|
46 |
* The class holds all the "virtual" functions, also knows as methods
|
|
47 |
* that are to be used with the object.
|
|
48 |
*
|
|
49 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
50 |
struct _SBaseObjectClass { |
51 |
// SBaseObjectInstance * (* initize)(SBaseObjectInstance *); |
|
52 |
void (*deinitize)(SBaseObjectInstance *); |
|
53 |
int (*ref)(SBaseObjectInstance *); |
|
54 |
int (*unref)(SBaseObjectInstance *); |
|
55 |
int (*get_refcount)(SBaseObjectInstance *); |
|
56 |
char * (*to_string)(SBaseObjectInstance *); |
|
57 |
};
|
|
58 |
||
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
59 |
/**
|
60 |
* The instance holds the data that is associated with the object.
|
|
61 |
* it also holds a pointer to the class of the object.
|
|
62 |
*
|
|
63 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
64 |
struct _SBaseObjectInstance { |
65 |
SBaseObjectClass * base_class; |
|
66 |
unsigned int refcount; |
|
67 |
};
|
|
68 |
||
|
1
by Gustav Hartvigsson
Initial Code. |
69 |
|
70 |
/* -----------------
|
|
71 |
* Helper functions...
|
|
72 |
* -----------------
|
|
73 |
*/
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
74 |
/*
|
75 |
* This function is used to set the method to initialize a new instance of an
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
76 |
* object.
|
77 |
*
|
|
78 |
* This has no use, rely...(?)
|
|
79 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
80 |
// void s_base_object_set_init_method (SBaseObjectInstance * self, SBaseObjectInstance * (* method)(* SBaseObjectInstance));
|
|
1
by Gustav Hartvigsson
Initial Code. |
81 |
|
82 |
/**
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
83 |
* This function is used to set the method to deinitialize an object.
|
|
1
by Gustav Hartvigsson
Initial Code. |
84 |
*
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
85 |
* set it to a method that deinitialize your object.
|
|
1
by Gustav Hartvigsson
Initial Code. |
86 |
*/
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
87 |
void s_base_object_set_deinit_method (SBaseObjectInstance * self, void (* method)(SBaseObjectInstance *)); |
|
1
by Gustav Hartvigsson
Initial Code. |
88 |
|
89 |
/**
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
90 |
* This function is used to set the ref method.
|
|
1
by Gustav Hartvigsson
Initial Code. |
91 |
*
|
92 |
* DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
|
|
93 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
94 |
void s_base_object_set_ref_method (SBaseObjectInstance * self, int (* method)(SBaseObjectInstance *)); |
|
1
by Gustav Hartvigsson
Initial Code. |
95 |
|
96 |
/**
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
97 |
* This function is used to set the unref method.
|
|
1
by Gustav Hartvigsson
Initial Code. |
98 |
*
|
99 |
* DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
|
|
100 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
101 |
void s_base_object_set_unref_method (SBaseObjectInstance * self, int (* method)(SBaseObjectInstance *)); |
|
1
by Gustav Hartvigsson
Initial Code. |
102 |
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
103 |
/**!
|
104 |
* This function is used to set the get_refcount method.
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
105 |
*
|
106 |
* DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
|
|
107 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
108 |
void s_base_object_set_get_refcount_method (SBaseObjectInstance * self, int (* method)(SBaseObjectInstance *)); |
|
1
by Gustav Hartvigsson
Initial Code. |
109 |
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
110 |
/**!
|
111 |
* This function is used to set the to_string method.
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
112 |
*/
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
113 |
void s_base_object_set_to_string_method (SBaseObjectInstance * self, char * (* method)(SBaseObjectInstance *)); |
|
1
by Gustav Hartvigsson
Initial Code. |
114 |
|
115 |
||
116 |
/*
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
117 |
* concrete functions are defined in the C file.
|
|
1
by Gustav Hartvigsson
Initial Code. |
118 |
*/
|
119 |
||
120 |
/* ----------------------
|
|
121 |
* Base object functions.
|
|
122 |
* ----------------------
|
|
123 |
*/
|
|
124 |
||
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
125 |
/** @brief
|
126 |
* Initializes an SBaseObjectInstance
|
|
127 |
*
|
|
128 |
* @param self The object to initialize.
|
|
129 |
*
|
|
130 |
* This function initializes an instance of the SBaseObjectInstance, it also sets
|
|
131 |
* the methods to be used with the object and sets the reference count to one.
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
132 |
*/
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
133 |
void s_base_object_initize (SBaseObjectInstance * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
134 |
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
135 |
/** @brief
|
|
1
by Gustav Hartvigsson
Initial Code. |
136 |
* This function creates a new base object.
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
137 |
*
|
138 |
*
|
|
139 |
*
|
|
140 |
* @return a new SBaseObjectInstance
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
141 |
*/
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
142 |
SBaseObjectInstance * s_base_object_new (); |
|
1
by Gustav Hartvigsson
Initial Code. |
143 |
|
144 |
/**
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
145 |
* This function desensitizes/frees an object even if it is still referenced.
|
146 |
* This is usually a bad idea, use s_base_object_unref () instead.
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
147 |
*/
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
148 |
void s_base_object_free (SBaseObjectInstance * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
149 |
|
150 |
/**
|
|
151 |
* This function gets the class (which hold the object methods).
|
|
152 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
153 |
void * s_base_object_get_class (SBaseObjectInstance * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
154 |
|
155 |
/**
|
|
156 |
* This function sets the instance class of an object.
|
|
157 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
158 |
void s_base_object_set_class (SBaseObjectInstance * self, SBaseObjectClass * klass); |
|
1
by Gustav Hartvigsson
Initial Code. |
159 |
|
160 |
/**
|
|
161 |
* 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. |
162 |
* When an object reaches zero, it will deinitialize the object using the
|
163 |
* objects deinitialize method.
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
164 |
*
|
165 |
* It returns the current (after change) reference count.
|
|
166 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
167 |
int s_base_object_unref (SBaseObjectInstance * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
168 |
|
169 |
/**
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
170 |
* This function is used to increase the reference count of an object.
|
|
1
by Gustav Hartvigsson
Initial Code. |
171 |
*
|
172 |
* Returns the current (after change) reference count.
|
|
173 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
174 |
int s_base_object_ref (SBaseObjectInstance * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
175 |
|
176 |
/**
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
177 |
* This function returns the current reference count without changing it.
|
|
1
by Gustav Hartvigsson
Initial Code. |
178 |
*/
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
179 |
int s_base_object_get_refcount (SBaseObjectInstance * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
180 |
|
181 |
/**
|
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
182 |
* This function returns a textual (string) that represents the object.
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
183 |
* The method can be set using s_base_object_set_to_string_method.
|
|
1
by Gustav Hartvigsson
Initial Code. |
184 |
*
|
185 |
* Note: The string that is returned must be freed.
|
|
186 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
187 |
char * s_base_object_to_string (SBaseObjectInstance * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
188 |
|
189 |
||
190 |
#endif
|