<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;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)
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);
<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="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>
<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>
</refsect1>

<refsect1>
<title>Details</title>
<refsect2>
<title><anchor id="G-VALUE-HOLDS-CAPS"/>G_VALUE_HOLDS()</title>
<indexterm><primary>G_VALUE_HOLDS</primary></indexterm><programlisting>#define G_VALUE_HOLDS(value,type)	(G_TYPE_CHECK_VALUE_TYPE ((value), (type)))
</programlisting>
<para>
Returns <link linkend="TRUE-CAPS"><type>TRUE</type></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"><type>NULL</type></link> and issue a
warning if the check fails.
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&nbsp;:</term>
<listitem><simpara>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>type</parameter>&nbsp;:</term>
<listitem><simpara>


</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="G-VALUE-TYPE-CAPS"/>G_VALUE_TYPE()</title>
<indexterm><primary>G_VALUE_TYPE</primary></indexterm><programlisting>#define	G_VALUE_TYPE(value)		(((GValue*) (value))-&gt;g_type)
</programlisting>
<para>
Returns the type identifier of <parameter>value</parameter>.
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&nbsp;:</term>
<listitem><simpara>A <link linkend="GValue"><type>GValue</type></link> structure.


</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="G-VALUE-TYPE-NAME-CAPS"/>G_VALUE_TYPE_NAME()</title>
<indexterm><primary>G_VALUE_TYPE_NAME</primary></indexterm><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><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&nbsp;:</term>
<listitem><simpara>A <link linkend="GValue"><type>GValue</type></link> structure.


</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="G-TYPE-IS-VALUE-CAPS"/>G_TYPE_IS_VALUE()</title>
<indexterm><primary>G_TYPE_IS_VALUE</primary></indexterm><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"><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><variablelist role="params">
<varlistentry><term><parameter>type</parameter>&nbsp;:</term>
<listitem><simpara>	  A <link linkend="GType"><type>GType</type></link> value.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>Whether <parameter>type</parameter> is suitable as a <link linkend="GValue"><type>GValue</type></link> type.


</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="G-TYPE-IS-VALUE-ABSTRACT-CAPS"/>G_TYPE_IS_VALUE_ABSTRACT()</title>
<indexterm><primary>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>
Returns <literal>TRUE</literal> 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><variablelist role="params">
<varlistentry><term><parameter>type</parameter>&nbsp;:</term>
<listitem><simpara>A <link linkend="GType"><type>GType</type></link> value.


</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="G-IS-VALUE-CAPS"/>G_IS_VALUE()</title>
<indexterm><primary>G_IS_VALUE</primary></indexterm><programlisting>#define	G_IS_VALUE(value)		(G_TYPE_CHECK_VALUE (value))
</programlisting>
<para>
Returns <link linkend="TRUE-CAPS"><type>TRUE</type></link> if <parameter>value</parameter> is a valid and initialized <link linkend="GValue"><type>GValue</type></link> structure.
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&nbsp;:</term>
<listitem><simpara>A <link linkend="GValue"><type>GValue</type></link> structure.


</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="GValue"/>struct GValue</title>
<indexterm><primary>GValue</primary></indexterm><programlisting>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 <link linkend="GValue"><type>GValue</type></link>.data[] union, and the g_type member should
only be accessed through the <link linkend="G-VALUE-TYPE-CAPS"><function>G_VALUE_TYPE()</function></link> macro.
</para></refsect2>
<refsect2>
<title><anchor id="G-TYPE-VALUE-CAPS"/>G_TYPE_VALUE</title>
<indexterm><primary>G_TYPE_VALUE</primary></indexterm><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>
<indexterm><primary>G_TYPE_VALUE_ARRAY</primary></indexterm><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>
<indexterm><primary>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><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&nbsp;:</term>
<listitem><simpara>		A zero-filled (uninitialized) <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>g_type</parameter>&nbsp;:</term>
<listitem><simpara>	Type the <link linkend="GValue"><type>GValue</type></link> should hold values of.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>


