53
53
* by the #GTypeValueTable associated with the type ID stored in the #GValue.
54
54
* Other #GValue operations (such as converting values between types) are
55
55
* provided by this interface.
57
* The code in the example program below demonstrates #GValue's
61
* #include <glib-object.h>
64
* int2string (const GValue *src_value,
67
* if (g_value_get_int (src_value) == 42)
68
* g_value_set_static_string (dest_value, "An important number");
70
* g_value_set_static_string (dest_value, "What's that?");
77
* /* GValues must start zero-filled */
80
* const gchar *message;
84
* /* The GValue starts empty */
85
* g_assert (!G_VALUE_HOLDS_STRING (&a));
87
* /* Put a string in it */
88
* g_value_init (&a, G_TYPE_STRING);
89
* g_assert (G_VALUE_HOLDS_STRING (&a));
90
* g_value_set_static_string (&a, "Hello, world!");
91
* g_printf ("%s\n", g_value_get_string (&a));
93
* /* Reset it to its pristine state */
94
* g_value_unset (&a);
96
* /* It can then be reused for another type */
97
* g_value_init (&a, G_TYPE_INT);
98
* g_value_set_int (&a, 42);
100
* /* Attempt to transform it into a GValue of type STRING */
101
* g_value_init (&b, G_TYPE_STRING);
103
* /* An INT is transformable to a STRING */
104
* g_assert (g_value_type_transformable (G_TYPE_INT, G_TYPE_STRING));
106
* g_value_transform (&a, &b);
107
* g_printf ("%s\n", g_value_get_string (&b));
109
* /* Attempt to transform it again using a custom transform function */
110
* g_value_register_transform_func (G_TYPE_INT, G_TYPE_STRING, int2string);
111
* g_value_transform (&a, &b);
112
* g_printf ("%s\n", g_value_get_string (&b));