Changeset 3c213f6 in mainline for uspace/lib/c/include/adt/char_map.h


Ignore:
Timestamp:
2010-09-26T15:00:29Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2544442
Parents:
0402bda5
Message:

Char map cleanup.

File:
1 edited

Legend:

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

    r0402bda5 r3c213f6  
    2727 */
    2828
    29 /** @addtogroup net
     29/** @addtogroup libc
    3030 *  @{
    3131 */
     
    3838#define __CHAR_MAP_H__
    3939
    40 /** Invalid assigned value used also if an&nbsp;entry does not exist.
    41  */
     40#include <libarch/types.h>
     41
     42/** Invalid assigned value used also if an&nbsp;entry does not exist. */
    4243#define CHAR_MAP_NULL   (-1)
    4344
     
    5051 *  @see char_map
    5152 */
    52 typedef char_map_t *    char_map_ref;
     53typedef char_map_t *char_map_ref;
    5354
    5455/** Character string to integer map item.
    55  *  This structure recursivelly contains itself as a&nbsp;character by character tree.
    56  *  The actually mapped character string consists o fall the parent characters and the actual one.
     56 *
     57 * This structure recursivelly contains itself as a character by character tree.
     58 * The actually mapped character string consists of all the parent characters
     59 * and the actual one.
    5760 */
    58 struct  char_map{
    59         /** Actually mapped character.
    60          */
     61struct char_map {
     62        /** Actually mapped character. */
    6163        char c;
    62         /** Stored integral value.
    63          */
     64        /** Stored integral value. */
    6465        int value;
    65         /** Next character array size.
    66          */
     66        /** Next character array size. */
    6767        int size;
    68         /** First free position in the next character array.
    69          */
     68        /** First free position in the next character array. */
    7069        int next;
    71         /** Next character array.
    72          */
    73         char_map_ref * items;
    74         /** Consistency check magic value.
    75          */
     70        /** Next character array. */
     71        char_map_ref *items;
     72        /** Consistency check magic value. */
    7673        int magic;
    7774};
    7875
    79 /** Adds the value with the key to the map.
    80  *  @param[in,out] map The character string to integer map.
    81  *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
    82  *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
    83  *  @param[in] value The integral value to be stored for the key character string.
    84  *  @returns EOK on success.
    85  *  @returns EINVAL if the map is not valid.
    86  *  @returns EINVAL if the identifier parameter is NULL.
    87  *  @returns EINVAL if the length parameter zero (0) and the identifier parameter is an empty character string (the first character is the terminating zero ('\\0') character.
    88  *  @returns EEXIST if the key character string is already used.
    89  *  @returns Other error codes as defined for the char_map_add_item() function.
    90  */
    91 extern int char_map_add(char_map_ref map, const char * identifier, size_t length, const int value);
    92 
    93 /** Clears and destroys the map.
    94  *  @param[in,out] map The character string to integer map.
    95  */
    96 extern void char_map_destroy(char_map_ref map);
    97 
    98 /** Excludes the value assigned to the key from the map.
    99  *  The entry is cleared from the map.
    100  *  @param[in,out] map The character string to integer map.
    101  *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
    102  *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
    103  *  @returns The integral value assigned to the key character string.
    104  *  @returns CHAR_MAP_NULL if the key is not assigned a&nbsp;value.
    105  */
    106 extern int char_map_exclude(char_map_ref map, const char * identifier, size_t length);
    107 
    108 /** Returns the value assigned to the key from the map.
    109  *  @param[in] map The character string to integer map.
    110  *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
    111  *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
    112  *  @returns The integral value assigned to the key character string.
    113  *  @returns CHAR_MAP_NULL if the key is not assigned a&nbsp;value.
    114  */
    115 extern int char_map_find(const char_map_ref map, const char * identifier, size_t length);
    116 
    117 /** Initializes the map.
    118  *  @param[in,out] map The character string to integer map.
    119  *  @returns EOK on success.
    120  *  @returns EINVAL if the map parameter is NULL.
    121  *  @returns ENOMEM if there is not enough memory left.
    122  */
    123 extern int char_map_initialize(char_map_ref map);
    124 
    125 /** Adds or updates the value with the key to the map.
    126  *  @param[in,out] map The character string to integer map.
    127  *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
    128  *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
    129  *  @param[in] value The integral value to be stored for the key character string.
    130  *  @returns EOK on success.
    131  *  @returns EINVAL if the map is not valid.
    132  *  @returns EINVAL if the identifier parameter is NULL.
    133  *  @returns EINVAL if the length parameter zero (0) and the identifier parameter is an empty character string (the first character is the terminating zero ('\\0) character.
    134  *  @returns EEXIST if the key character string is already used.
    135  *  @returns Other error codes as defined for the char_map_add_item() function.
    136  */
    137 extern int char_map_update(char_map_ref map, const char * identifier, size_t length, const int value);
     76extern int char_map_initialize(char_map_ref);
     77extern void char_map_destroy(char_map_ref);
     78extern int char_map_exclude(char_map_ref, const char *, size_t);
     79extern int char_map_add(char_map_ref, const char *, size_t, const int);
     80extern int char_map_find(const char_map_ref, const char *, size_t);
     81extern int char_map_update(char_map_ref, const char *, size_t, const int);
    13882
    13983#endif
Note: See TracChangeset for help on using the changeset viewer.