ubjsc
0.5
Enterprise-grade C library for manipulating UBJSON
|
Library handle, allocation callbacks, glues. More...
#include <ubjs_common.h>
Go to the source code of this file.
Data Structures | |
struct | ubjs_glue_array_builder |
Builder for array glues. More... | |
struct | ubjs_glue_array |
Glue to an array. More... | |
struct | ubjs_glue_array_iterator |
Glue to array iterator. More... | |
struct | ubjs_glue_dict_builder |
Builder for dictionary glues. More... | |
struct | ubjs_glue_dict |
Glue to a dictionary. More... | |
struct | ubjs_glue_dict_iterator |
Glue to dictionary iterator. More... | |
struct | ubjs_library |
Library handle. More... | |
Typedefs | |
typedef void *(* | ubjs_library_alloc_f) (unsigned long len) |
Allocation functor. More... | |
typedef void(* | ubjs_library_free_f) (void *ptr) |
Deallocation functor. More... | |
typedef struct ubjs_library_builder | ubjs_library_builder |
Library handle builder. More... | |
typedef struct ubjs_library | ubjs_library |
Library handle. More... | |
typedef struct ubjs_glue_array | ubjs_glue_array |
Glue to a array. More... | |
typedef struct ubjs_glue_array_builder | ubjs_glue_array_builder |
Builder for array glues. More... | |
typedef struct ubjs_glue_array_iterator | ubjs_glue_array_iterator |
Glue to a array iterator. More... | |
typedef struct ubjs_glue_dict | ubjs_glue_dict |
Glue to a dictionary. More... | |
typedef struct ubjs_glue_dict_builder | ubjs_glue_dict_builder |
Builder for dictionary glues. More... | |
typedef struct ubjs_glue_dict_iterator | ubjs_glue_dict_iterator |
Glue to a dictionary iterator. More... | |
typedef void(* | ubjs_glue_value_free) (void *pvalue) |
Frees the value held in a glue. Note that this is a generic callback, not related to actual ubjs_prmtv_object()-s. More... | |
typedef ubjs_result(* | ubjs_glue_array_builder_new_f) (ubjs_library *lib, ubjs_glue_array_builder **pthis) |
Creates a new array glue builder. More... | |
typedef ubjs_result(* | ubjs_glue_array_builder_free_f) (ubjs_glue_array_builder **) |
Frees the array glue builder. More... | |
typedef ubjs_result(* | ubjs_glue_array_builder_set_value_free_f) (ubjs_glue_array_builder *this, ubjs_glue_value_free value_free) |
Sets the value free callback method. More... | |
typedef ubjs_result(* | ubjs_glue_array_builder_set_length_f) (ubjs_glue_array_builder *this, unsigned int length) |
Sets the predicted length for the array. More... | |
typedef ubjs_result(* | ubjs_glue_array_builder_set_item_size_f) (ubjs_glue_array_builder *this, unsigned int item_size) |
Sets the predicted item size. More... | |
typedef ubjs_result(* | ubjs_glue_array_builder_build_f) (ubjs_glue_array_builder *this, ubjs_glue_array **parr) |
Callback that creates a new array glue based on what was passed to builder. More... | |
typedef ubjs_result(* | ubjs_glue_array_free) (ubjs_glue_array **) |
Frees the array glue. More... | |
typedef ubjs_result(* | ubjs_glue_array_get_length) (ubjs_glue_array *this, unsigned int *pvalue) |
Gets the length of the array under a glue. More... | |
typedef ubjs_result(* | ubjs_glue_array_get_first) (ubjs_glue_array *this, void **pvalue) |
Gets the value of first item. More... | |
typedef ubjs_result(* | ubjs_glue_array_get_last) (ubjs_glue_array *this, void **pvalue) |
Gets the value of last item. More... | |
typedef ubjs_result(* | ubjs_glue_array_get_at) (ubjs_glue_array *this, unsigned int index, void **pvalue) |
Gets the value of item under an index. More... | |
typedef ubjs_result(* | ubjs_glue_array_add_first) (ubjs_glue_array *this, void *value) |
Add the value at beginning. More... | |
typedef ubjs_result(* | ubjs_glue_array_add_last) (ubjs_glue_array *this, void *value) |
Add the value at end. More... | |
typedef ubjs_result(* | ubjs_glue_array_add_at) (ubjs_glue_array *this, unsigned int index, void *value) |
Add the value of item at an index. More... | |
typedef ubjs_result(* | ubjs_glue_array_delete_first) (ubjs_glue_array *this) |
Delete the first item. More... | |
typedef ubjs_result(* | ubjs_glue_array_delete_last) (ubjs_glue_array *this) |
Delete the last item. More... | |
typedef ubjs_result(* | ubjs_glue_array_delete_at) (ubjs_glue_array *this, unsigned int index) |
Delete the item at index. More... | |
typedef ubjs_result(* | ubjs_glue_array_iterate) (ubjs_glue_array *this, ubjs_glue_array_iterator **piterator) |
Creates an iterator over glued array. More... | |
typedef ubjs_result(* | ubjs_glue_array_iterator_next) (ubjs_glue_array_iterator *this) |
Tries to iterate to next item. More... | |
typedef ubjs_result(* | ubjs_glue_array_iterator_get) (ubjs_glue_array_iterator *this, void **pvalue) |
Gets current item's value. More... | |
typedef ubjs_result(* | ubjs_glue_array_iterator_free) (ubjs_glue_array_iterator **pthis) |
Frees the array iterator glue. More... | |
typedef ubjs_result(* | ubjs_glue_dict_builder_new_f) (ubjs_library *lib, ubjs_glue_dict_builder **pthis) |
Creates a new dictionary glue builder. More... | |
typedef ubjs_result(* | ubjs_glue_dict_builder_free_f) (ubjs_glue_dict_builder **) |
Frees the dictionary glue builder. More... | |
typedef ubjs_result(* | ubjs_glue_dict_builder_set_value_free_f) (ubjs_glue_dict_builder *this, ubjs_glue_value_free value_free) |
Sets the value free callback method. More... | |
typedef ubjs_result(* | ubjs_glue_dict_builder_set_length_f) (ubjs_glue_dict_builder *this, unsigned int length) |
Sets the predicted length for the dictionary. More... | |
typedef ubjs_result(* | ubjs_glue_dict_builder_set_item_size_f) (ubjs_glue_dict_builder *this, unsigned int item_size) |
Sets the predicted item size. More... | |
typedef ubjs_result(* | ubjs_glue_dict_builder_build_f) (ubjs_glue_dict_builder *this, ubjs_glue_dict **pdict) |
Callback that creates a new dictionary glue based on what was passed to builder. More... | |
typedef ubjs_result(* | ubjs_glue_dict_free) (ubjs_glue_dict **) |
Frees the dictionary glue. More... | |
typedef ubjs_result(* | ubjs_glue_dict_get_length) (ubjs_glue_dict *this, unsigned int *pvalue) |
Gets the length of the dictionary under a glue. More... | |
typedef ubjs_result(* | ubjs_glue_dict_get) (ubjs_glue_dict *this, unsigned int key_length, char *key, void **pvalue) |
Gets the value under a key. More... | |
typedef ubjs_result(* | ubjs_glue_dict_set) (ubjs_glue_dict *this, unsigned int key_length, char *key, void *value) |
Sets the value under a key. More... | |
typedef ubjs_result(* | ubjs_glue_dict_delete) (ubjs_glue_dict *this, unsigned int key_length, char *key) |
Deletes a key, with its value. More... | |
typedef ubjs_result(* | ubjs_glue_dict_iterate) (ubjs_glue_dict *this, ubjs_glue_dict_iterator **piterator) |
Creates an iterator over glued dictionary. More... | |
typedef ubjs_result(* | ubjs_glue_dict_iterator_next) (ubjs_glue_dict_iterator *this) |
Tries to iterate to next item. More... | |
typedef ubjs_result(* | ubjs_glue_dict_iterator_get_key_length) (ubjs_glue_dict_iterator *this, unsigned int *plen) |
Gets current key's length. More... | |
typedef ubjs_result(* | ubjs_glue_dict_iterator_copy_key) (ubjs_glue_dict_iterator *this, char *text) |
Copies the key to specified array. More... | |
typedef ubjs_result(* | ubjs_glue_dict_iterator_get_value) (ubjs_glue_dict_iterator *this, void **pvalue) |
Gets current value. More... | |
typedef ubjs_result(* | ubjs_glue_dict_iterator_free) (ubjs_glue_dict_iterator **pthis) |
Frees the dictionary iterator glue. More... | |
Functions | |
UBJS_EXPORT ubjs_result | ubjs_library_builder_new (ubjs_library_builder **pthis) |
Initializes the library handle builder. More... | |
UBJS_EXPORT ubjs_result | ubjs_library_builder_free (ubjs_library_builder **pthis) |
Frees the library handle builder. More... | |
UBJS_EXPORT ubjs_result | ubjs_library_builder_set_alloc_f (ubjs_library_builder *this, ubjs_library_alloc_f alloc_f) |
Sets the allocation functor for to use for everything. More... | |
UBJS_EXPORT ubjs_result | ubjs_library_builder_set_free_f (ubjs_library_builder *this, ubjs_library_free_f free_f) |
Sets the deallocation functor for to use for everything. More... | |
UBJS_EXPORT ubjs_result | ubjs_library_builder_set_glue_array_builder (ubjs_library_builder *this, ubjs_glue_array_builder_new_f builder) |
Sets the array glue builder. This allows to select a different implementation of actual key-value store used in arrays. More... | |
UBJS_EXPORT ubjs_result | ubjs_library_builder_set_glue_dict_builder (ubjs_library_builder *this, ubjs_glue_dict_builder_new_f builder) |
Sets the dict glue builder. This allows to select a different implementation of actual key-value store used in dictionaries. More... | |
UBJS_EXPORT ubjs_result | ubjs_library_builder_build (ubjs_library_builder *this, ubjs_library **plib) |
Builds the library and returns it. More... | |
UBJS_EXPORT ubjs_result | ubjs_library_new_stdlib (ubjs_library **pthis) |
Initializes the library handle using stdlib's malloc() and free(). More... | |
UBJS_EXPORT ubjs_result | ubjs_library_free (ubjs_library **pthis) |
Deinitializes the library handle. More... | |
Library handle, allocation callbacks, glues.
typedef struct ubjs_glue_array ubjs_glue_array |
Glue to a array.
typedef ubjs_result(* ubjs_glue_array_add_at) (ubjs_glue_array *this, unsigned int index, void *value) |
Add the value of item at an index.
this | Glue. |
index | Index. |
value | Value. |
typedef ubjs_result(* ubjs_glue_array_add_first) (ubjs_glue_array *this, void *value) |
Add the value at beginning.
this | Glue. |
value | Value. |
typedef ubjs_result(* ubjs_glue_array_add_last) (ubjs_glue_array *this, void *value) |
Add the value at end.
this | Glue. |
value | Value. |
typedef struct ubjs_glue_array_builder ubjs_glue_array_builder |
Builder for array glues.
typedef ubjs_result(* ubjs_glue_array_builder_build_f) (ubjs_glue_array_builder *this, ubjs_glue_array **parr) |
Callback that creates a new array glue based on what was passed to builder.
this | Builder.. |
parr | Pointer to where put new array glue. |
typedef ubjs_result(* ubjs_glue_array_builder_free_f) (ubjs_glue_array_builder **) |
Frees the array glue builder.
After this returns UR_OK, it is guaranteed that pthis points to 0.
pthis | Pointer to existing builder. |
typedef ubjs_result(* ubjs_glue_array_builder_new_f) (ubjs_library *lib, ubjs_glue_array_builder **pthis) |
Creates a new array glue builder.
lib | Library handle. |
pthis | Pointer to where put new builder. |
typedef ubjs_result(* ubjs_glue_array_builder_set_item_size_f) (ubjs_glue_array_builder *this, unsigned int item_size) |
Sets the predicted item size.
If this is called, this gives the clue for implementation that every item will be exactly n sized. If this is called, it is called exactly 1 time.
If this is not called, implementation still must be prepared for any item size.
Default is stdlib's free().
this | Builder. |
value_free | Callback. |
typedef ubjs_result(* ubjs_glue_array_builder_set_length_f) (ubjs_glue_array_builder *this, unsigned int length) |
Sets the predicted length for the array.
If this is called, this gives the clue for implementation that n items will be added to the array after creation. If this is called, it is called exactly 1 time.
If this is not called, implementation still must be prepared for any array size.
Default is stdlib's free().
this | Builder. |
value_free | Callback. |
typedef ubjs_result(* ubjs_glue_array_builder_set_value_free_f) (ubjs_glue_array_builder *this, ubjs_glue_value_free value_free) |
Sets the value free callback method.
This is required.
Default is stdlib's free().
this | Builder. |
value_free | Callback. |
typedef ubjs_result(* ubjs_glue_array_delete_at) (ubjs_glue_array *this, unsigned int index) |
Delete the item at index.
this | Glue. |
index | Index. |
typedef ubjs_result(* ubjs_glue_array_delete_first) (ubjs_glue_array *this) |
Delete the first item.
this | Glue. |
typedef ubjs_result(* ubjs_glue_array_delete_last) (ubjs_glue_array *this) |
Delete the last item.
this | Glue. |
typedef ubjs_result(* ubjs_glue_array_free) (ubjs_glue_array **) |
Frees the array glue.
After this returns UR_OK, it is guaranteed that pthis points to 0.
pthis | Pointer to where glue is. |
typedef ubjs_result(* ubjs_glue_array_get_at) (ubjs_glue_array *this, unsigned int index, void **pvalue) |
Gets the value of item under an index.
After this returns UR_OK, it is guaranteed that pvalue contains the value.
this | Glue. |
index | Index. |
pvalue | Pointer to where put value. |
typedef ubjs_result(* ubjs_glue_array_get_first) (ubjs_glue_array *this, void **pvalue) |
Gets the value of first item.
After this returns UR_OK, it is guaranteed that pvalue contains the value.
this | Glue. |
pvalue | Pointer to where put value. |
typedef ubjs_result(* ubjs_glue_array_get_last) (ubjs_glue_array *this, void **pvalue) |
Gets the value of last item.
After this returns UR_OK, it is guaranteed that pvalue contains the value.
this | Glue. |
pvalue | Pointer to where put value. |
typedef ubjs_result(* ubjs_glue_array_get_length) (ubjs_glue_array *this, unsigned int *pvalue) |
Gets the length of the array under a glue.
After this returns UR_OK, it is guaranteed that pvalue contains the length.
this | Glue. |
pvalue | Pointer to where put value. |
typedef ubjs_result(* ubjs_glue_array_iterate) (ubjs_glue_array *this, ubjs_glue_array_iterator **piterator) |
Creates an iterator over glued array.
this | Glue. |
piterator | Pointer to where put iterator. |
typedef struct ubjs_glue_array_iterator ubjs_glue_array_iterator |
Glue to a array iterator.
typedef ubjs_result(* ubjs_glue_array_iterator_free) (ubjs_glue_array_iterator **pthis) |
Frees the array iterator glue.
After this returns UR_OK, it is guaranteed that pthis points to 0.
pthis | Pointer to where glue is. |
typedef ubjs_result(* ubjs_glue_array_iterator_get) (ubjs_glue_array_iterator *this, void **pvalue) |
Gets current item's value.
this | Glue. |
pvalue | Pointer to where put the value. |
typedef ubjs_result(* ubjs_glue_array_iterator_next) (ubjs_glue_array_iterator *this) |
Tries to iterate to next item.
this | Glue. |
typedef struct ubjs_glue_dict ubjs_glue_dict |
Glue to a dictionary.
typedef struct ubjs_glue_dict_builder ubjs_glue_dict_builder |
Builder for dictionary glues.
typedef ubjs_result(* ubjs_glue_dict_builder_build_f) (ubjs_glue_dict_builder *this, ubjs_glue_dict **pdict) |
Callback that creates a new dictionary glue based on what was passed to builder.
this | Builder.. |
pdict | Pointer to where put new dictionary glue. |
typedef ubjs_result(* ubjs_glue_dict_builder_free_f) (ubjs_glue_dict_builder **) |
Frees the dictionary glue builder.
After this returns UR_OK, it is guaranteed that pthis points to 0.
pthis | Pointer to existing builder. |
typedef ubjs_result(* ubjs_glue_dict_builder_new_f) (ubjs_library *lib, ubjs_glue_dict_builder **pthis) |
Creates a new dictionary glue builder.
lib | Library handle. |
pthis | Pointer to where put new builder. |
typedef ubjs_result(* ubjs_glue_dict_builder_set_item_size_f) (ubjs_glue_dict_builder *this, unsigned int item_size) |
Sets the predicted item size.
If this is called, this gives the clue for implementation that every item will be exactly n sized. If this is called, it is called exactly 1 time.
If this is not called, implementation still must be prepared for any item size.
Default is stdlib's free().
this | Builder. |
value_free | Callback. |
typedef ubjs_result(* ubjs_glue_dict_builder_set_length_f) (ubjs_glue_dict_builder *this, unsigned int length) |
Sets the predicted length for the dictionary.
If this is called, this gives the clue for implementation that n items will be added to the dictionary after creation. If this is called, it is called exactly 1 time.
If this is not called, implementation still must be prepared for any dictionary size.
Default is stdlib's free().
this | Builder. |
value_free | Callback. |
typedef ubjs_result(* ubjs_glue_dict_builder_set_value_free_f) (ubjs_glue_dict_builder *this, ubjs_glue_value_free value_free) |
Sets the value free callback method.
This is required.
Default is stdlib's free().
this | Builder. |
value_free | Callback. |
typedef ubjs_result(* ubjs_glue_dict_delete) (ubjs_glue_dict *this, unsigned int key_length, char *key) |
Deletes a key, with its value.
this | Glue. |
key_length | Key length. |
key | Key. |
typedef ubjs_result(* ubjs_glue_dict_free) (ubjs_glue_dict **) |
Frees the dictionary glue.
After this returns UR_OK, it is guaranteed that pthis points to 0.
pthis | Pointer to where glue is. |
typedef ubjs_result(* ubjs_glue_dict_get) (ubjs_glue_dict *this, unsigned int key_length, char *key, void **pvalue) |
Gets the value under a key.
After this returns UR_OK, it is guaranteed that pvalue contains the value.
this | Glue. |
key_length | Key length. |
key | Key. |
pvalue | Pointer to where put value. |
typedef ubjs_result(* ubjs_glue_dict_get_length) (ubjs_glue_dict *this, unsigned int *pvalue) |
Gets the length of the dictionary under a glue.
After this returns UR_OK, it is guaranteed that pvalue contains the length.
this | Glue. |
pvalue | Pointer to where put value. |
typedef ubjs_result(* ubjs_glue_dict_iterate) (ubjs_glue_dict *this, ubjs_glue_dict_iterator **piterator) |
Creates an iterator over glued dictionary.
this | Glue. |
piterator | Pointer to where put iterator. |
typedef struct ubjs_glue_dict_iterator ubjs_glue_dict_iterator |
Glue to a dictionary iterator.
typedef ubjs_result(* ubjs_glue_dict_iterator_copy_key) (ubjs_glue_dict_iterator *this, char *text) |
Copies the key to specified array.
this | Glue. |
text | Allocated array. |
typedef ubjs_result(* ubjs_glue_dict_iterator_free) (ubjs_glue_dict_iterator **pthis) |
Frees the dictionary iterator glue.
After this returns UR_OK, it is guaranteed that pthis points to 0.
pthis | Pointer to where glue is. |
typedef ubjs_result(* ubjs_glue_dict_iterator_get_key_length) (ubjs_glue_dict_iterator *this, unsigned int *plen) |
Gets current key's length.
this | Glue. |
plen | Pointer to where put key's length. |
typedef ubjs_result(* ubjs_glue_dict_iterator_get_value) (ubjs_glue_dict_iterator *this, void **pvalue) |
Gets current value.
this | Glue. |
pvalue | Pointer to where put the value. |
typedef ubjs_result(* ubjs_glue_dict_iterator_next) (ubjs_glue_dict_iterator *this) |
Tries to iterate to next item.
this | Glue. |
typedef ubjs_result(* ubjs_glue_dict_set) (ubjs_glue_dict *this, unsigned int key_length, char *key, void *value) |
Sets the value under a key.
this | Glue. |
key_length | Key length. |
key | Key. |
value | Value. |
typedef void(* ubjs_glue_value_free) (void *pvalue) |
Frees the value held in a glue. Note that this is a generic callback, not related to actual ubjs_prmtv_object()-s.
pvalue | Pointer to value to be freed. |
typedef struct ubjs_library ubjs_library |
Library handle.
typedef void*(* ubjs_library_alloc_f) (unsigned long len) |
Allocation functor.
This roughly follows the prototype for malloc().
len | Length. |
typedef struct ubjs_library_builder ubjs_library_builder |
Library handle builder.
typedef void(* ubjs_library_free_f) (void *ptr) |
Deallocation functor.
This roughly follows the prototype for free().
ptr | Allocated pointer. |
UBJS_EXPORT ubjs_result ubjs_library_builder_build | ( | ubjs_library_builder * | this, |
ubjs_library ** | plib | ||
) |
Builds the library and returns it.
After this returns UR_OK, it is guaranteed that plib points to newly initialized library handle. Library is allocated using stdlib's malloc, and deallocated with free.
this | Builder. |
plib | Pointer to where put newly created library handle. |
References ubjs_library::alloc_f, ubjs_glue_dict_iterator::free_f, ubjs_library::free_f, ubjs_library::glue_array_builder, ubjs_library::glue_dict_builder, ubjs_glue_array_array_builder_new(), ubjs_glue_dict_list_builder_new(), UR_ERROR, and UR_OK.
Referenced by ubjs_library_new_stdlib().
UBJS_EXPORT ubjs_result ubjs_library_builder_free | ( | ubjs_library_builder ** | pthis | ) |
Frees the library handle builder.
After this returns UR_OK, it is guaranteed that pthis points to 0. Builder is freed with stdlib's free.
Required once after initializing the library.
pthis | Pointer to where put new builder. |
References UR_ERROR, and UR_OK.
Referenced by ubjs_library_new_stdlib().
UBJS_EXPORT ubjs_result ubjs_library_builder_new | ( | ubjs_library_builder ** | pthis | ) |
Initializes the library handle builder.
After this returns UR_OK, it is guaranteed that pthis points to already allocated builder. Builder is allocated with stdlib's malloc.
Required once to initialize library.
pthis | Pointer to where put new builder. |
References ubjs_glue_dict_iterator::free_f, UR_ERROR, and UR_OK.
Referenced by ubjs_library_new_stdlib().
UBJS_EXPORT ubjs_result ubjs_library_builder_set_alloc_f | ( | ubjs_library_builder * | this, |
ubjs_library_alloc_f | alloc_f | ||
) |
UBJS_EXPORT ubjs_result ubjs_library_builder_set_free_f | ( | ubjs_library_builder * | this, |
ubjs_library_free_f | free_f | ||
) |
Sets the deallocation functor for to use for everything.
By default, ubjs uses stdlib's free().
this | Builder. |
free_f | Deallocation functor. |
References ubjs_glue_dict_iterator::free_f, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_library_builder_set_glue_array_builder | ( | ubjs_library_builder * | this, |
ubjs_glue_array_builder_new_f | builder | ||
) |
Sets the array glue builder. This allows to select a different implementation of actual key-value store used in arrays.
By default, ubjs uses ubjs_glue_array_array_builder - built-in doubly-linked list.
this | Builder. |
builder | Glue array builder. |
UBJS_EXPORT ubjs_result ubjs_library_builder_set_glue_dict_builder | ( | ubjs_library_builder * | this, |
ubjs_glue_dict_builder_new_f | builder | ||
) |
Sets the dict glue builder. This allows to select a different implementation of actual key-value store used in dictionaries.
By default, ubjs uses ubjs_glue_dict_list_builder - built-in doubly-linked list.
this | Builder. |
builder | Glue dict builder. |
UBJS_EXPORT ubjs_result ubjs_library_free | ( | ubjs_library ** | pthis | ) |
UBJS_EXPORT ubjs_result ubjs_library_new_stdlib | ( | ubjs_library ** | pthis | ) |
Initializes the library handle using stdlib's malloc() and free().
After this returns UR_OK, it is guaranteed that pthis points to already allocated library handle.
Required for most operations.
pthis | Pointer to where put new library handle. |
References ubjs_library_builder_build(), ubjs_library_builder_free(), ubjs_library_builder_new(), UR_ERROR, and UR_OK.