libcdsb/include/vtype.h

142 lines
5.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_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_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;
/* 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);
#endif /* LIBCDSB_VTYPE_H */