dmlite  0.6
Typedefs | Functions
any.h File Reference

Opaque handler to pass different types of values to the API. More...

#include "dmlite/common/config.h"
#include <stddef.h>
#include <stdint.h>
Include dependency graph for any.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct dmlite_any dmlite_any
 Used to pass configuration values. More...
 
typedef struct dmlite_any_dict dmlite_any_dict
 Handles key->value pairs. More...
 

Functions

dmlite_anydmlite_any_new_string (const char *str)
 Creates a new dmlite_any. More...
 
dmlite_anydmlite_any_new_long (long l)
 Creates a new dmlite_any. More...
 
dmlite_anydmlite_any_new_s64 (int64_t i)
 Creates a new dmlite_any from an int64_t type. More...
 
dmlite_anydmlite_any_new_u64 (uint64_t i)
 Creates a new dmlite_any from an uint64_t type. More...
 
dmlite_anydmlite_any_new_string_array (unsigned n, const char **strv)
 Creates a new dmlite_any. More...
 
dmlite_anydmlite_any_new_long_array (unsigned n, long *lv)
 Creates a new dmlite_any. More...
 
void dmlite_any_free (dmlite_any *any)
 Frees a dmlite_any. More...
 
void dmlite_any_to_string (const dmlite_any *any, char *buffer, size_t bsize)
 Gets the string interpretation of the dmlite_any. More...
 
long dmlite_any_to_long (const dmlite_any *any)
 Returns the long interpretation of they dmlite_any. More...
 
int64_t dmlite_any_to_s64 (const dmlite_any *any)
 Returns the int64_t interpretation of they dmlite_any. More...
 
uint64_t dmlite_any_to_u64 (const dmlite_any *any)
 Returns the uint64_t interpretation of they dmlite_any. More...
 
dmlite_any_dictdmlite_any_dict_new ()
 Created a new generic dictionary. More...
 
dmlite_any_dictdmlite_any_dict_copy (const dmlite_any_dict *dict)
 Make a copy of the dictionary. More...
 
void dmlite_any_dict_free (dmlite_any_dict *d)
 Frees a dmlite_any_dict. More...
 
void dmlite_any_dict_clear (dmlite_any_dict *d)
 Clears the dictionary. More...
 
void dmlite_any_dict_insert (dmlite_any_dict *d, const char *k, const dmlite_any *v)
 Insert a new dmlite_any value into the dictionary. More...
 
unsigned long dmlite_any_dict_count (const dmlite_any_dict *d)
 Returns how many elements there are in a specific dictionary. More...
 
dmlite_anydmlite_any_dict_get (const dmlite_any_dict *d, const char *k)
 Returns the value associated with the key k. More...
 
void dmlite_any_dict_erase (dmlite_any_dict *d, const char *k)
 Removes a key-value from the dictionary. More...
 
char * dmlite_any_dict_to_json (const dmlite_any_dict *d, char *buffer, size_t bsize)
 Generates a JSON serialization of the dictionary. More...
 
dmlite_any_dictdmlite_any_dict_from_json (const char *json)
 Populates a dmlite_any_dict from a JSON string. More...
 
void dmlite_any_dict_keys (const dmlite_any_dict *d, unsigned *nkeys, char ***keys)
 Puts in keys a pointer to an array of strings with all the available keys in d. More...
 
void dmlite_any_dict_keys_free (unsigned n, char **keys)
 Frees an array of strings allocated by dmlite_any_dict_keys. More...
 

Detailed Description

Opaque handler to pass different types of values to the API.

Author
Alejandro Álvarez Ayllon aalva.nosp@m.rez@.nosp@m.cern..nosp@m.ch
Note
Basically it wraps boost::any and dmlite::Extensible.

Typedef Documentation

◆ dmlite_any

typedef struct dmlite_any dmlite_any

Used to pass configuration values.

◆ dmlite_any_dict

Handles key->value pairs.

Function Documentation

◆ dmlite_any_dict_clear()

void dmlite_any_dict_clear ( dmlite_any_dict d)

Clears the dictionary.

◆ dmlite_any_dict_copy()

dmlite_any_dict* dmlite_any_dict_copy ( const dmlite_any_dict dict)

Make a copy of the dictionary.

Parameters
dictThe original
Returns
A newly allocated copy of dict.

◆ dmlite_any_dict_count()

unsigned long dmlite_any_dict_count ( const dmlite_any_dict d)

Returns how many elements there are in a specific dictionary.

◆ dmlite_any_dict_erase()

void dmlite_any_dict_erase ( dmlite_any_dict d,
const char *  k 
)

Removes a key-value from the dictionary.

Parameters
dThe dictionary.
kThe key to be removed.

◆ dmlite_any_dict_free()

