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

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com