/simpletypesystem/trunk

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