Missing support for generic containers
Submitted by Michal Hruby
Link to original bug (#639908)
Description
Introspection currently doesn't have any support for generic containers, for example libgee provides containers where the types of the elements inside the container are specified during runtime. This information would be very useful for dynamic languages to be able to work with these, while static languages can still use a generic type like "gpointer".
I propose to add annotations similar to (array) ones - specifically (generic), (generic type-method) and (generic type-parameter).
Therefore a generic method could look like this:
/**
* mylib_container_get_item:
*
* @container: A #Container.
* @index: Element index.
* Return value: (transfer full) (generic type-method=mylib_container_get_element_type): Element from the collection.
*/
gpointer
mylib_container_get_item (MylibContainer *container, int index)
{
return container->priv->data[index];
}
/** .. */
GType
mylib_container_get_element_type (MylibContainer *container)
{
return container->priv->element_type;
}
/**
* mylib_heterogenous_container_get_item:
*
* @container: A #Container.
* @index: Element index.
* @elem_type: (out) Type of the element.
* Return value: (transfer full) (generic type-parameter=elem_type): Element from the collection.
*/
gpointer
mylib_heterogenous_container_get_item (MylibContainer *container, int index, GType *elem_type)
{
if (elem_type) *elem_type = container->priv->data_types[index];
return container->priv->data[index];
}
A possible gir xml could be:
<method name="get_item"
c:identifier="mylib_container_get_item">
<return-value transfer-ownership="full">
<generic type-method="mylib_container_get_element_type">
<type name="gpointer" c:type="gpointer"/>
</generic>
</return-value>
<parameters>
<parameter name="index" transfer-ownership="none">
<type name="gint" c:type="gint"/>
</parameter>
</parameters>
</method>
Blocking
Edited by Philip Chimento