G_PARAM_SPEC_VALUE_TYPE() question

2012-05-15 Thread Marc Balmer
Hi

I want to set properties of an object using the g_value_set_type()
functions and to cast my value (which I get from a Lua script, which
e.g. does not differentiate between integers and floats) I need to know
the type of the property.

Ideally something like the following:

switch (G_PARAM_SPEC_VALUE_TYPE(prop)) {
case G_TYPE_INT:
g_value_set_int(...);
break;
case G_TYPE_STRING:
g_value_set_string(...);
break;
}

You get the idea...  This works for basic types, but not for e.g.
GParamEnum, i.e. when G_PARAM_SPEC_TYPE_NAME() returns GParamEnum,
above scheme seems not to work.  There is a type G_TYPE_ENUM, but it is
not returned in case of GParamEnum.

(In my example I want to set the 'tab-pos' property of a Notebook widget).

Any hints how I can discriminate on the type of an enum?

- mb
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: G_PARAM_SPEC_VALUE_TYPE() question

2012-05-15 Thread David Nečas
On Tue, May 15, 2012 at 08:39:12AM +0200, Marc Balmer wrote:
 I want to set properties of an object using the g_value_set_type()
 functions and to cast my value (which I get from a Lua script, which
 e.g. does not differentiate between integers and floats) I need to know
 the type of the property.
 
 Ideally something like the following:
 
 switch (G_PARAM_SPEC_VALUE_TYPE(prop)) {
 case G_TYPE_INT:
   g_value_set_int(...);
   break;
 case G_TYPE_STRING:
   g_value_set_string(...);
   break;
 }
 
 You get the idea...  This works for basic types, but not for e.g.
 GParamEnum, i.e. when G_PARAM_SPEC_TYPE_NAME() returns GParamEnum,
 above scheme seems not to work.  There is a type G_TYPE_ENUM, but it is
 not returned in case of GParamEnum.

You need to use g_type_is_a(...) on the type obtained from
G_PARAM_SPEC_TYPE_NAME(), not direct comparison to some explicit GTypes.
Then it will work also with subclassable types such as enums.

Yeti

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list