op_prg_list_map()
Abstract
Applies a user-specified function to elements in the specified list.
Note: This KP is a macro call included for backward compatibility only. Use prg_list_map() in new code.
Syntax
op_prg_list_map (list_ptr, mapfun, state)
| Argument | Type | Description |
|---|---|---|
ist_ptr |
List* |
pointer to the list-of-interest [A pointer to a list can be obtained from several KPs: an empty list can be originally obtained from op_prg_list_create(), a list representing the contents of a file can be obtained from op_prg_gdf_read(), or a list can be allocated by user code, and initialized via op_prg_list_init().]. |
mapfun |
List_Map_Proc |
procedure to apply to each element of the specified list. See Details for prototype. |
state |
void* |
pointer used as the first argument in mapfun. |
Return Type
void
No return value.
Example
/* read a GDF file */
routing_list_ptr = op_prg_gdf_read ("routing_table");
/* Print out the contents of the list by applying */
/* the ’printf’ function to its elements. */
op_prg_list_map (routing_list_ptr, printf, "%s\n");
Details
The mapfun procedure is applied to each element of the list, starting at the head, until all elements are visited, or until mapfun returns 0. Mapfun is prototyped as follows:
int
List_Map_Proc (void* state, void* elem_ptr)
The mapping function is passed the state argument of op_prg_list_map as its first argument and a list element pointer as its second.
Note: This KP is MT unsafe, as described in “Multi-Threading Safety“ on page 11. Access to shared lists must be externally serialized.
Purpose
Applies a user-specified function to all or some elements of the specified list.
Errors
- Program Abort: Segmentation Violation (due to an invalid list pointer or malformed list).
Reference
- Use the KP op_prg_list_create() to allocate a new, empty list
- Use the KP op_prg_list_insert() to insert an element into a list
- Use the KP op_prg_list_insert_sorted() to insert an element into a list at the proper position