libcdsb/include/array.h
2022-08-16 18:39:55 +03:00

96 lines
8.7 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) Nonnull__(1);
extern void* array_at (const vtype_array* s, ssize_t index) Nonnull__(1);
extern size_t array_slice(vtype_array* x, vtype_array* src, ssize_t index, size_t count, bool cut) Nonnull__(1);
extern void array_sort (vtype_array* x) Nonnull__(1);
extern void array_reverse(vtype_array* x) Nonnull__(1);
#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 array_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) Nonnull__(1);
extern void libcdsb_array_push_cstring(vtype_array* x, const char* value) Nonnull__(1,2);
extern void libcdsb_array_push_string (vtype_array* x, const vtype_string* value) Nonnull__(1,2);
extern void libcdsb_array_push_array (vtype_array* x, const vtype_array* value) Nonnull__(1,2);
extern void libcdsb_array_push_list (vtype_array* x, const vtype_list* value) Nonnull__(1,2);
extern void libcdsb_array_push_map (vtype_array* x, const vtype_map* value) Nonnull__(1,2);
extern void libcdsb_array_push_vset (vtype_array* x, const vtype_set* value) Nonnull__(1,2);
extern void libcdsb_array_push_dict (vtype_array* x, const vtype_dict* value) Nonnull__(1,2);
extern void libcdsb_array_push_boolean(vtype_array* x, vtype_bool value) Nonnull__(1);
extern void libcdsb_array_push_uint8 (vtype_array* x, vtype_uint8 value) Nonnull__(1);
extern void libcdsb_array_push_uint16 (vtype_array* x, vtype_uint16 value) Nonnull__(1);
extern void libcdsb_array_push_uint32 (vtype_array* x, vtype_uint32 value) Nonnull__(1);
extern void libcdsb_array_push_uint64 (vtype_array* x, vtype_uint64 value) Nonnull__(1);
extern void libcdsb_array_push_int8 (vtype_array* x, vtype_int8 value) Nonnull__(1);
extern void libcdsb_array_push_int16 (vtype_array* x, vtype_int16 value) Nonnull__(1);
extern void libcdsb_array_push_int32 (vtype_array* x, vtype_int32 value) Nonnull__(1);
extern void libcdsb_array_push_int64 (vtype_array* x, vtype_int64 value) Nonnull__(1);
extern void libcdsb_array_push_float (vtype_array* x, vtype_float value) Nonnull__(1);
extern void libcdsb_array_push_double (vtype_array* x, vtype_double value) Nonnull__(1);
extern void libcdsb_array_push_ldouble(vtype_array* x, vtype_ldouble value) Nonnull__(1);
extern size_t libcdsb_array_count_pointer(const vtype_array* s, const void* value) Nonnull__(1);
extern size_t libcdsb_array_count_cstring(const vtype_array* s, const char* value) Nonnull__(1,2);
extern size_t libcdsb_array_count_string (const vtype_array* s, const vtype_string* value) Nonnull__(1,2);
extern size_t libcdsb_array_count_array (const vtype_array* s, const vtype_array* value) Nonnull__(1,2);
extern size_t libcdsb_array_count_list (const vtype_array* s, const vtype_list* value) Nonnull__(1,2);
extern size_t libcdsb_array_count_map (const vtype_array* s, const vtype_map* value) Nonnull__(1,2);
extern size_t libcdsb_array_count_vset (const vtype_array* s, const vtype_set* value) Nonnull__(1,2);
extern size_t libcdsb_array_count_dict (const vtype_array* s, const vtype_dict* value) Nonnull__(1,2);
extern size_t libcdsb_array_count_boolean(const vtype_array* s, vtype_bool value) Nonnull__(1);
extern size_t libcdsb_array_count_int8 (const vtype_array* s, vtype_int8 value) Nonnull__(1);
extern size_t libcdsb_array_count_int16 (const vtype_array* s, vtype_int16 value) Nonnull__(1);
extern size_t libcdsb_array_count_int32 (const vtype_array* s, vtype_int32 value) Nonnull__(1);
extern size_t libcdsb_array_count_int64 (const vtype_array* s, vtype_int64 value) Nonnull__(1);
extern size_t libcdsb_array_count_uint8 (const vtype_array* s, vtype_uint8 value) Nonnull__(1);
extern size_t libcdsb_array_count_uint16 (const vtype_array* s, vtype_uint16 value) Nonnull__(1);
extern size_t libcdsb_array_count_uint32 (const vtype_array* s, vtype_uint32 value) Nonnull__(1);
extern size_t libcdsb_array_count_uint64 (const vtype_array* s, vtype_uint64 value) Nonnull__(1);
extern size_t libcdsb_array_count_float (const vtype_array* s, vtype_float value) Nonnull__(1);
extern size_t libcdsb_array_count_double (const vtype_array* s, vtype_double value) Nonnull__(1);
extern size_t libcdsb_array_count_ldouble(const vtype_array* s, vtype_ldouble value) Nonnull__(1);
extern int libcdsb_array_find_pointer(vtype_array* x, const void* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1);
extern int libcdsb_array_find_cstring(vtype_array* x, const char* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1,2);
extern int libcdsb_array_find_string (vtype_array* x, const vtype_string* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1,2);
extern int libcdsb_array_find_array (vtype_array* x, const vtype_array* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1,2);
extern int libcdsb_array_find_list (vtype_array* x, const vtype_list* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1,2);
extern int libcdsb_array_find_map (vtype_array* x, const vtype_map* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1,2);
extern int libcdsb_array_find_vset (vtype_array* x, const vtype_set* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1,2);
extern int libcdsb_array_find_dict (vtype_array* x, const vtype_dict* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1,2);
extern int libcdsb_array_find_boolean(vtype_array* x, vtype_bool value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1);
extern int libcdsb_array_find_uint8 (vtype_array* x, vtype_uint8 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1);
extern int libcdsb_array_find_uint16 (vtype_array* x, vtype_uint16 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1);
extern int libcdsb_array_find_uint32 (vtype_array* x, vtype_uint32 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1);
extern int libcdsb_array_find_uint64 (vtype_array* x, vtype_uint64 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1);
extern int libcdsb_array_find_int8 (vtype_array* x, vtype_int8 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1);
extern int libcdsb_array_find_int16 (vtype_array* x, vtype_int16 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1);
extern int libcdsb_array_find_int32 (vtype_array* x, vtype_int32 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1);
extern int libcdsb_array_find_int64 (vtype_array* x, vtype_int64 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1);
extern int libcdsb_array_find_float (vtype_array* x, vtype_float value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1);
extern int libcdsb_array_find_double (vtype_array* x, vtype_double value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1);
extern int libcdsb_array_find_ldouble(vtype_array* x, vtype_ldouble value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1);
#endif /* LIBCDSB_ARRAY_H */