<refentry id="gobject-Generic-values">
<refmeta>
<refentrytitle>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><title>Synopsis</title>
<synopsis>

#include &lt;gobject.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)
struct      <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);
void        <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);
void        <link linkend="g-value-unset">g_value_unset</link>                   (<link linkend="GValue">GValue</link> *value);
<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);
void        (<link linkend="GValueTransform">*GValueTransform</link>)              (const <link linkend="GValue">GValue</link> *src_value,
                                             <link linkend="GValue">GValue</link> *dest_value);
void        <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>
<title>Description</title>
<para>
The <link linkend="GValue">GValue</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">GValue</link> structure always determines the
type of the associated value.
To create a undefined <link linkend="GValue">GValue</link> structure, simply create a zero-filled
<link linkend="GValue">GValue</link> structure. To initialize the <link linkend="GValue">GValue</link>, use the <link linkend="g-value-init">g_value_init</link>()
function. A <link linkend="GValue">GValue</link> cannot be used until it is initialized.
The basic type operations (such as freeing and copying) are determined
by the <link linkend="GTypeValueTable">GTypeValueTable</link> associated with the type ID stored in the <link linkend="GValue">GValue</link>.
Other <link linkend="GValue">GValue</link> operations (such as converting values between types) are
provided by this interface.
</para>
</refsect1>

