Mercurial > pidgin
comparison src/value.c @ 6562:c53a3f0649eb
[gaim-migrate @ 7084]
New GaimValue structure. We'll be using this for signals and stuff shortly.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Thu, 21 Aug 2003 20:29:33 +0000 |
parents | |
children | fa6395637e2c |
comparison
equal
deleted
inserted
replaced
6561:33ceba0dfd9b | 6562:c53a3f0649eb |
---|---|
1 /** | |
2 * @file value.c Value wrapper API | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
8 * | |
9 * This program is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 */ | |
23 #include "internal.h" | |
24 | |
25 #include "value.h" | |
26 | |
27 #define OUTGOING_FLAG 0x01 | |
28 | |
29 GaimValue * | |
30 gaim_value_new(GaimType type, ...) | |
31 { | |
32 GaimValue *value; | |
33 va_list args; | |
34 | |
35 g_return_val_if_fail(type != GAIM_TYPE_UNKNOWN, NULL); | |
36 | |
37 value = g_new0(GaimValue, 1); | |
38 | |
39 value->type = type; | |
40 | |
41 va_start(args, type); | |
42 | |
43 if (type == GAIM_TYPE_SUBTYPE) | |
44 value->u.subtype = va_arg(args, int); | |
45 else if (type == GAIM_TYPE_BOXED) | |
46 value->u.specific_type = g_strdup(va_arg(args, char *)); | |
47 | |
48 va_end(args); | |
49 | |
50 return value; | |
51 } | |
52 | |
53 GaimValue * | |
54 gaim_value_new_outgoing(GaimType type, ...) | |
55 { | |
56 GaimValue *value; | |
57 va_list args; | |
58 | |
59 g_return_val_if_fail(type != GAIM_TYPE_UNKNOWN, NULL); | |
60 | |
61 value = g_new0(GaimValue, 1); | |
62 | |
63 value->type = type; | |
64 | |
65 va_start(args, type); | |
66 | |
67 if (type == GAIM_TYPE_SUBTYPE) | |
68 value->u.subtype = va_arg(args, int); | |
69 else if (type == GAIM_TYPE_BOXED) | |
70 value->u.specific_type = g_strdup(va_arg(args, char *)); | |
71 | |
72 va_end(args); | |
73 | |
74 value->flags |= OUTGOING_FLAG; | |
75 | |
76 return value; | |
77 } | |
78 | |
79 void | |
80 gaim_value_destroy(GaimValue *value) | |
81 { | |
82 g_return_if_fail(value != NULL); | |
83 | |
84 if (gaim_value_get_type(value) == GAIM_TYPE_BOXED) | |
85 { | |
86 if (value->u.specific_type != NULL) | |
87 g_free(value->u.specific_type); | |
88 } | |
89 else if (gaim_value_get_type(value) == GAIM_TYPE_STRING) | |
90 { | |
91 if (value->data.string_data != NULL) | |
92 g_free(value->data.string_data); | |
93 } | |
94 | |
95 g_free(value); | |
96 } | |
97 | |
98 GaimType | |
99 gaim_value_get_type(const GaimValue *value) | |
100 { | |
101 g_return_val_if_fail(value != NULL, GAIM_TYPE_UNKNOWN); | |
102 | |
103 return value->type; | |
104 } | |
105 | |
106 unsigned int | |
107 gaim_value_get_subtype(const GaimValue *value) | |
108 { | |
109 g_return_val_if_fail(value != NULL, 0); | |
110 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_SUBTYPE, 0); | |
111 | |
112 return value->u.subtype; | |
113 } | |
114 | |
115 const char * | |
116 gaim_value_get_specific_type(const GaimValue *value) | |
117 { | |
118 g_return_val_if_fail(value != NULL, NULL); | |
119 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_BOXED, NULL); | |
120 | |
121 return value->u.specific_type; | |
122 } | |
123 | |
124 gboolean | |
125 gaim_value_is_outgoing(const GaimValue *value) | |
126 { | |
127 g_return_val_if_fail(value != NULL, FALSE); | |
128 | |
129 return (value->flags & OUTGOING_FLAG); | |
130 } | |
131 | |
132 void | |
133 gaim_value_set_char(GaimValue *value, char data) | |
134 { | |
135 g_return_if_fail(value != NULL); | |
136 | |
137 value->data.char_data = data; | |
138 } | |
139 | |
140 void | |
141 gaim_value_set_uchar(GaimValue *value, unsigned char data) | |
142 { | |
143 g_return_if_fail(value != NULL); | |
144 | |
145 value->data.uchar_data = data; | |
146 } | |
147 | |
148 void | |
149 gaim_value_set_boolean(GaimValue *value, gboolean data) | |
150 { | |
151 g_return_if_fail(value != NULL); | |
152 | |
153 value->data.boolean_data = data; | |
154 } | |
155 | |
156 void | |
157 gaim_value_set_short(GaimValue *value, short data) | |
158 { | |
159 g_return_if_fail(value != NULL); | |
160 | |
161 value->data.short_data = data; | |
162 } | |
163 | |
164 void | |
165 gaim_value_set_ushort(GaimValue *value, unsigned short data) | |
166 { | |
167 g_return_if_fail(value != NULL); | |
168 | |
169 value->data.ushort_data = data; | |
170 } | |
171 | |
172 void | |
173 gaim_value_set_int(GaimValue *value, int data) | |
174 { | |
175 g_return_if_fail(value != NULL); | |
176 | |
177 value->data.int_data = data; | |
178 } | |
179 | |
180 void | |
181 gaim_value_set_uint(GaimValue *value, unsigned int data) | |
182 { | |
183 g_return_if_fail(value != NULL); | |
184 | |
185 value->data.int_data = data; | |
186 } | |
187 | |
188 void | |
189 gaim_value_set_long(GaimValue *value, long data) | |
190 { | |
191 g_return_if_fail(value != NULL); | |
192 | |
193 value->data.long_data = data; | |
194 } | |
195 | |
196 void | |
197 gaim_value_set_ulong(GaimValue *value, unsigned long data) | |
198 { | |
199 g_return_if_fail(value != NULL); | |
200 | |
201 value->data.long_data = data; | |
202 } | |
203 | |
204 void | |
205 gaim_value_set_int64(GaimValue *value, gint64 data) | |
206 { | |
207 g_return_if_fail(value != NULL); | |
208 | |
209 value->data.int64_data = data; | |
210 } | |
211 | |
212 void | |
213 gaim_value_set_uint64(GaimValue *value, guint64 data) | |
214 { | |
215 g_return_if_fail(value != NULL); | |
216 | |
217 value->data.uint64_data = data; | |
218 } | |
219 | |
220 void | |
221 gaim_value_set_string(GaimValue *value, const char *data) | |
222 { | |
223 g_return_if_fail(value != NULL); | |
224 | |
225 if (value->data.string_data != NULL) | |
226 g_free(value->data.string_data); | |
227 | |
228 value->data.string_data = (data == NULL ? NULL : g_strdup(data)); | |
229 } | |
230 | |
231 void | |
232 gaim_value_set_object(GaimValue *value, void *data) | |
233 { | |
234 g_return_if_fail(value != NULL); | |
235 | |
236 value->data.object_data = data; | |
237 } | |
238 | |
239 void | |
240 gaim_value_set_pointer(GaimValue *value, void *data) | |
241 { | |
242 g_return_if_fail(value != NULL); | |
243 | |
244 value->data.pointer_data = data; | |
245 } | |
246 | |
247 void | |
248 gaim_value_set_enum(GaimValue *value, int data) | |
249 { | |
250 g_return_if_fail(value != NULL); | |
251 | |
252 value->data.enum_data = data; | |
253 } | |
254 | |
255 void | |
256 gaim_value_set_boxed(GaimValue *value, void *data) | |
257 { | |
258 g_return_if_fail(value != NULL); | |
259 | |
260 value->data.boxed_data = data; | |
261 } | |
262 | |
263 char | |
264 gaim_value_get_char(const GaimValue *value) | |
265 { | |
266 g_return_val_if_fail(value != NULL, 0); | |
267 | |
268 return value->data.char_data; | |
269 } | |
270 | |
271 unsigned char | |
272 gaim_value_get_uchar(const GaimValue *value) | |
273 { | |
274 g_return_val_if_fail(value != NULL, 0); | |
275 | |
276 return value->data.uchar_data; | |
277 } | |
278 | |
279 gboolean | |
280 gaim_value_get_boolean(const GaimValue *value) | |
281 { | |
282 g_return_val_if_fail(value != NULL, FALSE); | |
283 | |
284 return value->data.boolean_data; | |
285 } | |
286 | |
287 short | |
288 gaim_value_get_short(const GaimValue *value) | |
289 { | |
290 g_return_val_if_fail(value != NULL, 0); | |
291 | |
292 return value->data.short_data; | |
293 } | |
294 | |
295 unsigned short | |
296 gaim_value_get_ushort(const GaimValue *value) | |
297 { | |
298 g_return_val_if_fail(value != NULL, 0); | |
299 | |
300 return value->data.ushort_data; | |
301 } | |
302 | |
303 int | |
304 gaim_value_get_int(const GaimValue *value) | |
305 { | |
306 g_return_val_if_fail(value != NULL, 0); | |
307 | |
308 return value->data.int_data; | |
309 } | |
310 | |
311 unsigned int | |
312 gaim_value_get_uint(const GaimValue *value) | |
313 { | |
314 g_return_val_if_fail(value != NULL, 0); | |
315 | |
316 return value->data.int_data; | |
317 } | |
318 | |
319 long | |
320 gaim_value_get_long(const GaimValue *value) | |
321 { | |
322 g_return_val_if_fail(value != NULL, 0); | |
323 | |
324 return value->data.long_data; | |
325 } | |
326 | |
327 unsigned long | |
328 gaim_value_get_ulong(const GaimValue *value) | |
329 { | |
330 g_return_val_if_fail(value != NULL, 0); | |
331 | |
332 return value->data.long_data; | |
333 } | |
334 | |
335 gint64 | |
336 gaim_value_get_int64(const GaimValue *value) | |
337 { | |
338 g_return_val_if_fail(value != NULL, 0); | |
339 | |
340 return value->data.int64_data; | |
341 } | |
342 | |
343 guint64 | |
344 gaim_value_get_uint64(const GaimValue *value) | |
345 { | |
346 g_return_val_if_fail(value != NULL, 0); | |
347 | |
348 return value->data.uint64_data; | |
349 } | |
350 | |
351 const char * | |
352 gaim_value_get_string(const GaimValue *value) | |
353 { | |
354 g_return_val_if_fail(value != NULL, NULL); | |
355 | |
356 return value->data.string_data; | |
357 } | |
358 | |
359 void * | |
360 gaim_value_get_object(const GaimValue *value) | |
361 { | |
362 g_return_val_if_fail(value != NULL, NULL); | |
363 | |
364 return value->data.object_data; | |
365 } | |
366 | |
367 void * | |
368 gaim_value_get_pointer(const GaimValue *value) | |
369 { | |
370 g_return_val_if_fail(value != NULL, NULL); | |
371 | |
372 return value->data.pointer_data; | |
373 } | |
374 | |
375 int | |
376 gaim_value_get_enum(const GaimValue *value) | |
377 { | |
378 g_return_val_if_fail(value != NULL, -1); | |
379 | |
380 return value->data.enum_data; | |
381 } | |
382 | |
383 void * | |
384 gaim_value_get_boxed(const GaimValue *value) | |
385 { | |
386 g_return_val_if_fail(value != NULL, NULL); | |
387 | |
388 return value->data.boxed_data; | |
389 } | |
390 |