From 080b09bb96e155975f50da58979a29c10318907e Mon Sep 17 00:00:00 2001 From: Jehan Date: Sat, 25 Jan 2025 00:37:55 +0100 Subject: [PATCH] libgimp*: GimpParamSpecValueArray struct also hidden away! New libgimpbase function: gimp_param_spec_value_array_get_element_spec() --- libgimpbase/gimpbase.def | 1 + libgimpbase/gimpvaluearray.c | 36 ++++++++++++++++++++++++++ libgimpbase/gimpvaluearray.h | 30 +++++---------------- libgimpconfig/gimpconfig-deserialize.c | 22 +++++++--------- 4 files changed, 54 insertions(+), 35 deletions(-) diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def index a7bb794bdd..a0701b6c98 100644 --- a/libgimpbase/gimpbase.def +++ b/libgimpbase/gimpbase.def @@ -158,6 +158,7 @@ EXPORTS gimp_param_spec_unit_percent_allowed gimp_param_spec_unit_pixel_allowed gimp_param_spec_value_array + gimp_param_spec_value_array_get_element_spec gimp_param_unit_get_type gimp_param_value_array_get_type gimp_parasite_compare diff --git a/libgimpbase/gimpvaluearray.c b/libgimpbase/gimpvaluearray.c index 0e00916520..e53d6862e5 100644 --- a/libgimpbase/gimpvaluearray.c +++ b/libgimpbase/gimpvaluearray.c @@ -590,6 +590,26 @@ gimp_value_array_truncate (GimpValueArray *value_array, * GIMP_TYPE_PARAM_VALUE_ARRAY */ +#define GIMP_PARAM_SPEC_VALUE_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_VALUE_ARRAY, GimpParamSpecValueArray)) + +typedef struct _GimpParamSpecValueArray GimpParamSpecValueArray; + +/** + * GimpParamSpecValueArray: + * @parent_instance: private #GParamSpec portion + * @element_spec: the #GParamSpec of the array elements + * @fixed_n_elements: default length of the array + * + * A #GParamSpec derived structure that contains the meta data for + * value array properties. + **/ +struct _GimpParamSpecValueArray +{ + GParamSpec parent_instance; + GParamSpec *element_spec; + gint fixed_n_elements; +}; + static void gimp_param_value_array_class_init (GParamSpecClass *klass); static void gimp_param_value_array_init (GParamSpec *pspec); static void gimp_param_value_array_finalize (GParamSpec *pspec); @@ -849,3 +869,19 @@ gimp_param_spec_value_array (const gchar *name, return G_PARAM_SPEC (aspec); } + +/** + * gimp_param_spec_value_array_get_element_spec: + * @pspec: a #GParamSpec to hold a #GimpParamSpecValueArray value. + * + * Returns: (transfer none): param spec for elements of the value array. + * + * Since: 3.0 + **/ +GParamSpec * +gimp_param_spec_value_array_get_element_spec (GParamSpec *pspec) +{ + g_return_val_if_fail (GIMP_IS_PARAM_SPEC_VALUE_ARRAY (pspec), NULL); + + return GIMP_PARAM_SPEC_VALUE_ARRAY (pspec)->element_spec; +} diff --git a/libgimpbase/gimpvaluearray.h b/libgimpbase/gimpvaluearray.h index 0535735526..b293e4f646 100644 --- a/libgimpbase/gimpvaluearray.h +++ b/libgimpbase/gimpvaluearray.h @@ -85,33 +85,17 @@ void gimp_value_array_truncate (GimpValueArray * #define GIMP_TYPE_PARAM_VALUE_ARRAY (gimp_param_value_array_get_type ()) #define GIMP_IS_PARAM_SPEC_VALUE_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_VALUE_ARRAY)) -#define GIMP_PARAM_SPEC_VALUE_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_VALUE_ARRAY, GimpParamSpecValueArray)) -typedef struct _GimpParamSpecValueArray GimpParamSpecValueArray; -/** - * GimpParamSpecValueArray: - * @parent_instance: private #GParamSpec portion - * @element_spec: the #GParamSpec of the array elements - * @fixed_n_elements: default length of the array - * - * A #GParamSpec derived structure that contains the meta data for - * value array properties. - **/ -struct _GimpParamSpecValueArray -{ - GParamSpec parent_instance; - GParamSpec *element_spec; - gint fixed_n_elements; -}; +GType gimp_param_value_array_get_type (void) G_GNUC_CONST; -GType gimp_param_value_array_get_type (void) G_GNUC_CONST; +GParamSpec * gimp_param_spec_value_array (const gchar *name, + const gchar *nick, + const gchar *blurb, + GParamSpec *element_spec, + GParamFlags flags); -GParamSpec * gimp_param_spec_value_array (const gchar *name, - const gchar *nick, - const gchar *blurb, - GParamSpec *element_spec, - GParamFlags flags); +GParamSpec * gimp_param_spec_value_array_get_element_spec (GParamSpec *pspec); G_END_DECLS diff --git a/libgimpconfig/gimpconfig-deserialize.c b/libgimpconfig/gimpconfig-deserialize.c index 15247923d2..9139fc604f 100644 --- a/libgimpconfig/gimpconfig-deserialize.c +++ b/libgimpconfig/gimpconfig-deserialize.c @@ -824,14 +824,14 @@ gimp_config_deserialize_value_array (GValue *value, GParamSpec *prop_spec, GScanner *scanner) { - GimpParamSpecValueArray *array_spec; - GimpValueArray *array; - GValue array_value = G_VALUE_INIT; - gint n_values; - GTokenType token; - gint i; + GParamSpec *element_spec; + GimpValueArray *array; + GValue array_value = G_VALUE_INIT; + gint n_values; + GTokenType token; + gint i; - array_spec = GIMP_PARAM_SPEC_VALUE_ARRAY (prop_spec); + element_spec = gimp_param_spec_value_array_get_element_spec (prop_spec); if (! gimp_scanner_parse_int (scanner, &n_values)) return G_TOKEN_INT; @@ -840,12 +840,10 @@ gimp_config_deserialize_value_array (GValue *value, for (i = 0; i < n_values; i++) { - g_value_init (&array_value, array_spec->element_spec->value_type); + g_value_init (&array_value, element_spec->value_type); - token = gimp_config_deserialize_value (&array_value, - config, - array_spec->element_spec, - scanner); + token = gimp_config_deserialize_value (&array_value, config, + element_spec, scanner); if (token == G_TOKEN_RIGHT_PAREN) gimp_value_array_append (array, &array_value);