Re: G_PARAM_SPEC_VALUE_TYPE() question



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




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