libcdsb/include/vtype.h

180 lines
7.3 KiB
C

/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <stdint.h>
#include <unistd.h>
#include <stdbool.h>
#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,
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_value { void* mem; int flags; 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; };
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 struct libcdsb_value_pair vtype_kvpair;
typedef struct libcdsb_value vtype_value;
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_string vtype_string;
typedef struct libcdsb_iterator vtype_iterator;
/* Get utf8 chars count in string */
extern size_t string_size(const vtype_string* x) LIBCDSB_pure__ LIBCDSB_nn1__;
/* Get string size in bytes */
extern size_t string_nmemb(const vtype_string* x) LIBCDSB_pure__ LIBCDSB_nn1__;
/* Get count of the array elements */
extern size_t array_size(const vtype_array* x) LIBCDSB_pure__ LIBCDSB_nn1__;
/* Get array size in bytes */
extern size_t array_nmemb(const vtype_array* x) LIBCDSB_pure__ LIBCDSB_nn1__;
/* Get count of the list elements */
extern size_t list_size(const vtype_list* x) LIBCDSB_pure__ LIBCDSB_nn1__;
/* Get count of the map elements */
extern size_t map_size(const vtype_map* x) LIBCDSB_pure__ LIBCDSB_nn1__;
/* Get count of the set elements */
extern size_t vset_size(const vtype_set* x) LIBCDSB_pure__ LIBCDSB_nn1__;
/* Cpmpare 2 strings */
extern int string_compare(const vtype_string* s0, const vtype_string* s1) LIBCDSB_cmpattr__;
/* Compare 2 arrays */
extern int array_compare(const vtype_array* s0, const vtype_array* s1) LIBCDSB_cmpattr__;
/* Compare 2 lists */
extern int list_compare(const vtype_list* s0, const vtype_list* s1) LIBCDSB_cmpattr__;
/* Compare 2 maps */
extern int map_compare(const vtype_map* s0, const vtype_map* s1) LIBCDSB_cmpattr__;
/* Compare 2 sets */
extern int vset_compare(const vtype_set* s0, const vtype_set* s1) LIBCDSB_cmpattr__;
/* Copy string to another */
extern vtype_string string_copy(const vtype_string* s) LIBCDSB_cpyattr__;
/* Copy array to another */
extern vtype_array array_copy(const vtype_array* s) LIBCDSB_cpyattr__;
/* Copy list to another */
extern vtype_list list_copy(const vtype_list* s) LIBCDSB_cpyattr__;
/* Copy map to another */
extern vtype_map map_copy(const vtype_map* s) LIBCDSB_cpyattr__;
/* Copy set to another */
extern vtype_set vset_copy(const vtype_set* s) LIBCDSB_cpyattr__;
/* Duplicate string memory block */
extern vtype_string* string_duplicate(const vtype_string* s) LIBCDSB_dupattr__;
/* Duplicate array memory block */
extern vtype_array* array_duplicate(const vtype_array* s) LIBCDSB_dupattr__;
/* Duplicate list memory block */
extern vtype_list* list_duplicate(const vtype_list* s) LIBCDSB_dupattr__;
/* Duplicate map memory block */
extern vtype_map* map_duplicate(const vtype_map* s) LIBCDSB_dupattr__;
/* Duplicate set memory block */
extern vtype_set* vset_duplicate(const vtype_set* s) LIBCDSB_dupattr__;
/* Copy string and store result to the memory block */
extern void string_copy_init(vtype_string* x, const vtype_string* s) LIBCDSB_nn12__;
/* Copy array and store result to the memory block */
extern void array_copy_init(vtype_array* x, const vtype_array* s) LIBCDSB_nn12__;
/* Copy list and store result to the memory block */
extern void list_copy_init(vtype_list* x, const vtype_list* s) LIBCDSB_nn12__;
/* Copy map and store result to the memory block */
extern void map_copy_init(vtype_map* x, const vtype_map* s) LIBCDSB_nn12__;
/* Copy set and store result to the memory block */
extern void vset_copy_init(vtype_set* x, const vtype_set* s) LIBCDSB_nn12__;
/* 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);
extern void value_init(vtype_value* dest);
extern void value_free(vtype_value* dest);
extern _Bool value_is_readonly (const vtype_value* node);
extern _Bool value_is_strict_type(const vtype_value* node);
extern void value_is_null (const vtype_value* dest);
extern void value_nmemb (const vtype_value* dest);
extern void* value_get_pointer (const vtype_value* src);
extern _Bool value_set_pointer(vtype_value* node, const void* src);
extern _Bool value_set_cstring(vtype_value* node, const char* src);
extern _Bool value_set_string (vtype_value* node, const vtype_string* src);
extern _Bool value_set_array (vtype_value* node, const vtype_array* src);
extern _Bool value_set_list (vtype_value* node, const vtype_list* src);
extern _Bool value_set_map (vtype_value* node, const vtype_map* src);
extern _Bool value_set_vset (vtype_value* node, const vtype_set* src);
extern _Bool value_set_boolean(vtype_value* node, vtype_bool src);
extern _Bool value_set_uint8 (vtype_value* node, vtype_uint8 src);
extern _Bool value_set_uint16 (vtype_value* node, vtype_uint16 src);
extern _Bool value_set_uint32 (vtype_value* node, vtype_uint32 src);
extern _Bool value_set_uint64 (vtype_value* node, vtype_uint64 src);
extern _Bool value_set_int8 (vtype_value* node, vtype_int8 src);
extern _Bool value_set_int16 (vtype_value* node, vtype_int16 src);
extern _Bool value_set_int32 (vtype_value* node, vtype_int32 src);
extern _Bool value_set_int64 (vtype_value* node, vtype_int64 src);
extern _Bool value_set_float (vtype_value* node, vtype_float src);
extern _Bool value_set_double (vtype_value* node, vtype_double src);
extern _Bool value_set_ldouble(vtype_value* node, vtype_ldouble src);
#endif /* LIBCDSB_VTYPE_H */