Re: Function completion for GVariant maybe types?
- From: Markus Elfring <Markus Elfring web de>
- To: gtk-devel-list gnome org
- Cc: Simon McVittie <simon mcvittie collabora co uk>
- Subject: Re: Function completion for GVariant maybe types?
- Date: Fri, 22 Feb 2013 14:33:31 +0100
I imagine that this approach might need a bit more fine-tuning to avoid
unnecessary type checks.
Would the following implementation be useful in your software library?
diff --git a/glib/gvariant.c b/glib/gvariant.c
index c3d1947..ffa67da 100644
--- a/glib/gvariant.c
+++ b/glib/gvariant.c
@@ -682,6 +682,23 @@ g_variant_new_maybe (const GVariantType *child_type,
return value;
}
+GVariant *
+g_variant_new_nothing_from_type (GVariant const * value)
+{
+ if (value == NULL)
+ return g_variant_new ("ms", NULL);
+ else
+ {
+ GVariantType const * const type = g_variant_get_type (value);
+ gchar const * type_string = (gchar const *) type;
+
+ if (*type_string == 'm')
+ return g_variant_new_maybe ((GVariantType const *) ++type_string, NULL);
+ else
+ return g_variant_new_maybe (type, NULL);
+ }
+}
+
/**
* g_variant_get_maybe:
* @value: a maybe-typed value
Regards,
Markus
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]