~ubuntu-branches/ubuntu/intrepid/glib2.0/intrepid

« back to all changes in this revision

Viewing changes to gobject/gvalue.c

  • Committer: Bazaar Package Importer
  • Author(s): Loic Minier
  • Date: 2008-09-03 00:51:29 UTC
  • mfrom: (1.2.47 upstream)
  • Revision ID: james.westby@ubuntu.com-20080903005129-cuvzg72uin744gd6
Tags: 2.18.0-1
* New upstream stable release, with API addition.
  - Update symbols file for new g_object_get_type() symbol and drop
    g_slice_debug_tree_statistics() which shouldn't have been exported in
    the first place.
  - Refresh patches 01_gettext-desktopfiles,
    02_usr_share_gnome_applications, and 03_blacklist-directories to apply
    cleanly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
 
56
 *
 
57
 * The code in the example program below demonstrates #GValue's
 
58
 * features.
 
59
 *
 
60
 * |[
 
61
 * #include <glib-object.h>
 
62
 *
 
63
 * static void
 
64
 * int2string (const GValue *src_value,
 
65
 *             GValue       *dest_value)
 
66
 * {
 
67
 *   if (g_value_get_int (src_value) == 42)
 
68
 *     g_value_set_static_string (dest_value, "An important number");
 
69
 *   else
 
70
 *     g_value_set_static_string (dest_value, "What's that?");
 
71
 * }
 
72
 *
 
73
 * int
 
74
 * main (int   argc,
 
75
 *       char *argv[])
 
76
 * {
 
77
 *   /* GValues must start zero-filled */
 
78
 *   GValue a = {0};
 
79
 *   GValue b = {0};
 
80
 *   const gchar *message;
 
81
 *
 
82
 *   g_type_init ();
 
83
 *
 
84
 *   /* The GValue starts empty */
 
85
 *   g_assert (!G_VALUE_HOLDS_STRING (&a));
 
86
 *
 
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));
 
92
 *
 
93
 *   /* Reset it to its pristine state */
 
94
 *   g_value_unset (&a);
 
95
 *
 
96
 *   /* It can then be reused for another type */
 
97
 *   g_value_init (&a, G_TYPE_INT);
 
98
 *   g_value_set_int (&a, 42);
 
99
 *
 
100
 *   /* Attempt to transform it into a GValue of type STRING */
 
101
 *   g_value_init (&b, G_TYPE_STRING);
 
102
 *
 
103
 *   /* An INT is transformable to a STRING */
 
104
 *   g_assert (g_value_type_transformable (G_TYPE_INT, G_TYPE_STRING));
 
105
 *
 
106
 *   g_value_transform (&a, &b);
 
107
 *   g_printf ("%s\n", g_value_get_string (&b));
 
108
 *
 
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));
 
113
 *   return 0;
 
114
 * }
 
115
 * ]|
56
116
 */
57
117
 
58
118