Changeset 3c213f6 in mainline for uspace/lib/c/include/adt/char_map.h
- Timestamp:
- 2010-09-26T15:00:29Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2544442
- Parents:
- 0402bda5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/adt/char_map.h
r0402bda5 r3c213f6 27 27 */ 28 28 29 /** @addtogroup net29 /** @addtogroup libc 30 30 * @{ 31 31 */ … … 38 38 #define __CHAR_MAP_H__ 39 39 40 /** Invalid assigned value used also if an entry does not exist. 41 */ 40 #include <libarch/types.h> 41 42 /** Invalid assigned value used also if an entry does not exist. */ 42 43 #define CHAR_MAP_NULL (-1) 43 44 … … 50 51 * @see char_map 51 52 */ 52 typedef char_map_t * 53 typedef char_map_t *char_map_ref; 53 54 54 55 /** Character string to integer map item. 55 * This structure recursivelly contains itself as a 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. 57 60 */ 58 struct char_map{ 59 /** Actually mapped character. 60 */ 61 struct char_map { 62 /** Actually mapped character. */ 61 63 char c; 62 /** Stored integral value. 63 */ 64 /** Stored integral value. */ 64 65 int value; 65 /** Next character array size. 66 */ 66 /** Next character array size. */ 67 67 int size; 68 /** First free position in the next character array. 69 */ 68 /** First free position in the next character array. */ 70 69 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. */ 76 73 int magic; 77 74 }; 78 75 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 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 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); 76 extern int char_map_initialize(char_map_ref); 77 extern void char_map_destroy(char_map_ref); 78 extern int char_map_exclude(char_map_ref, const char *, size_t); 79 extern int char_map_add(char_map_ref, const char *, size_t, const int); 80 extern int char_map_find(const char_map_ref, const char *, size_t); 81 extern int char_map_update(char_map_ref, const char *, size_t, const int); 138 82 139 83 #endif
Note:
See TracChangeset
for help on using the changeset viewer.