Re: gvalue type conversions



On 8 Jan 2001, Owen Taylor wrote:

> 
> Sven Neumann <sven gimp org> writes:
> 
> > Havoc Pennington <hp redhat com> writes:
> > 
> > > It would seem useful to support conversions from most primitive types
> > > (int, float, etc.) to strings, for the purposes of the TreeView. If
> > > you have a GtkListStore containing integers, for example, it would be
> > > convenient if GtkCellRendererText could automatically display those as
> > > text.  It looks like adding an int->string conversion makes this
> > > happen automatically, because you can set the "text" property from a
> > > GValue with type G_VALUE_INT.
> > 
> > Yes please. At the moment we do this by hand when serializing/deserializing
> > values. Having the string conversion routines in glib would be nice.
> 
> We can't do this, because there is no support for failure in
> the GValue conversion API. So you can do int => string, but
> string => int doesn't work - something built on top
> of that won't be robust.

that's right.
1) i wouldn't really recommend automated value conversions for serialization
   uses
2) i don't want to explode GValue conversions beyond simple cando/cantdo
   return values, since they're mostly in place to cover up for type
   promotions when setting/getting object properties or when passing
   parameters to a function invocation.
   anything beyond that scope usually requires specialized implementations
   that also deal with various error cases

as an example, reading out an integer property from an object with
a STRING GValue to get the stringified version right away might still
be bearable, doing so for a boxed property certainly isn't.

otoh, that same mechanism shouldn't be used for deserialization, what
do you expect GLib to recognize as a TRUE boolean: "t", "true", "ja",
"naja, vielleicht", "!0", "positive"? you better be deterministic with
your own deserialization parser there ;)

> 
> Regards,
>                                         Owen
> 

---
ciaoTJ






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]