gvalue.h 5.3 KB

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