<refentry id="gobject-Generic-values">
<refmeta>
<refentrytitle role="top_of_page" id="gobject-Generic-values.top_of_page">Generic values</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GOBJECT Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>Generic values</refname>
<refpurpose>A polymorphic type that can hold values of any
    other type</refpurpose>
</refnamediv>

<refsynopsisdiv id="gobject-Generic-values.synopsis" role="synopsis">
<title role="synopsis.title">Synopsis</title>

<synopsis>

#include &lt;glib-object.h&gt;

#define             <link linkend="G-VALUE-HOLDS--CAPS">G_VALUE_HOLDS</link>                       (value,type)
#define             <link linkend="G-VALUE-TYPE--CAPS">G_VALUE_TYPE</link>                        (value)
#define             <link linkend="G-VALUE-TYPE-NAME--CAPS">G_VALUE_TYPE_NAME</link>                   (value)
#define             <link linkend="G-TYPE-IS-VALUE--CAPS">G_TYPE_IS_VALUE</link>                     (type)
#define             <link linkend="G-TYPE-IS-VALUE-ABSTRACT--CAPS">G_TYPE_IS_VALUE_ABSTRACT</link>            (type)
#define             <link linkend="G-IS-VALUE--CAPS">G_IS_VALUE</link>                          (value)
                    <link linkend="GValue">GValue</link>;
#define             <link linkend="G-TYPE-VALUE--CAPS">G_TYPE_VALUE</link>
#define             <link linkend="G-TYPE-VALUE-ARRAY--CAPS">G_TYPE_VALUE_ARRAY</link>
<link linkend="GValue">GValue</link>*             <link linkend="g-value-init">g_value_init</link>                        (<link linkend="GValue">GValue</link> *value,
                                                         <link linkend="GType">GType</link> g_type);
<link linkend="void">void</link>                <link linkend="g-value-copy">g_value_copy</link>                        (const <link linkend="GValue">GValue</link> *src_value,
                                                         <link linkend="GValue">GValue</link> *dest_value);
<link linkend="GValue">GValue</link>*             <link linkend="g-value-reset">g_value_reset</link>                       (<link linkend="GValue">GValue</link> *value);
<link linkend="void">void</link>                <link linkend="g-value-unset">g_value_unset</link>                       (<link linkend="GValue">GValue</link> *value);
<link linkend="void">void</link>                <link linkend="g-value-set-instance">g_value_set_instance</link>                (<link linkend="GValue">GValue</link> *value,
                                                         <link linkend="gpointer">gpointer</link> instance);
<link linkend="gboolean">gboolean</link>            <link linkend="g-value-fits-pointer">g_value_fits_pointer</link>                (const <link linkend="GValue">GValue</link> *value);
<link linkend="gpointer">gpointer</link>            <link linkend="g-value-peek-pointer">g_value_peek_pointer</link>                (const <link linkend="GValue">GValue</link> *value);
<link linkend="gboolean">gboolean</link>            <link linkend="g-value-type-compatible">g_value_type_compatible</link>             (<link linkend="GType">GType</link> src_type,
                                                         <link linkend="GType">GType</link> dest_type);
<link linkend="gboolean">gboolean</link>            <link linkend="g-value-type-transformable">g_value_type_transformable</link>          (<link linkend="GType">GType</link> src_type,
                                                         <link linkend="GType">GType</link> dest_type);
<link linkend="gboolean">gboolean</link>            <link linkend="g-value-transform">g_value_transform</link>                   (const <link linkend="GValue">GValue</link> *src_value,
                                                         <link linkend="GValue">GValue</link> *dest_value);
<link linkend="void">void</link>                (<link linkend="GValueTransform">*GValueTransform</link>)                  (const <link linkend="GValue">GValue</link> *src_value,
                                                         <link linkend="GValue">GValue</link> *dest_value);
<link linkend="void">void</link>                <link linkend="g-value-register-transform-func">g_value_register_transform_func</link>     (<link linkend="GType">GType</link> src_type,
                                                         <link linkend="GType">GType</link> dest_type,
                                                         <link linkend="GValueTransform">GValueTransform</link> transform_func);
