Ignore:
Timestamp:
2011-05-12T16:49:44Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
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.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    re80329d6 rb5e68c8  
    4040#include <unistd.h>
    4141#include <errno.h>
    42 #include <err.h>
    4342
    4443#include <adt/char_map.h>
     
    4746/** Internal magic value for a&nbsp;map consistency check. */
    4847#define GENERIC_CHAR_MAP_MAGIC_VALUE    0x12345622
     48
     49/** Generic destructor function pointer. */
     50#define DTOR_T(identifier) \
     51        void (*identifier)(const void *)
    4952
    5053/** Character string to generic type map declaration.
     
    5659        \
    5760        typedef struct name name##_t; \
    58         typedef name##_t *name##_ref; \
    5961        \
    6062        struct  name { \
     
    6466        }; \
    6567        \
    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 *);
    7375
    7476/** Character string to generic type map implementation.
     
    7678 * Should follow declaration with the same parameters.
    7779 *
    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 *
    8083 */
    8184#define GENERIC_CHAR_MAP_IMPLEMENT(name, type) \
    8285        GENERIC_FIELD_IMPLEMENT(name##_items, type) \
    8386        \
    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, \
    8588             type *value) \
    8689        { \
    87                 ERROR_DECLARE; \
    8890                int index; \
    8991                if (!name##_is_valid(map)) \
     
    9294                if (index < 0) \
    9395                        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); \
    10097        } \
    10198        \
    102         int name##_count(name##_ref map) \
     99        int name##_count(name##_t *map) \
    103100        { \
    104101                return name##_is_valid(map) ? \
     
    106103        } \
    107104        \
    108         void name##_destroy(name##_ref map) \
     105        void name##_destroy(name##_t *map, DTOR_T(dtor)) \
    109106        { \
    110107                if (name##_is_valid(map)) { \
    111108                        char_map_destroy(&map->names); \
    112                         name##_items_destroy(&map->values); \
     109                        name##_items_destroy(&map->values, dtor); \
    113110                } \
    114111        } \
    115112        \
    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)) \
    118115        { \
    119116                if (name##_is_valid(map)) { \
     
    122119                        if (index != CHAR_MAP_NULL) \
    123120                                name##_items_exclude_index(&map->values, \
    124                                      index); \
     121                                     index, dtor); \
    125122                } \
    126123        } \
    127124        \
    128         type *name##_find(name##_ref map, const char *name, \
     125        type *name##_find(name##_t *map, const uint8_t *name, \
    129126            const size_t length) \
    130127        { \
     
    139136        } \
    140137        \
    141         int name##_initialize(name##_ref map) \
     138        int name##_initialize(name##_t *map) \
    142139        { \
    143                 ERROR_DECLARE; \
     140                int rc; \
    144141                if (!map) \
    145142                        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) { \
    148148                        char_map_destroy(&map->names); \
    149                         return ERROR_CODE; \
     149                        return rc; \
    150150                } \
    151151                map->magic = GENERIC_CHAR_MAP_MAGIC_VALUE; \
     
    153153        } \
    154154        \
    155         int name##_is_valid(name##_ref map) \
     155        int name##_is_valid(name##_t *map) \
    156156        { \
    157157                return map && (map->magic == GENERIC_CHAR_MAP_MAGIC_VALUE); \
Note: See TracChangeset for help on using the changeset viewer.