From 40caeab174b1197906fe00cab7287753139b2e88 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Fri, 24 May 2002 17:42:21 +0000 Subject: [PATCH] added deserialization of GValueArrays (untested). Added 2002-05-24 Michael Natterer * app/config/gimpconfig-deserialize.c: added deserialization of GValueArrays (untested). Added gimp_config_deserialize_value() which is factored out from gimp_config_deserialize_property(). --- ChangeLog | 6 ++ app/config/gimpconfig-deserialize.c | 116 ++++++++++++++++++++----- libgimpconfig/gimpconfig-deserialize.c | 116 ++++++++++++++++++++----- 3 files changed, 190 insertions(+), 48 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2f351c8e7e..1a0e9e15c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2002-05-24 Michael Natterer + + * app/config/gimpconfig-deserialize.c: added deserialization of + GValueArrays (untested). Added gimp_config_deserialize_value() + which is factored out from gimp_config_deserialize_property(). + 2002-05-24 Sven Neumann * plug-ins/FractalExplorer/Dialogs.c diff --git a/app/config/gimpconfig-deserialize.c b/app/config/gimpconfig-deserialize.c index b2e7701550..1f08ceb2ba 100644 --- a/app/config/gimpconfig-deserialize.c +++ b/app/config/gimpconfig-deserialize.c @@ -54,6 +54,10 @@ static GTokenType gimp_config_deserialize_unknown (GObject *object, GScanner *scanner); static GTokenType gimp_config_deserialize_property (GObject *object, GScanner *scanner); +static GTokenType gimp_config_deserialize_value (GValue *value, + GObject *object, + GParamSpec *prop_spec, + GScanner *scanner); static GTokenType gimp_config_deserialize_fundamental (GValue *value, GParamSpec *prop_spec, GScanner *scanner); @@ -70,6 +74,10 @@ static GTokenType gimp_config_deserialize_path (GValue *value, static GTokenType gimp_config_deserialize_color (GValue *value, GParamSpec *prop_spec, GScanner *scanner); +static GTokenType gimp_config_deserialize_value_array (GValue *value, + GObject *object, + GParamSpec *prop_spec, + GScanner *scanner); static GTokenType gimp_config_deserialize_any (GValue *value, GParamSpec *prop_spec, GScanner *scanner); @@ -235,32 +243,9 @@ gimp_config_deserialize_property (GObject *object, { /* nop */ } - else if (G_TYPE_FUNDAMENTAL (prop_spec->value_type) == G_TYPE_ENUM) - { - token = gimp_config_deserialize_enum (&value, prop_spec, scanner); - } - else if (G_TYPE_IS_FUNDAMENTAL (prop_spec->value_type)) - { - token = gimp_config_deserialize_fundamental (&value, prop_spec, scanner); - } - else if (prop_spec->value_type == GIMP_TYPE_MEMSIZE) - { - token = gimp_config_deserialize_memsize (&value, prop_spec, scanner); - } - else if (prop_spec->value_type == GIMP_TYPE_PATH) - { - token = gimp_config_deserialize_path (&value, - object, prop_spec, scanner); - } - else if (prop_spec->value_type == GIMP_TYPE_COLOR) - { - token = gimp_config_deserialize_color (&value, prop_spec, scanner); - } else { - /* This fallback will only work for value_types that */ - /* can be transformed from a string value. */ - token = gimp_config_deserialize_any (&value, prop_spec, scanner); + token = gimp_config_deserialize_value (&value, object, prop_spec, scanner); } if (token == G_TOKEN_RIGHT_PAREN && @@ -283,6 +268,45 @@ gimp_config_deserialize_property (GObject *object, return token; } +static GTokenType +gimp_config_deserialize_value (GValue *value, + GObject *object, + GParamSpec *prop_spec, + GScanner *scanner) +{ + if (G_TYPE_FUNDAMENTAL (prop_spec->value_type) == G_TYPE_ENUM) + { + return gimp_config_deserialize_enum (value, prop_spec, scanner); + } + else if (G_TYPE_IS_FUNDAMENTAL (prop_spec->value_type)) + { + return gimp_config_deserialize_fundamental (value, prop_spec, scanner); + } + else if (prop_spec->value_type == GIMP_TYPE_MEMSIZE) + { + return gimp_config_deserialize_memsize (value, prop_spec, scanner); + } + else if (prop_spec->value_type == GIMP_TYPE_PATH) + { + return gimp_config_deserialize_path (value, + object, prop_spec, scanner); + } + else if (prop_spec->value_type == GIMP_TYPE_COLOR) + { + return gimp_config_deserialize_color (value, prop_spec, scanner); + } + else if (prop_spec->value_type == G_TYPE_VALUE_ARRAY) + { + return gimp_config_deserialize_value_array (value, + object, prop_spec, scanner); + } + + /* This fallback will only work for value_types that + * can be transformed from a string value. + */ + return gimp_config_deserialize_any (value, prop_spec, scanner); +} + static GTokenType gimp_config_deserialize_fundamental (GValue *value, GParamSpec *prop_spec, @@ -580,6 +604,50 @@ gimp_config_deserialize_color (GValue *value, return token; } +static GTokenType +gimp_config_deserialize_value_array (GValue *value, + GObject *object, + GParamSpec *prop_spec, + GScanner *scanner) +{ + GParamSpecValueArray *array_spec; + GValueArray *array; + GValue array_value = { 0, }; + gint n_values; + GTokenType token; + gint i; + + array_spec = G_PARAM_SPEC_VALUE_ARRAY (prop_spec); + + if (g_scanner_peek_next_token (scanner) != G_TOKEN_INT) + return G_TOKEN_INT; + + g_scanner_get_next_token (scanner); + n_values = scanner->value.v_int; + + array = g_value_array_new (n_values); + + for (i = 0; i < n_values; i++) + { + g_value_init (&array_value, array_spec->element_spec->value_type); + + token = gimp_config_deserialize_value (&array_value, + object, + array_spec->element_spec, + scanner); + + if (token == G_TOKEN_RIGHT_PAREN) + g_value_array_append (array, &array_value); + + g_value_unset (&array_value); + + if (token != G_TOKEN_RIGHT_PAREN) + return token; + } + + return G_TOKEN_RIGHT_PAREN; +} + static GTokenType gimp_config_deserialize_any (GValue *value, GParamSpec *prop_spec, diff --git a/libgimpconfig/gimpconfig-deserialize.c b/libgimpconfig/gimpconfig-deserialize.c index b2e7701550..1f08ceb2ba 100644 --- a/libgimpconfig/gimpconfig-deserialize.c +++ b/libgimpconfig/gimpconfig-deserialize.c @@ -54,6 +54,10 @@ static GTokenType gimp_config_deserialize_unknown (GObject *object, GScanner *scanner); static GTokenType gimp_config_deserialize_property (GObject *object, GScanner *scanner); +static GTokenType gimp_config_deserialize_value (GValue *value, + GObject *object, + GParamSpec *prop_spec, + GScanner *scanner); static GTokenType gimp_config_deserialize_fundamental (GValue *value, GParamSpec *prop_spec, GScanner *scanner); @@ -70,6 +74,10 @@ static GTokenType gimp_config_deserialize_path (GValue *value, static GTokenType gimp_config_deserialize_color (GValue *value, GParamSpec *prop_spec, GScanner *scanner); +static GTokenType gimp_config_deserialize_value_array (GValue *value, + GObject *object, + GParamSpec *prop_spec, + GScanner *scanner); static GTokenType gimp_config_deserialize_any (GValue *value, GParamSpec *prop_spec, GScanner *scanner); @@ -235,32 +243,9 @@ gimp_config_deserialize_property (GObject *object, { /* nop */ } - else if (G_TYPE_FUNDAMENTAL (prop_spec->value_type) == G_TYPE_ENUM) - { - token = gimp_config_deserialize_enum (&value, prop_spec, scanner); - } - else if (G_TYPE_IS_FUNDAMENTAL (prop_spec->value_type)) - { - token = gimp_config_deserialize_fundamental (&value, prop_spec, scanner); - } - else if (prop_spec->value_type == GIMP_TYPE_MEMSIZE) - { - token = gimp_config_deserialize_memsize (&value, prop_spec, scanner); - } - else if (prop_spec->value_type == GIMP_TYPE_PATH) - { - token = gimp_config_deserialize_path (&value, - object, prop_spec, scanner); - } - else if (prop_spec->value_type == GIMP_TYPE_COLOR) - { - token = gimp_config_deserialize_color (&value, prop_spec, scanner); - } else { - /* This fallback will only work for value_types that */ - /* can be transformed from a string value. */ - token = gimp_config_deserialize_any (&value, prop_spec, scanner); + token = gimp_config_deserialize_value (&value, object, prop_spec, scanner); } if (token == G_TOKEN_RIGHT_PAREN && @@ -283,6 +268,45 @@ gimp_config_deserialize_property (GObject *object, return token; } +static GTokenType +gimp_config_deserialize_value (GValue *value, + GObject *object, + GParamSpec *prop_spec, + GScanner *scanner) +{ + if (G_TYPE_FUNDAMENTAL (prop_spec->value_type) == G_TYPE_ENUM) + { + return gimp_config_deserialize_enum (value, prop_spec, scanner); + } + else if (G_TYPE_IS_FUNDAMENTAL (prop_spec->value_type)) + { + return gimp_config_deserialize_fundamental (value, prop_spec, scanner); + } + else if (prop_spec->value_type == GIMP_TYPE_MEMSIZE) + { + return gimp_config_deserialize_memsize (value, prop_spec, scanner); + } + else if (prop_spec->value_type == GIMP_TYPE_PATH) + { + return gimp_config_deserialize_path (value, + object, prop_spec, scanner); + } + else if (prop_spec->value_type == GIMP_TYPE_COLOR) + { + return gimp_config_deserialize_color (value, prop_spec, scanner); + } + else if (prop_spec->value_type == G_TYPE_VALUE_ARRAY) + { + return gimp_config_deserialize_value_array (value, + object, prop_spec, scanner); + } + + /* This fallback will only work for value_types that + * can be transformed from a string value. + */ + return gimp_config_deserialize_any (value, prop_spec, scanner); +} + static GTokenType gimp_config_deserialize_fundamental (GValue *value, GParamSpec *prop_spec, @@ -580,6 +604,50 @@ gimp_config_deserialize_color (GValue *value, return token; } +static GTokenType +gimp_config_deserialize_value_array (GValue *value, + GObject *object, + GParamSpec *prop_spec, + GScanner *scanner) +{ + GParamSpecValueArray *array_spec; + GValueArray *array; + GValue array_value = { 0, }; + gint n_values; + GTokenType token; + gint i; + + array_spec = G_PARAM_SPEC_VALUE_ARRAY (prop_spec); + + if (g_scanner_peek_next_token (scanner) != G_TOKEN_INT) + return G_TOKEN_INT; + + g_scanner_get_next_token (scanner); + n_values = scanner->value.v_int; + + array = g_value_array_new (n_values); + + for (i = 0; i < n_values; i++) + { + g_value_init (&array_value, array_spec->element_spec->value_type); + + token = gimp_config_deserialize_value (&array_value, + object, + array_spec->element_spec, + scanner); + + if (token == G_TOKEN_RIGHT_PAREN) + g_value_array_append (array, &array_value); + + g_value_unset (&array_value); + + if (token != G_TOKEN_RIGHT_PAREN) + return token; + } + + return G_TOKEN_RIGHT_PAREN; +} + static GTokenType gimp_config_deserialize_any (GValue *value, GParamSpec *prop_spec,