1. drmaa2_dict_list(3)
  2. DRMAA2
  3. drmaa2_dict_list(3)

NAME

drmaa2_dict_list - drmaa2_dict_list, Creates a list out of the dictionary keys.

SYNOPSIS

#include "drmaa2.h"

drmaa2_string_list drmaa2_dict_list(const drmaa2_dict dict)

DESCRIPTION

Creates a newly allocated drmaa2_string_list out of the keys from the dictionary. When the dictionary is defined but has 0 keys, a list with 0 elements is returned. The list is required to get the keys in order to traverse a dictionary. After using the list it must be freed with drmaa2_dict_free(3) by the caller.

RETURN VALUES

Returns a drmaa2_string_list or NULL in case of an error.

EXAMPLE

static void drmaa2_dict_string_free(char** key, char** value)
{
   drmaa2_string_free(key);
   drmaa2_string_free(value);
}

/* ... */
drmaa2_string_list keys;

/* Create dictionary for job environment variables. */
drmaa2_dict dict = drmaa2_dict_create((drmaa2_dict_entryfree)drmaa2_dict_string_free);

if (dict == NULL) {
   printf("Error: Could not create a new dictionary.\n");
   return;
}

if (drmaa2_dict_set(dict, strdup("key"), strdup("value")) != DRMAA2_SUCCESS) {
   printf("Error: Could not set a new value in the dictionary.\n");
   return;
}

if (drmaa2_dict_set(dict, strdup("key2"), strdup("")) != DRMAA2_SUCCESS) {
   printf("Error: Could not set a new value in the dictionary.\n");
   return;
}

if ((keys = drmaa2_dict_list(dict)) != NULL) {
   long size, i;
   size = drmaa2_list_size(keys);
   for (i = 0; i < size; i++) {
      drmaa2_string key = drmaa2_list_get(keys, i);
      /* use key for getting the value in the dict */
      printf("Key: %s Value: %s\n", key, drmaa2_dict_get(dict, key));
   }
   drmaa2_list_free(&keys);
}

/* Frees strings implicitly. */
drmaa2_dict_free(&dict);

SEE ALSO

drmaa2_dict_create(3), drmaa2_dict_free(3), drmaa2_dict_list(3), drmaa2_dict_has(3), drmaa2_dict_get(3), drmaa2_dict_del(3), drmaa2_dict_set(3)

AUTHOR

Copyright Univa Corporation 2013

  1. Univa Corporation
  2. October 2013
  3. drmaa2_dict_list(3)