gvarianttype.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*
  2. * Copyright © 2007, 2008 Ryan Lortie
  3. * Copyright © 2009, 2010 Codethink Limited
  4. *
  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.
  9. *
  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.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * Author: Ryan Lortie <[email protected]>
  19. */
  20. #ifndef __G_VARIANT_TYPE_H__
  21. #define __G_VARIANT_TYPE_H__
  22. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  23. #error "Only <glib.h> can be included directly."
  24. #endif
  25. #include <glib/gmessages.h>
  26. #include <glib/gtypes.h>
  27. G_BEGIN_DECLS
  28. /**
  29. * GVariantType:
  30. *
  31. * A type in the GVariant type system.
  32. *
  33. * Two types may not be compared by value; use g_variant_type_equal() or
  34. * g_variant_type_is_subtype_of(). May be copied using
  35. * g_variant_type_copy() and freed using g_variant_type_free().
  36. **/
  37. typedef struct _GVariantType GVariantType;
  38. /**
  39. * G_VARIANT_TYPE_BOOLEAN:
  40. *
  41. * The type of a value that can be either %TRUE or %FALSE.
  42. **/
  43. #define G_VARIANT_TYPE_BOOLEAN ((const GVariantType *) "b")
  44. /**
  45. * G_VARIANT_TYPE_BYTE:
  46. *
  47. * The type of an integer value that can range from 0 to 255.
  48. **/
  49. #define G_VARIANT_TYPE_BYTE ((const GVariantType *) "y")
  50. /**
  51. * G_VARIANT_TYPE_INT16:
  52. *
  53. * The type of an integer value that can range from -32768 to 32767.
  54. **/
  55. #define G_VARIANT_TYPE_INT16 ((const GVariantType *) "n")
  56. /**
  57. * G_VARIANT_TYPE_UINT16:
  58. *
  59. * The type of an integer value that can range from 0 to 65535.
  60. * There were about this many people living in Toronto in the 1870s.
  61. **/
  62. #define G_VARIANT_TYPE_UINT16 ((const GVariantType *) "q")
  63. /**
  64. * G_VARIANT_TYPE_INT32:
  65. *
  66. * The type of an integer value that can range from -2147483648 to
  67. * 2147483647.
  68. **/
  69. #define G_VARIANT_TYPE_INT32 ((const GVariantType *) "i")
  70. /**
  71. * G_VARIANT_TYPE_UINT32:
  72. *
  73. * The type of an integer value that can range from 0 to 4294967295.
  74. * That's one number for everyone who was around in the late 1970s.
  75. **/
  76. #define G_VARIANT_TYPE_UINT32 ((const GVariantType *) "u")
  77. /**
  78. * G_VARIANT_TYPE_INT64:
  79. *
  80. * The type of an integer value that can range from
  81. * -9223372036854775808 to 9223372036854775807.
  82. **/
  83. #define G_VARIANT_TYPE_INT64 ((const GVariantType *) "x")
  84. /**
  85. * G_VARIANT_TYPE_UINT64:
  86. *
  87. * The type of an integer value that can range from 0 to
  88. * 18446744073709551616. That's a really big number, but a Rubik's
  89. * cube can have a bit more than twice as many possible positions.
  90. **/
  91. #define G_VARIANT_TYPE_UINT64 ((const GVariantType *) "t")
  92. /**
  93. * G_VARIANT_TYPE_DOUBLE:
  94. *
  95. * The type of a double precision IEEE754 floating point number.
  96. * These guys go up to about 1.80e308 (plus and minus) but miss out on
  97. * some numbers in between. In any case, that's far greater than the
  98. * estimated number of fundamental particles in the observable
  99. * universe.
  100. **/
  101. #define G_VARIANT_TYPE_DOUBLE ((const GVariantType *) "d")
  102. /**
  103. * G_VARIANT_TYPE_STRING:
  104. *
  105. * The type of a string. "" is a string. %NULL is not a string.
  106. **/
  107. #define G_VARIANT_TYPE_STRING ((const GVariantType *) "s")
  108. /**
  109. * G_VARIANT_TYPE_OBJECT_PATH:
  110. *
  111. * The type of a D-Bus object reference. These are strings of a
  112. * specific format used to identify objects at a given destination on
  113. * the bus.
  114. *
  115. * If you are not interacting with D-Bus, then there is no reason to make
  116. * use of this type. If you are, then the D-Bus specification contains a
  117. * precise description of valid object paths.
  118. **/
  119. #define G_VARIANT_TYPE_OBJECT_PATH ((const GVariantType *) "o")
  120. /**
  121. * G_VARIANT_TYPE_SIGNATURE:
  122. *
  123. * The type of a D-Bus type signature. These are strings of a specific
  124. * format used as type signatures for D-Bus methods and messages.
  125. *
  126. * If you are not interacting with D-Bus, then there is no reason to make
  127. * use of this type. If you are, then the D-Bus specification contains a
  128. * precise description of valid signature strings.
  129. **/
  130. #define G_VARIANT_TYPE_SIGNATURE ((const GVariantType *) "g")
  131. /**
  132. * G_VARIANT_TYPE_VARIANT:
  133. *
  134. * The type of a box that contains any other value (including another
  135. * variant).
  136. **/
  137. #define G_VARIANT_TYPE_VARIANT ((const GVariantType *) "v")
  138. /**
  139. * G_VARIANT_TYPE_HANDLE:
  140. *
  141. * The type of a 32bit signed integer value, that by convention, is used
  142. * as an index into an array of file descriptors that are sent alongside
  143. * a D-Bus message.
  144. *
  145. * If you are not interacting with D-Bus, then there is no reason to make
  146. * use of this type.
  147. **/
  148. #define G_VARIANT_TYPE_HANDLE ((const GVariantType *) "h")
  149. /**
  150. * G_VARIANT_TYPE_UNIT:
  151. *
  152. * The empty tuple type. Has only one instance. Known also as "triv"
  153. * or "void".
  154. **/
  155. #define G_VARIANT_TYPE_UNIT ((const GVariantType *) "()")
  156. /**
  157. * G_VARIANT_TYPE_ANY:
  158. *
  159. * An indefinite type that is a supertype of every type (including
  160. * itself).
  161. **/
  162. #define G_VARIANT_TYPE_ANY ((const GVariantType *) "*")
  163. /**
  164. * G_VARIANT_TYPE_BASIC:
  165. *
  166. * An indefinite type that is a supertype of every basic (ie:
  167. * non-container) type.
  168. **/
  169. #define G_VARIANT_TYPE_BASIC ((const GVariantType *) "?")
  170. /**
  171. * G_VARIANT_TYPE_MAYBE:
  172. *
  173. * An indefinite type that is a supertype of every maybe type.
  174. **/
  175. #define G_VARIANT_TYPE_MAYBE ((const GVariantType *) "m*")
  176. /**
  177. * G_VARIANT_TYPE_ARRAY:
  178. *
  179. * An indefinite type that is a supertype of every array type.
  180. **/
  181. #define G_VARIANT_TYPE_ARRAY ((const GVariantType *) "a*")
  182. /**
  183. * G_VARIANT_TYPE_TUPLE:
  184. *
  185. * An indefinite type that is a supertype of every tuple type,
  186. * regardless of the number of items in the tuple.
  187. **/
  188. #define G_VARIANT_TYPE_TUPLE ((const GVariantType *) "r")
  189. /**
  190. * G_VARIANT_TYPE_DICT_ENTRY:
  191. *
  192. * An indefinite type that is a supertype of every dictionary entry
  193. * type.
  194. **/
  195. #define G_VARIANT_TYPE_DICT_ENTRY ((const GVariantType *) "{?*}")
  196. /**
  197. * G_VARIANT_TYPE_DICTIONARY:
  198. *
  199. * An indefinite type that is a supertype of every dictionary type --
  200. * that is, any array type that has an element type equal to any
  201. * dictionary entry type.
  202. **/
  203. #define G_VARIANT_TYPE_DICTIONARY ((const GVariantType *) "a{?*}")
  204. /**
  205. * G_VARIANT_TYPE_STRING_ARRAY:
  206. *
  207. * The type of an array of strings.
  208. **/
  209. #define G_VARIANT_TYPE_STRING_ARRAY ((const GVariantType *) "as")
  210. /**
  211. * G_VARIANT_TYPE_OBJECT_PATH_ARRAY:
  212. *
  213. * The type of an array of object paths.
  214. **/
  215. #define G_VARIANT_TYPE_OBJECT_PATH_ARRAY ((const GVariantType *) "ao")
  216. /**
  217. * G_VARIANT_TYPE_BYTESTRING:
  218. *
  219. * The type of an array of bytes. This type is commonly used to pass
  220. * around strings that may not be valid utf8. In that case, the
  221. * convention is that the nul terminator character should be included as
  222. * the last character in the array.
  223. **/
  224. #define G_VARIANT_TYPE_BYTESTRING ((const GVariantType *) "ay")
  225. /**
  226. * G_VARIANT_TYPE_BYTESTRING_ARRAY:
  227. *
  228. * The type of an array of byte strings (an array of arrays of bytes).
  229. **/
  230. #define G_VARIANT_TYPE_BYTESTRING_ARRAY ((const GVariantType *) "aay")
  231. /**
  232. * G_VARIANT_TYPE_VARDICT:
  233. *
  234. * The type of a dictionary mapping strings to variants (the ubiquitous
  235. * "a{sv}" type).
  236. *
  237. * Since: 2.30
  238. **/
  239. #define G_VARIANT_TYPE_VARDICT ((const GVariantType *) "a{sv}")
  240. /**
  241. * G_VARIANT_TYPE:
  242. * @type_string: a well-formed #GVariantType type string
  243. *
  244. * Converts a string to a const #GVariantType. Depending on the
  245. * current debugging level, this function may perform a runtime check
  246. * to ensure that @string is a valid GVariant type string.
  247. *
  248. * It is always a programmer error to use this macro with an invalid
  249. * type string. If in doubt, use g_variant_type_string_is_valid() to
  250. * check if the string is valid.
  251. *
  252. * Since 2.24
  253. **/
  254. #ifndef G_DISABLE_CHECKS
  255. # define G_VARIANT_TYPE(type_string) (g_variant_type_checked_ ((type_string)))
  256. #else
  257. # define G_VARIANT_TYPE(type_string) ((const GVariantType *) (type_string))
  258. #endif
  259. /* type string checking */
  260. GLIB_AVAILABLE_IN_ALL
  261. gboolean g_variant_type_string_is_valid (const gchar *type_string);
  262. GLIB_AVAILABLE_IN_ALL
  263. gboolean g_variant_type_string_scan (const gchar *string,
  264. const gchar *limit,
  265. const gchar **endptr);
  266. /* create/destroy */
  267. GLIB_AVAILABLE_IN_ALL
  268. void g_variant_type_free (GVariantType *type);
  269. GLIB_AVAILABLE_IN_ALL
  270. GVariantType * g_variant_type_copy (const GVariantType *type);
  271. GLIB_AVAILABLE_IN_ALL
  272. GVariantType * g_variant_type_new (const gchar *type_string);
  273. /* getters */
  274. GLIB_AVAILABLE_IN_ALL
  275. gsize g_variant_type_get_string_length (const GVariantType *type);
  276. GLIB_AVAILABLE_IN_ALL
  277. const gchar * g_variant_type_peek_string (const GVariantType *type);
  278. GLIB_AVAILABLE_IN_ALL
  279. gchar * g_variant_type_dup_string (const GVariantType *type);
  280. /* classification */
  281. GLIB_AVAILABLE_IN_ALL
  282. gboolean g_variant_type_is_definite (const GVariantType *type);
  283. GLIB_AVAILABLE_IN_ALL
  284. gboolean g_variant_type_is_container (const GVariantType *type);
  285. GLIB_AVAILABLE_IN_ALL
  286. gboolean g_variant_type_is_basic (const GVariantType *type);
  287. GLIB_AVAILABLE_IN_ALL
  288. gboolean g_variant_type_is_maybe (const GVariantType *type);
  289. GLIB_AVAILABLE_IN_ALL
  290. gboolean g_variant_type_is_array (const GVariantType *type);
  291. GLIB_AVAILABLE_IN_ALL
  292. gboolean g_variant_type_is_tuple (const GVariantType *type);
  293. GLIB_AVAILABLE_IN_ALL
  294. gboolean g_variant_type_is_dict_entry (const GVariantType *type);
  295. GLIB_AVAILABLE_IN_ALL
  296. gboolean g_variant_type_is_variant (const GVariantType *type);
  297. /* for hash tables */
  298. GLIB_AVAILABLE_IN_ALL
  299. guint g_variant_type_hash (gconstpointer type);
  300. GLIB_AVAILABLE_IN_ALL
  301. gboolean g_variant_type_equal (gconstpointer type1,
  302. gconstpointer type2);
  303. /* subtypes */
  304. GLIB_AVAILABLE_IN_ALL
  305. gboolean g_variant_type_is_subtype_of (const GVariantType *type,
  306. const GVariantType *supertype);
  307. /* type iterator interface */
  308. GLIB_AVAILABLE_IN_ALL
  309. const GVariantType * g_variant_type_element (const GVariantType *type);
  310. GLIB_AVAILABLE_IN_ALL
  311. const GVariantType * g_variant_type_first (const GVariantType *type);
  312. GLIB_AVAILABLE_IN_ALL
  313. const GVariantType * g_variant_type_next (const GVariantType *type);
  314. GLIB_AVAILABLE_IN_ALL
  315. gsize g_variant_type_n_items (const GVariantType *type);
  316. GLIB_AVAILABLE_IN_ALL
  317. const GVariantType * g_variant_type_key (const GVariantType *type);
  318. GLIB_AVAILABLE_IN_ALL
  319. const GVariantType * g_variant_type_value (const GVariantType *type);
  320. /* constructors */
  321. GLIB_AVAILABLE_IN_ALL
  322. GVariantType * g_variant_type_new_array (const GVariantType *element);
  323. GLIB_AVAILABLE_IN_ALL
  324. GVariantType * g_variant_type_new_maybe (const GVariantType *element);
  325. GLIB_AVAILABLE_IN_ALL
  326. GVariantType * g_variant_type_new_tuple (const GVariantType * const *items,
  327. gint length);
  328. GLIB_AVAILABLE_IN_ALL
  329. GVariantType * g_variant_type_new_dict_entry (const GVariantType *key,
  330. const GVariantType *value);
  331. /*< private >*/
  332. GLIB_AVAILABLE_IN_ALL
  333. const GVariantType * g_variant_type_checked_ (const gchar *);
  334. G_END_DECLS
  335. #endif /* __G_VARIANT_TYPE_H__ */