120 const char* sep =
"";
129 size_t key_length = 0;
140 key_length = strlen(key);
141 if(key_length != 0) {
151 length = intermediate.
data.s == NULL ? 0 : strlen(intermediate.
data.s);
162 string.buffer[
string.last_used] = 0;
163 dest->
data.s =
string.buffer;
248 if(convfn[dest->
type_id] != NULL) {
252 retval = convfn[dest->
type_id](dest, src);
260 const char*
const key,
283 const char*
const key,
290 if((current_hit != NULL) &&
297 if(current_hit != NULL) {
307 if(current_hit != NULL) {
315 if((current_hit == NULL) && (retval != 0)) {
362 if(size_l > size_r) {
365 }
else if(size_l < size_r) {
370 for(
size_t i = 0; i < size_l; i++) {
374 if((key_l == NULL) || (key_r == NULL)) {
377 *result = strcmp(key_l, key_r);
383 when_false((ret == 0) && (*result == 0), exit);
397 .convert_from = NULL,
405 .hit = { .ait = NULL, .key = NULL, .next = NULL },
#define when_failed(x, l)
Ambiorix string API header file.
#define amxc_var_from_htable_it(ht_it)
Get the variant pointer from an amxc htable iterator.
int PRIVATE amxc_var_default_convert_to_null(amxc_var_t *const dest, const amxc_var_t *const src)
uint32_t PRIVATE amxc_var_add_type(amxc_var_type_t *const type, const uint32_t index)
int PRIVATE amxc_var_remove_type(amxc_var_type_t *const type)
size_t amxc_array_size(const amxc_array_t *const array)
Calculates the number of used items in the array.
AMXC_INLINE void * amxc_array_get_data_at(const amxc_array_t *const array, const unsigned int index)
Gets the data pointer of the item at the given index.
void amxc_array_delete(amxc_array_t **array, const amxc_array_it_delete_t func)
Frees the previously allocated array.
void amxc_htable_it_clean(amxc_htable_it_t *const it, amxc_htable_it_delete_t func)
Removes the iterator from the htable and frees allocated memory.
AMXC_INLINE const char * amxc_htable_it_get_key(const amxc_htable_it_t *const it)
Gets the key from the iterator.
#define amxc_htable_it_get_data(it, type, member)
Gets the data pointer from an hash table iterator.
int amxc_htable_init(amxc_htable_t *const htable, const size_t reserve)
Initializes a hash table.
amxc_array_t * amxc_htable_get_sorted_keys(const amxc_htable_t *const htable)
Creates an array containing all keys of the hash table.
int amxc_htable_new(amxc_htable_t **htable, const size_t reserve)
Allocates a hash table.
AMXC_INLINE size_t amxc_htable_size(const amxc_htable_t *const htable)
Calculates the size of the hash table.
AMXC_INLINE bool amxc_htable_is_empty(const amxc_htable_t *const htable)
Checks that the hash table is empty.
int amxc_htable_move(amxc_htable_t *const dest, amxc_htable_t *const src)
Moves all items from one hash table to another hash table.
amxc_htable_it_t * amxc_htable_take(amxc_htable_t *const htable, const char *const key)
Removes a hash table iterator from the hash table.
amxc_htable_it_t * amxc_htable_get(const amxc_htable_t *const htable, const char *const key)
Gets a hash table iterator from the hash table.
AMXC_INLINE size_t amxc_htable_capacity(const amxc_htable_t *const htable)
Calculates the capacity of the hash table.
AMXC_INLINE amxc_htable_it_t * amxc_htable_take_first(const amxc_htable_t *const htable)
Removes the first item stored in the table.
int amxc_htable_insert(amxc_htable_t *const htable, const char *const key, amxc_htable_it_t *const it)
Inserts an item in the hash table.
#define amxc_htable_for_each(it, htable)
Loops over items in the hash table.
void amxc_htable_clean(amxc_htable_t *const htable, amxc_htable_it_delete_t func)
Removes all items from the hash table.
#define amxc_htable_iterate(it, htable)
Loops over items in the hash table.
int amxc_llist_append(amxc_llist_t *const llist, amxc_llist_it_t *const it)
Adds an item to the end of the linked list.
AMXC_INLINE int amxc_string_append(amxc_string_t *const string, const char *const text, const size_t length)
Appends text to the end of the current content of the string buffer.
int amxc_string_init(amxc_string_t *const string, const size_t length)
Initializes a string.
void amxc_string_clean(amxc_string_t *const string)
Frees the string buffer and reset length attributes.
#define AMXC_VAR_FLAG_DEFAULT
The default flag, do not copy, use variant as is.
#define AMXC_VAR_FLAG_COPY
Copy the variant, creates a new variant, leaves the source variant untouched.
#define AMXC_VAR_FLAG_UPDATE
Replaces the value of the variant, leaves the source variant untouched.
amxc_var_t * amxc_var_add_new_amxc_htable_t(amxc_var_t *const var, const amxc_htable_t *htable)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_amxc_htable_t(amxc_var_t *const var, const char *key, const amxc_htable_t *htable)
Conversion helper function.
amxc_htable_t * amxc_var_get_amxc_htable_t(const amxc_var_t *const var)
Conversion helper function.
const amxc_htable_t * amxc_var_get_const_amxc_htable_t(const amxc_var_t *const var)
Conversion helper function.
#define AMXC_VAR_ID_CUSTOM_BASE
Base variant id for custom variants.
#define AMXC_VAR_ID_CSTRING
C-string variant id (aka char *), null terminated string.
#define AMXC_VAR_ID_UINT64
Unsigned 64 bit integer variant id.
#define AMXC_VAR_NAME_HTABLE
Provides a name for variant id AMXC_VAR_ID_HTABLE.
#define AMXC_VAR_ID_ANY
Special variant id, typically used in cast or conversion functions.
#define AMXC_VAR_ID_HTABLE
Ambiorix Hash Table variant id.
int(* amxc_var_convert_fn_t)(amxc_var_t *const dest, const amxc_var_t *const src)
Variant type callback function prototype for dynamically converting one type to another.
int amxc_var_set_type(amxc_var_t *const var, const uint32_t type)
Change the variant data type.
amxc_var_t * amxc_var_get_key(const amxc_var_t *const var, const char *const key, const int flags)
Get a reference to a part of composed variant using a key.
int amxc_var_new(amxc_var_t **var)
Allocates a variant and initializes it to the null variant type.
int amxc_var_init(amxc_var_t *const var)
Initializes a variant.
amxc_var_t * amxc_var_add_new(amxc_var_t *const var)
Adds a new variant to a composite variant.
int amxc_var_copy(amxc_var_t *const dest, const amxc_var_t *const src)
Copy the type and data from one variant (source) in another variant (destination).
void amxc_var_clean(amxc_var_t *const var)
Clean-up and reset variant.
void amxc_var_delete(amxc_var_t **var)
Frees the previously allocated variant.
amxc_var_t * amxc_var_add_new_key(amxc_var_t *const var, const char *key)
Adds a new variant with a key to a composite variant.
int amxc_var_convert(amxc_var_t *const dest, const amxc_var_t *src, const uint32_t type_id)
Converts one variant (source) to another variant(destination) using the specified variant type id.
int amxc_var_compare(const amxc_var_t *const var1, const amxc_var_t *const var2, int *const result)
Compares two variants.
#define amxc_var_constcast(type, var)
Takes the content from a variant.
The hash table iterator structure.
The hash table structure.
A variant type structure.
The variant struct definition.
static amxc_htable_it_t it[2000]
static amxc_htable_t * htable
static int variant_htable_move(amxc_var_t *const dest, amxc_var_t *const src)
static int variant_htable_to_bool(amxc_var_t *const dest, const amxc_var_t *const src)
static int variant_htable_to_number(amxc_var_t *const dest, const amxc_var_t *const src)
static int variant_htable_set_key(amxc_var_t *const dest, amxc_var_t *const src, const char *const key, int flags)
static int variant_htable_copy_htable(amxc_var_t *const dest, const amxc_htable_t *const src_htable)
static amxc_var_type_t amxc_variant_htable
void variant_htable_it_free(UNUSED const char *key, amxc_htable_it_t *it)
static int variant_htable_convert_to(amxc_var_t *const dest, const amxc_var_t *const src)
static void variant_htable_delete(amxc_var_t *var)
static amxc_var_t * variant_htable_get_index(const amxc_var_t *const src, const int64_t index, int flags)
static int variant_htable_init(amxc_var_t *const var)
static int variant_htable_to_llist(amxc_var_t *const dest, const amxc_var_t *const src)
static int variant_htable_to_string(amxc_var_t *const dest, const amxc_var_t *const src)
static int variant_htable_compare(const amxc_var_t *const lval, const amxc_var_t *const rval, int *const result)
static amxc_var_t * variant_htable_get_key(const amxc_var_t *const src, const char *const key, int flags)
static CONSTRUCTOR void amxc_var_htable_init(void)
static DESTRUCTOR void amxc_var_htable_cleanup(void)
static int variant_htable_copy(amxc_var_t *const dest, const amxc_var_t *const src)