Changeset 99b65d2 in mainline for uspace/lib/c/include/adt/int_map.h
- Timestamp:
- 2011-03-29T20:02:46Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e3a3e3ad
- Parents:
- a716a75 (diff), 93ebe4e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/adt/int_map.h
ra716a75 r99b65d2 49 49 #define INT_MAP_ITEM_MAGIC_VALUE 0x55667788 50 50 51 /** Generic destructor function pointer. */ 52 #define DTOR_T(identifier) \ 53 void (*identifier)(const void *) 54 51 55 /** Integer to generic type map declaration. 52 56 * … … 72 76 \ 73 77 int name##_add(name##_t *, int, type *); \ 74 void name##_clear(name##_t * ); \78 void name##_clear(name##_t *, DTOR_T()); \ 75 79 int name##_count(name##_t *); \ 76 void name##_destroy(name##_t * ); \77 void name##_exclude(name##_t *, int ); \78 void name##_exclude_index(name##_t *, int ); \80 void name##_destroy(name##_t *, DTOR_T()); \ 81 void name##_exclude(name##_t *, int, DTOR_T()); \ 82 void name##_exclude_index(name##_t *, int, DTOR_T()); \ 79 83 type *name##_find(name##_t *, int); \ 80 84 int name##_update(name##_t *, int, int); \ … … 82 86 int name##_initialize(name##_t *); \ 83 87 int name##_is_valid(name##_t *); \ 84 void name##_item_destroy(name##_item_t * ); \88 void name##_item_destroy(name##_item_t *, DTOR_T()); \ 85 89 int name##_item_is_valid(name##_item_t *); 86 90 … … 115 119 } \ 116 120 \ 117 void name##_clear(name##_t *map ) \121 void name##_clear(name##_t *map, DTOR_T(dtor)) \ 118 122 { \ 119 123 if (name##_is_valid(map)) { \ … … 122 126 if (name##_item_is_valid(&map->items[index])) { \ 123 127 name##_item_destroy( \ 124 &map->items[index] ); \128 &map->items[index], dtor); \ 125 129 } \ 126 130 } \ … … 135 139 } \ 136 140 \ 137 void name##_destroy(name##_t *map ) \141 void name##_destroy(name##_t *map, DTOR_T(dtor)) \ 138 142 { \ 139 143 if (name##_is_valid(map)) { \ … … 143 147 if (name##_item_is_valid(&map->items[index])) { \ 144 148 name##_item_destroy( \ 145 &map->items[index] ); \149 &map->items[index], dtor); \ 146 150 } \ 147 151 } \ … … 150 154 } \ 151 155 \ 152 void name##_exclude(name##_t *map, int key ) \156 void name##_exclude(name##_t *map, int key, DTOR_T(dtor)) \ 153 157 { \ 154 158 if (name##_is_valid(map)) { \ … … 158 162 (map->items[index].key == key)) { \ 159 163 name##_item_destroy( \ 160 &map->items[index] ); \161 } \ 162 } \ 163 } \ 164 } \ 165 \ 166 void name##_exclude_index(name##_t *map, int index ) \164 &map->items[index], dtor); \ 165 } \ 166 } \ 167 } \ 168 } \ 169 \ 170 void name##_exclude_index(name##_t *map, int index, DTOR_T(dtor)) \ 167 171 { \ 168 172 if (name##_is_valid(map) && (index >= 0) && \ 169 173 (index < map->next) && \ 170 174 name##_item_is_valid(&map->items[index])) { \ 171 name##_item_destroy(&map->items[index] ); \175 name##_item_destroy(&map->items[index], dtor); \ 172 176 } \ 173 177 } \ … … 236 240 } \ 237 241 \ 238 void name##_item_destroy(name##_item_t *item ) \242 void name##_item_destroy(name##_item_t *item, DTOR_T(dtor)) \ 239 243 { \ 240 244 if (name##_item_is_valid(item)) { \ 241 245 item->magic = 0; \ 242 246 if (item->value) { \ 243 free(item->value); \ 247 if (dtor) \ 248 dtor(item->value); \ 244 249 item->value = NULL; \ 245 250 } \
Note:
See TracChangeset
for help on using the changeset viewer.