Dictionary Support in C for RAD
C does not support dictionary data types natively. To support dictionary in types and functions, you must enable the dictionary functionality for each dictionary type as part of a module's C binding. You can create, free, and query a dictionary for its size. The supported operations on a dictionary include getting, putting, and removing an element. The functions _keys
() and _values
() return an array of all keys and values, respectively. The _map
() function is called with a pointer to a function that is invoked with each key-value pair. For more information about dictionary, see Dictionary Definitions in RAD Modules in Remote Administration Daemon Module Developer's Guide.
The C binding dictionary is a wrapper around the libadr
library. The libadr
library functions that are supported for dictionary are similar to the functions supported by C. The functions are in the native C type instead of the libadr
(adr_data_t
()) type. For more information, see Dictionary Support in libadr in Remote Administration Daemon Module Developer's Guide.
The following is an example of a generated type and API of a dictionary where the key type is integer
and the value type is string
. In this example, <module>
is the name of the module.
typedef struct <module>__rad_dict_integer_string <module>__rad_dict_integer_string_t; <module>__rad_dict_integer_string_t * <module>__rad_dict_integer_string_create( const rc_instance_t *inst); void <module>__rad_dict_integer_string_free( <module>__rad_dict_integer_string_t *dict); rc_err_t <module>__rad_dict_integer_string_contains( <module>__rad_dict_integer_string_t *dict, int key); unsigned int <module>__rad_dict_integer_string_size( <module>__rad_dict_integer_string_t *dict); rc_err_t <module>__rad_dict_integer_string_remove( <module>__rad_dict_integer_string_t *dict, int key, char **value); rc_err_t <module>__rad_dict_integer_string_get( <module>__rad_dict_integer_string_t *dict, int key, char **value); rc_err_t <module>__rad_dict_integer_string_put( <module>__rad_dict_integer_string_t *dict, int key, const char *value, char **old_value); int *<module>__rad_dict_integer_string_keys( <module>__rad_dict_integer_string_t *dict); char **<module>__rad_dict_integer_string_values( <module>__rad_dict_integer_string_t *dict); int <module>__rad_dict_integer_string_map( <module>__rad_dict_integer_string_t *dict, int (*func)(int, const char *, void *), void *arg);
The generated type can be used like any other type in RAD. A sample C client binding definition is as follows:
rc_err_t <module>_<interface>_set_DictProp(rc_instance_t *, <module>__rad_dict_integer_string_t *);
Note:
The dictionary type and associated functions are thread-safe.