Mercurial > pidgin
annotate src/value.h @ 13623:51d436a267ac
[gaim-migrate @ 16009]
Use the GSlice allocator (for logs and log sets) when compiling with glib 2.10 or greater and eliminate some unnecessary memory zeroing. This cuts the log loading time in half for one of Luke's contacts.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Tue, 11 Apr 2006 16:06:24 +0000 |
parents | d9dbb874a30c |
children | f94309c7c480 |
rev | line source |
---|---|
6562 | 1 /** |
2 * @file value.h 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 #ifndef _GAIM_VALUE_H_ | |
26 #define _GAIM_VALUE_H_ | |
27 | |
6565
cb00e9647033
[gaim-migrate @ 7087]
Christian Hammond <chipx86@chipx86.com>
parents:
6563
diff
changeset
|
28 #include <glib.h> |
cb00e9647033
[gaim-migrate @ 7087]
Christian Hammond <chipx86@chipx86.com>
parents:
6563
diff
changeset
|
29 |
6562 | 30 /** |
31 * Specific value types. | |
32 */ | |
33 typedef enum | |
34 { | |
35 GAIM_TYPE_UNKNOWN = 0, /**< Unknown type. */ | |
36 GAIM_TYPE_SUBTYPE, /**< Subtype. */ | |
37 GAIM_TYPE_CHAR, /**< Character. */ | |
38 GAIM_TYPE_UCHAR, /**< Unsigned character. */ | |
39 GAIM_TYPE_BOOLEAN, /**< Boolean. */ | |
40 GAIM_TYPE_SHORT, /**< Short integer. */ | |
41 GAIM_TYPE_USHORT, /**< Unsigned short integer. */ | |
42 GAIM_TYPE_INT, /**< Integer. */ | |
43 GAIM_TYPE_UINT, /**< Unsigned integer. */ | |
44 GAIM_TYPE_LONG, /**< Long integer. */ | |
45 GAIM_TYPE_ULONG, /**< Unsigned long integer. */ | |
46 GAIM_TYPE_INT64, /**< 64-bit integer. */ | |
47 GAIM_TYPE_UINT64, /**< 64-bit unsigned integer. */ | |
48 GAIM_TYPE_STRING, /**< String. */ | |
49 GAIM_TYPE_OBJECT, /**< Object pointer. */ | |
50 GAIM_TYPE_POINTER, /**< Generic pointer. */ | |
51 GAIM_TYPE_ENUM, /**< Enum. */ | |
52 GAIM_TYPE_BOXED /**< Boxed pointer with specific type. */ | |
53 | |
54 } GaimType; | |
55 | |
56 /** | |
6563
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
57 * Gaim-specific subtype values. |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
58 */ |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
59 typedef enum |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
60 { |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
61 GAIM_SUBTYPE_UNKNOWN = 0, |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
62 GAIM_SUBTYPE_ACCOUNT, |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
63 GAIM_SUBTYPE_BLIST, |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
64 GAIM_SUBTYPE_BLIST_BUDDY, |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
65 GAIM_SUBTYPE_BLIST_GROUP, |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
66 GAIM_SUBTYPE_BLIST_CHAT, |
10934 | 67 GAIM_SUBTYPE_BUDDY_ICON, |
6563
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
68 GAIM_SUBTYPE_CONNECTION, |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
69 GAIM_SUBTYPE_CONVERSATION, |
8817 | 70 GAIM_SUBTYPE_PLUGIN, |
10684
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10477
diff
changeset
|
71 GAIM_SUBTYPE_BLIST_NODE, |
11979
717cbb3115bc
[gaim-migrate @ 14272]
Gary Kramlich <grim@reaperworld.com>
parents:
10934
diff
changeset
|
72 GAIM_SUBTYPE_CIPHER, |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
11979
diff
changeset
|
73 GAIM_SUBTYPE_STATUS, |
13219
d0f7f698b6de
[gaim-migrate @ 15583]
Richard Laager <rlaager@wiktel.com>
parents:
12837
diff
changeset
|
74 GAIM_SUBTYPE_LOG, |
13387
d9dbb874a30c
[gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents:
13219
diff
changeset
|
75 GAIM_SUBTYPE_XFER, |
d9dbb874a30c
[gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents:
13219
diff
changeset
|
76 GAIM_SUBTYPE_SAVEDSTATUS |
6563
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
77 } GaimSubType; |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
78 |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
79 /** |
6562 | 80 * A wrapper for a type, subtype, and specific type of value. |
81 */ | |
82 typedef struct | |
83 { | |
84 GaimType type; | |
85 unsigned short flags; | |
86 | |
87 union | |
88 { | |
89 char char_data; | |
90 unsigned char uchar_data; | |
91 gboolean boolean_data; | |
92 short short_data; | |
93 unsigned short ushort_data; | |
94 int int_data; | |
95 unsigned int uint_data; | |
96 long long_data; | |
97 unsigned long ulong_data; | |
98 gint64 int64_data; | |
99 guint64 uint64_data; | |
100 char *string_data; | |
101 void *object_data; | |
102 void *pointer_data; | |
103 int enum_data; | |
104 void *boxed_data; | |
105 | |
106 } data; | |
107 | |
108 union | |
109 { | |
110 unsigned int subtype; | |
111 char *specific_type; | |
112 | |
113 } u; | |
114 | |
115 } GaimValue; | |
116 | |
6563
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
117 #ifdef __cplusplus |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
118 extern "C" { |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
119 #endif |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
120 |
6562 | 121 /** |
122 * Creates a new GaimValue. | |
123 * | |
124 * This function takes a type and, depending on that type, a sub-type | |
125 * or specific type. | |
126 * | |
10477 | 127 * If @a type is GAIM_TYPE_BOXED, the next parameter must be a |
6562 | 128 * string representing the specific type. |
129 * | |
130 * If @a type is GAIM_TYPE_SUBTYPE, the next parameter must be a | |
131 * integer or enum representing the sub-type. | |
132 * | |
133 * If the subtype or specific type is not set when required, random | |
134 * errors may occur. You have been warned. | |
135 * | |
136 * @param type The type. | |
137 * | |
138 * @return The new value. | |
139 */ | |
140 GaimValue *gaim_value_new(GaimType type, ...); | |
141 | |
142 /** | |
10477 | 143 * Creates a new outgoing GaimValue. If a value is an "outgoing" value |
144 * it means the value can be modified by plugins and scripts. | |
6562 | 145 * |
146 * This function takes a type and, depending on that type, a sub-type | |
147 * or specific type. | |
148 * | |
10477 | 149 * If @a type is GAIM_TYPE_BOXED, the next parameter must be a |
6562 | 150 * string representing the specific type. |
151 * | |
152 * If @a type is GAIM_TYPE_SUBTYPE, the next parameter must be a | |
153 * integer or enum representing the sub-type. | |
154 * | |
155 * If the sub-type or specific type is not set when required, random | |
156 * errors may occur. You have been warned. | |
157 * | |
158 * @param type The type. | |
159 * | |
160 * @return The new value. | |
161 */ | |
162 GaimValue *gaim_value_new_outgoing(GaimType type, ...); | |
163 | |
164 /** | |
165 * Destroys a GaimValue. | |
166 * | |
167 * @param value The value to destroy. | |
168 */ | |
169 void gaim_value_destroy(GaimValue *value); | |
170 | |
171 /** | |
8809
fde4101fa183
[gaim-migrate @ 9571]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
172 * Duplicated a GaimValue. |
fde4101fa183
[gaim-migrate @ 9571]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
173 * |
fde4101fa183
[gaim-migrate @ 9571]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
174 * @param value The value to duplicate. |
fde4101fa183
[gaim-migrate @ 9571]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
175 * |
fde4101fa183
[gaim-migrate @ 9571]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
176 * @return The duplicate value. |
fde4101fa183
[gaim-migrate @ 9571]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
177 */ |
fde4101fa183
[gaim-migrate @ 9571]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
178 GaimValue *gaim_value_dup(const GaimValue *value); |
fde4101fa183
[gaim-migrate @ 9571]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
179 |
fde4101fa183
[gaim-migrate @ 9571]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
180 /** |
6562 | 181 * Returns a value's type. |
182 * | |
10071 | 183 * @param value The value whose type you want. |
184 * | |
6562 | 185 * @return The value's type. |
186 */ | |
187 GaimType gaim_value_get_type(const GaimValue *value); | |
188 | |
189 /** | |
190 * Returns a value's subtype. | |
191 * | |
192 * If the value's type is not GAIM_TYPE_SUBTYPE, this will return 0. | |
193 * Subtypes should never have a subtype of 0. | |
194 * | |
10071 | 195 * @param value The value whose subtype you want. |
196 * | |
6562 | 197 * @return The value's subtype, or 0 if @a type is not GAIM_TYPE_SUBTYPE. |
198 */ | |
199 unsigned int gaim_value_get_subtype(const GaimValue *value); | |
200 | |
201 /** | |
202 * Returns a value's specific type. | |
203 * | |
204 * If the value's type is not GAIM_TYPE_BOXED, this will return @c NULL. | |
205 * | |
10071 | 206 * @param value The value whose specific type you want. |
207 * | |
6562 | 208 * @return The value's specific type, or @a NULL if not GAIM_TYPE_BOXED. |
209 */ | |
210 const char *gaim_value_get_specific_type(const GaimValue *value); | |
211 | |
212 /** | |
213 * Returns whether or not the value is an outgoing value. | |
214 * | |
215 * @param value The value. | |
216 * | |
217 * @return TRUE if the value is outgoing, or FALSE otherwise. | |
218 */ | |
219 gboolean gaim_value_is_outgoing(const GaimValue *value); | |
220 | |
221 /** | |
222 * Sets the value's character data. | |
223 * | |
224 * @param value The value. | |
225 * @param data The character data. | |
226 */ | |
227 void gaim_value_set_char(GaimValue *value, char data); | |
228 | |
229 /** | |
230 * Sets the value's unsigned character data. | |
231 * | |
232 * @param value The value. | |
233 * @param data The unsigned character data. | |
234 */ | |
235 void gaim_value_set_uchar(GaimValue *value, unsigned char data); | |
236 | |
237 /** | |
238 * Sets the value's boolean data. | |
239 * | |
240 * @param value The value. | |
241 * @param data The boolean data. | |
242 */ | |
243 void gaim_value_set_boolean(GaimValue *value, gboolean data); | |
244 | |
245 /** | |
246 * Sets the value's short integer data. | |
247 * | |
248 * @param value The value. | |
249 * @param data The short integer data. | |
250 */ | |
251 void gaim_value_set_short(GaimValue *value, short data); | |
252 | |
253 /** | |
254 * Sets the value's unsigned short integer data. | |
255 * | |
256 * @param value The value. | |
257 * @param data The unsigned short integer data. | |
258 */ | |
259 void gaim_value_set_ushort(GaimValue *value, unsigned short data); | |
260 | |
261 /** | |
262 * Sets the value's integer data. | |
263 * | |
264 * @param value The value. | |
265 * @param data The integer data. | |
266 */ | |
267 void gaim_value_set_int(GaimValue *value, int data); | |
268 | |
269 /** | |
270 * Sets the value's unsigned integer data. | |
271 * | |
272 * @param value The value. | |
273 * @param data The unsigned integer data. | |
274 */ | |
275 void gaim_value_set_uint(GaimValue *value, unsigned int data); | |
276 | |
277 /** | |
278 * Sets the value's long integer data. | |
279 * | |
280 * @param value The value. | |
281 * @param data The long integer data. | |
282 */ | |
283 void gaim_value_set_long(GaimValue *value, long data); | |
284 | |
285 /** | |
286 * Sets the value's unsigned long integer data. | |
287 * | |
288 * @param value The value. | |
289 * @param data The unsigned long integer data. | |
290 */ | |
291 void gaim_value_set_ulong(GaimValue *value, unsigned long data); | |
292 | |
293 /** | |
294 * Sets the value's 64-bit integer data. | |
295 * | |
296 * @param value The value. | |
297 * @param data The 64-bit integer data. | |
298 */ | |
299 void gaim_value_set_int64(GaimValue *value, gint64 data); | |
300 | |
301 /** | |
302 * Sets the value's unsigned 64-bit integer data. | |
303 * | |
304 * @param value The value. | |
305 * @param data The unsigned 64-bit integer data. | |
306 */ | |
307 void gaim_value_set_uint64(GaimValue *value, guint64 data); | |
308 | |
309 /** | |
310 * Sets the value's string data. | |
311 * | |
312 * @param value The value. | |
313 * @param data The string data. | |
314 */ | |
315 void gaim_value_set_string(GaimValue *value, const char *data); | |
316 | |
317 /** | |
318 * Sets the value's object data. | |
319 * | |
320 * @param value The value. | |
321 * @param data The object data. | |
322 */ | |
323 void gaim_value_set_object(GaimValue *value, void *data); | |
324 | |
325 /** | |
326 * Sets the value's pointer data. | |
327 * | |
328 * @param value The value. | |
329 * @param data The pointer data. | |
330 */ | |
331 void gaim_value_set_pointer(GaimValue *value, void *data); | |
332 | |
333 /** | |
334 * Sets the value's enum data. | |
335 * | |
336 * @param value The value. | |
337 * @param data The enum data. | |
338 */ | |
339 void gaim_value_set_enum(GaimValue *value, int data); | |
340 | |
341 /** | |
342 * Sets the value's boxed data. | |
343 * | |
344 * @param value The value. | |
345 * @param data The boxed data. | |
346 */ | |
347 void gaim_value_set_boxed(GaimValue *value, void *data); | |
348 | |
349 /** | |
350 * Returns the value's character data. | |
351 * | |
352 * @param value The value. | |
353 * | |
354 * @return The character data. | |
355 */ | |
356 char gaim_value_get_char(const GaimValue *value); | |
357 | |
358 /** | |
359 * Returns the value's unsigned character data. | |
360 * | |
361 * @param value The value. | |
362 * | |
363 * @return The unsigned character data. | |
364 */ | |
365 unsigned char gaim_value_get_uchar(const GaimValue *value); | |
366 | |
367 /** | |
368 * Returns the value's boolean data. | |
369 * | |
370 * @param value The value. | |
371 * | |
372 * @return The boolean data. | |
373 */ | |
374 gboolean gaim_value_get_boolean(const GaimValue *value); | |
375 | |
376 /** | |
377 * Returns the value's short integer data. | |
378 * | |
379 * @param value The value. | |
380 * | |
381 * @return The short integer data. | |
382 */ | |
383 short gaim_value_get_short(const GaimValue *value); | |
384 | |
385 /** | |
386 * Returns the value's unsigned short integer data. | |
387 * | |
388 * @param value The value. | |
389 * | |
390 * @return The unsigned short integer data. | |
391 */ | |
392 unsigned short gaim_value_get_ushort(const GaimValue *value); | |
393 | |
394 /** | |
395 * Returns the value's integer data. | |
396 * | |
397 * @param value The value. | |
398 * | |
399 * @return The integer data. | |
400 */ | |
401 int gaim_value_get_int(const GaimValue *value); | |
402 | |
403 /** | |
404 * Returns the value's unsigned integer data. | |
405 * | |
406 * @param value The value. | |
407 * | |
408 * @return The unsigned integer data. | |
409 */ | |
410 unsigned int gaim_value_get_uint(const GaimValue *value); | |
411 | |
412 /** | |
413 * Returns the value's long integer data. | |
414 * | |
415 * @param value The value. | |
416 * | |
417 * @return The long integer data. | |
418 */ | |
419 long gaim_value_get_long(const GaimValue *value); | |
420 | |
421 /** | |
422 * Returns the value's unsigned long integer data. | |
423 * | |
424 * @param value The value. | |
425 * | |
426 * @return The unsigned long integer data. | |
427 */ | |
428 unsigned long gaim_value_get_ulong(const GaimValue *value); | |
429 | |
430 /** | |
431 * Returns the value's 64-bit integer data. | |
432 * | |
433 * @param value The value. | |
434 * | |
435 * @return The 64-bit integer data. | |
436 */ | |
437 gint64 gaim_value_get_int64(const GaimValue *value); | |
438 | |
439 /** | |
440 * Returns the value's unsigned 64-bit integer data. | |
441 * | |
442 * @param value The value. | |
443 * | |
444 * @return The unsigned 64-bit integer data. | |
445 */ | |
446 guint64 gaim_value_get_uint64(const GaimValue *value); | |
447 | |
448 /** | |
449 * Returns the value's string data. | |
450 * | |
451 * @param value The value. | |
452 * | |
453 * @return The string data. | |
454 */ | |
455 const char *gaim_value_get_string(const GaimValue *value); | |
456 | |
457 /** | |
458 * Returns the value's object data. | |
459 * | |
460 * @param value The value. | |
461 * | |
462 * @return The object data. | |
463 */ | |
464 void *gaim_value_get_object(const GaimValue *value); | |
465 | |
466 /** | |
467 * Returns the value's pointer data. | |
468 * | |
469 * @param value The value. | |
470 * | |
471 * @return The pointer data. | |
472 */ | |
473 void *gaim_value_get_pointer(const GaimValue *value); | |
474 | |
475 /** | |
476 * Returns the value's enum data. | |
477 * | |
478 * @param value The value. | |
479 * | |
480 * @return The enum data. | |
481 */ | |
482 int gaim_value_get_enum(const GaimValue *value); | |
483 | |
484 /** | |
485 * Returns the value's boxed data. | |
486 * | |
487 * @param value The value. | |
488 * | |
489 * @return The boxed data. | |
490 */ | |
491 void *gaim_value_get_boxed(const GaimValue *value); | |
492 | |
6563
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
493 #ifdef __cplusplus |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
494 } |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
495 #endif |
122cb375be2d
[gaim-migrate @ 7085]
Christian Hammond <chipx86@chipx86.com>
parents:
6562
diff
changeset
|
496 |
6562 | 497 #endif /* _GAIM_VALUE_H_ */ |