<link linkend="gchar">gchar</link>*              <link linkend="g-strdup-value-contents">g_strdup_value_contents</link>             (const <link linkend="GValue">GValue</link> *value);
</synopsis>
</refsynopsisdiv>









<refsect1 id="gobject-Generic-values.description" role="desc">
<title role="desc.title">Description</title>
<para>
The <link linkend="GValue"><type>GValue</type></link> structure is basically a variable container that consists
of a type identifier and a specific value of that type.
The type identifier within a <link linkend="GValue"><type>GValue</type></link> structure always determines the
type of the associated value.
To create a undefined <link linkend="GValue"><type>GValue</type></link> structure, simply create a zero-filled
<link linkend="GValue"><type>GValue</type></link> structure. To initialize the <link linkend="GValue"><type>GValue</type></link>, use the <link linkend="g-value-init"><function>g_value_init()</function></link>
function. A <link linkend="GValue"><type>GValue</type></link> cannot be used until it is initialized.
The basic type operations (such as freeing and copying) are determined
by the <link linkend="GTypeValueTable"><type>GTypeValueTable</type></link> associated with the type ID stored in the <link linkend="GValue"><type>GValue</type></link>.
Other <link linkend="GValue"><type>GValue</type></link> operations (such as converting values between types) are
provided by this interface.
</para>
<para>
The code in the example program below demonstrates <link linkend="GValue"><type>GValue</type></link>'s
features.
</para>
<para>
<informalexample><programlisting>
#include &lt;glib-object.h&gt;

static void
int2string (const GValue *src_value,
            GValue       *dest_value)
{
  if (g_value_get_int (src_value) == 42)
    g_value_set_static_string (dest_value, "An important number");
  else
    g_value_set_static_string (dest_value, "What's that?");
}

int
main (int   argc,
      char *argv[])
{
  /&ast; GValues must start zero-filled &ast;/
  GValue a = {0};
  GValue b = {0};
  const gchar *message;

  g_type_init ();

  /&ast; The GValue starts empty &ast;/
  g_assert (!G_VALUE_HOLDS_STRING (&amp;a));

  /&ast; Put a string in it &ast;/
  g_value_init (&amp;a, G_TYPE_STRING);
  g_assert (G_VALUE_HOLDS_STRING (&amp;a));
  g_value_set_static_string (&amp;a, "Hello, world!");
  g_printf ("%s\n", g_value_get_string (&amp;a));

  /&ast; Reset it to its pristine state &ast;/
  g_value_unset (&amp;a);

  /&ast; It can then be reused for another type &ast;/
  g_value_init (&amp;a, G_TYPE_INT);
  g_value_set_int (&amp;a, 42);

  /&ast; Attempt to transform it into a GValue of type STRING &ast;/
  g_value_init (&amp;b, G_TYPE_STRING);

  /&ast; An INT is transformable to a STRING &ast;/
  g_assert (g_value_type_transformable (G_TYPE_INT, G_TYPE_STRING));

  g_value_transform (&amp;a, &amp;b);
  g_printf ("%s\n", g_value_get_string (&amp;b));

  /&ast; Attempt to transform it again using a custom transform function &ast;/
  g_value_register_transform_func (G_TYPE_INT, G_TYPE_STRING, int2string);
  g_value_transform (&amp;a, &amp;b);
  g_printf ("%s\n", g_value_get_string (&amp;b));
  return 0;
}
</programlisting></informalexample></para>
<para>
</para>
</refsect1>

