Changeset eb522e8 in mainline for uspace/lib/c/include/adt/generic_char_map.h
- Timestamp:
- 2011-06-01T08:43:42Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8d6c1f1
- Parents:
- 9e2e715 (diff), e51a514 (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/generic_char_map.h
r9e2e715 reb522e8 47 47 #define GENERIC_CHAR_MAP_MAGIC_VALUE 0x12345622 48 48 49 /** Generic destructor function pointer. */ 50 #define DTOR_T(identifier) \ 51 void (*identifier)(const void *) 52 49 53 /** Character string to generic type map declaration. 50 54 * @param[in] name Name of the map. … … 55 59 \ 56 60 typedef struct name name##_t; \ 57 typedef name##_t *name##_ref; \58 61 \ 59 62 struct name { \ … … 63 66 }; \ 64 67 \ 65 int name##_add(name##_ ref, const char*, const size_t, type *); \66 int name##_count(name##_ ref); \67 void name##_destroy(name##_ ref); \68 void name##_exclude(name##_ ref, const char *, const size_t); \69 type *name##_find(name##_ ref, const char*, const size_t); \70 int name##_initialize(name##_ ref); \71 int name##_is_valid(name##_ ref);68 int name##_add(name##_t *, const uint8_t *, const size_t, type *); \ 69 int name##_count(name##_t *); \ 70 void name##_destroy(name##_t *, DTOR_T()); \ 71 void name##_exclude(name##_t *, const uint8_t *, const size_t, DTOR_T()); \ 72 type *name##_find(name##_t *, const uint8_t *, const size_t); \ 73 int name##_initialize(name##_t *); \ 74 int name##_is_valid(name##_t *); 72 75 73 76 /** Character string to generic type map implementation. … … 75 78 * Should follow declaration with the same parameters. 76 79 * 77 * @param[in] name Name of the map. 78 * @param[in] type Inner object type. 80 * @param[in] name Name of the map. 81 * @param[in] type Inner object type. 82 * 79 83 */ 80 84 #define GENERIC_CHAR_MAP_IMPLEMENT(name, type) \ 81 85 GENERIC_FIELD_IMPLEMENT(name##_items, type) \ 82 86 \ 83 int name##_add(name##_ ref map, const char*name, const size_t length, \87 int name##_add(name##_t *map, const uint8_t *name, const size_t length, \ 84 88 type *value) \ 85 89 { \ 86 int rc; \87 90 int index; \ 88 91 if (!name##_is_valid(map)) \ … … 91 94 if (index < 0) \ 92 95 return index; \ 93 rc = char_map_add(&map->names, name, length, index); \ 94 if (rc != EOK) { \ 95 name##_items_exclude_index(&map->values, index); \ 96 return rc; \ 97 } \ 98 return EOK; \ 96 return char_map_add(&map->names, name, length, index); \ 99 97 } \ 100 98 \ 101 int name##_count(name##_ refmap) \99 int name##_count(name##_t *map) \ 102 100 { \ 103 101 return name##_is_valid(map) ? \ … … 105 103 } \ 106 104 \ 107 void name##_destroy(name##_ ref map) \105 void name##_destroy(name##_t *map, DTOR_T(dtor)) \ 108 106 { \ 109 107 if (name##_is_valid(map)) { \ 110 108 char_map_destroy(&map->names); \ 111 name##_items_destroy(&map->values ); \109 name##_items_destroy(&map->values, dtor); \ 112 110 } \ 113 111 } \ 114 112 \ 115 void name##_exclude(name##_ ref map, const char*name, \116 const size_t length ) \113 void name##_exclude(name##_t *map, const uint8_t *name, \ 114 const size_t length, DTOR_T(dtor)) \ 117 115 { \ 118 116 if (name##_is_valid(map)) { \ … … 121 119 if (index != CHAR_MAP_NULL) \ 122 120 name##_items_exclude_index(&map->values, \ 123 index ); \121 index, dtor); \ 124 122 } \ 125 123 } \ 126 124 \ 127 type *name##_find(name##_ ref map, const char*name, \125 type *name##_find(name##_t *map, const uint8_t *name, \ 128 126 const size_t length) \ 129 127 { \ … … 138 136 } \ 139 137 \ 140 int name##_initialize(name##_ refmap) \138 int name##_initialize(name##_t *map) \ 141 139 { \ 142 140 int rc; \ … … 155 153 } \ 156 154 \ 157 int name##_is_valid(name##_ refmap) \155 int name##_is_valid(name##_t *map) \ 158 156 { \ 159 157 return map && (map->magic == GENERIC_CHAR_MAP_MAGIC_VALUE); \
Note:
See TracChangeset
for help on using the changeset viewer.