/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"
43 by Gustav Hartvigsson
* Code cleanup
5
#include "Func.h"
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
6
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
7
BEGIN_DECLS
8
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
9
/** @file
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
10
 * @defgroup SBox SBox
11
 * @addtogroup SBox
12
 * @{
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
13
 * An SBox is a boxed type.
14
 */
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
43 by Gustav Hartvigsson
* Code cleanup
46
/**
61 by Gustav Hartvigsson
* Made the code more easy to read.
47
 * C11 Generic macro to create object easily.
62 by Gustav Hartvigsson
* General documentation clean up.
48
 *
49
 * This is what is most likely to be used in real code, because it makes life
50
 * a lot easier than to remember all the other commands.
51
 *
52
 * The caveat is that there is no way to construct a macro to do the same
53
 * for the s_box_get_ functions.
61 by Gustav Hartvigsson
* Made the code more easy to read.
54
 */
55
#define  s_box_new(x) _Generic((x)\
56
                               spointer: s_box_new_pointer,\
62 by Gustav Hartvigsson
* General documentation clean up.
57
                               SObject: s_box_new_sobject,\
61 by Gustav Hartvigsson
* Made the code more easy to read.
58
                               long: s_box_new_long,\
59
                               short: s_box_new_short,\
60
                               char: s_box_new_char,\
61
                               wchar_t: s_box_new_wchar,\
62
                               char *: s_box_new_string,\
63
                               wchar_t *: s_box_new_wstring\
64
                               )(x)
65
66
/**
43 by Gustav Hartvigsson
* Code cleanup
67
 * Creates a new SBox object.
68
 * 
69
 * @param object The object to be boxed.
70
 *
71
 * @return A new SBox object.
72
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
73
SBox *
74
s_box_new_pointer (spointer object);
75
62 by Gustav Hartvigsson
* General documentation clean up.
76
/**
77
 * @param object the SObject to stored in the Box.
78
 *
79
 * @return a new SBox object.
80
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
81
SBox *
82
s_box_new_sobject (SObject * object);
83
62 by Gustav Hartvigsson
* General documentation clean up.
84
/**
85
 * @see s_box_get_pointer.
86
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
87
SBox *
88
s_box_new_int (int i);
89
62 by Gustav Hartvigsson
* General documentation clean up.
90
/**
91
 * @see s_box_get_pointer.
92
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
93
SBox *
94
s_box_new_long (long l);
95
62 by Gustav Hartvigsson
* General documentation clean up.
96
/**
97
 * @see s_box_get_pointer.
98
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
99
SBox *
100
s_box_new_short (short s);
101
62 by Gustav Hartvigsson
* General documentation clean up.
102
/**
103
 * @see s_box_get_pointer.
104
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
105
SBox *
106
s_box_new_char (char c);
107
62 by Gustav Hartvigsson
* General documentation clean up.
108
/**
109
 * @see s_box_get_pointer.
110
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
111
SBox *
112
s_box_new_wchar (wchar_t wc);
113
62 by Gustav Hartvigsson
* General documentation clean up.
114
/**
115
 * @see s_box_get_pointer.
116
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
117
SBox *
118
s_box_new_uint (unsigned int ui);
119
62 by Gustav Hartvigsson
* General documentation clean up.
120
/**
121
 * @see s_box_get_pointer.
122
 */
123
SBox *
124
s_box_new_ulong (unsigned long l);
125
126
/**
127
 * @see s_box_get_pointer.
128
 */
