libcdsb/include/__generics.h
2022-08-14 18:20:17 +03:00

72 lines
4.5 KiB
C

/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#ifndef LIBCDSB_CORE_GENERICS_H
#define LIBCDSB_CORE_GENERICS_H
#define _LIBCDSB_Generic(T, f, v) _Generic((v),\
void*: T ## _ ## f ## _pointer, const void*: T ## _ ## f ## _pointer,\
char*: T ## _ ## f ## _cstring, const char*: T ## _ ## f ## _cstring,\
vtype_string*: T ## _ ## f ## _string, const vtype_string*: T ## _ ## f ## _string,\
vtype_array*: T ## _ ## f ## _array, const vtype_array*: T ## _ ## f ## _array,\
vtype_list*: T ## _ ## f ## _list, const vtype_list*: T ## _ ## f ## _list,\
vtype_map*: T ## _ ## f ## _map, const vtype_map*: T ## _ ## f ## _map,\
vtype_set*: T ## _ ## f ## _vset, const vtype_set*: T ## _ ## f ## _vset,\
vtype_dict*: T ## _ ## f ## _dict, const vtype_dict*: T ## _ ## f ## _dict,\
vtype_bool: T ## _ ## f ## _boolean,\
vtype_uint8: T ## _ ## f ## _uint8,\
vtype_uint16: T ## _ ## f ## _uint16,\
vtype_uint32: T ## _ ## f ## _uint32,\
vtype_uint64: T ## _ ## f ## _uint64,\
vtype_int8: T ## _ ## f ## _int8,\
vtype_int16: T ## _ ## f ## _int16,\
vtype_int32: T ## _ ## f ## _int32,\
vtype_int64: T ## _ ## f ## _int64,\
vtype_float: T ## _ ## f ## _float,\
vtype_double: T ## _ ## f ## _double,\
vtype_ldouble: T ## _ ## f ## _ldouble\
)
#define _LIBCDSB_Generic2(T, f, k, v) _Generic((k),\
void*: _LIBCDSB_Generic(T, f ## _pointer, v), const void*: _LIBCDSB_Generic(T, f ## _pointer, v),\
char*: _LIBCDSB_Generic(T, f ## _cstring, v), const char*: _LIBCDSB_Generic(T, f ## _cstring, v),\
vtype_string*: _LIBCDSB_Generic(T, f ## _string, v), const vtype_string*: _LIBCDSB_Generic(T, f ## _string, v),\
vtype_array*: _LIBCDSB_Generic(T, f ## _array, v), const vtype_array*: _LIBCDSB_Generic(T, f ## _array, v),\
vtype_list*: _LIBCDSB_Generic(T, f ## _list, v), const vtype_list*: _LIBCDSB_Generic(T, f ## _list, v),\
vtype_map*: _LIBCDSB_Generic(T, f ## _map, v), const vtype_map*: _LIBCDSB_Generic(T, f ## _map, v),\
vtype_set*: _LIBCDSB_Generic(T, f ## _vset, v), const vtype_set*: _LIBCDSB_Generic(T, f ## _vset, v),\
vtype_dict*: _LIBCDSB_Generic(T, f ## _dict, v), const vtype_dict*: _LIBCDSB_Generic(T, f ## _dict, v),\
vtype_bool: _LIBCDSB_Generic(T, f ## _boolean, v),\
vtype_uint8: _LIBCDSB_Generic(T, f ## _uint8, v),\
vtype_uint16: _LIBCDSB_Generic(T, f ## _uint16, v),\
vtype_uint32: _LIBCDSB_Generic(T, f ## _uint32, v),\
vtype_uint64: _LIBCDSB_Generic(T, f ## _uint64, v),\
vtype_int8: _LIBCDSB_Generic(T, f ## _int8, v),\
vtype_int16: _LIBCDSB_Generic(T, f ## _int16, v),\
vtype_int32: _LIBCDSB_Generic(T, f ## _int32, v),\
vtype_int64: _LIBCDSB_Generic(T, f ## _int64, v),\
vtype_float: _LIBCDSB_Generic(T, f ## _float, v),\
vtype_double: _LIBCDSB_Generic(T, f ## _double, v),\
vtype_ldouble: _LIBCDSB_Generic(T, f ## _ldouble, v)\
)
#define _LIBCDSB_GenericS(T, f, v) _Generic((v),\
void*: T ## _ ## f ## _cstring, const void*: T ## _ ## f ## _cstring,\
char*: T ## _ ## f ## _cstring, const char*: T ## _ ## f ## _cstring,\
vtype_string*: T ## _ ## f ## _string, const vtype_string*: T ## _ ## f ## _string,\
int: T ## _ ## f ## _char, unsigned int: T ## _ ## f ## _char,\
char: T ## _ ## f ## _char, unsigned char: T ## _ ## f ## _char,\
short: T ## _ ## f ## _char, unsigned short: T ## _ ## f ## _char\
)
#define _LIBCDSB_GenericS2(T, f, s, d) _Generic((s),\
void*: _LIBCDSB_GenericS(T, f ## _cstring, d), const void*: _LIBCDSB_GenericS(T, f ## _cstring, d),\
char*: _LIBCDSB_GenericS(T, f ## _cstring, d), const char*: _LIBCDSB_GenericS(T, f ## _cstring, d),\
vtype_string*: _LIBCDSB_GenericS(T, f ## _string, d), const vtype_string*: _LIBCDSB_GenericS(T, f ## _string, d),\
int: _LIBCDSB_GenericS(T, f ## _char, d), unsigned int: _LIBCDSB_GenericS(T, f ## _char, d),\
char: _LIBCDSB_GenericS(T, f ## _char, d), unsigned char: _LIBCDSB_GenericS(T, f ## _char, d),\
short: _LIBCDSB_GenericS(T, f ## _char, d), unsigned short: _LIBCDSB_GenericS(T, f ## _char, d)\
)
#endif /* LIBCDSB_CORE_GENERICS_H */