54 lines
2.5 KiB
C
54 lines
2.5 KiB
C
/* This software is licensed by the MIT License, see LICENSE file */
|
|
/* Copyright © 2022 Gregory Lirent */
|
|
|
|
#ifndef LIBCDSB_BITS_GENERICS_H
|
|
#define LIBCDSB_BITS_GENERICS_H
|
|
|
|
#define vtypeof(x) (vtype)(_Generic((x),\
|
|
const void*: VTYPE_POINTER, void*: VTYPE_POINTER,\
|
|
const char**: VTYPE_STRING, char**: VTYPE_STRING,\
|
|
const vtype_string*: VTYPE_STRING, vtype_string*: VTYPE_STRING,\
|
|
const vtype_array*: VTYPE_ARRAY, vtype_array*: VTYPE_ARRAY,\
|
|
const vtype_list*: VTYPE_LIST, vtype_list*: VTYPE_LIST,\
|
|
const vtype_map*: VTYPE_MAP, vtype_map*: VTYPE_MAP,\
|
|
const vtype_set*: VTYPE_SET, vtype_set*: VTYPE_SET,\
|
|
const vtype_dict*: VTYPE_DICT, vtype_dict*: VTYPE_DICT,\
|
|
vtype_bool: VTYPE_BOOLEAN,\
|
|
vtype_uint8: VTYPE_UINT8,\
|
|
vtype_uint16: VTYPE_UINT16,\
|
|
vtype_uint32: VTYPE_UINT32,\
|
|
vtype_uint64: VTYPE_UINT64,\
|
|
vtype_int8: VTYPE_INT8,\
|
|
vtype_int16: VTYPE_INT16,\
|
|
vtype_int32: VTYPE_INT32,\
|
|
vtype_int64: VTYPE_INT64,\
|
|
vtype_float: VTYPE_FLOAT,\
|
|
vtype_double: VTYPE_DOUBLE,\
|
|
vtype_ldouble: VTYPE_LDOUBLE))
|
|
|
|
|
|
#define _LIBCDSB_vtypeof(x) vtypeof(_Generic((x), default: (x), const char*: &(x), char*: &(x)))
|
|
#define _LIBCDSB_value_pointer(x) _Generic((x), default: &(x),\
|
|
vtype_string*: (x), const vtype_string*: (x),\
|
|
vtype_array*: (x), const vtype_array*: (x),\
|
|
vtype_list*: (x), const vtype_list*: (x),\
|
|
vtype_map*: (x), const vtype_map*: (x),\
|
|
vtype_set*: (x), const vtype_set*: (x),\
|
|
vtype_dict*: (x), const vtype_dict*: (x))
|
|
#define _LIBCDSB_var(x) libcdsb_variable_build(_LIBCDSB_value_pointer(x), _LIBCDSB_vtypeof(x))
|
|
|
|
#define _LIBCDSB_to_cstring(x) _Generic((x), default: _LIBCDSB_nothing,\
|
|
vtype_string*: _LIBCDSB_deref1, const vtype_string*: _LIBCDSB_deref1,\
|
|
int: libcdsb_char_to_cstring, unsigned int: libcdsb_char_to_cstring,\
|
|
char: libcdsb_char_to_cstring, unsigned char: libcdsb_char_to_cstring,\
|
|
short: libcdsb_char_to_cstring, unsigned short: libcdsb_char_to_cstring\
|
|
)(x)
|
|
|
|
inline const void* _LIBCDSB_nothing(const void* x) __attribute__((always_inline));
|
|
inline const void* _LIBCDSB_deref1 (const void* x) __attribute__((always_inline));
|
|
|
|
inline const void* _LIBCDSB_nothing(const void* x) { return x; }
|
|
inline const void* _LIBCDSB_deref1 (const void* x) { return *(void**)x; }
|
|
|
|
#endif /* LIBCDSB_BITS_GENERICS_H */
|