GNOME Bugzilla – Bug 81040
G_TYPE_GTYPE is missing from fundamental types
Last modified: 2011-02-18 15:49:17 UTC
I think the fundamental types should be extended to include G_TYPE_GTYPE. Then GValue needs to be extended so it can hold GType and GParamSpecGType should be introduced. I see a couple of usage cases for this essential feature. Container objects for example want to know about the type of elements they hold. GimpContainer is such an example where we had to use a GParamSpecPointer where GParamSpecGType would have been the appropriate solution. This workaround fails if you try to write a serializable container where you'd want to serialize the container properties in a generic fashion. This is not possible if the element_type property is a pointer property. Gtypes may also be used in signal emissions used in generic object factories. G_TYPE_GTYPE would be useful here too. Unless I miss something the addition of G_TYPE_GTYPE should be pretty straightforward. Let me know if you would like me to come up with a patch.
i don't see why this needs to be a new fundamental. as for the merit of it, i agree, i think i used something like type-gtype in beast for a while, but that was nothing more than g_pointer_type_register_static("GType"). a paramspec for that should be pretty easy to create (derive from GParamSpecPointer and add a GType default_type; field, that's it), so a patch would be apprechiated.
Created attachment 54619 [details] [review] a patch Here is a patch which adds a fundamental type for GType, a param spec to go with it, and setter/getter for GValue. The param spec allows to restrict the possible values by specifying an "is_a_type".
patch sent to timj for review
the patch required some fixes, as it tried to partly implement a fundamental type in one place. that's not quite suitable, fundamental types require much more things to be implemented. as outlined earlier, i don't think we need a new fundamental type here though, rather, i've added a G_TYPE_POINTER variant. this needs some test code to be added though, i.e. something that simply makes sue of the newly written accessors, and tries to compare and vbalidate GType values.
Added a bunch of tests to tests/gobject/gvalue-test and tests/gobject/paramspec-test
the tests look good. thanks matthias.