/* 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_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_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)\ ) #define _LIBCDSB_GenericP(T, f, v) _Generic((v),\ void**: T ## _ ## f ## _pointers, const void**: T ## _ ## f ## _pointers,\ STRING_VIEW*: T ## _ ## f ## _strings, const STRING_VIEW*: T ## _ ## f ## _strings,\ ARRAY*: T ## _ ## f ## _arrays, const ARRAY*: T ## _ ## f ## _arrays,\ LIST*: T ## _ ## f ## _lists, const LIST*: T ## _ ## f ## _lists,\ MAP*: T ## _ ## f ## _maps, const MAP*: T ## _ ## f ## _maps,\ VSET*: T ## _ ## f ## _vsets, const VSET*: T ## _ ## f ## _vsets,\ vtype_bool*: T ## _ ## f ## _booleans, const vtype_bool*: T ## _ ## f ## _booleans,\ vtype_uint8*: T ## _ ## f ## _uint8s, const vtype_uint8*: T ## _ ## f ## _uint8s,\ vtype_uint16*: T ## _ ## f ## _uint16s, const vtype_uint16*: T ## _ ## f ## _uint16s,\ vtype_uint32*: T ## _ ## f ## _uint32s, const vtype_uint32*: T ## _ ## f ## _uint32s,\ vtype_uint64*: T ## _ ## f ## _uint64s, const vtype_uint64*: T ## _ ## f ## _uint64s,\ vtype_int8*: T ## _ ## f ## _int8s, const vtype_int8*: T ## _ ## f ## _int8s,\ vtype_int16*: T ## _ ## f ## _int16s, const vtype_int16*: T ## _ ## f ## _int16s,\ vtype_int32*: T ## _ ## f ## _int32s, const vtype_int32*: T ## _ ## f ## _int32s,\ vtype_int64*: T ## _ ## f ## _int64s, const vtype_int64*: T ## _ ## f ## _int64s,\ vtype_float*: T ## _ ## f ## _floats, const vtype_float*: T ## _ ## f ## _floats,\ vtype_double*: T ## _ ## f ## _doubles, const vtype_double*: T ## _ ## f ## _doubles,\ vtype_ldouble*: T ## _ ## f ## _ldoubles, const vtype_ldouble*: T ## _ ## f ## _ldoubles\ ) #endif /* LIBCDSB_CORE_GENERICS_H */