Dictionary Support in libadr

The libadr functions that are supported for dictionary are as follows:

  • adr_data_t *adr_data_new_dictionary(adr_type_t *type)
  • boolean_t adr_dictionary_contains(adr_data_t *dict, adr_data_t *key)
  • adr_data_t *adr_dictionary_get(adr_data_t *dict, adr_data_t *key)
  • adr_data_t *adr_dictionary_keys(adr_data_t *dict)
  • int adr_dictionary_map(adr_data_t *dict,int (*func)(adr_data_t *, adr_data_t *, void *), void *data)
  • adr_data_t *adr_dictionary_put(adr_data_t *dict, adr_data_t *key, adr_data_t *value)
  • adr_data_t *adr_dictionary_remove(adr_data_t *dict, adr_data_t *key)
  • unsigned int adr_dictionary_size(adr_data_t *dict)
  • adr_data_t *adr_dictionary_values(adr_data_t *dict)

For more information, see Dictionary Definitions in RAD Modules.

Example 3-5 Using libadr for Dictionary Operations

This example shows the dictionary operations by using the libadr functions. For information about defining dictionaries, see Defining a Dictionary for RAD.

/*Create a new dictionary with a key type of integer and a value type of string*/
adr_data_t *ex_dict = adr_data_new_dictionary(&t__dict_integer_string);


/*Put a key value pair [ 1 : "value1" ] in the empty dictionary*/
(void) adr_dictionary_put(ex_dict, adr_data_new_integer(1), adr_data_new_string("value1"));


/*Get the value for the key (1)*/
adr_data_t *value = adr_dictionary_get(ex_dict, adr_data_new_integer(1));


/*Replace the value for the key (1)*/
adr_data_t *old_value = adr_dictionary_put(ex_dict, adr_data_new_integer(1), adr_data_new_string("value2"));


/*Remove the value for the key (1)*/
adr_data_t *value = adr_dictionary_remove(ex_dict, adr_data_new_integer(1));