<refsect1 id="gobject-Generic-values.details" role="details">
<title role="details.title">Details</title>
<refsect2 id="G-VALUE-HOLDS--CAPS" role="macro">
<title>G_VALUE_HOLDS()</title>
<indexterm zone="G-VALUE-HOLDS--CAPS"><primary sortas="VALUE_HOLDS">G_VALUE_HOLDS</primary></indexterm><programlisting>#define G_VALUE_HOLDS(value,type)	(G_TYPE_CHECK_VALUE_TYPE ((value), (type)))
</programlisting>
<para>
Checks if <parameter>value</parameter> holds (or contains) a value of <parameter>type</parameter>.
This macro will also check for <parameter>value</parameter> != <link linkend="NULL--CAPS"><literal>NULL</literal></link> and issue a
warning if the check fails.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&#160;:</term>
<listitem><simpara> A <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>type</parameter>&#160;:</term>
<listitem><simpara> A <link linkend="GType"><type>GType</type></link> value.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="G-VALUE-TYPE--CAPS" role="macro">
<title>G_VALUE_TYPE()</title>
<indexterm zone="G-VALUE-TYPE--CAPS"><primary sortas="VALUE_TYPE">G_VALUE_TYPE</primary></indexterm><programlisting>#define	G_VALUE_TYPE(value)		(((GValue*) (value))-&gt;g_type)
</programlisting>
<para>
Get the type identifier of <parameter>value</parameter>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&#160;:</term>
<listitem><simpara> A <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="G-VALUE-TYPE-NAME--CAPS" role="macro">
<title>G_VALUE_TYPE_NAME()</title>
<indexterm zone="G-VALUE-TYPE-NAME--CAPS"><primary sortas="VALUE_TYPE_NAME">G_VALUE_TYPE_NAME</primary></indexterm><programlisting>#define	G_VALUE_TYPE_NAME(value)	(g_type_name (G_VALUE_TYPE (value)))
</programlisting>
<para>
Gets the the type name of <parameter>value</parameter>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&#160;:</term>
<listitem><simpara> A <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="G-TYPE-IS-VALUE--CAPS" role="macro">
<title>G_TYPE_IS_VALUE()</title>
<indexterm zone="G-TYPE-IS-VALUE--CAPS"><primary sortas="TYPE_IS_VALUE">G_TYPE_IS_VALUE</primary></indexterm><programlisting>#define	G_TYPE_IS_VALUE(type)		(g_type_check_is_value_type (type))
</programlisting>
<para>
Checks whether the passed in type ID can be used for <link linkend="g-value-init"><function>g_value_init()</function></link>.
That is, this macro checks whether this type provides an implementation
of the <link linkend="GTypeValueTable"><type>GTypeValueTable</type></link> functions required for a type to create a <link linkend="GValue"><type>GValue</type></link> of.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>type</parameter>&#160;:</term>
<listitem><simpara> A <link linkend="GType"><type>GType</type></link> value.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="G-TYPE-IS-VALUE-ABSTRACT--CAPS" role="macro">
<title>G_TYPE_IS_VALUE_ABSTRACT()</title>
<indexterm zone="G-TYPE-IS-VALUE-ABSTRACT--CAPS"><primary sortas="TYPE_IS_VALUE_ABSTRACT">G_TYPE_IS_VALUE_ABSTRACT</primary></indexterm><programlisting>#define G_TYPE_IS_VALUE_ABSTRACT(type)          (g_type_test_flags ((type), G_TYPE_FLAG_VALUE_ABSTRACT))
</programlisting>
<para>
Checks if <parameter>type</parameter> is an abstract value type.  An abstract value type introduces
a value table, but can't be used for <link linkend="g-value-init"><function>g_value_init()</function></link> and is normally used as
an abstract base type for derived value types.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>type</parameter>&#160;:</term>
<listitem><simpara> A <link linkend="GType"><type>GType</type></link> value.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="G-IS-VALUE--CAPS" role="macro">
<title>G_IS_VALUE()</title>
<indexterm zone="G-IS-VALUE--CAPS"><primary sortas="IS_VALUE">G_IS_VALUE</primary></indexterm><programlisting>#define	G_IS_VALUE(value)		(G_TYPE_CHECK_VALUE (value))
</programlisting>
<para>
Checks if <parameter>value</parameter> is a valid and initialized <link linkend="GValue"><type>GValue</type></link> structure.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&#160;:</term>
<listitem><simpara> A <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="GValue" role="struct">
<title>GValue</title>
<indexterm zone="GValue"><primary sortas="Value">GValue</primary></indexterm><programlisting>typedef struct {
} GValue;
</programlisting>
<para>
An opaque structure used to hold different types of values.
The data within the structure has protected scope: it is accessible only
to functions within a <link linkend="GTypeValueTable"><type>GTypeValueTable</type></link> structure, or implementations of
the g_value_*() API. That is, code portions which implement new fundamental
types.
<link linkend="GValue"><type>GValue</type></link> users can not make any assumptions about how data is stored
within the 2 element <parameter>data</parameter> union, and the <parameter>g_type</parameter> member should
only be accessed through the <link linkend="G-VALUE-TYPE--CAPS"><function>G_VALUE_TYPE()</function></link> macro.</para>
<para>
</para></refsect2>
<refsect2 id="G-TYPE-VALUE--CAPS" role="macro">
<title>G_TYPE_VALUE</title>
<indexterm zone="G-TYPE-VALUE--CAPS"><primary sortas="TYPE_VALUE">G_TYPE_VALUE</primary></indexterm><programlisting>#define	G_TYPE_VALUE		(g_value_get_type ())
</programlisting>
<para>
The type ID of the "GValue" type which is a boxed type,
used to pass around pointers to GValues.</para>
<para>
</para></refsect2>
<refsect2 id="G-TYPE-VALUE-ARRAY--CAPS" role="macro">
<title>G_TYPE_VALUE_ARRAY</title>
<indexterm zone="G-TYPE-VALUE-ARRAY--CAPS"><primary sortas="TYPE_VALUE_ARRAY">G_TYPE_VALUE_ARRAY</primary></indexterm><programlisting>#define	G_TYPE_VALUE_ARRAY	(g_value_array_get_type ())
</programlisting>
<para>
The type ID of the "GValueArray" type which is a boxed type,
used to pass around pointers to GValueArrays.</para>
<para>
</para></refsect2>
<refsect2 id="g-value-init" role="function">
<title>g_value_init ()</title>
<indexterm zone="g-value-init"><primary sortas="value_init">g_value_init</primary></indexterm><programlisting><link linkend="GValue">GValue</link>*             g_value_init                        (<link linkend="GValue">GValue</link> *value,
                                                         <link linkend="GType">GType</link> g_type);</programlisting>
