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