next up previous contents
Next: List and Ddlist functions Up: Generic Lists Previous: Recursive Lists   Contents

Applying Functions

It is often convenient to apply a function to all members of a list (or through some other data structure used in Tina). To facilitate this a standard form of indirect function calling has been adopted with the following arguments

void indirect_function(void *ptr, int type, void* data)

The function call for applying this function to all the members of a list is

void    list_apply_func(List * list, void (*func) ( /* ??? */ ), void *data)
{
    List   *lptr;

    for (lptr = list; lptr != NULL; lptr = lptr->next)
        func(lptr->to, lptr->type, data);
}
The type field supplied to the indirectly called function is obtained from the list element. Note that for some Tina structures the associated function apply procedure provides additional arguments. These follow the standard ones to allow indirect function calls of the general type as well as more specific variants.

For example the function

void    er_apply_to_all_edges(Imrect * edgerect,
                              void (*edge_save_pos_prop),
                              (void *)IMPOS)

applies the following function call to all edges in the edgerect

void    edge_save_pos_prop(Edgel * edge, int type, int prop_type)
{
    Vec2   *p;

    if (type != EDGE || edge == NULL)
        return;

    p = vec2_alloc();
    *p = edge->pos;
    edge->props = proplist_addifnp(edge->props, (void *) p, prop_type, vec2_free
, true);
}

Where 1#1 is the proplist type for the structure to be added to each edgel proplist.

Two other forms of standard function call exist in Tina, these are for copying and updating elementary data referenced by various Tina connector structures (including lists).

void *copy_func(void *ptr, int type, void *data)

void *update_func(void* ptr, int *type_ptr, void *data)

Each is very similar except that the update version is also able to change the type field by which the data is referenced.


next up previous contents
Next: List and Ddlist functions Up: Generic Lists Previous: Recursive Lists   Contents
root 2017-11-22