/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
126.1.1 by Gustav Hartvigsson
* Using
1
#pragma once
2
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
3
#include "defs.h"
4
#include "baseobject.h"
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
5
#include "Error.h"
43 by Gustav Hartvigsson
* Code cleanup
6
#include "Func.h"
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
7
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
8
S_BEGIN_DECLS
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
9
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
10
/** @file
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
11
 * @defgroup SBox SBox
12
 * @addtogroup SBox
13
 * @{
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
14
 * An SBox is a boxed type.
15
 */
16
17
/** @brief
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
18
 * A reference counted box sitting on top of an SObject.
63 by Gustav Hartvigsson
* Working on SMatrix to finish it off.
19
 *
20
 * When creating an SBox use the s_box_new() macro, it expands to the correct
21
 * constructor using the C11 _Generic macro.
22
 *
23
 * When freeing the SBox use s_object_free() function. If you depend
24
 * on reference counting use s_object_unref() to do this.
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
25
 */
43 by Gustav Hartvigsson
* Code cleanup
26
typedef struct SBox SBox;
27
28
typedef struct SBoxClass SBoxClass;
29
30
typedef struct SBoxPrivate SBoxPrivate;
31
61 by Gustav Hartvigsson
* Made the code more easy to read.
32
struct
33
SBox {
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
34
  SObject parent;
35
  SBoxPrivate * priv;
43 by Gustav Hartvigsson
* Code cleanup
36
};
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
37
61 by Gustav Hartvigsson
* Made the code more easy to read.
38
struct
39
SBoxClass {
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
40
  SObjectClass parent_class;
43 by Gustav Hartvigsson
* Code cleanup
41
};
42
49 by Gustav Hartvigsson
* started work SBox (Untested).
43
#define S_BOX(o) (SBox *)(o);
44
#define S_BOX_CLASS(k) (SBoxClass *)(k);
45
83 by Gustav Hartvigsson
* vec.h:
46
#ifndef __MSC_VER
43 by Gustav Hartvigsson
* Code cleanup
47
/**
61 by Gustav Hartvigsson
* Made the code more easy to read.
48
 * C11 Generic macro to create object easily.
62 by Gustav Hartvigsson
* General documentation clean up.
49
 *
50
 * This is what is most likely to be used in real code, because it makes life
51
 * a lot easier than to remember all the other commands.
52
 *
53
 * The caveat is that there is no way to construct a macro to do the same
54
 * for the s_box_get_ functions.
61 by Gustav Hartvigsson
* Made the code more easy to read.
55
 */
56
#define  s_box_new(x) _Generic((x)\
57
                               spointer: s_box_new_pointer,\
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
58
                               SObject *: s_box_new_sobject,\
59
                               slong: s_box_new_long,\
60
                               sshort: s_box_new_short,\
61
                               schar: s_box_new_char,\
61 by Gustav Hartvigsson
* Made the code more easy to read.
62
                               wchar_t: s_box_new_wchar,\
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
63
                               suchar: s_box_new_uchar,\
64
                               schar *: s_box_new_string,\
61 by Gustav Hartvigsson
* Made the code more easy to read.
65
                               wchar_t *: s_box_new_wstring\
66
                               )(x)
