From e10f510ce22c553ab82f6a750b0a4fbbf51b1267 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Sun, 3 Mar 2002 18:41:25 +0000 Subject: added gst_util_set_value_from_string. Original commit message from CVS: added gst_util_set_value_from_string. this could probably be refactored with gst_util_set_object_arg at a later date. --- gst/gstutils.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gst/gstutils.h | 2 +- 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/gst/gstutils.c b/gst/gstutils.c index d0177bb588..c44323f4fc 100644 --- a/gst/gstutils.c +++ b/gst/gstutils.c @@ -247,6 +247,88 @@ gst_util_dump_mem (guchar * mem, guint size) g_print ("\n"); } + +/** + * gst_util_set_value_from_string: + * @value: the value to set + * @value_str: the string to get the value from + * + * Converts the string to the type of the value and + * sets the value with it. + */ +void +gst_util_set_value_from_string(GValue *value, const gchar *value_str) +{ + + g_return_if_fail(value != NULL); + g_return_if_fail(value_str != NULL); + + GST_DEBUG(GST_CAT_PARAMS, "parsing '%s' to type %s\n", value_str, g_type_name(G_VALUE_TYPE(value))); + + switch (G_VALUE_TYPE(value)) { + case G_TYPE_STRING: + g_value_set_string(value, g_strdup(value_str)); + break; + case G_TYPE_ENUM: + case G_TYPE_INT: { + gint i; + sscanf (value_str, "%d", &i); + g_value_set_int(value, i); + break; + } + case G_TYPE_UINT: { + guint i; + sscanf (value_str, "%u", &i); + g_value_set_uint(value, i); + break; + } + case G_TYPE_LONG: { + glong i; + sscanf (value_str, "%ld", &i); + g_value_set_long(value, i); + break; + } + case G_TYPE_ULONG: { + gulong i; + sscanf (value_str, "%lu", &i); + g_value_set_ulong(value, i); + break; + } + case G_TYPE_BOOLEAN: { + gboolean i = FALSE; + if (!strncmp ("true", value_str, 4)) i = TRUE; + g_value_set_boolean(value, i); + break; + } + case G_TYPE_CHAR: { + gchar i; + sscanf (value_str, "%c", &i); + g_value_set_char(value, i); + break; + } + case G_TYPE_UCHAR: { + guchar i; + sscanf (value_str, "%c", &i); + g_value_set_uchar(value, i); + break; + } + case G_TYPE_FLOAT: { + gfloat i; + sscanf (value_str, "%f", &i); + g_value_set_float(value, i); + break; + } + case G_TYPE_DOUBLE: { + gfloat i; + sscanf (value_str, "%g", &i); + g_value_set_double(value, (gdouble)i); + break; + } + default: + break; + } +} + /** * gst_util_set_object_arg: * @object: the object to set the argument of diff --git a/gst/gstutils.h b/gst/gstutils.h index 2a445bfdfe..9124cfe885 100644 --- a/gst/gstutils.h +++ b/gst/gstutils.h @@ -42,7 +42,7 @@ gdouble gst_util_get_double_arg (GObject *object, const gchar *argname); const gchar* gst_util_get_string_arg (GObject *object, const gchar *argname); gpointer gst_util_get_pointer_arg (GObject *object, const gchar *argname); /*GtkWidget* gst_util_get_widget_property (GObject *object, const gchar *argname);*/ - +void gst_util_set_value_from_string(GValue *value, const gchar *value_str); void gst_util_set_object_arg (GObject *object, const gchar *name, const gchar *value); void gst_util_dump_mem (guchar *mem, guint size); -- cgit v1.2.3