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 #ifndef __G_VARIANT_TYPE_H__
24 #define __G_VARIANT_TYPE_H__
26 #include <glib/gmessages.h>
27 #include <glib/gtypes.h>
34 * A type in the GVariant type system.
36 * Two types may not be compared by value; use g_variant_type_equal() or
37 * g_variant_type_is_subtype(). May be copied using
38 * g_variant_type_copy() and freed using g_variant_type_free().
40 typedef struct _GVariantType GVariantType;
43 * G_VARIANT_TYPE_BOOLEAN:
45 * The type of a value that can be either %TRUE or %FALSE.
47 #define G_VARIANT_TYPE_BOOLEAN ((const GVariantType *) "b")
50 * G_VARIANT_TYPE_BYTE:
52 * The type of an integer value that can range from 0 to 255.
54 #define G_VARIANT_TYPE_BYTE ((const GVariantType *) "y")
57 * G_VARIANT_TYPE_INT16:
59 * The type of an integer value that can range from -32768 to 32767.
61 #define G_VARIANT_TYPE_INT16 ((const GVariantType *) "n")
64 * G_VARIANT_TYPE_UINT16:
66 * The type of an integer value that can range from 0 to 65535.
67 * There were about this many people living in Toronto in the 1870s.
69 #define G_VARIANT_TYPE_UINT16 ((const GVariantType *) "q")
72 * G_VARIANT_TYPE_INT32:
74 * The type of an integer value that can range from -2147483648 to
77 #define G_VARIANT_TYPE_INT32 ((const GVariantType *) "i")
80 * G_VARIANT_TYPE_UINT32:
82 * The type of an integer value that can range from 0 to 4294967295.
83 * That's one number for everyone who was around in the late 1970s.
85 #define G_VARIANT_TYPE_UINT32 ((const GVariantType *) "u")
88 * G_VARIANT_TYPE_INT64:
90 * The type of an integer value that can range from
91 * -9223372036854775808 to 9223372036854775807.
93 #define G_VARIANT_TYPE_INT64 ((const GVariantType *) "x")
96 * G_VARIANT_TYPE_UINT64:
98 * The type of an integer value that can range from 0 to
99 * 18446744073709551616. That's a really big number, but a Rubik's
100 * cube can have a bit more than twice as many possible positions.
102 #define G_VARIANT_TYPE_UINT64 ((const GVariantType *) "t")
105 * G_VARIANT_TYPE_DOUBLE:
107 * The type of a double precision IEEE754 floating point number.
108 * These guys go up to about 1.80e308 (plus and minus) but miss out on
109 * some numbers in between. In any case, that's far greater than the
110 * estimated number of fundamental particles in the observable
113 #define G_VARIANT_TYPE_DOUBLE ((const GVariantType *) "d")
116 * G_VARIANT_TYPE_STRING:
118 * The type of a string. "" is a string. %NULL is not a string.
120 #define G_VARIANT_TYPE_STRING ((const GVariantType *) "s")
123 * G_VARIANT_TYPE_OBJECT_PATH:
125 * The type of a DBus object reference. These are strings of a
126 * specific format used to identify objects at a given destination on
129 * If you are not interacting with DBus, then there is no reason to make
130 * use of this type. If you are, then the DBus specification contains a
131 * precise description of valid object paths.
133 #define G_VARIANT_TYPE_OBJECT_PATH ((const GVariantType *) "o")
136 * G_VARIANT_TYPE_SIGNATURE:
138 * The type of a DBus type signature. These are strings of a specific
139 * format used as type signatures for DBus methods and messages.
141 * If you are not interacting with DBus, then there is no reason to make
142 * use of this type. If you are, then the DBus specification contains a
143 * precise description of valid signature strings.
145 #define G_VARIANT_TYPE_SIGNATURE ((const GVariantType *) "g")
148 * G_VARIANT_TYPE_VARIANT:
150 * The type of a box that contains any other value (including another
153 #define G_VARIANT_TYPE_VARIANT ((const GVariantType *) "v")
156 * G_VARIANT_TYPE_HANDLE:
158 * The type of a 32bit signed integer value, that by convention, is used
159 * as an index into an array of file descriptors that are sent alongside
162 * If you are not interacting with DBus, then there is no reason to make
165 #define G_VARIANT_TYPE_HANDLE ((const GVariantType *) "h")
168 * G_VARIANT_TYPE_UNIT:
170 * The empty tuple type. Has only one instance. Known also as "triv"
173 #define G_VARIANT_TYPE_UNIT ((const GVariantType *) "()")
176 * G_VARIANT_TYPE_ANY:
178 * An indefinite type that is a supertype of every type (including
181 #define G_VARIANT_TYPE_ANY ((const GVariantType *) "*")
184 * G_VARIANT_TYPE_BASIC:
186 * An indefinite type that is a supertype of every basic (ie:
187 * non-container) type.
189 #define G_VARIANT_TYPE_BASIC ((const GVariantType *) "?")
192 * G_VARIANT_TYPE_MAYBE:
194 * An indefinite type that is a supertype of every maybe type.
196 #define G_VARIANT_TYPE_MAYBE ((const GVariantType *) "m*")
199 * G_VARIANT_TYPE_ARRAY:
201 * An indefinite type that is a supertype of every array type.
203 #define G_VARIANT_TYPE_ARRAY ((const GVariantType *) "a*")
206 * G_VARIANT_TYPE_TUPLE:
208 * An indefinite type that is a supertype of every tuple type,
209 * regardless of the number of items in the tuple.
211 #define G_VARIANT_TYPE_TUPLE ((const GVariantType *) "r")
214 * G_VARIANT_TYPE_DICT_ENTRY:
216 * An indefinite type that is a supertype of every dictionary entry
219 #define G_VARIANT_TYPE_DICT_ENTRY ((const GVariantType *) "{?*}")
222 * G_VARIANT_TYPE_DICTIONARY:
224 * An indefinite type that is a supertype of every dictionary type --
225 * that is, any array type that has an element type equal to any
226 * dictionary entry type.
228 #define G_VARIANT_TYPE_DICTIONARY ((const GVariantType *) "a{?*}")
232 * @type_string: a well-formed #GVariantType type string
234 * Converts a string to a const #GVariantType. Depending on the
235 * current debugging level, this function may perform a runtime check
236 * to ensure that @string is a valid GVariant type string.
238 * It is always a programmer error to use this macro with an invalid
243 #ifndef G_DISABLE_CHECKS
244 # define G_VARIANT_TYPE(type_string) (g_variant_type_checked_ ((type_string)))
246 # define G_VARIANT_TYPE(type_string) ((const GVariantType *) (type_string))
249 /* type string checking */
250 gboolean g_variant_type_string_is_valid (const gchar *type_string);
251 gboolean g_variant_type_string_scan (const gchar *string,
253 const gchar **endptr);
256 void g_variant_type_free (GVariantType *type);
257 GVariantType * g_variant_type_copy (const GVariantType *type);
258 GVariantType * g_variant_type_new (const gchar *type_string);
261 gsize g_variant_type_get_string_length (const GVariantType *type);
262 const gchar * g_variant_type_peek_string (const GVariantType *type);
263 gchar * g_variant_type_dup_string (const GVariantType *type);
266 gboolean g_variant_type_is_definite (const GVariantType *type);
267 gboolean g_variant_type_is_container (const GVariantType *type);
268 gboolean g_variant_type_is_basic (const GVariantType *type);
269 gboolean g_variant_type_is_maybe (const GVariantType *type);
270 gboolean g_variant_type_is_array (const GVariantType *type);
271 gboolean g_variant_type_is_tuple (const GVariantType *type);
272 gboolean g_variant_type_is_dict_entry (const GVariantType *type);
273 gboolean g_variant_type_is_variant (const GVariantType *type);
275 /* for hash tables */
276 guint g_variant_type_hash (gconstpointer type);
277 gboolean g_variant_type_equal (gconstpointer type1,
278 gconstpointer type2);
281 gboolean g_variant_type_is_subtype_of (const GVariantType *type,
282 const GVariantType *supertype);
284 /* type iterator interface */
285 const GVariantType * g_variant_type_element (const GVariantType *type);
286 const GVariantType * g_variant_type_first (const GVariantType *type);
287 const GVariantType * g_variant_type_next (const GVariantType *type);
288 gsize g_variant_type_n_items (const GVariantType *type);
289 const GVariantType * g_variant_type_key (const GVariantType *type);
290 const GVariantType * g_variant_type_value (const GVariantType *type);
293 GVariantType * g_variant_type_new_array (const GVariantType *element);
294 GVariantType * g_variant_type_new_maybe (const GVariantType *element);
295 GVariantType * g_variant_type_new_tuple (const GVariantType * const *items,
297 GVariantType * g_variant_type_new_dict_entry (const GVariantType *key,
298 const GVariantType *value);
301 const GVariantType * g_variant_type_checked_ (const gchar *);
305 #endif /* __G_VARIANT_TYPE_H__ */