129
SBox *
130
s_box_new_ushort (unsigned short s);
131
132
/**
133
 * @see s_box_get_pointer.
134
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
135
SBox *
136
s_box_new_string (char * s);
137
62 by Gustav Hartvigsson
* General documentation clean up.
138
/**
139
 * @see s_box_get_pointer.
140
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
141
SBox *
142
s_box_new_wstring (wchar_t * ws);
43 by Gustav Hartvigsson
* Code cleanup
143
144
/**
145
 * Free the an SBox.
146
 *
147
 * @param box The SBox to be freed.
148
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
149
void
150
s_box_free (SBox * box);
43 by Gustav Hartvigsson
* Code cleanup
151
62 by Gustav Hartvigsson
* General documentation clean up.
152
153
 /**
154
 * @param self The SBox to get the pointer from.
155
 *
156
 * @return the pointer stored in the SBox.
157
 *
158
 * @note you must cast to the correct type.
159
 */
160
spointer *
161
s_box_get_pointer (SBox * self);
162
163
 /**
164
 * @param self The SBox to get the object from.
165
 *
166
 * @return the SObject stored in the SBox.
167
 *
168
 * @note You should cast to the correct SObject derivative type.
169
 */
170
SObject *
171
s_box_get_sobject (SBox * self);
172
173
/**
174
 * @param self The box to get the int from.
175
 *
176
 * @return the int that was stored in the 
177
 */
178
int
179
s_box_get_int (SBox * self);
180
181
/**
182
 * @param self the box to get the long from.
183
 *
184
 * @return the long stored in the box.
185
 */
186
long
187
s_box_get_long (SBox * self);
188
189
/**
190
 * @param self the box to get short from.
191
 *
192
 * @return the short from the box.
193
 */
194
short
195
s_box_get_short (SBox * self);
196
197
/**
198
 * @param self the box to get the char from.
199
 *
200
 * @return the char stored in the 
201
 */
202
char
203
s_box_get_char (SBox * self);
204
205
/**
206
 * @param self the box to get the wide char from.
207
 *
208
 * @return the wide char stored in the box.
209
 */
210
wchar_t
211
s_box_get_wchar (SBox * self);
212
213
/**
214
 * @param self 
215
 */
216
unsigned int
217
s_box_get_uint (SBox * self);
218
219
unsigned long
220
s_box_get_ulong (SBox * self);
221
222
unsigned short
223
s_box_get_ushort (SBox * self);
224
225
char *
226
s_box_get_string (SBox * self);
227
228
wchar_t *
229
s_box_get_wstring (SBox * self);
43 by Gustav Hartvigsson
* Code cleanup
230
231
/**
232
 * Gets the SType of the object that is stored in the SBox.
233
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
234
SType
235
s_box_get_type (SBox * box);
43 by Gustav Hartvigsson
* Code cleanup
236
237
/**
238
 * Gets the type name of the object.
239
 *
240
 * @param box The SBox to get the type name from.
241
 * @return A String containing the name of the type.
242
 * 
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
243
 * @note caller must free the string.
43 by Gustav Hartvigsson
* Code cleanup
244
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
245
char *
246
s_box_get_type_name (SBox * box);
49 by Gustav Hartvigsson
* started work SBox (Untested).
247
62 by Gustav Hartvigsson
* General documentation clean up.
248
/**
249
 * Set the free func to be used when the box is freed.
250
 *
251
 * This will only work on Strings, Pointers and SObjects.
252
 *
253
 * @param box the SBox to add the free function to.
254
 *
255
 * @param free_func the function to be used when freeing the data.
256
 *
257
 * @return #TRUE on error, #FALSE when everything went all-right.
258
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
259
void
260
s_box_set_free_func (SBox * box, FreeFunc free_func);
49 by Gustav Hartvigsson
* started work SBox (Untested).
261
262
/**
62 by Gustav Hartvigsson
* General documentation clean up.
263
 * Set whether or not the data should be freed when the box is freed.
49 by Gustav Hartvigsson
* started work SBox (Untested).
264
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
265
void
266
s_box_set_free_data_on_free (SBox * self, sboolean free_data);
49 by Gustav Hartvigsson
* started work SBox (Untested).
267
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
268
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
269
/** @} */
270
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
271
END_DECLS
272
273
#endif