Changes in uspace/lib/c/include/adt/generic_char_map.h [aaa3f33a:4edd39fc] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/adt/generic_char_map.h
raaa3f33a r4edd39fc 40 40 #include <unistd.h> 41 41 #include <errno.h> 42 #include <err.h> 42 43 43 44 #include <adt/char_map.h> … … 55 56 \ 56 57 typedef struct name name##_t; \ 58 typedef name##_t *name##_ref; \ 57 59 \ 58 60 struct name { \ … … 62 64 }; \ 63 65 \ 64 int name##_add(name##_ t *, const char *, const size_t, type *); \65 int name##_count(name##_ t *); \66 void name##_destroy(name##_ t *); \67 void name##_exclude(name##_ t *, const char *, const size_t); \68 type *name##_find(name##_ t *, const char *, const size_t); \69 int name##_initialize(name##_ t *); \70 int name##_is_valid(name##_ t *);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); 71 73 72 74 /** Character string to generic type map implementation. … … 80 82 GENERIC_FIELD_IMPLEMENT(name##_items, type) \ 81 83 \ 82 int name##_add(name##_ t *map, const char *name, const size_t length, \84 int name##_add(name##_ref map, const char *name, const size_t length, \ 83 85 type *value) \ 84 86 { \ 85 int rc; \87 ERROR_DECLARE; \ 86 88 int index; \ 87 89 if (!name##_is_valid(map)) \ … … 90 92 if (index < 0) \ 91 93 return index; \ 92 rc = char_map_add(&map->names, name, length, index);\93 if (rc != EOK) { \94 if (ERROR_OCCURRED(char_map_add(&map->names, name, length, \ 95 index))) { \ 94 96 name##_items_exclude_index(&map->values, index); \ 95 return rc; \97 return ERROR_CODE; \ 96 98 } \ 97 99 return EOK; \ 98 100 } \ 99 101 \ 100 int name##_count(name##_ t *map) \102 int name##_count(name##_ref map) \ 101 103 { \ 102 104 return name##_is_valid(map) ? \ … … 104 106 } \ 105 107 \ 106 void name##_destroy(name##_ t *map) \108 void name##_destroy(name##_ref map) \ 107 109 { \ 108 110 if (name##_is_valid(map)) { \ … … 112 114 } \ 113 115 \ 114 void name##_exclude(name##_ t *map, const char *name, \116 void name##_exclude(name##_ref map, const char *name, \ 115 117 const size_t length) \ 116 118 { \ … … 124 126 } \ 125 127 \ 126 type *name##_find(name##_ t *map, const char *name, \128 type *name##_find(name##_ref map, const char *name, \ 127 129 const size_t length) \ 128 130 { \ … … 137 139 } \ 138 140 \ 139 int name##_initialize(name##_ t *map) \141 int name##_initialize(name##_ref map) \ 140 142 { \ 141 int rc; \143 ERROR_DECLARE; \ 142 144 if (!map) \ 143 145 return EINVAL; \ 144 rc = char_map_initialize(&map->names); \ 145 if (rc != EOK) \ 146 return rc; \ 147 rc = name##_items_initialize(&map->values); \ 148 if (rc != EOK) { \ 146 ERROR_PROPAGATE(char_map_initialize(&map->names)); \ 147 if (ERROR_OCCURRED(name##_items_initialize(&map->values))) { \ 149 148 char_map_destroy(&map->names); \ 150 return rc; \149 return ERROR_CODE; \ 151 150 } \ 152 151 map->magic = GENERIC_CHAR_MAP_MAGIC_VALUE; \ … … 154 153 } \ 155 154 \ 156 int name##_is_valid(name##_ t *map) \155 int name##_is_valid(name##_ref map) \ 157 156 { \ 158 157 return map && (map->magic == GENERIC_CHAR_MAP_MAGIC_VALUE); \
Note:
See TracChangeset
for help on using the changeset viewer.