Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/adt/generic_char_map.h

    raaa3f33a r4edd39fc  
    4040#include <unistd.h>
    4141#include <errno.h>
     42#include <err.h>
    4243
    4344#include <adt/char_map.h>
     
    5556        \
    5657        typedef struct name name##_t; \
     58        typedef name##_t *name##_ref; \
    5759        \
    5860        struct  name { \
     
    6264        }; \
    6365        \
    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);
    7173
    7274/** Character string to generic type map implementation.
     
    8082        GENERIC_FIELD_IMPLEMENT(name##_items, type) \
    8183        \
    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, \
    8385             type *value) \
    8486        { \
    85                 int rc; \
     87                ERROR_DECLARE; \
    8688                int index; \
    8789                if (!name##_is_valid(map)) \
     
    9092                if (index < 0) \
    9193                        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))) { \
    9496                        name##_items_exclude_index(&map->values, index); \
    95                         return rc; \
     97                        return ERROR_CODE; \
    9698                } \
    9799                return EOK; \
    98100        } \
    99101        \
    100         int name##_count(name##_t *map) \
     102        int name##_count(name##_ref map) \
    101103        { \
    102104                return name##_is_valid(map) ? \
     
    104106        } \
    105107        \
    106         void name##_destroy(name##_t *map) \
     108        void name##_destroy(name##_ref map) \
    107109        { \
    108110                if (name##_is_valid(map)) { \
     
    112114        } \
    113115        \
    114         void name##_exclude(name##_t *map, const char *name, \
     116        void name##_exclude(name##_ref map, const char *name, \
    115117            const size_t length) \
    116118        { \
     
    124126        } \
    125127        \
    126         type *name##_find(name##_t *map, const char *name, \
     128        type *name##_find(name##_ref map, const char *name, \
    127129            const size_t length) \
    128130        { \
     
    137139        } \
    138140        \
    139         int name##_initialize(name##_t *map) \
     141        int name##_initialize(name##_ref map) \
    140142        { \
    141                 int rc; \
     143                ERROR_DECLARE; \
    142144                if (!map) \
    143145                        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))) { \
    149148                        char_map_destroy(&map->names); \
    150                         return rc; \
     149                        return ERROR_CODE; \
    151150                } \
    152151                map->magic = GENERIC_CHAR_MAP_MAGIC_VALUE; \
     
    154153        } \
    155154        \
    156         int name##_is_valid(name##_t *map) \
     155        int name##_is_valid(name##_ref map) \
    157156        { \
    158157                return map && (map->magic == GENERIC_CHAR_MAP_MAGIC_VALUE); \
Note: See TracChangeset for help on using the changeset viewer.