1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
4 * SPDX-License-Identifier: LGPL-2.1-or-later
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.
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.
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/>.
19 * gvalue.h: generic GValue functions
24 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
25 #error "Only <glib-object.h> can be included directly."
28 #include <gobject/gtype.h>
32 /* --- type macros --- */
35 * @type: A #GType value.
37 * Checks whether the passed in type ID can be used for g_value_init().
39 * That is, this macro checks whether this type provides an implementation
40 * of the #GTypeValueTable functions required for a type to create a #GValue of.
42 * Returns: Whether @type is suitable as a #GValue type.
44 #define G_TYPE_IS_VALUE(type) (g_type_check_is_value_type (type))
47 * @value: A #GValue structure.
49 * Checks if @value is a valid and initialized #GValue structure.
51 * Returns: %TRUE on success.
53 #define G_IS_VALUE(value) (G_TYPE_CHECK_VALUE (value))
56 * @value: A #GValue structure.
58 * Get the type identifier of @value.
60 * Returns: the #GType.
62 #define G_VALUE_TYPE(value) (((GValue*) (value))->g_type)
65 * @value: A #GValue structure.
67 * Gets the type name of @value.
69 * Returns: the type name.
71 #define G_VALUE_TYPE_NAME(value) (g_type_name (G_VALUE_TYPE (value)))
74 * @value: A #GValue structure.
75 * @type: A #GType value.
77 * Checks if @value holds (or contains) a value of @type.
78 * This macro will also check for @value != %NULL and issue a
79 * warning if the check fails.
81 * Returns: %TRUE if @value holds the @type.
83 #define G_VALUE_HOLDS(value,type) (G_TYPE_CHECK_VALUE_TYPE ((value), (type)))
86 /* --- typedefs & structures --- */
89 * @src_value: Source value.
90 * @dest_value: Target value.
92 * The type of value transformation functions which can be registered with
93 * g_value_register_transform_func().
95 * @dest_value will be initialized to the correct destination type.
97 typedef void (*GValueTransform) (const GValue *src_value,
102 * An opaque structure used to hold different types of values.
104 * The data within the structure has protected scope: it is accessible only
105 * to functions within a #GTypeValueTable structure, or implementations of
106 * the g_value_*() API. That is, code portions which implement new fundamental
109 * #GValue users cannot make any assumptions about how data is stored
110 * within the 2 element @data union, and the @g_type member should
111 * only be accessed through the G_VALUE_TYPE() macro.
118 /* public for GTypeValueTable methods */
133 /* --- prototypes --- */
134 GOBJECT_AVAILABLE_IN_ALL
135 GValue* g_value_init (GValue *value,
137 GOBJECT_AVAILABLE_IN_ALL
138 void g_value_copy (const GValue *src_value,
140 GOBJECT_AVAILABLE_IN_ALL
141 GValue* g_value_reset (GValue *value);
142 GOBJECT_AVAILABLE_IN_ALL
143 void g_value_unset (GValue *value);
144 GOBJECT_AVAILABLE_IN_ALL
145 void g_value_set_instance (GValue *value,
147 GOBJECT_AVAILABLE_IN_2_42
148 void g_value_init_from_instance (GValue *value,
152 /* --- private --- */
153 GOBJECT_AVAILABLE_IN_ALL
154 gboolean g_value_fits_pointer (const GValue *value);
155 GOBJECT_AVAILABLE_IN_ALL
156 gpointer g_value_peek_pointer (const GValue *value);
159 /* --- implementation details --- */
160 GOBJECT_AVAILABLE_IN_ALL
161 gboolean g_value_type_compatible (GType src_type,
163 GOBJECT_AVAILABLE_IN_ALL
164 gboolean g_value_type_transformable (GType src_type,
166 GOBJECT_AVAILABLE_IN_ALL
167 gboolean g_value_transform (const GValue *src_value,
169 GOBJECT_AVAILABLE_IN_ALL
170 void g_value_register_transform_func (GType src_type,
172 GValueTransform transform_func);
175 * G_VALUE_NOCOPY_CONTENTS:
177 * If passed to G_VALUE_COLLECT(), allocated data won't be copied
178 * but used verbatim. This does not affect ref-counted types like
179 * objects. This does not affect usage of g_value_copy(), the data will
180 * be copied if it is not ref-counted.
182 #define G_VALUE_NOCOPY_CONTENTS (1 << 27)
185 * G_VALUE_INTERNED_STRING:
187 * For string values, indicates that the string contained is canonical and will
188 * exist for the duration of the process. See g_value_set_interned_string().
192 #define G_VALUE_INTERNED_STRING (1 << 28) GOBJECT_AVAILABLE_MACRO_IN_2_66
197 * A #GValue must be initialized before it can be used. This macro can
198 * be used as initializer instead of an explicit `{ 0 }` when declaring
199 * a variable, but it cannot be assigned to a variable.
201 * |[<!-- language="C" -->
202 * GValue value = G_VALUE_INIT;
207 #define G_VALUE_INIT { 0, { { 0 } } }
212 #endif /* __G_VALUE_H__ */