Re: Function completion for GVariant maybe types?
- From: Simon McVittie <simon mcvittie collabora co uk>
- To: gtk-devel-list gnome org
- Subject: Re: Function completion for GVariant maybe types?
- Date: Mon, 10 Oct 2011 20:43:21 +0100
On Mon, 10 Oct 2011 at 20:00:32 +0200, Markus Elfring wrote:
> 1. g_variant_is_maybe
> A new predicate function that can provide another type check (like
> "g_variant_is_container").
g_variant_type_is_maybe exists. If you have a GVariant* variable, you should
usually know what type it is already, but if not, g_variant_get_type() will
tell you.
> 2. g_variant_can_be_nothing/undefined/optional/maybe
That's exactly g_variant_type_is_maybe (g_variant_get_type (v))
(or g_variant_is_maybe (v) if someone adds that). The only nullable GVariants
are those that have a "maybe" type.
> 3. g_variant_convert_to_maybe
> I see a need for a alternative to the interface "g_variant_new_maybe". I
> would like to replace a maybe instance directly instead of allocating a new one.
GVariants are immutable. Once a GVariant instance has been created, you can't
change its value/contents - you can only throw it away and create a new
GVariant.
(... but if you have a (GVariant *) variable, you can make it point to a
different GVariant, of course.)
The rationale is basically the same as Python strings being immutable. It
makes them a lot simpler to reason about, by giving them "value" semantics.
> 4. g_variant_set_to_nothing/none
> How should a GVariant variable be reset to the special marker "nothing" after
> it was used with other concrete values for a while?
There's no such thing as "a GVariant variable" (or at least, not usefully),
and if there was, it'd be immutable.
You can reset a (GVariant *) variable to point to a variant representing
"nothing" the same way you'd make it point to anything else. I'm using
"maybe int32" as the type here, for the sake of an example.
GVariant *v;
v = g_variant_new_maybe (G_VARIANT_TYPE ("mi"), g_variant_new_int32 (42));
...
g_variant_unref (v);
v = g_variant_new_maybe (G_VARIANT_TYPE ("mi"), NULL);
...
g_variant_unref (v);
v = g_variant_new_maybe (G_VARIANT_TYPE ("mi"), g_variant_new_int32 (23));
...
g_variant_unref (v);
Regards,
S
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]