[glib/param-speedups2: 1/3] param: Add g_param_value_is_valid




commit 935e9811a61b3236b5fd5a16d4b55130fcb9f6dd
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                            | 36 +++++++++++++++++++++++++++++
 gobject/gparam.h                            |  3 +++
 3 files changed, 40 insertions(+)
---
diff --git a/docs/reference/gobject/gobject-sections.txt b/docs/reference/gobject/gobject-sections.txt
index 278c756104..1cc679cf9c 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..72ab796dd2 100644
--- a/gobject/gparam.c
+++ b/gobject/gparam.c
@@ -705,6 +705,42 @@ 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 = *value;
+      return !class->value_validate (pspec, &val);
+    }
+
+  return TRUE;
+}
+
 /**
  * g_param_value_convert:
  * @pspec: a valid #GParamSpec
diff --git a/gobject/gparam.h b/gobject/gparam.h
index 387201d934..5bb45ad3e2 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]