<para>
Initializes <parameter>value</parameter> with the default value of <parameter>type</parameter>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&#160;:</term>
<listitem><simpara> A zero-filled (uninitialized) <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>g_type</parameter>&#160;:</term>
<listitem><simpara> Type the <link linkend="GValue"><type>GValue</type></link> should hold values of.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> the <link linkend="GValue"><type>GValue</type></link> structure that has been passed in
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-value-copy" role="function">
<title>g_value_copy ()</title>
<indexterm zone="g-value-copy"><primary sortas="value_copy">g_value_copy</primary></indexterm><programlisting><link linkend="void">void</link>                g_value_copy                        (const <link linkend="GValue">GValue</link> *src_value,
                                                         <link linkend="GValue">GValue</link> *dest_value);</programlisting>
<para>
Copies the value of <parameter>src_value</parameter> into <parameter>dest_value</parameter>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>src_value</parameter>&#160;:</term>
<listitem><simpara> An initialized <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>dest_value</parameter>&#160;:</term>
<listitem><simpara> An initialized <link linkend="GValue"><type>GValue</type></link> structure of the same type as <parameter>src_value</parameter>.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-value-reset" role="function">
<title>g_value_reset ()</title>
<indexterm zone="g-value-reset"><primary sortas="value_reset">g_value_reset</primary></indexterm><programlisting><link linkend="GValue">GValue</link>*             g_value_reset                       (<link linkend="GValue">GValue</link> *value);</programlisting>
<para>
Clears the current value in <parameter>value</parameter> and resets it to the default value
(as if the value had just been initialized).</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&#160;:</term>
<listitem><simpara> An initialized <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> the <link linkend="GValue"><type>GValue</type></link> structure that has been passed in
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-value-unset" role="function">
<title>g_value_unset ()</title>
<indexterm zone="g-value-unset"><primary sortas="value_unset">g_value_unset</primary></indexterm><programlisting><link linkend="void">void</link>                g_value_unset                       (<link linkend="GValue">GValue</link> *value);</programlisting>
<para>
Clears the current value in <parameter>value</parameter> and "unsets" the type,
this releases all resources associated with this GValue.
An unset value is the same as an uninitialized (zero-filled)
<link linkend="GValue"><type>GValue</type></link> structure.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&#160;:</term>
<listitem><simpara> An initialized <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-value-set-instance" role="function">
<title>g_value_set_instance ()</title>
<indexterm zone="g-value-set-instance"><primary sortas="value_set_instance">g_value_set_instance</primary></indexterm><programlisting><link linkend="void">void</link>                g_value_set_instance                (<link linkend="GValue">GValue</link> *value,
                                                         <link linkend="gpointer">gpointer</link> instance);</programlisting>