83 by Gustav Hartvigsson
* vec.h:
67
#endif /* __MSC_VER */
61 by Gustav Hartvigsson
* Made the code more easy to read.
68
69
/**
43 by Gustav Hartvigsson
* Code cleanup
70
 * Creates a new SBox object.
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
71
 *
43 by Gustav Hartvigsson
* Code cleanup
72
 * @param object The object to be boxed.
73
 *
74
 * @return A new SBox object.
75
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
76
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
77
SBox *
78
s_box_new_pointer (spointer object);
79
62 by Gustav Hartvigsson
* General documentation clean up.
80
/**
81
 * @param object the SObject to stored in the Box.
82
 *
83
 * @return a new SBox object.
84
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
85
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
86
SBox *
87
s_box_new_sobject (SObject * object);
88
62 by Gustav Hartvigsson
* General documentation clean up.
89
/**
90
 * @see s_box_get_pointer.
91
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
92
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
93
SBox *
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
94
s_box_new_int (sint i);
95
96
/**
97
 * @see s_box_get_pointer.
98
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
99
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
100
SBox *
101
s_box_new_long (slong l);
102
103
/**
104
 * @see s_box_get_pointer.
105
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
106
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
107
SBox *
108
s_box_new_short (sshort s);
109
110
/**
111
 * @see s_box_get_pointer.
112
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
113
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
114
SBox *
115
s_box_new_char (schar c);
116
117
/**
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
118
 * @S_DEPRECATED For everyone's sanity.
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
119
 * @see s_box_get_pointer.
120
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
121
S_EXPORTED
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
122
S_DEPRECATED
61 by Gustav Hartvigsson
* Made the code more easy to read.
123
SBox *
124
s_box_new_wchar (wchar_t wc);
125
62 by Gustav Hartvigsson
* General documentation clean up.
126
/**
127
 * @see s_box_get_pointer.
128
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
129
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
130
SBox *
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
131
s_box_new_uchar (suchar c);
132
133
/**
134
 * @see s_box_get_pointer.
135
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
136
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
137
SBox *
138
s_box_new_uint (suint ui);
139
140
/**
141
 * @see s_box_get_pointer.
142
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
143
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
144
SBox *
145
s_box_new_ulong (sulong l);
146
147
/**
148
 * @see s_box_get_pointer.
149
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
150
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
151
SBox *
152
s_box_new_ushort (sushort s);
153
154
/**
155
 * @see s_box_get_pointer.
156
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
157
158
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
159
SBox *
160
s_box_new_string (schar * s);
161
162
/**
163
 * @see s_box_get_pointer.
164
 */
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
165
S_DEPRECATED
61 by Gustav Hartvigsson
* Made the code more easy to read.
166
SBox *
167
s_box_new_wstring (wchar_t * ws);
43 by Gustav Hartvigsson
* Code cleanup
168
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
169
43 by Gustav Hartvigsson
* Code cleanup
170
/**
171
 * Free the an SBox.
172
 *
173
 * @param box The SBox to be freed.
174
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
175
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
176
void
177
s_box_free (SBox * box);
43 by Gustav Hartvigsson
* Code cleanup
178
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
179
/* *********************
180
   ****** Getters ******
181
   ********************* */
