/* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ #include #include #include #include "__attributes.h" #ifndef LIBCDSB_VTYPE_H #define LIBCDSB_VTYPE_H typedef enum libcdsb_value_types { VTYPE_POINTER = 0, VTYPE_BOOLEAN = 1, VTYPE_UINT8 = 2, VTYPE_UINT16 = 3, VTYPE_UINT32 = 4, VTYPE_UINT64 = 5, VTYPE_INT8 = 6, VTYPE_INT16 = 7, VTYPE_INT32 = 8, VTYPE_INT64 = 9, VTYPE_FLOAT = 10, VTYPE_DOUBLE = 11, VTYPE_LDOUBLE = 12, VTYPE_STRING = 13, VTYPE_MAP = 14, VTYPE_ARRAY = 15, 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; struct libcdsb_string { char* buffer; }; struct libcdsb_array { void* mem; size_t size; vtype type; }; struct libcdsb_map { struct libcdsb_map_node* root; vtype type; }; struct libcdsb_set { struct libcdsb_rbtree_node* root; vtype type; }; struct libcdsb_list { struct libcdsb_list_node* last; struct libcdsb_list_node* first; }; struct libcdsb_dict { struct libcdsb_dict_node** nodes; size_t capacity; size_t size; }; typedef void* vtype_pointer; typedef bool vtype_bool; typedef uint_least8_t vtype_uint8; typedef uint_least16_t vtype_uint16; typedef uint_least32_t vtype_uint32; typedef uint_least64_t vtype_uint64; typedef int_least8_t vtype_int8; typedef int_least16_t vtype_int16; typedef int_least32_t vtype_int32; typedef int_least64_t vtype_int64; typedef float vtype_float; typedef double vtype_double; typedef long double vtype_ldouble; typedef size_t vtype_hash; typedef struct libcdsb_array vtype_array; typedef struct libcdsb_map vtype_map; typedef struct libcdsb_set vtype_set; typedef struct libcdsb_list vtype_list; typedef struct libcdsb_dict vtype_dict; typedef struct libcdsb_string vtype_string; /* Get utf8 chars count in string */ extern size_t string_size(const vtype_string* x) Pure__ Warn_unused_result__ Nonnull__(1); /* Get string size in bytes */ extern size_t string_nmemb(const vtype_string* x) Pure__ Warn_unused_result__ Nonnull__(1); /* Get count of the array elements */ extern size_t array_size(const vtype_array* x) Pure__ Warn_unused_result__ Nonnull__(1); /* Get array size in bytes */ extern size_t array_nmemb(const vtype_array* x) Pure__ Warn_unused_result__ Nonnull__(1); /* Get count of the list elements */ extern size_t list_size(const vtype_list* x) Pure__ Warn_unused_result__ Nonnull__(1); /* Get count of the map elements */ extern size_t map_size(const vtype_map* x) Pure__ Warn_unused_result__ Nonnull__(1); /* Get count of the set elements */ extern size_t vset_size(const vtype_set* x) Pure__ Warn_unused_result__ Nonnull__(1); /* Get count of the dict elements */ extern size_t dict_size(const vtype_dict* x) Pure__ Warn_unused_result__ Nonnull__(1); /* Get count of the available nodes */ extern size_t dict_capacity(const vtype_dict* x) Pure__ Warn_unused_result__ Nonnull__(1); /* Cpmpare 2 strings */ extern int string_compare(const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); /* Compare 2 arrays */ extern int array_compare(const vtype_array* s0, const vtype_array* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); /* Compare 2 lists */ extern int list_compare(const vtype_list* s0, const vtype_list* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); /* Compare 2 maps */ extern int map_compare(const vtype_map* s0, const vtype_map* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); /* Compare 2 sets */ extern int vset_compare(const vtype_set* s0, const vtype_set* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); /* Compare 2 dicts */ extern int dict_compare(const vtype_dict* s0, const vtype_dict* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); /* Copy string to another */ extern vtype_string string_copy(const vtype_string* s) Pure__ Warn_unused_result__ Nonnull__(1); /* Copy array to another */ extern vtype_array array_copy(const vtype_array* s) Pure__ Warn_unused_result__ Nonnull__(1); /* Copy list to another */ extern vtype_list list_copy(const vtype_list* s) Pure__ Warn_unused_result__ Nonnull__(1); /* Copy map to another */ extern vtype_map map_copy(const vtype_map* s) Pure__ Warn_unused_result__ Nonnull__(1); /* Copy set to another */ extern vtype_set vset_copy(const vtype_set* s) Pure__ Warn_unused_result__ Nonnull__(1); /* Copy set to another */ extern vtype_dict dict_copy(const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); /* Duplicate string memory block */ extern vtype_string* string_duplicate(const vtype_string* s) Warn_unused_result__ Nonnull__(1); /* Duplicate array memory block */ extern vtype_array* array_duplicate(const vtype_array* s) Warn_unused_result__ Nonnull__(1); /* Duplicate list memory block */ extern vtype_list* list_duplicate(const vtype_list* s) Warn_unused_result__ Nonnull__(1); /* Duplicate map memory block */ extern vtype_map* map_duplicate(const vtype_map* s) Warn_unused_result__ Nonnull__(1); /* Duplicate set memory block */ extern vtype_set* vset_duplicate(const vtype_set* s) Warn_unused_result__ Nonnull__(1); /* Duplicate dict memory block */ extern vtype_dict* dict_duplicate(const vtype_dict* s) Warn_unused_result__ Nonnull__(1); /* Copy string and store result to the memory block */ extern void string_copy_init(vtype_string* x, const vtype_string* s) Nonnull__(1,2); /* Copy array and store result to the memory block */ extern void array_copy_init(vtype_array* x, const vtype_array* s) Nonnull__(1,2); /* Copy list and store result to the memory block */ extern void list_copy_init(vtype_list* x, const vtype_list* s) Nonnull__(1,2); /* Copy map and store result to the memory block */ extern void map_copy_init(vtype_map* x, const vtype_map* s) Nonnull__(1,2); /* Copy set and store result to the memory block */ extern void vset_copy_init(vtype_set* x, const vtype_set* s) Nonnull__(1,2); /* Copy dict and store result to the memory block */ extern void dict_copy_init(vtype_dict* x, const vtype_dict* s) Nonnull__(1,2); /* Free string resources */ extern void string_free(vtype_string* x); /* Free array resources */ extern void array_free(vtype_array* x); /* Free list resources */ extern void list_free(vtype_list* x); /* Free map resources */ extern void map_free(vtype_map* x); /* Free set resources */ extern void vset_free(vtype_set* x); /* Free dict resources */ extern void dict_free(vtype_dict* x); /* Get hash of the string */ extern vtype_hash string_hash(const vtype_string* s) Pure__ Warn_unused_result__ Nonnull__(1); /* Get hash of the array */ extern vtype_hash array_hash(const vtype_array* s) Pure__ Warn_unused_result__ Nonnull__(1); /* Get hash of the list */ extern vtype_hash list_hash(const vtype_list* s) Pure__ Warn_unused_result__ Nonnull__(1); /* Get hash of the map */ extern vtype_hash map_hash(const vtype_map* s) Pure__ Warn_unused_result__ Nonnull__(1); /* Get hash of the set */ extern vtype_hash vset_hash(const vtype_set* s) Pure__ Warn_unused_result__ Nonnull__(1); /* Get hash of the dict */ extern vtype_hash dict_hash(const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); #endif /* LIBCDSB_VTYPE_H */