GTypeInfo and class/instance sizes



Hi,

this may sound a bit strange, but if you have a GType (without
knowing anything in particular about that type) there doesn't
seem to be a way to get it's class and instance size.

If you want to derive that type, you need to fill in the class
and instance sizes into the GTypeInfo struct even if you don't
want to create new C types for it.

Basically, what I want to do is write a function like this:

====
GType
gtype_wrapper_create_object (GType parent_type, const gchar *name,
                             GTypeFlags flags)
{
    GTypeInfo *info;
    GType new_type;

    g_return_val_if_fail (G_TYPE_FUNDAMENTAL (parent_type) == G_TYPE_OBJECT,
                          G_TYPE_INVALID);

    info = g_new0 (GTypeInfo, 1);
    info->class_init = override_this_with_something_of_my_choice;
    info->class_finalize = override_this_with_something_of_my_choice;
    info->instance_init = override_this_with_something_of_my_choice;

    new_type = g_type_register_static (parent_type, name, info, flags);

    return new_type;
}
====

And then add properties, signals etc. to the derived type.

Would it be possible to change g_type_register_static() to allow
`info->class_size' and `info->instance_size' to be 0 and just use the
size of the parent class/instance in that case ?

-- 
Martin Baulig
martin gnome org (private)
baulig suse de (work)




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