62 by Gustav Hartvigsson
* General documentation clean up.
182
183
 /**
184
 * @param self The SBox to get the pointer from.
185
 *
186
 * @return the pointer stored in the SBox.
187
 *
188
 * @note you must cast to the correct type.
189
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
190
S_EXPORTED
62 by Gustav Hartvigsson
* General documentation clean up.
191
spointer *
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
192
s_box_get_pointer (SBox * self, SError * err);
62 by Gustav Hartvigsson
* General documentation clean up.
193
194
 /**
195
 * @param self The SBox to get the object from.
196
 *
197
 * @return the SObject stored in the SBox.
198
 *
199
 * @note You should cast to the correct SObject derivative type.
200
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
201
S_EXPORTED
62 by Gustav Hartvigsson
* General documentation clean up.
202
SObject *
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
203
s_box_get_sobject (SBox * self, SError * err);
62 by Gustav Hartvigsson
* General documentation clean up.
204
205
/**
206
 * @param self The box to get the int from.
207
 *
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
208
 * @return the int that was stored in the
62 by Gustav Hartvigsson
* General documentation clean up.
209
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
210
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
211
sint
212
s_box_get_int (SBox * self, SError * err);
62 by Gustav Hartvigsson
* General documentation clean up.
213
214
/**
215
 * @param self the box to get the long from.
216
 *
217
 * @return the long stored in the box.
218
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
219
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
220
slong
221
s_box_get_long (SBox * self, SError * err);
62 by Gustav Hartvigsson
* General documentation clean up.
222
223
/**
224
 * @param self the box to get short from.
225
 *
226
 * @return the short from the box.
227
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
228
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
229
sshort
230
s_box_get_short (SBox * self, SError * err);
62 by Gustav Hartvigsson
* General documentation clean up.
231
232
/**
233
 * @param self the box to get the char from.
234
 *
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
235
 * @return the char stored in the
62 by Gustav Hartvigsson
* General documentation clean up.
236
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
237
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
238
schar
239
s_box_get_char (SBox * self, SError * err);
62 by Gustav Hartvigsson
* General documentation clean up.
240
241
/**
242
 * @param self the box to get the wide char from.
243
 *
244
 * @return the wide char stored in the box.
245
 */
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
246
S_DEPRECATED
62 by Gustav Hartvigsson
* General documentation clean up.
247
wchar_t
73 by Gustav Hartvigsson
* Derp.
248
s_box_get_wchar (SBox * self, SError * err);
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
249
250
/**
251
 * @param self the box to get the char from.
252
 *
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
253
 * @return the char stored in the
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
254
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
255
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
256
suchar
257
s_box_get_uchar (SBox * self, SError * err);
62 by Gustav Hartvigsson
* General documentation clean up.
258
259
/**
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
260
 * @param self
62 by Gustav Hartvigsson
* General documentation clean up.
261
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
262
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
263
suint
264
s_box_get_uint (SBox * self, SError * err);
265
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
266
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
267
sulong
268
s_box_get_ulong (SBox * self, SError * err);
269
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
270
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
271
sushort
272
s_box_get_ushort (SBox * self, SError * err);
273
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
274
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
275
schar *
276
s_box_get_string (SBox * self, SError * err);
62 by Gustav Hartvigsson
* General documentation clean up.
277
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
278
S_DEPRECATED
62 by Gustav Hartvigsson
* General documentation clean up.
279
wchar_t *
73 by Gustav Hartvigsson
* Derp.
280
s_box_get_wstring (SBox * self, SError * err);
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
281
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
282
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
283
suchar *
284
s_box_get_ustring (SBox * self, SError * err);
43 by Gustav Hartvigsson
* Code cleanup
285
286
/**
287
 * Gets the SType of the object that is stored in the SBox.
288
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
289
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
290
SType
291
s_box_get_type (SBox * box);
43 by Gustav Hartvigsson
* Code cleanup
292
293
/**
294
 * Gets the type name of the object.
295
 *
296
 * @param box The SBox to get the type name from.
297
 * @return A String containing the name of the type.
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
298
 *
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
299
 * @note caller must free the string.
43 by Gustav Hartvigsson
* Code cleanup
300
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
301
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
302
char *
303
s_box_get_type_name (SBox * box);
49 by Gustav Hartvigsson
* started work SBox (Untested).
304
62 by Gustav Hartvigsson
* General documentation clean up.
305
/**
306
 * Set the free func to be used when the box is freed.
307
 *
308
 * This will only work on Strings, Pointers and SObjects.
309
 *
310
 * @param box the SBox to add the free function to.
311
 *
312
 * @param free_func the function to be used when freeing the data.
313
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
314
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
315
void
316
s_box_set_free_func (SBox * box, FreeFunc free_func);
49 by Gustav Hartvigsson
* started work SBox (Untested).
317
318
/**
62 by Gustav Hartvigsson
* General documentation clean up.
319
 * Set whether or not the data should be freed when the box is freed.
49 by Gustav Hartvigsson
* started work SBox (Untested).
320
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
321
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
322
void
323
s_box_set_free_data_on_free (SBox * self, sboolean free_data);
49 by Gustav Hartvigsson
* started work SBox (Untested).
324
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
325
/** @} */
326
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
327
S_END_DECLS