<para>
Sets <parameter>value</parameter> from an instantiatable type via the
value_table's <link linkend="collect-value"><function>collect_value()</function></link> function.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&#160;:</term>
<listitem><simpara> An initialized <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>instance</parameter>&#160;:</term>
<listitem><simpara> the instance
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-value-fits-pointer" role="function">
<title>g_value_fits_pointer ()</title>
<indexterm zone="g-value-fits-pointer"><primary sortas="value_fits_pointer">g_value_fits_pointer</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_value_fits_pointer                (const <link linkend="GValue">GValue</link> *value);</programlisting>
<para>
Determines if <parameter>value</parameter> will fit inside the size of a pointer value.
This is an internal function introduced mainly for C marshallers.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&#160;:</term>
<listitem><simpara> An initialized <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if <parameter>value</parameter> will fit inside a pointer value.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-value-peek-pointer" role="function">
<title>g_value_peek_pointer ()</title>
<indexterm zone="g-value-peek-pointer"><primary sortas="value_peek_pointer">g_value_peek_pointer</primary></indexterm><programlisting><link linkend="gpointer">gpointer</link>            g_value_peek_pointer                (const <link linkend="GValue">GValue</link> *value);</programlisting>
<para>
Return the value contents as pointer. This function asserts that
<link linkend="g-value-fits-pointer"><function>g_value_fits_pointer()</function></link> returned <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> for the passed in value.
This is an internal function introduced mainly for C marshallers.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&#160;:</term>
<listitem><simpara> An initialized <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if <parameter>value</parameter> will fit inside a pointer value.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-value-type-compatible" role="function">
<title>g_value_type_compatible ()</title>
<indexterm zone="g-value-type-compatible"><primary sortas="value_type_compatible">g_value_type_compatible</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_value_type_compatible             (<link linkend="GType">GType</link> src_type,
                                                         <link linkend="GType">GType</link> dest_type);</programlisting>
<para>
Returns whether a <link linkend="GValue"><type>GValue</type></link> of type <parameter>src_type</parameter> can be copied into
a <link linkend="GValue"><type>GValue</type></link> of type <parameter>dest_type</parameter>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>src_type</parameter>&#160;:</term>
<listitem><simpara> source type to be copied.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>dest_type</parameter>&#160;:</term>
<listitem><simpara> destination type for copying.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if <link linkend="g-value-copy"><function>g_value_copy()</function></link> is possible with <parameter>src_type</parameter> and <parameter>dest_type</parameter>.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-value-type-transformable" role="function">
<title>g_value_type_transformable ()</title>
<indexterm zone="g-value-type-transformable"><primary sortas="value_type_transformable">g_value_type_transformable</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_value_type_transformable          (<link linkend="GType">GType</link> src_type,
                                                         <link linkend="GType">GType</link> dest_type);</programlisting>
<para>
Check whether <link linkend="g-value-transform"><function>g_value_transform()</function></link> is able to transform values
of type <parameter>src_type</parameter> into values of type <parameter>dest_type</parameter>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>src_type</parameter>&#160;:</term>
<listitem><simpara> Source type.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>dest_type</parameter>&#160;:</term>
<listitem><simpara> Target type.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if the transformation is possible, <link linkend="FALSE--CAPS"><literal>FALSE</literal></link> otherwise.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-value-transform" role="function">
<title>g_value_transform ()</title>
<indexterm zone="g-value-transform"><primary sortas="value_transform">g_value_transform</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_value_transform                   (const <link linkend="GValue">GValue</link> *src_value,
                                                         <link linkend="GValue">GValue</link> *dest_value);</programlisting>
