gvalue.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /* GObject - GLib Type, Object, Parameter and Signal Library
  2. * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
  3. *
  4. * SPDX-License-Identifier: LGPL-2.1-or-later
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General
  17. * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * gvalue.h: generic GValue functions
  20. */
  21. #ifndef __G_VALUE_H__
  22. #define __G_VALUE_H__
  23. #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
  24. #error "Only <glib-object.h> can be included directly."
  25. #endif
  26. #include <gobject/gtype.h>
  27. G_BEGIN_DECLS
  28. /* --- type macros --- */
  29. /**
  30. * G_TYPE_IS_VALUE:
  31. * @type: A #GType value.
  32. *
  33. * Checks whether the passed in type ID can be used for g_value_init().
  34. *
  35. * That is, this macro checks whether this type provides an implementation
  36. * of the #GTypeValueTable functions required for a type to create a #GValue of.
  37. *
  38. * Returns: Whether @type is suitable as a #GValue type.
  39. */
  40. #define G_TYPE_IS_VALUE(type) (g_type_check_is_value_type (type))
  41. /**
  42. * G_IS_VALUE:
  43. * @value: A #GValue structure.
  44. *
  45. * Checks if @value is a valid and initialized #GValue structure.
  46. *
  47. * Returns: %TRUE on success.
  48. */
  49. #define G_IS_VALUE(value) (G_TYPE_CHECK_VALUE (value))
  50. /**
  51. * G_VALUE_TYPE:
  52. * @value: A #GValue structure.
  53. *
  54. * Get the type identifier of @value.
  55. *
  56. * Returns: the #GType.
  57. */
  58. #define G_VALUE_TYPE(value) (((GValue*) (value))->g_type)
  59. /**
  60. * G_VALUE_TYPE_NAME:
  61. * @value: A #GValue structure.
  62. *
  63. * Gets the type name of @value.
  64. *
  65. * Returns: the type name.
  66. */
  67. #define G_VALUE_TYPE_NAME(value) (g_type_name (G_VALUE_TYPE (value)))
  68. /**
  69. * G_VALUE_HOLDS:
  70. * @value: A #GValue structure.
  71. * @type: A #GType value.
  72. *
  73. * Checks if @value holds (or contains) a value of @type.
  74. * This macro will also check for @value != %NULL and issue a
  75. * warning if the check fails.
  76. *
  77. * Returns: %TRUE if @value holds the @type.
  78. */
  79. #define G_VALUE_HOLDS(value,type) (G_TYPE_CHECK_VALUE_TYPE ((value), (type)))
  80. /* --- typedefs & structures --- */
  81. /**
  82. * GValueTransform:
  83. * @src_value: Source value.
  84. * @dest_value: Target value.
  85. *
  86. * The type of value transformation functions which can be registered with
  87. * g_value_register_transform_func().
  88. *
  89. * @dest_value will be initialized to the correct destination type.
  90. */
  91. typedef void (*GValueTransform) (const GValue *src_value,
  92. GValue *dest_value);
  93. /**
  94. * GValue:
  95. *
  96. * An opaque structure used to hold different types of values.
  97. *
  98. * The data within the structure has protected scope: it is accessible only
  99. * to functions within a #GTypeValueTable structure, or implementations of
  100. * the g_value_*() API. That is, code portions which implement new fundamental
  101. * types.
  102. *
  103. * #GValue users cannot make any assumptions about how data is stored
  104. * within the 2 element @data union, and the @g_type member should
  105. * only be accessed through the G_VALUE_TYPE() macro.
  106. */
  107. struct _GValue
  108. {
  109. /*< private >*/
  110. GType g_type;
  111. /* public for GTypeValueTable methods */
  112. union {
  113. gint v_int;
  114. guint v_uint;
  115. glong v_long;
  116. gulong v_ulong;
  117. gint64 v_int64;
  118. guint64 v_uint64;
  119. gfloat v_float;
  120. gdouble v_double;
  121. gpointer v_pointer;
  122. } data[2];
  123. };
  124. /* --- prototypes --- */
  125. GOBJECT_AVAILABLE_IN_ALL
  126. GValue* g_value_init (GValue *value,
  127. GType g_type);
  128. GOBJECT_AVAILABLE_IN_ALL
  129. void g_value_copy (const GValue *src_value,
  130. GValue *dest_value);
  131. GOBJECT_AVAILABLE_IN_ALL
  132. GValue* g_value_reset (GValue *value);
  133. GOBJECT_AVAILABLE_IN_ALL
  134. void g_value_unset (GValue *value);
  135. GOBJECT_AVAILABLE_IN_ALL
  136. void g_value_set_instance (GValue *value,
  137. gpointer instance);
  138. GOBJECT_AVAILABLE_IN_2_42
  139. void g_value_init_from_instance (GValue *value,
  140. gpointer instance);
  141. /* --- private --- */
  142. GOBJECT_AVAILABLE_IN_ALL
  143. gboolean g_value_fits_pointer (const GValue *value);
  144. GOBJECT_AVAILABLE_IN_ALL
  145. gpointer g_value_peek_pointer (const GValue *value);
  146. /* --- implementation details --- */
  147. GOBJECT_AVAILABLE_IN_ALL
  148. gboolean g_value_type_compatible (GType src_type,
  149. GType dest_type);
  150. GOBJECT_AVAILABLE_IN_ALL
  151. gboolean g_value_type_transformable (GType src_type,
  152. GType dest_type);
  153. GOBJECT_AVAILABLE_IN_ALL
  154. gboolean g_value_transform (const GValue *src_value,
  155. GValue *dest_value);
  156. GOBJECT_AVAILABLE_IN_ALL
  157. void g_value_register_transform_func (GType src_type,
  158. GType dest_type,
  159. GValueTransform transform_func);
  160. /**
  161. * G_VALUE_NOCOPY_CONTENTS:
  162. *
  163. * If passed to G_VALUE_COLLECT(), allocated data won't be copied
  164. * but used verbatim. This does not affect ref-counted types like
  165. * objects. This does not affect usage of g_value_copy(), the data will
  166. * be copied if it is not ref-counted.
  167. */
  168. #define G_VALUE_NOCOPY_CONTENTS (1 << 27)
  169. /**
  170. * G_VALUE_INTERNED_STRING:
  171. *
  172. * For string values, indicates that the string contained is canonical and will
  173. * exist for the duration of the process. See g_value_set_interned_string().
  174. *
  175. * Since: 2.66
  176. */
  177. #define G_VALUE_INTERNED_STRING (1 << 28) GOBJECT_AVAILABLE_MACRO_IN_2_66
  178. /**
  179. * G_VALUE_INIT:
  180. *
  181. * A #GValue must be initialized before it can be used. This macro can
  182. * be used as initializer instead of an explicit `{ 0 }` when declaring
  183. * a variable, but it cannot be assigned to a variable.
  184. *
  185. * |[<!-- language="C" -->
  186. * GValue value = G_VALUE_INIT;
  187. * ]|
  188. *
  189. * Since: 2.30
  190. */
  191. #define G_VALUE_INIT { 0, { { 0 } } }
  192. G_END_DECLS
  193. #endif /* __G_VALUE_H__ */