libcdsb/include/array.h

94 lines
8.6 KiB
C

/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "__generics.h"
#include "vtype.h"
#ifndef LIBCDSB_ARRAY_H
#define LIBCDSB_ARRAY_H
/*#####################################################################################################################*/
typedef int (*array_access_callback)(void* value, ssize_t index, vtype type, void* data);
extern void array_init(vtype_array* x, vtype type) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void* array_at(const vtype_array* s, ssize_t index) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t array_slice(vtype_array* x, vtype_array* src, ssize_t index, size_t count, _Bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void array_sort (vtype_array* x) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void array_reverse(vtype_array* x) LIBCDSB_nt__ LIBCDSB_nn1__;
#define array_pop(x, value, data, callback) _LIBCDSB_Generic(libcdsb_array, find, value)(x, value, data, callback, 0, 1)
#define array_find(x, value, data, callback) _LIBCDSB_Generic(libcdsb_array, find, value)(x, value, data, callback, 0, 0)
#define array_rfind(x, value, data, callback) _LIBCDSB_Generic(libcdsb_array, find, value)(x, value, data, callback, 1, 0)
#define list_countof(x, value) _LIBCDSB_Generic(libcdsb_array, count, value)(x, value)
#define array_remove(x, value) array_pop(x, value, 0, 0)
#define in_array(x, value) (array_find(x, value, 0, 0) == 0)
#define array_push_back(x, value) _LIBCDSB_Generic(libcdsb_array, push, value)(x, value)
/*#####################################################################################################################*/
extern void libcdsb_array_push_pointer(vtype_array* x, const void* value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_cstring(vtype_array* x, const char* value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_string (vtype_array* x, const vtype_string* value) LIBCDSB_nt__ LIBCDSB_nn12__;
extern void libcdsb_array_push_array (vtype_array* x, const vtype_array* value) LIBCDSB_nt__ LIBCDSB_nn12__;
extern void libcdsb_array_push_list (vtype_array* x, const vtype_list* value) LIBCDSB_nt__ LIBCDSB_nn12__;
extern void libcdsb_array_push_map (vtype_array* x, const vtype_map* value) LIBCDSB_nt__ LIBCDSB_nn12__;
extern void libcdsb_array_push_vset (vtype_array* x, const vtype_set* value) LIBCDSB_nt__ LIBCDSB_nn12__;
extern void libcdsb_array_push_boolean(vtype_array* x, vtype_bool value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_uint8 (vtype_array* x, vtype_uint8 value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_uint16 (vtype_array* x, vtype_uint16 value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_uint32 (vtype_array* x, vtype_uint32 value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_uint64 (vtype_array* x, vtype_uint64 value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_int8 (vtype_array* x, vtype_int8 value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_int16 (vtype_array* x, vtype_int16 value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_int32 (vtype_array* x, vtype_int32 value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_int64 (vtype_array* x, vtype_int64 value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_float (vtype_array* x, vtype_float value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_double (vtype_array* x, vtype_double value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_ldouble(vtype_array* x, vtype_ldouble value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t libcdsb_array_count_pointer(const vtype_array* s, const void* value);
extern size_t libcdsb_array_count_cstring(const vtype_array* s, const char* value);
extern size_t libcdsb_array_count_string (const vtype_array* s, const vtype_string* value);
extern size_t libcdsb_array_count_array (const vtype_array* s, const vtype_array* value);
extern size_t libcdsb_array_count_list (const vtype_array* s, const vtype_list* value);
extern size_t libcdsb_array_count_map (const vtype_array* s, const vtype_map* value);
extern size_t libcdsb_array_count_vset (const vtype_array* s, const vtype_set* value);
extern size_t libcdsb_array_count_boolean(const vtype_array* s, vtype_bool value);
extern size_t libcdsb_array_count_int8 (const vtype_array* s, vtype_int8 value);
extern size_t libcdsb_array_count_int16 (const vtype_array* s, vtype_int16 value);
extern size_t libcdsb_array_count_int32 (const vtype_array* s, vtype_int32 value);
extern size_t libcdsb_array_count_int64 (const vtype_array* s, vtype_int64 value);
extern size_t libcdsb_array_count_uint8 (const vtype_array* s, vtype_uint8 value);
extern size_t libcdsb_array_count_uint16 (const vtype_array* s, vtype_uint16 value);
extern size_t libcdsb_array_count_uint32 (const vtype_array* s, vtype_uint32 value);
extern size_t libcdsb_array_count_uint64 (const vtype_array* s, vtype_uint64 value);
extern size_t libcdsb_array_count_float (const vtype_array* s, vtype_float value);
extern size_t libcdsb_array_count_double (const vtype_array* s, vtype_double value);
extern size_t libcdsb_array_count_ldouble(const vtype_array* s, vtype_ldouble value);
extern int libcdsb_array_find_pointer(vtype_array* x, const void* value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_string (vtype_array* x, const char* value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn12__;
extern int libcdsb_array_find_array (vtype_array* x, const vtype_string* value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn12__;
extern int libcdsb_array_find_list (vtype_array* x, const vtype_array* value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn12__;
extern int libcdsb_array_find_map (vtype_array* x, const vtype_list* value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn12__;
extern int libcdsb_array_find_vset (vtype_array* x, const vtype_map* value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn12__;
extern int libcdsb_array_find_cstring(vtype_array* x, const vtype_set* value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_boolean(vtype_array* x, vtype_bool value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_uint8 (vtype_array* x, vtype_uint8 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_uint16 (vtype_array* x, vtype_uint16 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_uint32 (vtype_array* x, vtype_uint32 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_uint64 (vtype_array* x, vtype_uint64 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_int8 (vtype_array* x, vtype_int8 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_int16 (vtype_array* x, vtype_int16 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_int32 (vtype_array* x, vtype_int32 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_int64 (vtype_array* x, vtype_int64 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_float (vtype_array* x, vtype_float value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_double (vtype_array* x, vtype_double value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_ldouble(vtype_array* x, vtype_ldouble value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
#endif /* LIBCDSB_ARRAY_H */