Typesafe, dynamic object store based on talloc. More...
#include <errno.h>#include <inttypes.h>#include <stdbool.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <strings.h>#include <talloc.h>#include <atalk/errchk.h>#include <atalk/util.h>#include <atalk/logger.h>#include <atalk/dalloc.h>Functions | |
| int | dalloc_add_talloc_chunk (DALLOC_CTX *dd, void *talloc_chunk, void *obj, size_t size) |
| void * | dalloc_get (const DALLOC_CTX *d,...) |
| Get pointer to value from a DALLOC object. | |
| void * | dalloc_value_for_key (const DALLOC_CTX *d,...) |
| char * | dalloc_strdup (const void *ctx, const char *string) |
| char * | dalloc_strndup (const void *ctx, const char *string, size_t n) |
Typesafe, dynamic object store based on talloc.
Usage:
Define some terminal types:
A key/value store aka dictionary that supports retrieving elements by key
An ordered set that can store different objects which can be retrieved by number
Create an dalloc object and add elementes of different type
Allocate a new talloc context
Create a new dalloc object
Store an int value in the object
Store a string
Add a nested object, you later can't fetch this directly
Add an int value to the nested object, this can be fetched
Add a nested set
Add an int value to the set
Add a dictionary (key/value store)
Store a string as key in the dict
Add a value for the key
Fetching value references
You can fetch anything that is not a DALLOC_CTXs, because passing "DALLOC_CTXs" as type to the functions dalloc_get() and dalloc_value_for_key() tells the function to step into that object and expect more arguments that specify which element to fetch.
Get reference to an objects element by position
p now points to the first int with a value of 1
Get reference to the "hello world" string
You can't fetch a pure DALLOC_CTX
But you can do this
p now points to the value 2
You can fetch types that are typedefd DALLOC_CTXs
Fetch int from set, note that you must use DALLOC_CTX as type for the set
p points to 3
Fetch value by key from dictionary
p now point to 4
| int dalloc_add_talloc_chunk | ( | DALLOC_CTX * | dd, |
| void * | talloc_chunk, | ||
| void * | obj, | ||
| size_t | size ) |
Use dalloc_add_copy() macro, not this function
| void * dalloc_get | ( | const DALLOC_CTX * | d, |
| ... ) |
Get pointer to value from a DALLOC object.
Returns pointer to object from a DALLOC object. Nested object interation is supported by using the type string "DALLOC_CTX". Any other type string designates the requested objects type.
| char * dalloc_strdup | ( | const void * | ctx, |
| const char * | string ) |
| char * dalloc_strndup | ( | const void * | ctx, |
| const char * | string, | ||
| size_t | n ) |
| void * dalloc_value_for_key | ( | const DALLOC_CTX * | d, |
| ... ) |