Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3845 → Rev 3846

/branches/network/uspace/srv/net/char_map.h
31,33 → 31,124
*/
 
/** @file
* A character string to integer map header file.
*/
 
#ifndef __CHAR_MAP_H__
#define __CHAR_MAP_H__
 
/** An invalid assigned value used also if an entry does not exist.
*/
#define CHAR_MAP_NULL ( -1 )
 
/** A type definition of a character string to integer map.
* @see char_map
*/
typedef struct char_map char_map_t;
 
/** A type definition of a character string to integer map pointer.
* @see char_map
*/
typedef char_map_t * char_map_ref;
 
/** A character string to integer map item.
* This structure recursivelly contains itself as a character by character tree.
* The actually mapped character string consists o fall the parent characters and the actual one.
*/
struct char_map{
char c;
int value;
int size;
int next;
 
/** An actually mapped character.
*/
char c;
 
/** A stored integral value.
*/
int value;
 
/** A next character array size.
*/
int size;
 
/** The first free position in the next character array.
*/
int next;
 
/** The next character array.
*/
char_map_ref * items;
int magic;
 
/** The consistency check magic value.
*/
int magic;
};
 
int char_map_add( char_map_ref map, const char * identifier, const int value );
/** Adds the value with the key to the map.
* @param map The character string to integer map. Input/output parameter.
* @param 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. Input parameter.
* @param 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. Input parameter.
* @param value The integral value to be stored for the key character string. Input parameter.
* @returns EOK on success.
* @returns EINVAL if the map is not valid.
* @returns EINVAL if the identifier parameter is NULL.
* @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.
* @returns EEXIST if the key character string is already used.
* @returns Other error codes as defined for the char_map_add_item() function.
*/
int char_map_add( char_map_ref map, const char * identifier, size_t length, const int value );
 
/** Clears and destroys the map.
* @param map The character string to integer map. Input/output parameter.
*/
void char_map_destroy( char_map_ref map );
int char_map_exclude( char_map_ref map, const char * identifier );
int char_map_find( char_map_ref map, const char * identifier );
int char_map_get_value( char_map_ref map );
 
/** Excludes the value assigned to the key from the map.
* The entry is cleared from the map.
* @param map The character string to integer map. Input/output parameter.
* @param 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. Input parameter.
* @param 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. Input parameter.
* @returns The integral value assigned to the key character string.
* @returns CHAR_MAP_NULL if the key is not assigned a value.
*/
int char_map_exclude( char_map_ref map, const char * identifier, size_t length );
 
/** Returns the value assigned to the key from the map.
* @param map The character string to integer map. Input parameter.
* @param 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. Input parameter.
* @param 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. Input parameter.
* @returns The integral value assigned to the key character string.
* @returns CHAR_MAP_NULL if the key is not assigned a value.
*/
int char_map_find( const char_map_ref map, const char * identifier, size_t length );
 
/** Returns the value assigned to the map.
* @param map The character string to integer map. Input parameter.
* @returns The integral value assigned to the map.
* @returns CHAR_MAP_NULL if the map is not assigned a value.
*/
int char_map_get_value( const char_map_ref map );
 
/** Initializes the map.
* @param map The character string to integer map. Input/output parameter.
* @returns EOK on success.
* @returns EINVAL if the map parameter is NULL.
* @returns ENOMEM if there is no memory left.
*/
int char_map_initialize( char_map_ref map );
int char_map_update( char_map_ref map, const char * identifier, const int value );
 
/** Adds or updates the value with the key to the map.
* @param map The character string to integer map. Input/output parameter.
* @param 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. Input parameter.
* @param 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. Input parameter.
* @param value The integral value to be stored for the key character string. Input parameter.
* @returns EOK on success.
* @returns EINVAL if the map is not valid.
* @returns EINVAL if the identifier parameter is NULL.
* @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.
* @returns EEXIST if the key character string is already used.
* @returns Other error codes as defined for the char_map_add_item() function.
*/
int char_map_update( char_map_ref map, const char * identifier, size_t length, const int value );
 
#endif
 
/** @}