55 #if !defined(__AMXC_VARIANT_H__)
56 #define __AMXC_VARIANT_H__
122 #define AMXC_VAR_ID_INVALID UINT32_MAX
128 #define AMXC_VAR_ID_NULL 0
134 #define AMXC_VAR_ID_CSTRING 1
140 #define AMXC_VAR_ID_INT8 2
146 #define AMXC_VAR_ID_INT16 3
152 #define AMXC_VAR_ID_INT32 4
158 #define AMXC_VAR_ID_INT64 5
164 #define AMXC_VAR_ID_UINT8 6
170 #define AMXC_VAR_ID_UINT16 7
176 #define AMXC_VAR_ID_UINT32 8
182 #define AMXC_VAR_ID_UINT64 9
188 #define AMXC_VAR_ID_FLOAT 10
194 #define AMXC_VAR_ID_DOUBLE 11
200 #define AMXC_VAR_ID_BOOL 12
206 #define AMXC_VAR_ID_LIST 13
212 #define AMXC_VAR_ID_HTABLE 14
218 #define AMXC_VAR_ID_FD 15
224 #define AMXC_VAR_ID_TIMESTAMP 16
230 #define AMXC_VAR_ID_CSV_STRING 17
236 #define AMXC_VAR_ID_SSV_STRING 18
247 #define AMXC_VAR_ID_ANY 19
257 #define AMXC_VAR_ID_CUSTOM_BASE 20
263 #define AMXC_VAR_ID_MAX UINT32_MAX
270 #define AMXC_VAR_NAME_NULL "null"
276 #define AMXC_VAR_NAME_CSTRING "cstring_t"
282 #define AMXC_VAR_NAME_INT8 "int8_t"
288 #define AMXC_VAR_NAME_INT16 "int16_t"
294 #define AMXC_VAR_NAME_INT32 "int32_t"
300 #define AMXC_VAR_NAME_INT64 "int64_t"
306 #define AMXC_VAR_NAME_UINT8 "uint8_t"
312 #define AMXC_VAR_NAME_UINT16 "uint16_t"
318 #define AMXC_VAR_NAME_UINT32 "uint32_t"
324 #define AMXC_VAR_NAME_UINT64 "uint64_t"
330 #define AMXC_VAR_NAME_FLOAT "float"
336 #define AMXC_VAR_NAME_DOUBLE "double"
342 #define AMXC_VAR_NAME_BOOL "bool"
348 #define AMXC_VAR_NAME_LIST "amxc_llist_t"
354 #define AMXC_VAR_NAME_HTABLE "amxc_htable_t"
360 #define AMXC_VAR_NAME_FD "fd_t"
366 #define AMXC_VAR_NAME_TIMESTAMP "amxc_ts_t"
372 #define AMXC_VAR_NAME_CSV_STRING "csv_string_t"
378 #define AMXC_VAR_NAME_SSV_STRING "ssv_string_t"
392 #define AMXC_VAR_FLAG_DEFAULT 0x00
398 #define AMXC_VAR_FLAG_COPY 0x01
404 #define AMXC_VAR_FLAG_UPDATE 0x02
411 #define AMXC_VAR_FLAG_NO_INDEX 0x04
418 #define AMXC_VAR_FLAG_AUTO_ADD 0x08
436 #define GET_ARG(a, n) amxc_var_get_key(a, n, AMXC_VAR_FLAG_DEFAULT)
446 #define GET_BOOL(a, n) amxc_var_dyncast(bool, n == NULL ? a : GET_ARG(a, n))
456 #define GET_CHAR(a, n) amxc_var_constcast(cstring_t, n == NULL ? a : GET_ARG(a, n))
466 #define GET_UINT32(a, n) amxc_var_dyncast(uint32_t, n == NULL ? a : GET_ARG(a, n))
476 #define GET_INT32(a, n) amxc_var_dyncast(int32_t, n == NULL ? a : GET_ARG(a, n))
487 #define GETI_ARG(a, i) amxc_var_get_index(a, i, AMXC_VAR_FLAG_DEFAULT)
497 #define GETI_BOOL(a, i) amxc_var_dyncast(bool, GETI_ARG(a, i))
507 #define GETI_CHAR(a, i) amxc_var_constcast(cstring_t, GETI_ARG(a, i))
517 #define GETI_UINT32(a, i) amxc_var_dyncast(uint32_t, GETI_ARG(a, i))
527 #define GETI_INT32(a, i) amxc_var_dyncast(int32_t, GETI_ARG(a, i))
538 #define GETP_ARG(a, p) amxc_var_get_path(a, p, AMXC_VAR_FLAG_DEFAULT)
548 #define GETP_BOOL(a, p) amxc_var_dyncast(bool, p == NULL ? a : GETP_ARG(a, p))
558 #define GETP_CHAR(a, p) amxc_var_constcast(cstring_t, p == NULL ? a : GETP_ARG(a, p))
568 #define GETP_UINT32(a, p) amxc_var_dyncast(uint32_t, p == NULL ? a : GETP_ARG(a, p))
578 #define GETP_INT32(a, p) amxc_var_dyncast(int32_t, p == NULL ? a : GETP_ARG(a, p))
584 #define cstring_t char*
589 #define csv_string_t char*
594 #define ssv_string_t char*
609 #define amxc_var_set(type, var, data) amxc_var_set_ ## type(var, data)
618 #define amxc_var_add(type, var, data) amxc_var_add_new_ ## type(var, data)
627 #define amxc_var_add_key(type, var, key, data) amxc_var_add_new_key_ ## type(var, key, data)
678 #define amxc_var_dyncast(type, var) amxc_var_get_ ## type(var)
722 #define amxc_var_constcast(type, var) amxc_var_get_const_ ## type(var)
757 #define amxc_var_take(type, var) amxc_var_take_ ## type(var)
780 #define amxc_var_push(type, var, val) amxc_var_push_ ## type(var, val)
790 #define amxc_var_from_htable_it(ht_it) \
791 ((amxc_var_t*) (((char*) ht_it) - offsetof(amxc_var_t, hit)))
799 #define amxc_var_from_llist_it(ll_it) \
800 ((amxc_var_t*) (((char*) ll_it) - offsetof(amxc_var_t, lit)))
819 #define amxc_var_for_each(var, var_list) \
820 for(amxc_var_t* var = amxc_var_get_first(var_list), \
821 * var ## _next = amxc_var_get_next(var); \
823 var = var ## _next, \
824 var ## _next = amxc_var_get_next(var))
843 #define amxc_var_for_each_reverse(var, var_list) \
844 for(amxc_var_t* var = amxc_var_get_last(var_list), \
845 * var ## _prev = amxc_var_get_previous(var); \
847 var = var ## _prev, \
848 var ## _prev = amxc_var_get_previous(var))
1044 const uint32_t type_id);
1068 const uint32_t type_id);
1133 const char*
const key,
1163 const char*
const key,
1190 const char*
const key) {
1214 const int64_t index,
1242 const int64_t index,
1269 const int64_t index) {
1335 const char*
const path,
1363 const char*
const fmt,
1365 ) __attribute__ ((format(printf, 3, 4)));
1394 const
char* const path,
1428 const
char* const fmt,
1430 ) __attribute__ ((format(printf, 4, 5)));
Ambiorix hash table API header file.
Ambiorix linked list API header file.
Ambiorix string API header file.
Ambiorix timestamp header file.
#define fd_t
Convenience macro.
#define cstring_t
Convenience macro.
void amxc_htable_it_take(amxc_htable_it_t *const it)
Removes the iterator from the hash table.
void amxc_llist_it_take(amxc_llist_it_t *const it)
Removes the iterator from the list.
#define AMXC_VAR_FLAG_DEFAULT
The default flag, do not copy, use variant as is.
uint64_t amxc_var_get_uint64_t(const amxc_var_t *const var)
Conversion helper function.
int amxc_var_push_ssv_string_t(amxc_var_t *const var, char *val)
Pushes a value in a variant.
amxc_var_t * amxc_var_add_new_uint32_t(amxc_var_t *const var, uint32_t val)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_csv_string_t(amxc_var_t *const var, const char *key, const char *const val)
Conversion helper function.
AMXC_INLINE char * amxc_var_get_csv_string_t(const amxc_var_t *const var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_uint8_t(amxc_var_t *const var, uint8_t val)
Conversion helper function.
int amxc_var_set_cstring_t(amxc_var_t *const var, const char *const val)
Setter helper function.
int16_t amxc_var_get_int16_t(const amxc_var_t *const var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_uint64_t(amxc_var_t *const var, uint64_t val)
Conversion helper function.
int8_t amxc_var_get_const_int8_t(const amxc_var_t *const var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_ssv_string_t(amxc_var_t *const var, const char *key, const char *const val)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_uint64_t(amxc_var_t *const var, const char *key, uint64_t val)
Conversion helper function.
const amxc_llist_t * amxc_var_get_const_amxc_llist_t(const amxc_var_t *const var)
Conversion helper function.
int32_t amxc_var_get_const_int32_t(const amxc_var_t *const var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_int64_t(amxc_var_t *const var, const char *key, int64_t val)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_cstring_t(amxc_var_t *const var, const char *key, const char *const val)
Conversion helper function.
char * amxc_var_take_cstring_t(amxc_var_t *const var)
Takes a value from a variant.
int amxc_var_set_double(amxc_var_t *var, double val)
Setter helper function.
amxc_var_t * amxc_var_add_new_cstring_t(amxc_var_t *const var, const char *const val)
Conversion helper function.
double amxc_var_get_double(const amxc_var_t *var)
Conversion helper function.
AMXC_INLINE const char * amxc_var_get_const_csv_string_t(const amxc_var_t *const var)
Conversion helper function.
void variant_list_it_free(amxc_llist_it_t *it)
Helper functions, can be used as delete function for linked lists.
amxc_llist_t * amxc_var_get_amxc_llist_t(const amxc_var_t *const var)
Conversion helper function.
int amxc_var_set_bool(amxc_var_t *const var, bool boolean)
Setter helper function.
int amxc_var_set_uint32_t(amxc_var_t *const var, uint32_t val)
Setter helper function.
amxc_var_t * amxc_var_add_new_amxc_llist_t(amxc_var_t *const var, const amxc_llist_t *list)
Conversion helper function.
amxc_string_t * amxc_var_take_amxc_string_t(amxc_var_t *const var)
Takes a value from a variant.
bool amxc_var_get_bool(const amxc_var_t *const var)
Conversion helper function.
int64_t amxc_var_get_int64_t(const amxc_var_t *const var)
Conversion helper function.
int16_t amxc_var_get_const_int16_t(const amxc_var_t *const var)
Conversion helper function.
void variant_htable_it_free(const char *key, amxc_htable_it_t *it)
Helper functions, can be used as delete function for htable.
amxc_var_t * amxc_var_add_new_int32_t(amxc_var_t *const var, int32_t val)
Conversion helper function.
int32_t amxc_var_get_int32_t(const amxc_var_t *const var)
Conversion helper function.
AMXC_INLINE const char * amxc_var_get_const_ssv_string_t(const amxc_var_t *const var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_uint16_t(amxc_var_t *const var, const char *key, uint16_t val)
Conversion helper function.
const amxc_ts_t * amxc_var_get_const_amxc_ts_t(const amxc_var_t *const var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_int64_t(amxc_var_t *const var, int64_t val)
Conversion helper function.
uint8_t amxc_var_get_uint8_t(const amxc_var_t *const var)
Conversion helper function.
int amxc_var_get_fd_t(const amxc_var_t *var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_bool(amxc_var_t *const var, bool boolean)
Conversion helper function.
int amxc_var_push_csv_string_t(amxc_var_t *const var, char *val)
Pushes a value in a variant.
int amxc_var_set_ssv_string_t(amxc_var_t *const var, const char *const val)
Setter helper function.
amxc_var_t * amxc_var_add_new_double(amxc_var_t *const var, double val)
Conversion helper function.
amxc_var_t * amxc_var_add_new_csv_string_t(amxc_var_t *const var, const char *const val)
Conversion helper function.
bool amxc_var_get_const_bool(const amxc_var_t *const var)
Conversion helper function.
int amxc_var_set_int16_t(amxc_var_t *const var, int16_t val)
Setter helper function.
amxc_var_t * amxc_var_add_new_amxc_htable_t(amxc_var_t *const var, const amxc_htable_t *htable)
Conversion helper function.
int amxc_var_set_int32_t(amxc_var_t *const var, int32_t val)
Setter helper function.
AMXC_INLINE char * amxc_var_take_csv_string_t(amxc_var_t *const var)
Takes a value from a variant.
AMXC_INLINE char * amxc_var_get_ssv_string_t(const amxc_var_t *const var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_amxc_llist_t(amxc_var_t *const var, const char *key, const amxc_llist_t *list)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_double(amxc_var_t *const var, const char *key, double val)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_bool(amxc_var_t *const var, const char *key, bool boolean)
Conversion helper function.
int amxc_var_set_uint64_t(amxc_var_t *const var, uint64_t val)
Setter helper function.
uint8_t amxc_var_get_const_uint8_t(const amxc_var_t *const var)
Conversion helper function.
int amxc_var_set_int64_t(amxc_var_t *const var, int64_t val)
Setter 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.
int amxc_var_set_amxc_ts_t(amxc_var_t *var, amxc_ts_t *val)
Setter helper function.
int amxc_var_set_fd_t(amxc_var_t *var, int val)
Setter helper function.
amxc_var_t * amxc_var_add_new_key_amxc_ts_t(amxc_var_t *const var, const char *key, amxc_ts_t *ts)
Conversion helper function.
amxc_var_t * amxc_var_add_new_uint16_t(amxc_var_t *const var, uint16_t val)
Conversion helper function.
const char * amxc_var_get_const_cstring_t(const amxc_var_t *const var)
Conversion helper function.
char * amxc_var_get_cstring_t(const amxc_var_t *const var)
Conversion helper function.
amxc_htable_t * amxc_var_get_amxc_htable_t(const amxc_var_t *const var)
Conversion helper function.
uint16_t amxc_var_get_const_uint16_t(const amxc_var_t *const var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_int8_t(amxc_var_t *const var, int8_t val)
Conversion helper function.
uint64_t amxc_var_get_const_uint64_t(const amxc_var_t *const var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_fd_t(amxc_var_t *const var, const char *key, int val)
Conversion helper function.
amxc_var_t * amxc_var_add_new_amxc_ts_t(amxc_var_t *const var, amxc_ts_t *ts)
Conversion helper function.
int amxc_var_set_csv_string_t(amxc_var_t *const var, const char *const val)
Setter helper function.
amxc_var_t * amxc_var_add_new_int16_t(amxc_var_t *const var, int16_t val)
Conversion helper function.
int amxc_var_get_const_fd_t(const amxc_var_t *const var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_fd_t(amxc_var_t *const var, int val)
Conversion helper function.
int amxc_var_push_amxc_string_t(amxc_var_t *const var, amxc_string_t *val)
Pushes a value in a variant.
amxc_ts_t * amxc_var_get_amxc_ts_t(const amxc_var_t *var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_int8_t(amxc_var_t *const var, const char *key, int8_t val)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_int32_t(amxc_var_t *const var, const char *key, int32_t val)
Conversion helper function.
const amxc_htable_t * amxc_var_get_const_amxc_htable_t(const amxc_var_t *const var)
Conversion helper function.
int amxc_var_set_uint8_t(amxc_var_t *const var, uint8_t val)
Setter helper function.
uint32_t amxc_var_get_const_uint32_t(const amxc_var_t *const var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_uint32_t(amxc_var_t *const var, const char *key, uint32_t val)
Conversion helper function.
int amxc_var_set_uint16_t(amxc_var_t *const var, uint16_t val)
Setter helper function.
int64_t amxc_var_get_const_int64_t(const amxc_var_t *const var)
Conversion helper function.
int amxc_var_push_cstring_t(amxc_var_t *const var, char *val)
Pushes a value in a variant.
uint32_t amxc_var_get_uint32_t(const amxc_var_t *var)
Conversion helper function.
AMXC_INLINE char * amxc_var_take_ssv_string_t(amxc_var_t *const var)
Takes a value from a variant.
int8_t amxc_var_get_int8_t(const amxc_var_t *const var)
Conversion helper function.
int amxc_var_set_int8_t(amxc_var_t *const var, int8_t val)
Setter helper function.
amxc_var_t * amxc_var_add_new_ssv_string_t(amxc_var_t *const var, const char *const val)
Conversion helper function.
uint16_t amxc_var_get_uint16_t(const amxc_var_t *var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_uint8_t(amxc_var_t *const var, const char *key, uint8_t val)
Conversion helper function.
double amxc_var_get_const_double(const amxc_var_t *const var)
Conversion helper function.
amxc_var_t * amxc_var_add_new_key_int16_t(amxc_var_t *const var, const char *key, int16_t val)
Conversion helper function.
#define AMXC_VAR_ID_NULL
Null variant type id (aka void)
int amxc_var_dump(const amxc_var_t *const var, int fd)
Dumps the content of the variant in a human readable manner.
int amxc_var_log(const amxc_var_t *const var)
Logs the content of the variant in a human readable manner to syslog.
int amxc_var_dump_stream(const amxc_var_t *const var, FILE *stream)
Dumps the content of the variant in a human readable manner.
int amxc_var_move(amxc_var_t *const dest, amxc_var_t *const src)
Moves the type and data from one variant (source) in another variant (destination).
uint32_t amxc_var_type_of(const amxc_var_t *const var)
Gets the variant type id of a variant.
amxc_var_t * amxc_var_get_pathf(const amxc_var_t *const var, const int flags, const char *const fmt,...) __attribute__((format(printf
Retrieves the variant at the given path of a composite variant.
amxc_var_t * amxc_var_get_last(const amxc_var_t *const var)
Gets the last variant in a htable or list variant.
AMXC_INLINE bool amxc_var_is_null(const amxc_var_t *const var)
Checks if the given variant is of the "null" type.
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_path(const amxc_var_t *const var, const char *const path, const int flags)
Retrieves the variant at the given path of a composite variant.
AMXC_INLINE amxc_var_t * amxc_var_take_key(amxc_var_t *const var, const char *const key)
Get a reference to a part of composed variant using a key and removes it from the composed variant.
amxc_var_t int amxc_var_set_path(amxc_var_t *const var, const char *const path, amxc_var_t *data, const int flags)
Sets the variant at the given path of a composite variant.
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.
const char * amxc_var_key(const amxc_var_t *const var)
Gets the key, with which the variant is stored in a htable variant.
int amxc_var_cast(amxc_var_t *const var, const uint32_t type_id)
Casts the variant to another variant type id.
int amxc_var_set_index(amxc_var_t *const var, const int64_t index, amxc_var_t *data, const int flags)
Set a part of composed variant using an index.
amxc_var_t * amxc_var_get_previous(const amxc_var_t *const var)
Gets the previous variant.
struct _amxc_var amxc_var_t
The variant struct definition.
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.
int amxc_var_set_pathf(amxc_var_t *const var, amxc_var_t *data, const int flags, const char *const fmt,...) __attribute__((format(printf
Sets the variant at the given path of a composite variant.
void amxc_var_delete(amxc_var_t **var)
Frees the previously allocated variant.
int amxc_var_set_key(amxc_var_t *const var, const char *const key, amxc_var_t *data, const int flags)
Sets a part of composed variant using a key.
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.
amxc_var_t * amxc_var_get_parent(const amxc_var_t *const var)
Gets the containing variant.
amxc_var_t * amxc_var_get_index(const amxc_var_t *const var, const int64_t index, const int flags)
Get a reference to a part of composed variant using an index.
amxc_var_t * amxc_var_get_next(const amxc_var_t *const var)
Gets the next variant.
int amxc_var_t * amxc_var_get_first(const amxc_var_t *const var)
Gets the first variant in a htable or list variant.
AMXC_INLINE void amxc_var_take_it(amxc_var_t *const var)
Removes the variant for a llist and/or a htable.
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.
AMXC_INLINE amxc_var_t * amxc_var_take_index(amxc_var_t *const var, const int64_t index)
Get a reference to a part of composed variant using an index and removes it from the composed variant...
const char * amxc_var_type_name_of(const amxc_var_t *const var)
Gets the variant type name of a variant.
The hash table iterator structure.
The hash table structure.
The linked list iterator structure.
The linked list structure.
The variant struct definition.
The timestamp structure (unix epoch time).
static amxc_htable_it_t it[2000]
static amxc_htable_t * htable