Remove redundant header inclusions
[glib.git] / glib / gvarianttype.h
blob124fa46b59f7db8f5156da70b663573185e826fb
1 /*
2 * Copyright © 2007, 2008 Ryan Lortie
3 * Copyright © 2009, 2010 Codethink Limited
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the licence, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Ryan Lortie <desrt@desrt.ca>
23 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
24 #error "Only <glib.h> can be included directly."
25 #endif
27 #ifndef __G_VARIANT_TYPE_H__
28 #define __G_VARIANT_TYPE_H__
30 #include <glib/gmessages.h>
31 #include <glib/gtypes.h>
33 G_BEGIN_DECLS
35 /**
36 * GVariantType:
38 * A type in the GVariant type system.
40 * Two types may not be compared by value; use g_variant_type_equal() or
41 * g_variant_type_is_subtype(). May be copied using
42 * g_variant_type_copy() and freed using g_variant_type_free().
43 **/
44 typedef struct _GVariantType GVariantType;
46 /**
47 * G_VARIANT_TYPE_BOOLEAN:
49 * The type of a value that can be either %TRUE or %FALSE.
50 **/
51 #define G_VARIANT_TYPE_BOOLEAN ((const GVariantType *) "b")
53 /**
54 * G_VARIANT_TYPE_BYTE:
56 * The type of an integer value that can range from 0 to 255.
57 **/
58 #define G_VARIANT_TYPE_BYTE ((const GVariantType *) "y")
60 /**
61 * G_VARIANT_TYPE_INT16:
63 * The type of an integer value that can range from -32768 to 32767.
64 **/
65 #define G_VARIANT_TYPE_INT16 ((const GVariantType *) "n")
67 /**
68 * G_VARIANT_TYPE_UINT16:
70 * The type of an integer value that can range from 0 to 65535.
71 * There were about this many people living in Toronto in the 1870s.
72 **/
73 #define G_VARIANT_TYPE_UINT16 ((const GVariantType *) "q")
75 /**
76 * G_VARIANT_TYPE_INT32:
78 * The type of an integer value that can range from -2147483648 to
79 * 2147483647.
80 **/
81 #define G_VARIANT_TYPE_INT32 ((const GVariantType *) "i")
83 /**
84 * G_VARIANT_TYPE_UINT32:
86 * The type of an integer value that can range from 0 to 4294967295.
87 * That's one number for everyone who was around in the late 1970s.
88 **/
89 #define G_VARIANT_TYPE_UINT32 ((const GVariantType *) "u")
91 /**
92 * G_VARIANT_TYPE_INT64:
94 * The type of an integer value that can range from
95 * -9223372036854775808 to 9223372036854775807.
96 **/
97 #define G_VARIANT_TYPE_INT64 ((const GVariantType *) "x")
99 /**
100 * G_VARIANT_TYPE_UINT64:
102 * The type of an integer value that can range from 0 to
103 * 18446744073709551616. That's a really big number, but a Rubik's
104 * cube can have a bit more than twice as many possible positions.
106 #define G_VARIANT_TYPE_UINT64 ((const GVariantType *) "t")
109 * G_VARIANT_TYPE_DOUBLE:
111 * The type of a double precision IEEE754 floating point number.
112 * These guys go up to about 1.80e308 (plus and minus) but miss out on
113 * some numbers in between. In any case, that's far greater than the
114 * estimated number of fundamental particles in the observable
115 * universe.
117 #define G_VARIANT_TYPE_DOUBLE ((const GVariantType *) "d")
120 * G_VARIANT_TYPE_STRING:
122 * The type of a string. "" is a string. %NULL is not a string.
124 #define G_VARIANT_TYPE_STRING ((const GVariantType *) "s")
127 * G_VARIANT_TYPE_OBJECT_PATH:
129 * The type of a DBus object reference. These are strings of a
130 * specific format used to identify objects at a given destination on
131 * the bus.
133 * If you are not interacting with DBus, then there is no reason to make
134 * use of this type. If you are, then the DBus specification contains a
135 * precise description of valid object paths.
137 #define G_VARIANT_TYPE_OBJECT_PATH ((const GVariantType *) "o")
140 * G_VARIANT_TYPE_SIGNATURE:
142 * The type of a DBus type signature. These are strings of a specific
143 * format used as type signatures for DBus methods and messages.
145 * If you are not interacting with DBus, then there is no reason to make
146 * use of this type. If you are, then the DBus specification contains a
147 * precise description of valid signature strings.
149 #define G_VARIANT_TYPE_SIGNATURE ((const GVariantType *) "g")
152 * G_VARIANT_TYPE_VARIANT:
154 * The type of a box that contains any other value (including another
155 * variant).
157 #define G_VARIANT_TYPE_VARIANT ((const GVariantType *) "v")
160 * G_VARIANT_TYPE_HANDLE:
162 * The type of a 32bit signed integer value, that by convention, is used
163 * as an index into an array of file descriptors that are sent alongside
164 * a DBus message.
166 * If you are not interacting with DBus, then there is no reason to make
167 * use of this type.
169 #define G_VARIANT_TYPE_HANDLE ((const GVariantType *) "h")
172 * G_VARIANT_TYPE_UNIT:
174 * The empty tuple type. Has only one instance. Known also as "triv"
175 * or "void".
177 #define G_VARIANT_TYPE_UNIT ((const GVariantType *) "()")
180 * G_VARIANT_TYPE_ANY:
182 * An indefinite type that is a supertype of every type (including
183 * itself).
185 #define G_VARIANT_TYPE_ANY ((const GVariantType *) "*")
188 * G_VARIANT_TYPE_BASIC:
190 * An indefinite type that is a supertype of every basic (ie:
191 * non-container) type.
193 #define G_VARIANT_TYPE_BASIC ((const GVariantType *) "?")
196 * G_VARIANT_TYPE_MAYBE:
198 * An indefinite type that is a supertype of every maybe type.
200 #define G_VARIANT_TYPE_MAYBE ((const GVariantType *) "m*")
203 * G_VARIANT_TYPE_ARRAY:
205 * An indefinite type that is a supertype of every array type.
207 #define G_VARIANT_TYPE_ARRAY ((const GVariantType *) "a*")
210 * G_VARIANT_TYPE_TUPLE:
212 * An indefinite type that is a supertype of every tuple type,
213 * regardless of the number of items in the tuple.
215 #define G_VARIANT_TYPE_TUPLE ((const GVariantType *) "r")
218 * G_VARIANT_TYPE_DICT_ENTRY:
220 * An indefinite type that is a supertype of every dictionary entry
221 * type.
223 #define G_VARIANT_TYPE_DICT_ENTRY ((const GVariantType *) "{?*}")
226 * G_VARIANT_TYPE_DICTIONARY:
228 * An indefinite type that is a supertype of every dictionary type --
229 * that is, any array type that has an element type equal to any
230 * dictionary entry type.
232 #define G_VARIANT_TYPE_DICTIONARY ((const GVariantType *) "a{?*}")
235 * G_VARIANT_TYPE_STRING_ARRAY:
237 * The type of an array of strings.
239 #define G_VARIANT_TYPE_STRING_ARRAY ((const GVariantType *) "as")
242 * G_VARIANT_TYPE_BYTESTRING:
244 * The type of an array of bytes. This type is commonly used to pass
245 * around strings that may not be valid utf8. In that case, the
246 * convention is that the nul terminator character should be included as
247 * the last character in the array.
249 #define G_VARIANT_TYPE_BYTESTRING ((const GVariantType *) "ay")
252 * G_VARIANT_TYPE_BYTESTRING_ARRAY:
254 * The type of an array of byte strings (an array of arrays of bytes).
256 #define G_VARIANT_TYPE_BYTESTRING_ARRAY ((const GVariantType *) "aay")
260 * G_VARIANT_TYPE:
261 * @type_string: a well-formed #GVariantType type string
263 * Converts a string to a const #GVariantType. Depending on the
264 * current debugging level, this function may perform a runtime check
265 * to ensure that @string is a valid GVariant type string.
267 * It is always a programmer error to use this macro with an invalid
268 * type string.
270 * Since 2.24
272 #ifndef G_DISABLE_CHECKS
273 # define G_VARIANT_TYPE(type_string) (g_variant_type_checked_ ((type_string)))
274 #else
275 # define G_VARIANT_TYPE(type_string) ((const GVariantType *) (type_string))
276 #endif
278 /* type string checking */
279 gboolean g_variant_type_string_is_valid (const gchar *type_string);
280 gboolean g_variant_type_string_scan (const gchar *string,
281 const gchar *limit,
282 const gchar **endptr);
284 /* create/destroy */
285 void g_variant_type_free (GVariantType *type);
286 GVariantType * g_variant_type_copy (const GVariantType *type);
287 GVariantType * g_variant_type_new (const gchar *type_string);
289 /* getters */
290 gsize g_variant_type_get_string_length (const GVariantType *type);
291 const gchar * g_variant_type_peek_string (const GVariantType *type);
292 gchar * g_variant_type_dup_string (const GVariantType *type);
294 /* classification */
295 gboolean g_variant_type_is_definite (const GVariantType *type);
296 gboolean g_variant_type_is_container (const GVariantType *type);
297 gboolean g_variant_type_is_basic (const GVariantType *type);
298 gboolean g_variant_type_is_maybe (const GVariantType *type);
299 gboolean g_variant_type_is_array (const GVariantType *type);
300 gboolean g_variant_type_is_tuple (const GVariantType *type);
301 gboolean g_variant_type_is_dict_entry (const GVariantType *type);
302 gboolean g_variant_type_is_variant (const GVariantType *type);
304 /* for hash tables */
305 guint g_variant_type_hash (gconstpointer type);
306 gboolean g_variant_type_equal (gconstpointer type1,
307 gconstpointer type2);
309 /* subtypes */
310 gboolean g_variant_type_is_subtype_of (const GVariantType *type,
311 const GVariantType *supertype);
313 /* type iterator interface */
314 const GVariantType * g_variant_type_element (const GVariantType *type);
315 const GVariantType * g_variant_type_first (const GVariantType *type);
316 const GVariantType * g_variant_type_next (const GVariantType *type);
317 gsize g_variant_type_n_items (const GVariantType *type);
318 const GVariantType * g_variant_type_key (const GVariantType *type);
319 const GVariantType * g_variant_type_value (const GVariantType *type);
321 /* constructors */
322 GVariantType * g_variant_type_new_array (const GVariantType *element);
323 GVariantType * g_variant_type_new_maybe (const GVariantType *element);
324 GVariantType * g_variant_type_new_tuple (const GVariantType * const *items,
325 gint length);
326 GVariantType * g_variant_type_new_dict_entry (const GVariantType *key,
327 const GVariantType *value);
329 /*< private >*/
330 const GVariantType * g_variant_type_checked_ (const gchar *);
332 G_END_DECLS
334 #endif /* __G_VARIANT_TYPE_H__ */