void dmlite_any_dict_free ( dmlite_any_dict d)

Frees a dmlite_any_dict.

◆ dmlite_any_dict_from_json()

dmlite_any_dict* dmlite_any_dict_from_json ( const char *  json)

Populates a dmlite_any_dict from a JSON string.

◆ dmlite_any_dict_get()

dmlite_any* dmlite_any_dict_get ( const dmlite_any_dict d,
const char *  k 
)

Returns the value associated with the key k.

Returns
NULL if not found.

◆ dmlite_any_dict_insert()

void dmlite_any_dict_insert ( dmlite_any_dict d,
const char *  k,
const dmlite_any v 
)

Insert a new dmlite_any value into the dictionary.

Replaces if already present.

Parameters
dThe dictionary.
kThe key.
vThe value.

◆ dmlite_any_dict_keys()

void dmlite_any_dict_keys ( const dmlite_any_dict d,
unsigned *  nkeys,
char ***  keys 
)

Puts in keys a pointer to an array of strings with all the available keys in d.

Use dmlite_any_dict_keys_free to free.

Parameters
dThe Dictionary.
nkeysWill be set to the number of stored keys.

◆ dmlite_any_dict_keys_free()

void dmlite_any_dict_keys_free ( unsigned  n,
char **  keys 
)

Frees an array of strings allocated by dmlite_any_dict_keys.

Parameters
nThe number of keys in **keys
keysThe array of keys.

◆ dmlite_any_dict_new()

dmlite_any_dict* dmlite_any_dict_new ( )

Created a new generic dictionary.

Returns
A newly allocated dmlite_any_dict.

◆ dmlite_any_dict_to_json()

char* dmlite_any_dict_to_json ( const dmlite_any_dict d,
char *  buffer,
size_t  bsize 
)

Generates a JSON serialization of the dictionary.

Returns
The same pointer as buffer.

◆ dmlite_any_free()

void dmlite_any_free ( dmlite_any any)

Frees a dmlite_any.

Parameters
anyThe dmlite_any to destroy.

◆ dmlite_any_new_long()

dmlite_any* dmlite_any_new_long ( long  l)

Creates a new dmlite_any.

Parameters
lThe long that will be wrapped.
Returns
A newly allocated dmlite_any.

◆ dmlite_any_new_long_array()

dmlite_any* dmlite_any_new_long_array ( unsigned  n,
long *  lv 
)

Creates a new dmlite_any.

Parameters
nThe number of elements.
lvThe longs that will be wrapped.
Returns
A newly allocated dmlite_any.
Deprecated:
Use dmlite_set_array instead.

◆ dmlite_any_new_s64()

dmlite_any* dmlite_any_new_s64 ( int64_t  i)

Creates a new dmlite_any from an int64_t type.

Parameters
iThe int64_t value.
Returns
A newly allocated dmlite_any.

◆ dmlite_any_new_string()

dmlite_any* dmlite_any_new_string ( const char *  str)

Creates a new dmlite_any.

Parameters
strThe string that will be wrapped. It is safe to free afterwards.
Returns
A newly allocated dmlite_any.

◆ dmlite_any_new_string_array()

dmlite_any* dmlite_any_new_string_array ( unsigned  n,
const char **  strv 
)

Creates a new dmlite_any.

Parameters
nThe number of elements.
strvThe strings that will be wrapped. It is safe to free afterwards.
Returns
A newly allocated dmlite_any.
Deprecated:
Use dmlite_set_array instead.

◆ dmlite_any_new_u64()

dmlite_any* dmlite_any_new_u64 ( uint64_t  i)

Creates a new dmlite_any from an uint64_t type.

Parameters
iThe uint64_t value.
Returns
A newly allocated dmlite_any.

◆ dmlite_any_to_long()

long dmlite_any_to_long ( const dmlite_any any)

Returns the long interpretation of they dmlite_any.

Defaults to 0.

Parameters
anyThe dmlite_any to convert.

◆ dmlite_any_to_s64()

int64_t dmlite_any_to_s64 ( const dmlite_any any)

Returns the int64_t interpretation of they dmlite_any.

Defaults to 0.

Parameters
anyThe dmlite_any to convert.

◆ dmlite_any_to_string()

void dmlite_any_to_string ( const dmlite_any any,
char *  buffer,
size_t  bsize 
)

Gets the string interpretation of the dmlite_any.

Defaults to "".

Parameters
anyThe dmlite_any to convert.
bufferWhere to put the string.
bsizeThe size of the buffer.

◆ dmlite_any_to_u64()

uint64_t dmlite_any_to_u64 ( const dmlite_any any)

Returns the uint64_t interpretation of they dmlite_any.

Defaults to 0.

Parameters
anyThe dmlite_any to convert.