/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to src/Box.h

  • Committer: Gustav Hartvigsson
  • Date: 2015-08-26 21:43:01 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20150826214301-a3ms101kvjx4g0qq
* General documentation clean up.
* Made the doxygen optimise for C
* Changed SBoxPrivate to use union
* Implemented the s_box_new_xxx functions
* moved free_func from SBoxClass to SBoxPrivate to lessen confusion with SObjectClass->free, and keep it private.
* Added S_ERROR_TYPE_ERROR to represent generic type errors.
* Added CALLBACK(k) macro
* Made a group for SMatrix.
* Added documentation for various functions and what not.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
struct
33
33
SBoxClass {
34
34
  SObjectClass parent_class;
35
 
  FreeFunc free_func;
36
35
};
37
36
 
38
37
#define S_BOX(o) (SBox *)(o);
40
39
 
41
40
/**
42
41
 * C11 Generic macro to create object easily.
 
42
 *
 
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.
 
45
 *
 
46
 * The caveat is that there is no way to construct a macro to do the same
 
47
 * for the s_box_get_ functions.
43
48
 */
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.
57
62
 * 
58
63
 * @param object The object to be boxed.
59
 
 * @param freefunc The Function to be used when freeing the boxed object.
60
64
 *
61
65
 * @return A new SBox object.
62
66
 */
63
67
SBox *
64
68
s_box_new_pointer (spointer object);
65
69
 
 
70
/**
 
71
 * @param object the SObject to stored in the Box.
 
72
 *
 
73
 * @return a new SBox object.
 
74
 */
66
75
SBox *
67
76
s_box_new_sobject (SObject * object);
68
77
 
 
78
/**
 
79
 * @see s_box_get_pointer.
 
80
 */
69
81
SBox *
70
82
s_box_new_int (int i);
71
83
 
 
84
/**
 
85
 * @see s_box_get_pointer.
 
86
 */
72
87
SBox *
73
88
s_box_new_long (long l);
74
89
 
 
90
/**
 
91
 * @see s_box_get_pointer.
 
92
 */
75
93
SBox *
76
94
s_box_new_short (short s);
77
95
 
 
96
/**
 
97
 * @see s_box_get_pointer.
 
98
 */
78
99
SBox *
79
100
s_box_new_char (char c);
80
101
 
 
102
/**
 
103
 * @see s_box_get_pointer.
 
104
 */
81
105
SBox *
82
106
s_box_new_wchar (wchar_t wc);
83
107
 
 
108
/**
 
109
 * @see s_box_get_pointer.
 
110
 */
84
111
SBox *
85
112
s_box_new_uint (unsigned int ui);
86
113
 
87
 
SBox *
88
 
s_box_new_ulong (long l);
89
 
 
90
 
SBox *
91
 
s_box_new_ushort (short s);
92
 
 
 
114
/**
 
115
 * @see s_box_get_pointer.
 
116
 */
 
117
SBox *
 
118
s_box_new_ulong (unsigned long l);
 
119
 
 
120
/**
 
121
 * @see s_box_get_pointer.
 
122
 */
 
123
SBox *
 
124
s_box_new_ushort (unsigned short s);
 
125
 
 
126
/**
 
127
 * @see s_box_get_pointer.
 
128
 */
93
129
SBox *
94
130
s_box_new_string (char * s);
95
131
 
 
132
/**
 
133
 * @see s_box_get_pointer.
 
134
 */
96
135
SBox *
97
136
s_box_new_wstring (wchar_t * ws);
98
137
 
104
143
void
105
144
s_box_free (SBox * box);
106
145
 
107
 
/**
108
 
 * Get the object that is contained inside the SBox.
109
 
 *
110
 
 * @param box The SBox to get the object from.
111
 
 *
112
 
 * @return a pointer to the object.
113
 
 */
114
 
spointer
115
 
s_box_get_object (SBox * box);
 
146
 
 
147
 /**
 
148
 * @param self The SBox to get the pointer from.
 
149
 *
 
150
 * @return the pointer stored in the SBox.
 
151
 *
 
152
 * @note you must cast to the correct type.
 
153
 */
 
154
spointer *
 
155
s_box_get_pointer (SBox * self);
 
156
 
 
157
 /**
 
158
 * @param self The SBox to get the object from.
 
159
 *
 
160
 * @return the SObject stored in the SBox.
 
161
 *
 
162
 * @note You should cast to the correct SObject derivative type.
 
163
 */
 
164
SObject *
 
165
s_box_get_sobject (SBox * self);
 
166
 
 
167
/**
 
168
 * @param self The box to get the int from.
 
169
 *
 
170
 * @return the int that was stored in the 
 
171
 */
 
172
int
 
173
s_box_get_int (SBox * self);
 
174
 
 
175
/**
 
176
 * @param self the box to get the long from.
 
177
 *
 
178
 * @return the long stored in the box.
 
179
 */
 
180
long
 
181
s_box_get_long (SBox * self);
 
182
 
 
183
/**
 
184
 * @param self the box to get short from.
 
185
 *
 
186
 * @return the short from the box.
 
187
 */
 
188
short
 
189
s_box_get_short (SBox * self);
 
190
 
 
191
/**
 
192
 * @param self the box to get the char from.
 
193
 *
 
194
 * @return the char stored in the 
 
195
 */
 
196
char
 
197
s_box_get_char (SBox * self);
 
198
 
 
199
/**
 
200
 * @param self the box to get the wide char from.
 
201
 *
 
202
 * @return the wide char stored in the box.
 
203
 */
 
204
wchar_t
 
205
s_box_get_wchar (SBox * self);
 
206
 
 
207
/**
 
208
 * @param self 
 
209
 */
 
210
unsigned int
 
211
s_box_get_uint (SBox * self);
 
212
 
 
213
unsigned long
 
214
s_box_get_ulong (SBox * self);
 
215
 
 
216
unsigned short
 
217
s_box_get_ushort (SBox * self);
 
218
 
 
219
char *
 
220
s_box_get_string (SBox * self);
 
221
 
 
222
wchar_t *
 
223
s_box_get_wstring (SBox * self);
116
224
 
117
225
/**
118
226
 * Gets the SType of the object that is stored in the SBox.
131
239
char *
132
240
s_box_get_type_name (SBox * box);
133
241
 
 
242
/**
 
243
 * Set the free func to be used when the box is freed.
 
244
 *
 
245
 * This will only work on Strings, Pointers and SObjects.
 
246
 *
 
247
 * @param box the SBox to add the free function to.
 
248
 *
 
249
 * @param free_func the function to be used when freeing the data.
 
250
 *
 
251
 * @return #TRUE on error, #FALSE when everything went all-right.
 
252
 */
134
253
void
135
254
s_box_set_free_func (SBox * box, FreeFunc free_func);
136
255
 
137
256
/**
138
 
 * 
 
257
 * Set whether or not the data should be freed when the box is freed.
139
258
 */
140
259
void
141
260
s_box_set_free_data_on_free (SBox * self, sboolean free_data);