42
41
* C11 Generic macro to create object easily.
43
* This is what is most likely to be used in real code, because it makes life
44
* a lot easier than to remember all the other commands.
46
* The caveat is that there is no way to construct a macro to do the same
47
* for the s_box_get_ functions.
44
49
#define s_box_new(x) _Generic((x)\
45
50
spointer: s_box_new_pointer,\
46
SObject: s_box_new_object,\
51
SObject: s_box_new_sobject,\
47
52
long: s_box_new_long,\
48
53
short: s_box_new_short,\
49
54
char: s_box_new_char,\
56
61
* Creates a new SBox object.
58
63
* @param object The object to be boxed.
59
* @param freefunc The Function to be used when freeing the boxed object.
61
65
* @return A new SBox object.
64
68
s_box_new_pointer (spointer object);
71
* @param object the SObject to stored in the Box.
73
* @return a new SBox object.
67
76
s_box_new_sobject (SObject * object);
79
* @see s_box_get_pointer.
70
82
s_box_new_int (int i);
85
* @see s_box_get_pointer.
73
88
s_box_new_long (long l);
91
* @see s_box_get_pointer.
76
94
s_box_new_short (short s);
97
* @see s_box_get_pointer.
79
100
s_box_new_char (char c);
103
* @see s_box_get_pointer.
82
106
s_box_new_wchar (wchar_t wc);
109
* @see s_box_get_pointer.
85
112
s_box_new_uint (unsigned int ui);
88
s_box_new_ulong (long l);
91
s_box_new_ushort (short s);
115
* @see s_box_get_pointer.
118
s_box_new_ulong (unsigned long l);
121
* @see s_box_get_pointer.
124
s_box_new_ushort (unsigned short s);
127
* @see s_box_get_pointer.
94
130
s_box_new_string (char * s);
133
* @see s_box_get_pointer.
97
136
s_box_new_wstring (wchar_t * ws);
105
144
s_box_free (SBox * box);
108
* Get the object that is contained inside the SBox.
110
* @param box The SBox to get the object from.
112
* @return a pointer to the object.
115
s_box_get_object (SBox * box);
148
* @param self The SBox to get the pointer from.
150
* @return the pointer stored in the SBox.
152
* @note you must cast to the correct type.
155
s_box_get_pointer (SBox * self);
158
* @param self The SBox to get the object from.
160
* @return the SObject stored in the SBox.
162
* @note You should cast to the correct SObject derivative type.
165
s_box_get_sobject (SBox * self);
168
* @param self The box to get the int from.
170
* @return the int that was stored in the
173
s_box_get_int (SBox * self);
176
* @param self the box to get the long from.
178
* @return the long stored in the box.
181
s_box_get_long (SBox * self);
184
* @param self the box to get short from.
186
* @return the short from the box.
189
s_box_get_short (SBox * self);
192
* @param self the box to get the char from.
194
* @return the char stored in the
197
s_box_get_char (SBox * self);
200
* @param self the box to get the wide char from.
202
* @return the wide char stored in the box.
205
s_box_get_wchar (SBox * self);
211
s_box_get_uint (SBox * self);
214
s_box_get_ulong (SBox * self);
217
s_box_get_ushort (SBox * self);
220
s_box_get_string (SBox * self);
223
s_box_get_wstring (SBox * self);
118
226
* Gets the SType of the object that is stored in the SBox.
132
240
s_box_get_type_name (SBox * box);
243
* Set the free func to be used when the box is freed.
245
* This will only work on Strings, Pointers and SObjects.
247
* @param box the SBox to add the free function to.
249
* @param free_func the function to be used when freeing the data.
251
* @return #TRUE on error, #FALSE when everything went all-right.
135
254
s_box_set_free_func (SBox * box, FreeFunc free_func);
257
* Set whether or not the data should be freed when the box is freed.
141
260
s_box_set_free_data_on_free (SBox * self, sboolean free_data);