<para>
Tries to cast the contents of <parameter>src_value</parameter> into a type appropriate
to store in <parameter>dest_value</parameter>, e.g. to transform a <link linkend="G-TYPE-INT--CAPS"><literal>G_TYPE_INT</literal></link> value
into a <link linkend="G-TYPE-FLOAT--CAPS"><literal>G_TYPE_FLOAT</literal></link> value. Performing transformations between
value types might incur precision lossage. Especially
transformations into strings might reveal seemingly arbitrary
results and shouldn't be relied upon for production code (such
as rcfile value or object property serialization).</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>src_value</parameter>&#160;:</term>
<listitem><simpara> Source value.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>dest_value</parameter>&#160;:</term>
<listitem><simpara> Target value.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> Whether a transformation rule was found and could be applied.
 Upon failing transformations, <parameter>dest_value</parameter> is left untouched.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="GValueTransform" role="function">
<title>GValueTransform ()</title>
<indexterm zone="GValueTransform"><primary sortas="ValueTransform">GValueTransform</primary></indexterm><programlisting><link linkend="void">void</link>                (*GValueTransform)                  (const <link linkend="GValue">GValue</link> *src_value,
                                                         <link linkend="GValue">GValue</link> *dest_value);</programlisting>
<para>
The type of value transformation functions which can be registered with
<link linkend="g-value-register-transform-func"><function>g_value_register_transform_func()</function></link>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>src_value</parameter>&#160;:</term>
<listitem><simpara> Source value.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>dest_value</parameter>&#160;:</term>
<listitem><simpara> Target value.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-value-register-transform-func" role="function">
<title>g_value_register_transform_func ()</title>
<indexterm zone="g-value-register-transform-func"><primary sortas="value_register_transform_func">g_value_register_transform_func</primary></indexterm><programlisting><link linkend="void">void</link>                g_value_register_transform_func     (<link linkend="GType">GType</link> src_type,
                                                         <link linkend="GType">GType</link> dest_type,
                                                         <link linkend="GValueTransform">GValueTransform</link> transform_func);</programlisting>
<para>
Registers a value transformation function for use in <link linkend="g-value-transform"><function>g_value_transform()</function></link>.
A previously registered transformation function for <parameter>src_type</parameter> and <parameter>dest_type</parameter>
will be replaced.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>src_type</parameter>&#160;:</term>
<listitem><simpara> Source type.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>dest_type</parameter>&#160;:</term>
<listitem><simpara> Target type.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>transform_func</parameter>&#160;:</term>
<listitem><simpara> a function which transforms values of type <parameter>src_type</parameter>
 into value of type <parameter>dest_type</parameter>
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-strdup-value-contents" role="function">
<title>g_strdup_value_contents ()</title>
<indexterm zone="g-strdup-value-contents"><primary sortas="strdup_value_contents">g_strdup_value_contents</primary></indexterm><programlisting><link linkend="gchar">gchar</link>*              g_strdup_value_contents             (const <link linkend="GValue">GValue</link> *value);</programlisting>
<para>
Return a newly allocated string, which describes the contents of a
<link linkend="GValue"><type>GValue</type></link>.  The main purpose of this function is to describe <link linkend="GValue"><type>GValue</type></link>
contents for debugging output, the way in which the contents are
described may change between different GLib versions.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&#160;:</term>
<listitem><simpara> <link linkend="GValue"><type>GValue</type></link> which contents are to be described.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> Newly allocated string.
</simpara></listitem></varlistentry>
</variablelist></refsect2>

</refsect1>



<refsect1 id="gobject-Generic-values.see-also">
<title>See Also</title>
The fundamental types which all support <link linkend="GValue"><type>GValue</type></link>
    operations and thus can be used as a type initializer for
    <link linkend="g-value-init"><function>g_value_init()</function></link> are defined by a separate interface.  See the <link
    linkend="gobject-Standard-Parameter-and-Value-Types">Standard
    Values API</link> for details.
</refsect1>

</refentry>
