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