</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-value-copy"/>g_value_copy ()</title>
<indexterm><primary>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><variablelist role="params">
<varlistentry><term><parameter>src_value</parameter>&nbsp;:</term>
<listitem><simpara>	An initialized <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>dest_value</parameter>&nbsp;:</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>
<title><anchor id="g-value-reset"/>g_value_reset ()</title>
<indexterm><primary>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><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&nbsp;:</term>
<listitem><simpara>	An initialized <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>


</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-value-unset"/>g_value_unset ()</title>
<indexterm><primary>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><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&nbsp;:</term>
<listitem><simpara>	An initialized <link linkend="GValue"><type>GValue</type></link> structure.


</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-value-fits-pointer"/>g_value_fits_pointer ()</title>
<indexterm><primary>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><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&nbsp;:</term>
<listitem><simpara>		An initialized <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>	<link linkend="TRUE-CAPS"><type>TRUE</type></link> if <parameter>value</parameter> will fit inside a pointer value.


</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-value-peek-pointer"/>g_value_peek_pointer ()</title>
<indexterm><primary>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"><type>TRUE</type></link> for the passed in value.
This is an internal function introduced mainly for C marshallers.
</para><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&nbsp;:</term>
<listitem><simpara>		An initialized <link linkend="GValue"><type>GValue</type></link> structure.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>	<link linkend="TRUE-CAPS"><type>TRUE</type></link> if <parameter>value</parameter> will fit inside a pointer value.


</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-value-type-compatible"/>g_value_type_compatible ()</title>
<indexterm><primary>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><variablelist role="params">
<varlistentry><term><parameter>src_type</parameter>&nbsp;:</term>
<listitem><simpara> source type to be copied.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>dest_type</parameter>&nbsp;:</term>
<listitem><simpara>destination type for copying.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>  <literal>TRUE</literal> 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>
<title><anchor id="g-value-type-transformable"/>g_value_type_transformable ()</title>
<indexterm><primary>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><variablelist role="params">
<varlistentry><term><parameter>src_type</parameter>&nbsp;:</term>
<listitem><simpara> Source type.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>dest_type</parameter>&nbsp;:</term>
<listitem><simpara>Target type.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>  <literal>TRUE</literal> if the transformation is possible, <literal>FALSE</literal> otherwise.


</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-value-transform"/>g_value_transform ()</title>
<indexterm><primary>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 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><variablelist role="params">
<varlistentry><term><parameter>src_value</parameter>&nbsp;:</term>
<listitem><simpara> Source value.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>dest_value</parameter>&nbsp;:</term>
<listitem><simpara>Target value.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</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>
<title><anchor id="GValueTransform"/>GValueTransform ()</title>
<indexterm><primary>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><variablelist role="params">
<varlistentry><term><parameter>src_value</parameter>&nbsp;:</term>
<listitem><simpara> Source value.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>dest_value</parameter>&nbsp;:</term>
<listitem><simpara>Target value.


</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-value-register-transform-func"/>g_value_register_transform_func ()</title>
<indexterm><primary>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><variablelist role="params">
<varlistentry><term><parameter>src_type</parameter>&nbsp;:</term>
<listitem><simpara> Source type.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>dest_type</parameter>&nbsp;:</term>
<listitem><simpara>Target type.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>transform_func</parameter>&nbsp;:</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>
<title><anchor id="g-strdup-value-contents"/>g_strdup_value_contents ()</title>
<indexterm><primary>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><variablelist role="params">
<varlistentry><term><parameter>value</parameter>&nbsp;:</term>
<listitem><simpara>  <link linkend="GValue"><type>GValue</type></link> which contents are to be described.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>Newly allocated string.


</simpara></listitem></varlistentry>
</variablelist></refsect2>

</refsect1>



<refsect1>
<title>See Also</title>
<para>
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 Standard Values API for details.
</para>
</refsect1>

</refentry>
