libsc
2.8.7
The SC library provides support for parallel scientific applications.
|
This file provides a lookup structure for key-value pairs. More...
#include <sc_containers.h>
Go to the source code of this file.
Typedefs | |
typedef struct sc_keyvalue | sc_keyvalue_t |
The key-value container is an opaque structure. | |
typedef int(* | sc_keyvalue_foreach_t) (const char *key, const sc_keyvalue_entry_type_t type, void *entry, const void *u) |
Function to call on every key value pair. More... | |
Enumerations | |
enum | sc_keyvalue_entry_type_t { SC_KEYVALUE_ENTRY_NONE = 0 , SC_KEYVALUE_ENTRY_INT , SC_KEYVALUE_ENTRY_DOUBLE , SC_KEYVALUE_ENTRY_STRING , SC_KEYVALUE_ENTRY_POINTER } |
The values can have different types. More... | |
Functions | |
sc_keyvalue_t * | sc_keyvalue_new () |
Create a new key-value container. More... | |
sc_keyvalue_t * | sc_keyvalue_newf (int dummy,...) |
Create a container and set one or more key-value pairs. More... | |
sc_keyvalue_t * | sc_keyvalue_newv (va_list ap) |
Create a container and set one or more key-value pairs. More... | |
void | sc_keyvalue_destroy (sc_keyvalue_t *kv) |
Free a key-value container and all internal memory for key storage. More... | |
sc_keyvalue_entry_type_t | sc_keyvalue_exists (sc_keyvalue_t *kv, const char *key) |
Routine to check existence of an entry. More... | |
sc_keyvalue_entry_type_t | sc_keyvalue_unset (sc_keyvalue_t *kv, const char *key) |
Routine to remove an entry. More... | |
int | sc_keyvalue_get_int (sc_keyvalue_t *kv, const char *key, int dvalue) |
Routines to retrieve an integer value by its key. More... | |
double | sc_keyvalue_get_double (sc_keyvalue_t *kv, const char *key, double dvalue) |
Retrieve a double value by its key. More... | |
const char * | sc_keyvalue_get_string (sc_keyvalue_t *kv, const char *key, const char *dvalue) |
Retrieve a string value by its key. More... | |
void * | sc_keyvalue_get_pointer (sc_keyvalue_t *kv, const char *key, void *dvalue) |
Retrieve a pointer value by its key. More... | |
int | sc_keyvalue_get_int_check (sc_keyvalue_t *kv, const char *key, int *status) |
Query an integer key with error checking. More... | |
void | sc_keyvalue_set_int (sc_keyvalue_t *kv, const char *key, int newvalue) |
Routine to set an integer value for a given key. More... | |
void | sc_keyvalue_set_double (sc_keyvalue_t *kv, const char *key, double newvalue) |
Routine to set a double value for a given key. More... | |
void | sc_keyvalue_set_string (sc_keyvalue_t *kv, const char *key, const char *newvalue) |
Routine to set a string value for a given key. More... | |
void | sc_keyvalue_set_pointer (sc_keyvalue_t *kv, const char *key, void *newvalue) |
Routine to set a pointer value for a given key. More... | |
void | sc_keyvalue_foreach (sc_keyvalue_t *kv, sc_keyvalue_foreach_t fn, void *user_data) |
Iterate through all stored key-value pairs. More... | |
This file provides a lookup structure for key-value pairs.
typedef int(* sc_keyvalue_foreach_t) (const char *key, const sc_keyvalue_entry_type_t type, void *entry, const void *u) |
Function to call on every key value pair.
[in] | key | The key for this pair |
[in] | type | The type of entry |
[in] | entry | Pointer to the entry |
[in] | u | Arbitrary user data. |
The values can have different types.
void sc_keyvalue_destroy | ( | sc_keyvalue_t * | kv | ) |
Free a key-value container and all internal memory for key storage.
[in,out] | kv | The key-value container is invalidated by this call. |
sc_keyvalue_entry_type_t sc_keyvalue_exists | ( | sc_keyvalue_t * | kv, |
const char * | key | ||
) |
Routine to check existence of an entry.
[in] | kv | Valid key-value container. |
[in] | key | Lookup key to query. |
void sc_keyvalue_foreach | ( | sc_keyvalue_t * | kv, |
sc_keyvalue_foreach_t | fn, | ||
void * | user_data | ||
) |
Iterate through all stored key-value pairs.
[in] | kv | Valid key-value container. |
[in] | fn | Function to call on each key-value pair. |
[in,out] | user_data | This pointer is passed through to fn. |
double sc_keyvalue_get_double | ( | sc_keyvalue_t * | kv, |
const char * | key, | ||
double | dvalue | ||
) |
Retrieve a double value by its key.
This function asserts that the key, if existing, points to the correct type.
[in] | kv | Valid key-value container. |
[in] | key | Lookup key, may or may not exist. |
[in] | dvalue | Default value returned if key is not found. |
int sc_keyvalue_get_int | ( | sc_keyvalue_t * | kv, |
const char * | key, | ||
int | dvalue | ||
) |
Routines to retrieve an integer value by its key.
This function asserts that the key, if existing, points to the correct type.
[in] | kv | Valid key-value container. |
[in] | key | Lookup key, may or may not exist. |
[in] | dvalue | Default value returned if key is not found. |
int sc_keyvalue_get_int_check | ( | sc_keyvalue_t * | kv, |
const char * | key, | ||
int * | status | ||
) |
Query an integer key with error checking.
We check whether the key is not found or it is of the wrong type. A default value to be returned on error can be passed in as *status. If status is NULL, then the result on error is undefined.
[in] | kv | Valid key-value table. |
[in] | key | Non-NULL key string. |
[in,out] | status | If not NULL, set to 0 if there is no error, 1 if the key is not found, 2 if a value is found but its type is not integer, and return the input value *status on error. |
void* sc_keyvalue_get_pointer | ( | sc_keyvalue_t * | kv, |
const char * | key, | ||
void * | dvalue | ||
) |
Retrieve a pointer value by its key.
This function asserts that the key, if existing, points to the correct type.
[in] | kv | Valid key-value container. |
[in] | key | Lookup key, may or may not exist. |
[in] | dvalue | Default value returned if key is not found. |
const char* sc_keyvalue_get_string | ( | sc_keyvalue_t * | kv, |
const char * | key, | ||
const char * | dvalue | ||
) |
Retrieve a string value by its key.
This function asserts that the key, if existing, points to the correct type.
[in] | kv | Valid key-value container. |
[in] | key | Lookup key, may or may not exist. |
[in] | dvalue | Default value returned if key is not found. |
sc_keyvalue_t* sc_keyvalue_new | ( | ) |
sc_keyvalue_t* sc_keyvalue_newf | ( | int | dummy, |
... | |||
) |
Create a container and set one or more key-value pairs.
Arguments come in pairs of 2: a static string "type:key" and a value. The type is the letter i, g, s, p for int, double, const char *, and void *, respectively.
[in] | dummy | Not touched, just to use the varargs feature. |
sc_keyvalue_t* sc_keyvalue_newv | ( | va_list | ap | ) |
Create a container and set one or more key-value pairs.
This function works analogously to sc_keyvalue_newf. Arguments come in pairs of 2: a static string "type:key" and a value. The type is the letter i, g, s, p for int, double, const char *, and void *, respectively.
[in] | ap | Varargs pointer; see stdarg.h for the syntax. |
void sc_keyvalue_set_double | ( | sc_keyvalue_t * | kv, |
const char * | key, | ||
double | newvalue | ||
) |
Routine to set a double value for a given key.
[in] | kv | Valid key-value table. |
[in] | key | Non-NULL key to insert or replace. If it already exists, it must be of type double. |
[in] | newvalue | New value will be stored under key. |
void sc_keyvalue_set_int | ( | sc_keyvalue_t * | kv, |
const char * | key, | ||
int | newvalue | ||
) |
Routine to set an integer value for a given key.
[in] | kv | Valid key-value table. |
[in] | key | Non-NULL key to insert or replace. If it already exists, it must be of type integer. |
[in] | newvalue | New value will be stored under key. |
void sc_keyvalue_set_pointer | ( | sc_keyvalue_t * | kv, |
const char * | key, | ||
void * | newvalue | ||
) |
Routine to set a pointer value for a given key.
[in] | kv | Valid key-value table. |
[in] | key | Non-NULL key to insert or replace. If it already exists, it must be of type pointer. |
[in] | newvalue | New value will be stored under key. |
void sc_keyvalue_set_string | ( | sc_keyvalue_t * | kv, |
const char * | key, | ||
const char * | newvalue | ||
) |
Routine to set a string value for a given key.
[in] | kv | Valid key-value table. |
[in] | key | Non-NULL key to insert or replace. If it already exists, it must be of type string. |
[in] | newvalue | New value will be stored under key. |
sc_keyvalue_entry_type_t sc_keyvalue_unset | ( | sc_keyvalue_t * | kv, |
const char * | key | ||
) |
Routine to remove an entry.
[in] | kv | Valid key-value container. |
[in] | key | Lookup key to remove if it exists. |