[glib/param-speedups2: 15/19] param: Add g_param_value_is_valid
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/param-speedups2: 15/19] param: Add g_param_value_is_valid
- Date: Mon, 23 May 2022 20:20:18 +0000 (UTC)
commit dacfe8c88a123e4ec249a352f35a35ea345ff35e
Author: Matthias Clasen <mclasen redhat com>
Date: Fri May 20 08:46:39 2022 -0400
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.
docs/reference/gobject/gobject-sections.txt | 1 +
gobject/gparam.c | 45 +++++++++++++++++++++++++++++
gobject/gparam.h | 3 ++
3 files changed, 49 insertions(+)
---
diff --git a/docs/reference/gobject/gobject-sections.txt b/docs/reference/gobject/gobject-sections.txt
index c742de9f63..dc1c89e3e2 100644
--- a/docs/reference/gobject/gobject-sections.txt
+++ b/docs/reference/gobject/gobject-sections.txt
@@ -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
diff --git a/gobject/gparam.c b/gobject/gparam.c
index 4311dbbc68..873f2c3c66 100644
--- a/gobject/gparam.c
+++ b/gobject/gparam.c
@@ -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
diff --git a/gobject/gparam.h b/gobject/gparam.h
index 76629aa117..d92d6f237c 100644
--- a/gobject/gparam.h
+++ b/gobject/gparam.h
@@ -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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]