| Maestro Audio Framework v 1.0 NXP Semiconductors

container.h File Reference

Contains macros and functions that are common and generic across OSA container data types. More...

## Macros
#define | container_iter_end(name, c, ci) (name##_iter_equal(ci, name##_iter_end(c)))
| Returns the iterator pointing to the end of the container. More...
#define | container_foreach(name, c, ci, n)
| Iterate over each element in a container. More...

## Detailed Description

Data types have been defined for iteration to allow applications to be as portable as possible, and include: list, doubly linked list, vector, and associated container iterators. Additional iterators can be defined by the application developer using the criteria below. Each container may define a set of iterator functions and an iterator data type. The macros and functions detailed below can operate on all container types as long as the iterators are defined. The 'container' prefix for the container macros specifies the container type.

The iterator functions should look like these:

Iterator container_iter_begin(container *data) - Returns an iterator pointing to the first element in the container.

Iterator container_iter_end(container *data) - Returns an iterator pointing to the end of the container.

Iterator container_iter_next(Iterator iter) - Returns an iterator pointing to the next element in the container.

Iterator container_iter_prev(Iterator iter) - Returns an iterator pointing to the previous element in the container.

void *container_iter_node(Iterator iter) - Returns the data contained in the element pointed to by the iterator.

bool container_iter_equal(Iterator iter_a, Iterator iter_b) - Compares two iterators for equality.

## Macro Definition Documentation

## ◆ container_iter_end

#define container_iter_end | ( |  | name,
|  |  | c,
|  |  | ci
| ) |  | (name##_iter_equal(ci, name##_iter_end(c)))

Parameters

  name | prefix of the container (eg: list)
  c | pointer to container data (eg: List*)
  ci | container iterator (eg: ListIter)

## ◆ container_foreach

#define container_foreach | ( |  | name,
|  |  | c,
|  |  | ci,
|  |  | n
| ) |  |

Value:
for (ci = name##_iter_begin(c); \
(!container_iter_end(name, c, ci) && \
((n = name##_iter_node(ci)), 1)); \
ci = name##_iter_next(ci))
container_iter_end
#define container_iter_end(name, c, ci)
Returns the iterator pointing to the end of the container.
Definition: container.h:61

Parameters

  name | prefix of the container (eg: list)
  c | pointer to container data (eg: List*)
  ci | container iterator (eg: ListIter)
  n | Output storing the data inside the container.

Note the ', 1' hack in the test condition: this is done so that it always returns true. This allows the _iter_end() test to be the only one used to break out, and it will disallow out-of-bounds memory access by doing it first with the &&.