mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-14 19:48:05 +02:00
param: Add g_param_value_is_valid
This is wrapper for the new value_is_valid vfunc, but it falls back to using value_validate to obtain the same information.
This commit is contained in:
parent
bdc8b025c5
commit
dacfe8c88a
@ -531,6 +531,7 @@ g_param_spec_get_default_value
|
||||
g_param_value_set_default
|
||||
g_param_value_defaults
|
||||
g_param_value_validate
|
||||
g_param_value_is_valid
|
||||
g_param_value_convert
|
||||
g_param_values_cmp
|
||||
g_param_spec_is_valid_name
|
||||
|
@ -705,6 +705,51 @@ g_param_value_validate (GParamSpec *pspec,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_param_value_is_valid:
|
||||
* @pspec: a valid #GParamSpec
|
||||
* @value: a #GValue of correct type for @pspec
|
||||
*
|
||||
* Return whether the contents of @value comply with the specifications
|
||||
* set out by @pspec.
|
||||
*
|
||||
* Returns: whether the contents of @value comply with the specifications
|
||||
* set out by @pspec.
|
||||
*
|
||||
* Since: 2.74
|
||||
*/
|
||||
gboolean
|
||||
g_param_value_is_valid (GParamSpec *pspec,
|
||||
const GValue *value)
|
||||
{
|
||||
GParamSpecClass *class;
|
||||
|
||||
g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), TRUE);
|
||||
g_return_val_if_fail (G_IS_VALUE (value), TRUE);
|
||||
g_return_val_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value), TRUE);
|
||||
|
||||
class = G_PARAM_SPEC_GET_CLASS (pspec);
|
||||
|
||||
if (class->value_is_valid)
|
||||
return class->value_is_valid (pspec, value);
|
||||
else if (class->value_validate)
|
||||
{
|
||||
GValue val = G_VALUE_INIT;
|
||||
gboolean changed;
|
||||
|
||||
g_value_init (&val, G_VALUE_TYPE (value));
|
||||
g_value_copy (value, &val);
|
||||
|
||||
changed = class->value_validate (pspec, &val);
|
||||
|
||||
g_value_unset (&val);
|
||||
|
||||
return !changed;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_param_value_convert:
|
||||
* @pspec: a valid #GParamSpec
|
||||
|
@ -326,6 +326,9 @@ gboolean g_param_value_defaults (GParamSpec *pspec,
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
gboolean g_param_value_validate (GParamSpec *pspec,
|
||||
GValue *value);
|
||||
GLIB_AVAILABLE_IN_2_74
|
||||
gboolean g_param_value_is_valid (GParamSpec *pspec,
|
||||
const GValue *value);
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
gboolean g_param_value_convert (GParamSpec *pspec,
|
||||
const GValue *src_value,
|
||||
|
Loading…
x
Reference in New Issue
Block a user