Remove useless comparison
[pidgin-git.git] / libpurple / value.h
blob155c0146b4ac9c1def0d834dc93dce779f5c925e
1 /**
2 * @file value.h Value wrapper API
3 * @ingroup core
4 */
6 /* purple
8 * Purple is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 #ifndef _PURPLE_VALUE_H_
27 #define _PURPLE_VALUE_H_
29 #include <glib.h>
31 /**
32 * Specific value types.
34 typedef enum
36 PURPLE_TYPE_UNKNOWN = 0, /**< Unknown type. */
37 PURPLE_TYPE_SUBTYPE, /**< Subtype. */
38 PURPLE_TYPE_CHAR, /**< Character. */
39 PURPLE_TYPE_UCHAR, /**< Unsigned character. */
40 PURPLE_TYPE_BOOLEAN, /**< Boolean. */
41 PURPLE_TYPE_SHORT, /**< Short integer. */
42 PURPLE_TYPE_USHORT, /**< Unsigned short integer. */
43 PURPLE_TYPE_INT, /**< Integer. */
44 PURPLE_TYPE_UINT, /**< Unsigned integer. */
45 PURPLE_TYPE_LONG, /**< Long integer. */
46 PURPLE_TYPE_ULONG, /**< Unsigned long integer. */
47 PURPLE_TYPE_INT64, /**< 64-bit integer. */
48 PURPLE_TYPE_UINT64, /**< 64-bit unsigned integer. */
49 PURPLE_TYPE_STRING, /**< String. */
50 PURPLE_TYPE_OBJECT, /**< Object pointer. */
51 PURPLE_TYPE_POINTER, /**< Generic pointer. */
52 PURPLE_TYPE_ENUM, /**< Enum. */
53 PURPLE_TYPE_BOXED /**< Boxed pointer with specific type. */
55 } PurpleType;
58 /**
59 * Purple-specific subtype values.
61 typedef enum
63 PURPLE_SUBTYPE_UNKNOWN = 0,
64 PURPLE_SUBTYPE_ACCOUNT,
65 PURPLE_SUBTYPE_BLIST,
66 PURPLE_SUBTYPE_BLIST_BUDDY,
67 PURPLE_SUBTYPE_BLIST_GROUP,
68 PURPLE_SUBTYPE_BLIST_CHAT,
69 PURPLE_SUBTYPE_BUDDY_ICON,
70 PURPLE_SUBTYPE_CONNECTION,
71 PURPLE_SUBTYPE_CONVERSATION,
72 PURPLE_SUBTYPE_PLUGIN,
73 PURPLE_SUBTYPE_BLIST_NODE,
74 PURPLE_SUBTYPE_CIPHER,
75 PURPLE_SUBTYPE_STATUS,
76 PURPLE_SUBTYPE_LOG,
77 PURPLE_SUBTYPE_XFER,
78 PURPLE_SUBTYPE_SAVEDSTATUS,
79 PURPLE_SUBTYPE_XMLNODE,
80 PURPLE_SUBTYPE_USERINFO,
81 PURPLE_SUBTYPE_STORED_IMAGE,
82 PURPLE_SUBTYPE_CERTIFICATEPOOL,
83 PURPLE_SUBTYPE_CHATBUDDY
84 } PurpleSubType;
86 /**
87 * A wrapper for a type, subtype, and specific type of value.
89 typedef struct
91 PurpleType type;
92 unsigned short flags;
94 union
96 char char_data;
97 unsigned char uchar_data;
98 gboolean boolean_data;
99 short short_data;
100 unsigned short ushort_data;
101 int int_data;
102 unsigned int uint_data;
103 long long_data;
104 unsigned long ulong_data;
105 gint64 int64_data;
106 guint64 uint64_data;
107 char *string_data;
108 void *object_data;
109 void *pointer_data;
110 int enum_data;
111 void *boxed_data;
113 } data;
115 union
117 unsigned int subtype;
118 char *specific_type;
120 } u;
122 } PurpleValue;
124 #ifdef __cplusplus
125 extern "C" {
126 #endif
129 * Creates a new PurpleValue.
131 * This function takes a type and, depending on that type, a sub-type
132 * or specific type.
134 * If @a type is PURPLE_TYPE_BOXED, the next parameter must be a
135 * string representing the specific type.
137 * If @a type is PURPLE_TYPE_SUBTYPE, the next parameter must be a
138 * integer or enum representing the sub-type.
140 * If the subtype or specific type is not set when required, random
141 * errors may occur. You have been warned.
143 * @param type The type.
145 * @return The new value.
147 PurpleValue *purple_value_new(PurpleType type, ...);
150 * Creates a new outgoing PurpleValue. If a value is an "outgoing" value
151 * it means the value can be modified by plugins and scripts.
153 * This function takes a type and, depending on that type, a sub-type
154 * or specific type.
156 * If @a type is PURPLE_TYPE_BOXED, the next parameter must be a
157 * string representing the specific type.
159 * If @a type is PURPLE_TYPE_SUBTYPE, the next parameter must be a
160 * integer or enum representing the sub-type.
162 * If the sub-type or specific type is not set when required, random
163 * errors may occur. You have been warned.
165 * @param type The type.
167 * @return The new value.
169 PurpleValue *purple_value_new_outgoing(PurpleType type, ...);
172 * Destroys a PurpleValue.
174 * @param value The value to destroy.
176 void purple_value_destroy(PurpleValue *value);
179 * Duplicated a PurpleValue.
181 * @param value The value to duplicate.
183 * @return The duplicate value.
185 PurpleValue *purple_value_dup(const PurpleValue *value);
188 * Returns a value's type.
190 * @param value The value whose type you want.
192 * @return The value's type.
194 PurpleType purple_value_get_type(const PurpleValue *value);
197 * Returns a value's subtype.
199 * If the value's type is not PURPLE_TYPE_SUBTYPE, this will return 0.
200 * Subtypes should never have a subtype of 0.
202 * @param value The value whose subtype you want.
204 * @return The value's subtype, or 0 if @a type is not PURPLE_TYPE_SUBTYPE.
206 unsigned int purple_value_get_subtype(const PurpleValue *value);
209 * Returns a value's specific type.
211 * If the value's type is not PURPLE_TYPE_BOXED, this will return @c NULL.
213 * @param value The value whose specific type you want.
215 * @return The value's specific type, or @a NULL if not PURPLE_TYPE_BOXED.
217 const char *purple_value_get_specific_type(const PurpleValue *value);
220 * Returns whether or not the value is an outgoing value.
222 * @param value The value.
224 * @return TRUE if the value is outgoing, or FALSE otherwise.
226 gboolean purple_value_is_outgoing(const PurpleValue *value);
229 * Sets the value's character data.
231 * @param value The value.
232 * @param data The character data.
234 void purple_value_set_char(PurpleValue *value, char data);
237 * Sets the value's unsigned character data.
239 * @param value The value.
240 * @param data The unsigned character data.
242 void purple_value_set_uchar(PurpleValue *value, unsigned char data);
245 * Sets the value's boolean data.
247 * @param value The value.
248 * @param data The boolean data.
250 void purple_value_set_boolean(PurpleValue *value, gboolean data);
253 * Sets the value's short integer data.
255 * @param value The value.
256 * @param data The short integer data.
258 void purple_value_set_short(PurpleValue *value, short data);
261 * Sets the value's unsigned short integer data.
263 * @param value The value.
264 * @param data The unsigned short integer data.
266 void purple_value_set_ushort(PurpleValue *value, unsigned short data);
269 * Sets the value's integer data.
271 * @param value The value.
272 * @param data The integer data.
274 void purple_value_set_int(PurpleValue *value, int data);
277 * Sets the value's unsigned integer data.
279 * @param value The value.
280 * @param data The unsigned integer data.
282 void purple_value_set_uint(PurpleValue *value, unsigned int data);
285 * Sets the value's long integer data.
287 * @param value The value.
288 * @param data The long integer data.
290 void purple_value_set_long(PurpleValue *value, long data);
293 * Sets the value's unsigned long integer data.
295 * @param value The value.
296 * @param data The unsigned long integer data.
298 void purple_value_set_ulong(PurpleValue *value, unsigned long data);
301 * Sets the value's 64-bit integer data.
303 * @param value The value.
304 * @param data The 64-bit integer data.
306 void purple_value_set_int64(PurpleValue *value, gint64 data);
309 * Sets the value's unsigned 64-bit integer data.
311 * @param value The value.
312 * @param data The unsigned 64-bit integer data.
314 void purple_value_set_uint64(PurpleValue *value, guint64 data);
317 * Sets the value's string data.
319 * @param value The value.
320 * @param data The string data.
322 void purple_value_set_string(PurpleValue *value, const char *data);
325 * Sets the value's object data.
327 * @param value The value.
328 * @param data The object data.
330 void purple_value_set_object(PurpleValue *value, void *data);
333 * Sets the value's pointer data.
335 * @param value The value.
336 * @param data The pointer data.
338 void purple_value_set_pointer(PurpleValue *value, void *data);
341 * Sets the value's enum data.
343 * @param value The value.
344 * @param data The enum data.
346 void purple_value_set_enum(PurpleValue *value, int data);
349 * Sets the value's boxed data.
351 * @param value The value.
352 * @param data The boxed data.
354 void purple_value_set_boxed(PurpleValue *value, void *data);
357 * Returns the value's character data.
359 * @param value The value.
361 * @return The character data.
363 char purple_value_get_char(const PurpleValue *value);
366 * Returns the value's unsigned character data.
368 * @param value The value.
370 * @return The unsigned character data.
372 unsigned char purple_value_get_uchar(const PurpleValue *value);
375 * Returns the value's boolean data.
377 * @param value The value.
379 * @return The boolean data.
381 gboolean purple_value_get_boolean(const PurpleValue *value);
384 * Returns the value's short integer data.
386 * @param value The value.
388 * @return The short integer data.
390 short purple_value_get_short(const PurpleValue *value);
393 * Returns the value's unsigned short integer data.
395 * @param value The value.
397 * @return The unsigned short integer data.
399 unsigned short purple_value_get_ushort(const PurpleValue *value);
402 * Returns the value's integer data.
404 * @param value The value.
406 * @return The integer data.
408 int purple_value_get_int(const PurpleValue *value);
411 * Returns the value's unsigned integer data.
413 * @param value The value.
415 * @return The unsigned integer data.
417 unsigned int purple_value_get_uint(const PurpleValue *value);
420 * Returns the value's long integer data.
422 * @param value The value.
424 * @return The long integer data.
426 long purple_value_get_long(const PurpleValue *value);
429 * Returns the value's unsigned long integer data.
431 * @param value The value.
433 * @return The unsigned long integer data.
435 unsigned long purple_value_get_ulong(const PurpleValue *value);
438 * Returns the value's 64-bit integer data.
440 * @param value The value.
442 * @return The 64-bit integer data.
444 gint64 purple_value_get_int64(const PurpleValue *value);
447 * Returns the value's unsigned 64-bit integer data.
449 * @param value The value.
451 * @return The unsigned 64-bit integer data.
453 guint64 purple_value_get_uint64(const PurpleValue *value);
456 * Returns the value's string data.
458 * @param value The value.
460 * @return The string data.
462 const char *purple_value_get_string(const PurpleValue *value);
465 * Returns the value's object data.
467 * @param value The value.
469 * @return The object data.
471 void *purple_value_get_object(const PurpleValue *value);
474 * Returns the value's pointer data.
476 * @param value The value.
478 * @return The pointer data.
480 void *purple_value_get_pointer(const PurpleValue *value);
483 * Returns the value's enum data.
485 * @param value The value.
487 * @return The enum data.
489 int purple_value_get_enum(const PurpleValue *value);
492 * Returns the value's boxed data.
494 * @param value The value.
496 * @return The boxed data.
498 void *purple_value_get_boxed(const PurpleValue *value);
500 #ifdef __cplusplus
502 #endif
504 #endif /* _PURPLE_VALUE_H_ */