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 |
||
18 |
#ifndef __H_BASE_OBJECT__
|
|
19 |
#define __H_BASE_OBJECT__
|
|
20 |
||
21 |
/* ---------------------------------------------------
|
|
22 |
* This is just a test of creating a small typesystem.
|
|
23 |
* It will include refrence counting.
|
|
24 |
* ---------------------------------------------------
|
|
25 |
*/
|
|
26 |
||
27 |
/**
|
|
28 |
* The class holds all the "virtual" functions/methods that are to be used with
|
|
29 |
* the object.
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
30 |
*
|
31 |
*
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
32 |
*/
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
33 |
typedef struct _SBaseObjectClass SBaseObjectClass; |
|
1
by Gustav Hartvigsson
Initial Code. |
34 |
|
35 |
/**
|
|
36 |
* The instance holds the data that is associated with the object.
|
|
37 |
* it also holds a pointer to the class of the object.
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
38 |
*
|
39 |
*
|
|
|
1
by Gustav Hartvigsson
Initial Code. |
40 |
*/
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
41 |
typedef struct _SBaseObjectInstance SBaseObjectInstance; |
42 |
||
43 |
struct _SBaseObjectClass { |
|
44 |
// SBaseObjectInstance * (* initize)(SBaseObjectInstance *); |
|
45 |
void (*deinitize)(SBaseObjectInstance *); |
|
46 |
int (*ref)(SBaseObjectInstance *); |
|
47 |
int (*unref)(SBaseObjectInstance *); |
|
48 |
int (*get_refcount)(SBaseObjectInstance *); |
|
49 |
char * (*to_string)(SBaseObjectInstance *); |
|
50 |
};
|
|
51 |
||
52 |
struct _SBaseObjectInstance { |
|
53 |
SBaseObjectClass * base_class; |
|
54 |
unsigned int refcount; |
|
55 |
};
|
|
56 |
||
|
1
by Gustav Hartvigsson
Initial Code. |
57 |
|
58 |
/* -----------------
|
|
59 |
* Helper functions...
|
|
60 |
* -----------------
|
|
61 |
*/
|
|
62 |
/**
|
|
63 |
* This function is used to set the method to initize a new instance of an
|
|
64 |
* object.
|
|
65 |
*
|
|
66 |
* This has no use, rely...(?)
|
|
67 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
68 |
// void s_base_object_set_init_method (SBaseObjectInstance * self, SBaseObjectInstance * (* method)(* SBaseObjectInstance));
|
|
1
by Gustav Hartvigsson
Initial Code. |
69 |
|
70 |
/**
|
|
71 |
* This function is used to set the method to deinitize an object.
|
|
72 |
*
|
|
73 |
* set it to a method that deinitize your object.
|
|
74 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
75 |
void s_base_object_set_deinit_method (SBaseObjectInstance * self, void (* method)(SBaseObjectInstance *)); |
|
1
by Gustav Hartvigsson
Initial Code. |
76 |
|
77 |
/**
|
|
78 |
* This fuction is used to set the ref method.
|
|
79 |
*
|
|
80 |
* DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
|
|
81 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
82 |
void s_base_object_set_ref_method (SBaseObjectInstance * self, int (* method)(SBaseObjectInstance *)); |
|
1
by Gustav Hartvigsson
Initial Code. |
83 |
|
84 |
/**
|
|
85 |
* This fuction is used to set the unref method.
|
|
86 |
*
|
|
87 |
* DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
|
|
88 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
89 |
void s_base_object_set_unref_method (SBaseObjectInstance * self, int (* method)(SBaseObjectInstance *)); |
|
1
by Gustav Hartvigsson
Initial Code. |
90 |
|
91 |
/**
|
|
92 |
* This fuction is used to set the get_refcount method.
|
|
93 |
*
|
|
94 |
* DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
|
|
95 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
96 |
void s_base_object_set_get_refcount_method (SBaseObjectInstance * self, int (* method)(SBaseObjectInstance *)); |
|
1
by Gustav Hartvigsson
Initial Code. |
97 |
|
98 |
/**
|
|
99 |
* This fuction is used to set the to_string method.
|
|
100 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
101 |
void s_base_object_set_to_string_method (SBaseObjectInstance * self, char * (* method)(SBaseObjectInstance *)); |
|
1
by Gustav Hartvigsson
Initial Code. |
102 |
|
103 |
||
104 |
/*
|
|
105 |
* concreate functions are defined in the C file.
|
|
106 |
*/
|
|
107 |
||
108 |
/* ----------------------
|
|
109 |
* Base object functions.
|
|
110 |
* ----------------------
|
|
111 |
*/
|
|
112 |
||
113 |
/**
|
|
114 |
* This function initizes an intance of the BaseObject, it also sets the methods
|
|
115 |
* to be used with the object and sets the refrence count to one.
|
|
116 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
117 |
void s_base_object_initize (SBaseObjectInstance * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
118 |
|
119 |
/**
|
|
120 |
* This function creates a new base object.
|
|
121 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
122 |
SBaseObjectInstance * s_base_object_new (); |
|
1
by Gustav Hartvigsson
Initial Code. |
123 |
|
124 |
/**
|
|
125 |
* This function deinitizes/frees an object even if it is still referenced.
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
126 |
* This is usualy a bad idea, use s_base_object_unref instead.
|
|
1
by Gustav Hartvigsson
Initial Code. |
127 |
*/
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
128 |
void s_base_object_free (SBaseObjectInstance * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
129 |
|
130 |
/**
|
|
131 |
* This function gets the class (which hold the object methods).
|
|
132 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
133 |
void * s_base_object_get_class (SBaseObjectInstance * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
134 |
|
135 |
/**
|
|
136 |
* This function sets the instance class of an object.
|
|
137 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
138 |
void s_base_object_set_class (SBaseObjectInstance * self, SBaseObjectClass * klass); |
|
1
by Gustav Hartvigsson
Initial Code. |
139 |
|
140 |
/**
|
|
141 |
* This function is used to decrese the reference count of an object.
|
|
142 |
* When an object reaches zero, it will deinitize the object using the objects
|
|
143 |
* deititize method.
|
|
144 |
*
|
|
145 |
* It returns the current (after change) reference count.
|
|
146 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
147 |
int s_base_object_unref (SBaseObjectInstance * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
148 |
|
149 |
/**
|
|
150 |
* This function is used to increse the reference count of an object.
|
|
151 |
*
|
|
152 |
* Returns the current (after change) reference count.
|
|
153 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
154 |
int s_base_object_ref (SBaseObjectInstance * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
155 |
|
156 |
/**
|
|
157 |
* This function returns the current reference count without chaning it.
|
|
158 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
159 |
int s_base_object_get_refcount (SBaseObjectInstance * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
160 |
|
161 |
/**
|
|
162 |
* This function returns a textual (string) that represesnts the object.
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
163 |
* The method can be set using s_base_object_set_to_string_method.
|
|
1
by Gustav Hartvigsson
Initial Code. |
164 |
*
|
165 |
* Note: The string that is returned must be freed.
|
|
166 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
167 |
char * s_base_object_to_string (SBaseObjectInstance * self); |
|
1
by Gustav Hartvigsson
Initial Code. |
168 |
|
169 |
||
170 |
#endif
|