pw_map Class Reference

A map. More...

Collaboration diagram for pw_map:
[legend]

## Public Member Functions

#define | PW_MAP_ID_TO_PTR(id) (SPA_UINT32_TO_PTR((id)<<1))
| Convert an id to a pointer that can be inserted into the map. More...
#define | PW_MAP_PTR_TO_ID(p) (SPA_PTR_TO_UINT32(p)>>1)
| Convert a pointer to an id that can be retrieved from the map. More...
static void | pw_map_init (struct pw_map *map, size_t size, size_t extend)
| Initialize a map. More...
static void | pw_map_clear (struct pw_map *map)
| Clear a map. More...
static uint32_t | pw_map_insert_new (struct pw_map *map, void *data)
| Insert data in the map. More...
static bool | pw_map_insert_at (struct pw_map *map, uint32_t id, void *data)
| Insert data in the map at an index. More...
static void | pw_map_remove (struct pw_map *map, uint32_t id)
| Remove an item at index. More...
static void * | pw_map_lookup (struct pw_map *map, uint32_t id)
| Find an item in the map. More...
static int | pw_map_for_each (struct pw_map *map, int(*func)(void *item_data, void *data), void *data)
| Iterate all map items. More...

## Data Fields

struct pw_array | items
| an array with the map items More...
uint32_t | free_list
| the free items More...

## Detailed Description

A map.

A map that holds objects indexed by id.

## Member Function Documentation

## pw_map_clear()

static void pw_map_clear | ( | struct pw_map * | map | ) |

inline

Clear a map.

Parameters

  map | the map to clear

## pw_map_for_each()

static int pw_map_for_each | ( | struct pw_map * | map,
|  | int(*)(void *item_data, void *data) | func,
|  | void * | data
| ) |  |

inline

Iterate all map items.

Parameters

  map | the map to iterate
  func | the function to call for each item, the item data and data is passed to the function. When func returns a non-zero result, iteration ends and the result is returned.
  data | data to pass to func

Returns
  the result of the last call to func or 0 when all callbacks returned 0.

References pw_map_item::data, items, pw_array_for_each, and pw_map_item_is_free.

## pw_map_init()

static void pw_map_init | ( | struct pw_map * | map,
|  | size_t | size,
|  | size_t | extend
| ) |  |

inline

Initialize a map.

Parameters

  map | the map to initialize
  size | the initial size of the map
  extend | the amount to bytes to grow the map with when needed

References free_list, items, pw_array::pw_array_ensure_size(), and pw_array::pw_array_init().

## pw_map_insert_at()

static bool pw_map_insert_at | ( | struct pw_map * | map,
|  | uint32_t | id,
|  | void * | data
| ) |  |

inline

Insert data in the map at an index.

Parameters

  map | the map to inser into
  id | the index to insert at
  data | the data to insert

Returns
  true on success, false when the index is invalid

References pw_map_item::data, items, pw_map_get_item, and pw_map_get_size.

## pw_map_insert_new()

static uint32_t pw_map_insert_new | ( | struct pw_map * | map,
|  | void * | data
| ) |  |

inline

Insert data in the map.

Parameters

  map | the map to insert into
  data | the item to add

Returns
  the id where the item was inserted

References pw_array::data, pw_map_item::data, free_list, items, and pw_map_item::next.

Referenced by pw_node::pw_node_get_free_port(), and pw_node_get_free_port_id().

## pw_map_lookup()

static void * pw_map_lookup | ( | struct pw_map * | map,
|  | uint32_t | id
| ) |  |

inline

Find an item in the map.

Parameters

  map | the map to use
  id | the index to look at

Returns
  the item at id or NULL when no such item exists

References pw_map_item::data, pw_map_check_id, pw_map_get_item, and pw_map_item_is_free.

Referenced by pw_node_find_port().

## pw_map_remove()

static void pw_map_remove | ( | struct pw_map * | map,
|  | uint32_t | id
| ) |  |

inline

Remove an item at index.

Parameters

  map | the map to remove from
  id | the index to remove

References free_list, and pw_map_get_item.

## Field Documentation

## free_list

uint32_t pw_map::free_list

the free items

Referenced by pw_map_init(), pw_map_insert_new(), and pw_map_remove().

## items

struct pw_array pw_map::items

an array with the map items

Referenced by pw_map_for_each(), pw_map_init(), pw_map_insert_at(), and pw_map_insert_new().

The documentation for this class was generated from the following file:

- map.h