Update headers

This commit is contained in:
Gregory Lirent 2022-08-17 22:20:04 +03:00
parent 283cc9ba4a
commit 9f83f59502
11 changed files with 34 additions and 16 deletions

View File

@ -7,6 +7,8 @@
#ifndef LIBCDSB_DICT_H
#define LIBCDSB_DICT_H
/*#####################################################################################################################*/
typedef int (*dict_access_callback)(const void* key, vtype key_type, void* value, vtype value_type, void* data);
extern void dict_init(vtype_dict* x) Nonnull__(1);
@ -16,6 +18,10 @@ extern void dict_init(vtype_dict* x) Nonnull__(1);
#define dict_update(x, key, value) _LIBCDSB_Generic2(libcdsb_dict, update, key, value)(x, key, value)
#define dict_remove(x, key) dict_pop(x, key, 0, 0)
#define in_dict(x, key) (dict_get(&x, key, 0, 0) == 0)
/*#####################################################################################################################*/
extern int libcdsb_dict_get_by_pointer(vtype_dict* x, const void* key, void* data, dict_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_dict_get_by_cstring(vtype_dict* x, const char* key, void* data, dict_access_callback, bool cut) Nonnull__(1,2);
extern int libcdsb_dict_get_by_string (vtype_dict* x, const vtype_string* key, void* data, dict_access_callback, bool cut) Nonnull__(1,2);

View File

@ -9,7 +9,7 @@
#define dict_foreach(x, data, callback) libcdsb_dict_foreach(x, data, callback, 0)
extern bool libcdsb_dict_update (vtype_dict* x, const void* key, vtype key_type, const void* value, vtype value_type) Nonnull__(1);
extern int libcdsb_dict_get (vtype_dict* x, const void* key, vtype key_type, void* data, dict_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_dict_find (vtype_dict* x, const void* key, vtype key_type, void* data, dict_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_dict_foreach (vtype_dict* x, void* data, dict_access_callback, bool flush) Nonnull__(1,3);
extern bool libcdsb_dict_shrink_to_fit(vtype_dict* x) Nonnull__(1);

View File

@ -22,10 +22,13 @@ extern void* libcdsb_malloc (size_t n) Warn_unused_result__;
extern void* libcdsb_calloc (size_t n, size_t c) Warn_unused_result__;
extern void* libcdsb_realloc(void *p, size_t n) Warn_unused_result__;
extern void libcdsb_free(void* s);
#define aligned_alloc libcdsb_aalloc
#define malloc libcdsb_malloc
#define calloc libcdsb_calloc
#define realloc libcdsb_realloc
#define free libcdsb_free
#define stack_init libcdsb_stack_init
#define stack_push libcdsb_stack_push

View File

@ -8,7 +8,7 @@
/*#####################################################################################################################*/
#define string_split(x, sep, maxn) _LIBCDSB_GenericS(libcdsb_string, split, sep)(x, sep, maxn)
#define string_split(s, sep, maxn) _LIBCDSB_GenericS(libcdsb_string, split, sep)(s, sep, maxn)
#define string_case_compare string_compare_case_insensitive
#define string_replace_r(x, src, dest, maxn) _LIBCDSB_GenericS2(libcdsb_string, replace_r, src, dest)(x, src, dest, maxn)
@ -27,15 +27,15 @@ extern size_t string_align_center(vtype_string* x, size_t padsize, int padchr) N
extern size_t string_align_right (vtype_string* x, size_t padsize, int padchr) Nonnull__(1);
extern size_t string_align_left (vtype_string* x, size_t padsize, int padchr) Nonnull__(1);
extern int string_compare_case_insensitive(const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2);
extern void libcdsb_string_replace(vtype_string* x, char* dest, size_t dest_nmemb, const char* src, size_t nmemb) Nonnull__(1,2);
/*#####################################################################################################################*/
inline vtype_array libcdsb_string_split_string (const vtype_string* x, const vtype_string* sep, size_t maxn) Nonnull__(1) Always_inline__;
extern vtype_array libcdsb_string_split_cstring(const vtype_string* string, const char* sep, size_t maxn) Nonnull__(1);
extern vtype_array libcdsb_string_split_char (const vtype_string* string, int chr, size_t maxn) Nonnull__(1);
extern int string_compare_case_insensitive(const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2);
inline vtype_array libcdsb_string_split_string (const vtype_string* s, const vtype_string* sep, size_t maxn) Nonnull__(1) Always_inline__;
extern vtype_array libcdsb_string_split_cstring(const vtype_string* s, const char* sep, size_t maxn) Nonnull__(1);
extern vtype_array libcdsb_string_split_char (const vtype_string* s, int chr, size_t maxn) Nonnull__(1);
inline void libcdsb_string_trim_string (vtype_string* x, const vtype_string* s, int direction) Nonnull__(1) Always_inline__;
extern void libcdsb_string_trim_cstring(vtype_string* x, const char* s, int direction) Nonnull__(1);

View File

@ -6,8 +6,6 @@
#ifndef LIBCDSB_EXTRA_VTYPE_H
#define LIBCDSB_EXTRA_VTYPE_H
extern const size_t LIBCDSB_VTYPE_SIZES[18];
extern const char* libcdsb_vtype_name(vtype t) Warn_unused_result__;
extern const char* libcdsb_vtype_stringify(const void* value, vtype t) Warn_unused_result__;

View File

@ -11,8 +11,8 @@
typedef int (*list_access_callback)(void* value, ssize_t index, vtype type, void* data);
extern void list_init (vtype_list* x) Nonnull__(1);
extern void list_extend(vtype_list* x, const vtype_list* s) Nonnull__(1,2);
extern void list_init (vtype_list* x) Nonnull__(1);
extern void list_extend (vtype_list* x, const vtype_list* s) Nonnull__(1,2);
extern size_t list_slice (vtype_list* x, vtype_list* src, ssize_t index, size_t count, bool cut) Nonnull__(1,2);
extern void list_sort (vtype_list* x) Nonnull__(1);
extern void list_reverse(vtype_list* x) Nonnull__(1);

View File

@ -7,6 +7,8 @@
#ifndef LIBCDSB_MAP_H
#define LIBCDSB_MAP_H
/*#####################################################################################################################*/
typedef int (*map_access_callback)(const void* key, vtype key_type, void* value, vtype value_type, void* data);
extern void map_init(vtype_map* x, vtype key_type) Nonnull__(1);
@ -16,6 +18,10 @@ extern void map_init(vtype_map* x, vtype key_type) Nonnull__(1);
#define map_update(x, key, value) _LIBCDSB_Generic2(libcdsb_map, update, key, value)(x, key, value)
#define map_remove(x, key) map_pop(x, key, 0, 0)
#define in_map(x, key) (map_get(&x, key, 0, 0) == 0)
/*#####################################################################################################################*/
extern int libcdsb_map_find_pointer(vtype_map* x, const void* key, void* data, map_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_map_find_cstring(vtype_map* x, const char* key, void* data, map_access_callback, bool cut) Nonnull__(1,2);
extern int libcdsb_map_find_string (vtype_map* x, const vtype_string* key, void* data, map_access_callback, bool cut) Nonnull__(1,2);

View File

@ -7,6 +7,8 @@
#ifndef LIBCDSB_SET_H
#define LIBCDSB_SET_H
/*#####################################################################################################################*/
typedef int (*vset_access_callback)(const void* value, vtype type, void* data);
extern void vset_init(vtype_set* x, vtype type) Nonnull__(1);
@ -14,8 +16,11 @@ extern void vset_init(vtype_set* x, vtype type) Nonnull__(1);
#define vset_pop(x, value, data, callback) _LIBCDSB_Generic (libcdsb_vset, find, value)(x, value, data, callback, 1)
#define vset_get(x, value, data, callback) _LIBCDSB_Generic (libcdsb_vset, find, value)(x, value, data, callback, 0)
#define vset_push(x, value) _LIBCDSB_Generic (libcdsb_vset, push, value)(x, value)
#define vset_remove(x, value) vset_pop(x, value, 0, 0)
#define in_vset(x, value) (vset_get(&x, value, 0, 0, 0) == 0)
#define in_vset(x, value) (vset_get(&x, value, 0, 0) == 0)
/*#####################################################################################################################*/
extern bool libcdsb_vset_push_pointer(vtype_set* x, const void* value) Nonnull__(1);
extern bool libcdsb_vset_push_cstring(vtype_set* x, const char* value) Nonnull__(1,2);

View File

@ -13,11 +13,11 @@
extern void string_init(vtype_string* x, const char* value) Nonnull__(1);
extern char* string_at(const vtype_string* s, ssize_t index) Nonnull__(1);
extern bool string_slice(vtype_string* x, vtype_string* s, ssize_t index, size_t nchars, bool cut) Nonnull__(1,2);
extern size_t string_slice(vtype_string* x, vtype_string* s, ssize_t index, size_t nchars, bool cut) Nonnull__(1,2);
#define string_indexof(s, arg) _LIBCDSB_GenericS(libcdsb_string, indexof, arg)(s, arg)
#define string_count(s, arg) _LIBCDSB_GenericS(libcdsb_string, count, arg)(s, arg)
#define string_concat(s, value) _LIBCDSB_GenericS(libcdsb_string, concat, value)(s, value)
#define string_concat(x, value) _LIBCDSB_GenericS(libcdsb_string, concat, value)(x, value)
#define string_trim_spaces(x) libcdsb_string_trim_spaces(x, 0)
#define string_ltrim_spaces(x) libcdsb_string_trim_spaces(x, -1)

View File

@ -31,8 +31,6 @@ typedef enum libcdsb_value_types {
VTYPE_LIST = 16,
VTYPE_SET = 17,
VTYPE_DICT = 18,
LIBCDSB_VTYPE_TERMINATION, /* It must be at the end of the enum. Never be used */
} vtype;

View File

@ -14,6 +14,8 @@
#ifndef LIBCDSB_SRC_INTERNAL_INCLUDE
#define LIBCDSB_SRC_INTERNAL_INCLUDE
extern const size_t LIBCDSB_VTYPE_SIZES[19];
#define is_x64 (sizeof(void*) == sizeof(vtype_uint64))
#define is_big_endian (*((unsigned int*)"\0\0\0\1") < (unsigned int)0xffff)
#define is_little_endian (!is_big_endian)