/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#ifndef __H_BOX__
#define __H_BOX__
#include "defs.h"
#include "baseobject.h"
#include "Error.h"
#include "Func.h"

BEGIN_DECLS

/** @file
 * @defgroup SBox SBox
 * @addtogroup SBox
 * @{
 * An SBox is a boxed type.
 */


/** @brief
 * A reference counted box sitting on top of an SObject.
 *
 * When creating an SBox use the s_box_new() macro, it expands to the correct
 * constructor using the C11 _Generic macro.
 *
 * When freeing the SBox use s_object_free() function. If you depend
 * on reference counting use s_object_unref() to do this.
 */
typedef struct SBox SBox;

typedef struct SBoxClass SBoxClass;

typedef struct SBoxPrivate SBoxPrivate;

struct
SBox {
  SObject parent;
  SBoxPrivate * priv;
};

struct
SBoxClass {
  SObjectClass parent_class;
};

#define S_BOX(o) (SBox *)(o);
#define S_BOX_CLASS(k) (SBoxClass *)(k);

#ifndef __MSC_VER
/**
 * C11 Generic macro to create object easily.
 *
 * This is what is most likely to be used in real code, because it makes life
 * a lot easier than to remember all the other commands.
 *
 * The caveat is that there is no way to construct a macro to do the same
 * for the s_box_get_ functions.
 */
#define  s_box_new(x) _Generic((x)\
                               spointer: s_box_new_pointer,\
                               SObject *: s_box_new_sobject,\
                               slong: s_box_new_long,\
                               sshort: s_box_new_short,\
                               schar: s_box_new_char,\
                               wchar_t: s_box_new_wchar,\
                               suchar: s_box_new_uchar,\
                               schar *: s_box_new_string,\
                               wchar_t *: s_box_new_wstring\
                               )(x)
#endif /* __MSC_VER */

/**
 * Creates a new SBox object.
 * 
 * @param object The object to be boxed.
 *
 * @return A new SBox object.
 */
SBox *
s_box_new_pointer (spointer object);

/**
 * @param object the SObject to stored in the Box.
 *
 * @return a new SBox object.
 */
SBox *
s_box_new_sobject (SObject * object);

/**
 * @see s_box_get_pointer.
 */
SBox *
s_box_new_int (sint i);

/**
 * @see s_box_get_pointer.
 */
SBox *
s_box_new_long (slong l);

/**
 * @see s_box_get_pointer.
 */
SBox *
s_box_new_short (sshort s);

/**
 * @see s_box_get_pointer.
 */
SBox *
s_box_new_char (schar c);

/**
 * @deprecated For everyone's sanity.
 * @see s_box_get_pointer.
 */
DEPRECATED
SBox *
s_box_new_wchar (wchar_t wc);

/**
 * @see s_box_get_pointer.
 */
SBox *
s_box_new_uchar (suchar c);

/**
 * @see s_box_get_pointer.
 */
SBox *
s_box_new_uint (suint ui);

/**
 * @see s_box_get_pointer.
 */
SBox *
s_box_new_ulong (sulong l);

/**
 * @see s_box_get_pointer.
 */
SBox *
s_box_new_ushort (sushort s);

/**
 * @see s_box_get_pointer.
 */
SBox *
s_box_new_string (schar * s);

/**
 * @see s_box_get_pointer.
 */
DEPRECATED
SBox *
s_box_new_wstring (wchar_t * ws);


/**
 * Free the an SBox.
 *
 * @param box The SBox to be freed.
 */
void
s_box_free (SBox * box);

/* *********************
   ****** Getters ******
   ********************* */

 /**
 * @param self The SBox to get the pointer from.
 *
 * @return the pointer stored in the SBox.
 *
 * @note you must cast to the correct type.
 */
spointer *
s_box_get_pointer (SBox * self, SError * err);

 /**
 * @param self The SBox to get the object from.
 *
 * @return the SObject stored in the SBox.
 *
 * @note You should cast to the correct SObject derivative type.
 */
SObject *
s_box_get_sobject (SBox * self, SError * err);

/**
 * @param self The box to get the int from.
 *
 * @return the int that was stored in the 
 */
sint
s_box_get_int (SBox * self, SError * err);

/**
 * @param self the box to get the long from.
 *
 * @return the long stored in the box.
 */
slong
s_box_get_long (SBox * self, SError * err);

/**
 * @param self the box to get short from.
 *
 * @return the short from the box.
 */
sshort
s_box_get_short (SBox * self, SError * err);

/**
 * @param self the box to get the char from.
 *
 * @return the char stored in the 
 */
schar
s_box_get_char (SBox * self, SError * err);

/**
 * @param self the box to get the wide char from.
 *
 * @return the wide char stored in the box.
 */
DEPRECATED
wchar_t
s_box_get_wchar (SBox * self, SError * err);

/**
 * @param self the box to get the char from.
 *
 * @return the char stored in the 
 */
suchar
s_box_get_uchar (SBox * self, SError * err);

/**
 * @param self 
 */
suint
s_box_get_uint (SBox * self, SError * err);

sulong
s_box_get_ulong (SBox * self, SError * err);

sushort
s_box_get_ushort (SBox * self, SError * err);

schar *
s_box_get_string (SBox * self, SError * err);

DEPRECATED
wchar_t *
s_box_get_wstring (SBox * self, SError * err);

suchar *
s_box_get_ustring (SBox * self, SError * err);

/**
 * Gets the SType of the object that is stored in the SBox.
 */
SType
s_box_get_type (SBox * box);

/**
 * Gets the type name of the object.
 *
 * @param box The SBox to get the type name from.
 * @return A String containing the name of the type.
 * 
 * @note caller must free the string.
 */
char *
s_box_get_type_name (SBox * box);

/**
 * Set the free func to be used when the box is freed.
 *
 * This will only work on Strings, Pointers and SObjects.
 *
 * @param box the SBox to add the free function to.
 *
 * @param free_func the function to be used when freeing the data.
 */
void
s_box_set_free_func (SBox * box, FreeFunc free_func);

/**
 * Set whether or not the data should be freed when the box is freed.
 */
void
s_box_set_free_data_on_free (SBox * self, sboolean free_data);

/** @} */

END_DECLS

#endif