mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-31 04:43:06 +02:00
Dump the default value of object properties
We use g_param_spec_get_default_value() to get the default GValue of a GParamSpec, and then we serialize it into a string according to the value's own contents and type.
This commit is contained in:
parent
7e8a8bfb14
commit
3063615313
47
gdump.c
47
gdump.c
@ -119,6 +119,40 @@ invoke_error_quark (GModule *self, const char *symbol, GError **error)
|
|||||||
return sym ();
|
return sym ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A simpler version of g_strdup_value_contents(), but with stable
|
||||||
|
* output and less complex semantics
|
||||||
|
*/
|
||||||
|
static char *
|
||||||
|
value_to_string (const GValue *value)
|
||||||
|
{
|
||||||
|
if (G_VALUE_HOLDS_STRING (value))
|
||||||
|
{
|
||||||
|
const char *s = g_value_get_string (value);
|
||||||
|
|
||||||
|
if (s == NULL)
|
||||||
|
return g_strdup ("NULL");
|
||||||
|
|
||||||
|
return g_strescape (s, NULL);
|
||||||
|
}
|
||||||
|
else if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING))
|
||||||
|
{
|
||||||
|
GValue tmp = G_VALUE_INIT;
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
g_value_init (&tmp, G_TYPE_STRING);
|
||||||
|
g_value_transform (value, &tmp);
|
||||||
|
s = g_strescape (g_value_get_string (&tmp), NULL);
|
||||||
|
g_value_unset (&tmp);
|
||||||
|
|
||||||
|
if (s == NULL)
|
||||||
|
return g_strdup ("NULL");
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return g_strdup ("NULL");
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dump_properties (GType type, GOutputStream *out)
|
dump_properties (GType type, GOutputStream *out)
|
||||||
{
|
{
|
||||||
@ -147,9 +181,18 @@ dump_properties (GType type, GOutputStream *out)
|
|||||||
if (prop->owner_type != type)
|
if (prop->owner_type != type)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
escaped_printf (out, " <property name=\"%s\" type=\"%s\" flags=\"%d\"/>\n",
|
const GValue *v = g_param_spec_get_default_value (prop);
|
||||||
prop->name, g_type_name (prop->value_type), prop->flags);
|
char *default_value = value_to_string (v);
|
||||||
|
|
||||||
|
escaped_printf (out, " <property name=\"%s\" type=\"%s\" flags=\"%d\" default-value=\"%s\"/>\n",
|
||||||
|
prop->name,
|
||||||
|
g_type_name (prop->value_type),
|
||||||
|
prop->flags,
|
||||||
|
default_value);
|
||||||
|
|
||||||
|
g_free (default_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (props);
|
g_free (props);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user