mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
GVariant: add g_variant_default_value()
Returns various kinds of false, zero, empty arrays, etc.
This commit is contained in:
parent
6a1cb9f697
commit
b205dc77cb
@ -2813,6 +2813,7 @@ g_variant_get_type_string
|
||||
g_variant_is_of_type
|
||||
g_variant_is_container
|
||||
g_variant_compare
|
||||
g_variant_default_value
|
||||
|
||||
<SUBSECTION>
|
||||
g_variant_classify
|
||||
|
@ -1725,6 +1725,7 @@ g_variant_is_of_type
|
||||
g_variant_is_container
|
||||
g_variant_classify
|
||||
g_variant_compare
|
||||
g_variant_default_value
|
||||
|
||||
g_variant_new_boolean
|
||||
g_variant_new_byte
|
||||
|
@ -1377,7 +1377,7 @@ g_variant_dup_strv (GVariant *value,
|
||||
return strv;
|
||||
}
|
||||
|
||||
/* Type checking and querying {{{1 */
|
||||
/* Type checking, querying, default value {{{1 */
|
||||
/**
|
||||
* g_variant_get_type:
|
||||
* @value: a #GVariant
|
||||
@ -1455,7 +1455,6 @@ g_variant_is_container (GVariant *value)
|
||||
return g_variant_type_is_container (g_variant_get_type (value));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* g_variant_classify:
|
||||
* @value: a #GVariant
|
||||
@ -1500,6 +1499,35 @@ g_variant_classify (GVariant *value)
|
||||
return *g_variant_get_type_string (value);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_variant_default_value:
|
||||
* @type: a definite #GVariantType
|
||||
* @returns: a reference to a #GVariant of the requested type
|
||||
*
|
||||
* Returns the "default value" for @type. The default boolean instance
|
||||
* is false, the default value for any numeric type is (positive) zero,
|
||||
* the default array is empty and the default maybe instance is Nothing.
|
||||
* The default value for a tuple type is the tuple containing the
|
||||
* default value for each child. This is roughly equivalent to the
|
||||
* values produced by the serialiser when it detects invalid data.
|
||||
*
|
||||
* Since: 2.26
|
||||
**/
|
||||
GVariant *
|
||||
g_variant_default_value (const GVariantType *type)
|
||||
{
|
||||
GVariant *broken, *fixed;
|
||||
|
||||
g_return_val_if_fail (g_variant_type_is_definite (type), NULL);
|
||||
|
||||
/* let the serialiser figure it out */
|
||||
broken = g_variant_new_from_data (type, NULL, 0, FALSE, NULL, NULL);
|
||||
fixed = g_variant_get_normal_form (broken);
|
||||
g_variant_unref (broken);
|
||||
|
||||
return fixed;
|
||||
}
|
||||
|
||||
/* Pretty printer {{{1 */
|
||||
/**
|
||||
* g_variant_print_string:
|
||||
|
@ -62,6 +62,7 @@ gboolean g_variant_is_of_type (GVarian
|
||||
const GVariantType *type);
|
||||
gboolean g_variant_is_container (GVariant *value);
|
||||
GVariantClass g_variant_classify (GVariant *value);
|
||||
GVariant * g_variant_default_value (const GVariantType *type);
|
||||
GVariant * g_variant_new_boolean (gboolean boolean);
|
||||
GVariant * g_variant_new_byte (guchar byte);
|
||||
GVariant * g_variant_new_int16 (gint16 int16);
|
||||
|
Loading…
Reference in New Issue
Block a user