<refsect1>
<title>Details</title>
<refsect2>
<title><anchor id="G-VALUE-HOLDS-CAPS">G_VALUE_HOLDS()</title>
<programlisting>#define G_VALUE_HOLDS(value,type)	(G_TYPE_CHECK_VALUE_TYPE ((value), (type)))
</programlisting>
<para>
Returns <link linkend="TRUE-CAPS">TRUE</link> 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">NULL</link> and issue a
warning if the check fails.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>value</parameter>&nbsp;:</entry>
<entry>
</entry></row>
<row><entry align="right"><parameter>type</parameter>&nbsp;:</entry>
<entry>


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="G-VALUE-TYPE-CAPS">G_VALUE_TYPE()</title>
<programlisting>#define	G_VALUE_TYPE(value)		(((GValue*) (value))-&gt;g_type)
</programlisting>
<para>
Returns the type identifier of <parameter>value</parameter>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>value</parameter>&nbsp;:</entry>
<entry>A <link linkend="GValue">GValue</link> structure.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="G-VALUE-TYPE-NAME-CAPS">G_VALUE_TYPE_NAME()</title>
<programlisting>#define	G_VALUE_TYPE_NAME(value)	(g_type_name (G_VALUE_TYPE (value)))
</programlisting>
<para>
Returns the type name of <parameter>value</parameter>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>value</parameter>&nbsp;:</entry>
<entry>A <link linkend="GValue">GValue</link> structure.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="G-TYPE-IS-VALUE-CAPS">G_TYPE_IS_VALUE()</title>
<programlisting>#define	G_TYPE_IS_VALUE(type)		(g_type_check_is_value_type (type))
</programlisting>
<para>
Return whether the passed in type ID can be used for <link linkend="g-value-init">g_value_init</link>().
That is, this macro checks whether this type provides an implementation
of the <link linkend="GTypeValueTable">GTypeValueTable</link> functions required for a type to create a <link linkend="GValue">GValue</link> of.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>type</parameter>&nbsp;:</entry>
<entry>	  A <link linkend="GType">GType</link> value.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>Whether <parameter>type</parameter> is suitable as a <link linkend="GValue">GValue</link> type.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="G-TYPE-IS-VALUE-ABSTRACT-CAPS">G_TYPE_IS_VALUE_ABSTRACT()</title>
<programlisting>#define G_TYPE_IS_VALUE_ABSTRACT(type)          (g_type_test_flags ((type), G_TYPE_FLAG_VALUE_ABSTRACT))
</programlisting>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>type</parameter>&nbsp;:</entry>
<entry>


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="G-IS-VALUE-CAPS">G_IS_VALUE()</title>
<programlisting>#define	G_IS_VALUE(value)		(G_TYPE_CHECK_VALUE (value))
</programlisting>
<para>
Returns <link linkend="TRUE-CAPS">TRUE</link> if <parameter>value</parameter> is a valid and initialized <link linkend="GValue">GValue</link> structure.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>value</parameter>&nbsp;:</entry>
<entry>A <link linkend="GValue">GValue</link> structure.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="GValue">struct GValue</title>
<programlisting>struct GValue
{
  /*&lt; private &gt;*/
  GType		g_type;

  /* public for GTypeValueTable methods */
  union {
    gint	v_int;
    guint	v_uint;
    glong	v_long;
    gulong	v_ulong;
    gint64      v_int64;
    guint64     v_uint64;
    gfloat	v_float;
    gdouble	v_double;
    gpointer	v_pointer;
  } data[2];
};
</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">GTypeValueTable</link> structure, or implementations of
the g_value_*() API. That is, code portions which implement new fundamental
types.
<link linkend="GValue">GValue</link> users can not make any assumptions about how data is stored
within the 2 element <link linkend="GValue">GValue</link>.data[] union, and the g_type member should
only be accessed through the <link linkend="G-VALUE-TYPE-CAPS">G_VALUE_TYPE</link>() macro.
</para></refsect2>
<refsect2>
<title><anchor id="G-TYPE-VALUE-CAPS">G_TYPE_VALUE</title>
<programlisting>#define	G_TYPE_VALUE		(g_value_get_type ())
</programlisting>
<para>
Returns the type ID of the "GValue" type which is a boxed type,
used to pass around pointers to GValues.
</para></refsect2>
<refsect2>
<title><anchor id="G-TYPE-VALUE-ARRAY-CAPS">G_TYPE_VALUE_ARRAY</title>
<programlisting>#define	G_TYPE_VALUE_ARRAY	(g_value_array_get_type ())
</programlisting>
<para>
Returns the type ID of the "GValueArray" type which is a boxed type,
used to pass around pointers to GValueArrays.
</para></refsect2>
<refsect2>
<title><anchor id="g-value-init">g_value_init ()</title>
<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><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>value</parameter>&nbsp;:</entry>
<entry>		A zero-filled (uninitialized) <link linkend="GValue">GValue</link> structure.
</entry></row>
<row><entry align="right"><parameter>g_type</parameter>&nbsp;:</entry>
<entry>	Type the <link linkend="GValue">GValue</link> should hold values of.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-value-copy">g_value_copy ()</title>
<programlisting>void        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><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>src_value</parameter>&nbsp;:</entry>
<entry>	An initialized <link linkend="GValue">GValue</link> structure.
</entry></row>
<row><entry align="right"><parameter>dest_value</parameter>&nbsp;:</entry>
<entry>	An initialized <link linkend="GValue">GValue</link> structure of the same type as <parameter>src_value</parameter>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-value-reset">g_value_reset ()</title>
<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><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>value</parameter>&nbsp;:</entry>
<entry>	An initialized <link linkend="GValue">GValue</link> structure.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-value-unset">g_value_unset ()</title>
<programlisting>void        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">GValue</link> structure.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>value</parameter>&nbsp;:</entry>
<entry>	An initialized <link linkend="GValue">GValue</link> structure.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-value-fits-pointer">g_value_fits_pointer ()</title>
<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><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>value</parameter>&nbsp;:</entry>
<entry>		An initialized <link linkend="GValue">GValue</link> structure.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>	<link linkend="TRUE-CAPS">TRUE</link> if <parameter>value</parameter> will fit inside a pointer value.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-value-peek-pointer">g_value_peek_pointer ()</title>
<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">g_value_fits_pointer</link>() returned <link linkend="TRUE-CAPS">TRUE</link> for the passed in value.
This is an internal function introduced mainly for C marshallers.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>value</parameter>&nbsp;:</entry>
<entry>		An initialized <link linkend="GValue">GValue</link> structure.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>	<link linkend="TRUE-CAPS">TRUE</link> if <parameter>value</parameter> will fit inside a pointer value.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-value-type-compatible">g_value_type_compatible ()</title>
<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">GValue</link> of type <parameter>src_type</parameter> can be copied into
a <link linkend="GValue">GValue</link> of type <parameter>dest_type</parameter>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>src_type</parameter>&nbsp;:</entry>
<entry> source type to be copied.
</entry></row>
<row><entry align="right"><parameter>dest_type</parameter>&nbsp;:</entry>
<entry>destination type for copying.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>  <literal>TRUE</literal> if <link linkend="g-value-copy">g_value_copy</link>() is possible with <parameter>src_type</parameter> and <parameter>dest_type</parameter>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-value-type-transformable">g_value_type_transformable ()</title>
<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">g_value_transform</link>() is able to transform values
of type <parameter>src_type</parameter> into values of type <parameter>dest_type</parameter>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>src_type</parameter>&nbsp;:</entry>
<entry> Source type.
</entry></row>
<row><entry align="right"><parameter>dest_type</parameter>&nbsp;:</entry>
<entry>Target type.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>  <literal>TRUE</literal> if the transformation is possible, <literal>FALSE</literal> otherwise.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-value-transform">g_value_transform ()</title>
<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 apropriate
to store in <parameter>dest_value</parameter>, e.g. to transform a <literal>G_TYPE_INT</literal> value
into a <literal>G_TYPE_FLOAT</literal> value. Performing transformations between
value types might incour 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><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>src_value</parameter>&nbsp;:</entry>
<entry> Source value.
</entry></row>
<row><entry align="right"><parameter>dest_value</parameter>&nbsp;:</entry>
<entry>Target value.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>   Whether a transformation rule was found and could be applied.
             Upon failing transformations, <parameter>dest_value</parameter> is left untouched.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="GValueTransform">GValueTransform ()</title>
<programlisting>void        (*GValueTransform)              (const <link linkend="GValue">GValue</link> *src_value,
                                             <link linkend="GValue">GValue</link> *dest_value);</programlisting>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>src_value</parameter>&nbsp;:</entry>
<entry>
</entry></row>
<row><entry align="right"><parameter>dest_value</parameter>&nbsp;:</entry>
<entry>


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-value-register-transform-func">g_value_register_transform_func ()</title>
<programlisting>void        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>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>src_type</parameter>&nbsp;:</entry>
<entry>
</entry></row>
<row><entry align="right"><parameter>dest_type</parameter>&nbsp;:</entry>
<entry>
</entry></row>
<row><entry align="right"><parameter>transform_func</parameter>&nbsp;:</entry>
<entry>


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-strdup-value-contents">g_strdup_value_contents ()</title>
<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">GValue</link>.
The main purpose of this function is to describe <link linkend="GValue">GValue</link> contents for debugging
output, the way in which the contents are described may change between different
GLib versions.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>value</parameter>&nbsp;:</entry>
<entry>  <link linkend="GValue">GValue</link> which contents are to be described.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>Newly allocated string.


</entry></row>
</tbody></tgroup></informaltable></refsect2>

</refsect1>



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

</refentry>
