/simpletypesystem/trunk

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