1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
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.
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.
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/>.
17 * gvalue.h: generic GValue functions
22 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
23 #error "Only <glib-object.h> can be included directly."
26 #include <gobject/gtype.h>
30 /* --- type macros --- */
33 * @type: A #GType value.
35 * Checks whether the passed in type ID can be used for g_value_init().
36 * That is, this macro checks whether this type provides an implementation
37 * of the #GTypeValueTable functions required for a type to create a #GValue of.
39 * Returns: Whether @type is suitable as a #GValue type.
41 #define G_TYPE_IS_VALUE(type) (g_type_check_is_value_type (type))
44 * @value: A #GValue structure.
46 * Checks if @value is a valid and initialized #GValue structure.
48 * Returns: %TRUE on success.
50 #define G_IS_VALUE(value) (G_TYPE_CHECK_VALUE (value))
53 * @value: A #GValue structure.
55 * Get the type identifier of @value.
57 * Returns: the #GType.
59 #define G_VALUE_TYPE(value) (((GValue*) (value))->g_type)
62 * @value: A #GValue structure.
64 * Gets the type name of @value.
66 * Returns: the type name.
68 #define G_VALUE_TYPE_NAME(value) (g_type_name (G_VALUE_TYPE (value)))
71 * @value: A #GValue structure.
72 * @type: A #GType value.
74 * Checks if @value holds (or contains) a value of @type.
75 * This macro will also check for @value != %NULL and issue a
76 * warning if the check fails.
78 * Returns: %TRUE if @value holds the @type.
80 #define G_VALUE_HOLDS(value,type) (G_TYPE_CHECK_VALUE_TYPE ((value), (type)))
83 /* --- typedefs & structures --- */
86 * @src_value: Source value.
87 * @dest_value: Target value.
89 * The type of value transformation functions which can be registered with
90 * g_value_register_transform_func().
92 typedef void (*GValueTransform) (const GValue *src_value,
97 * An opaque structure used to hold different types of values.
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
102 * #GValue users cannot make any assumptions about how data is stored
103 * within the 2 element @data union, and the @g_type member should
104 * only be accessed through the G_VALUE_TYPE() macro.
111 /* public for GTypeValueTable methods */
126 /* --- prototypes --- */
127 GLIB_AVAILABLE_IN_ALL
128 GValue* g_value_init (GValue *value,
130 GLIB_AVAILABLE_IN_ALL
131 void g_value_copy (const GValue *src_value,
133 GLIB_AVAILABLE_IN_ALL
134 GValue* g_value_reset (GValue *value);
135 GLIB_AVAILABLE_IN_ALL
136 void g_value_unset (GValue *value);
137 GLIB_AVAILABLE_IN_ALL
138 void g_value_set_instance (GValue *value,
140 GLIB_AVAILABLE_IN_2_42
141 void g_value_init_from_instance (GValue *value,
145 /* --- private --- */
146 GLIB_AVAILABLE_IN_ALL
147 gboolean g_value_fits_pointer (const GValue *value);
148 GLIB_AVAILABLE_IN_ALL
149 gpointer g_value_peek_pointer (const GValue *value);
152 /* --- implementation details --- */
153 GLIB_AVAILABLE_IN_ALL
154 gboolean g_value_type_compatible (GType src_type,
156 GLIB_AVAILABLE_IN_ALL
157 gboolean g_value_type_transformable (GType src_type,
159 GLIB_AVAILABLE_IN_ALL
160 gboolean g_value_transform (const GValue *src_value,
162 GLIB_AVAILABLE_IN_ALL
163 void g_value_register_transform_func (GType src_type,
165 GValueTransform transform_func);
168 * G_VALUE_NOCOPY_CONTENTS:
170 * If passed to G_VALUE_COLLECT(), allocated data won't be copied
171 * but used verbatim. This does not affect ref-counted types like
174 #define G_VALUE_NOCOPY_CONTENTS (1 << 27)
179 * A #GValue must be initialized before it can be used. This macro can
180 * be used as initializer instead of an explicit `{ 0 }` when declaring
181 * a variable, but it cannot be assigned to a variable.
184 * GValue value = G_VALUE_INIT;
189 #define G_VALUE_INIT { 0, { { 0 } } }
194 #endif /* __G_VALUE_H__ */