Refactor set, add attaching functional

This commit is contained in:
2022-08-19 17:19:22 +03:00
parent 925a8855ed
commit b789b133e2
12 changed files with 278 additions and 315 deletions
-15
View File
@@ -1,15 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "../set.h"
#ifndef LIBCDSB_EXTRA_SET_H
#define LIBCDSB_EXTRA_SET_H
#define vset_foreach(x, data, callback) libcdsb_vset_foreach(x, data, callback, 0)
extern bool libcdsb_vset_insert (vtype_set* x, const void* value, vtype type) Nonnull__(1);
extern int libcdsb_vset_find (vtype_set* x, const void* value, vtype type, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_foreach(vtype_set* x, void* data, vset_access_callback, bool flush) Nonnull__(1,3);
#endif /* LIBCDSB_EXTRA_SET_H */
+15 -48
View File
@@ -7,61 +7,28 @@
#ifndef LIBCDSB_SET_H
#define LIBCDSB_SET_H
/*#####################################################################################################################*/
typedef int (*vset_access_callback)(const void* value, vtype type, void* data);
/*#####################################################################################################################*/
extern void vset_init(vtype_set* x, vtype type) Nonnull__(1);
#define vset_pop(x, value, data, callback) _LIBCDSB_Generic (libcdsb_vset, find, value)(x, value, data, callback, 1)
#define vset_get(x, value, data, callback) _LIBCDSB_Generic (libcdsb_vset, find, value)(x, value, data, callback, 0)
#define vset_push(x, value) _LIBCDSB_Generic (libcdsb_vset, push, value)(x, value)
#define vset_remove(x, value) vset_pop(x, value, 0, 0)
/*#####################################################################################################################*/
#define in_vset(x, value) (vset_get(&x, value, 0, 0) == 0)
#define vset_pop(x, value, data, callback) libcdsb_vset_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 1)
#define vset_get(x, value, data, callback) libcdsb_vset_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 0)
#define vset_push(x, value) libcdsb_vset_insert (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value))
#define vset_attach(x, value) libcdsb_vset_attach (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value))
#define vset_foreach(x, data, callback) libcdsb_vset_foreach(x, data, callback, 0)
#define vset_remove(x, value) vset_pop (x, value, 0, 0)
#define in_vset(x, value) (vset_get(x, value, 0, 0) == 0)
/*#####################################################################################################################*/
extern bool libcdsb_vset_push_pointer(vtype_set* x, const void* value) Nonnull__(1);
extern bool libcdsb_vset_push_cstring(vtype_set* x, const char* value) Nonnull__(1,2);
extern bool libcdsb_vset_push_string (vtype_set* x, const vtype_string* value) Nonnull__(1,2);
extern bool libcdsb_vset_push_array (vtype_set* x, const vtype_array* value) Nonnull__(1,2);
extern bool libcdsb_vset_push_list (vtype_set* x, const vtype_list* value) Nonnull__(1,2);
extern bool libcdsb_vset_push_map (vtype_set* x, const vtype_map* value) Nonnull__(1,2);
extern bool libcdsb_vset_push_vset (vtype_set* x, const vtype_set* value) Nonnull__(1,2);
extern bool libcdsb_vset_push_dict (vtype_set* x, const vtype_dict* value) Nonnull__(1,2);
extern bool libcdsb_vset_push_boolean(vtype_set* x, vtype_bool value) Nonnull__(1);
extern bool libcdsb_vset_push_uint8 (vtype_set* x, vtype_uint8 value) Nonnull__(1);
extern bool libcdsb_vset_push_uint16 (vtype_set* x, vtype_uint16 value) Nonnull__(1);
extern bool libcdsb_vset_push_uint32 (vtype_set* x, vtype_uint32 value) Nonnull__(1);
extern bool libcdsb_vset_push_uint64 (vtype_set* x, vtype_uint64 value) Nonnull__(1);
extern bool libcdsb_vset_push_int8 (vtype_set* x, vtype_int8 value) Nonnull__(1);
extern bool libcdsb_vset_push_int16 (vtype_set* x, vtype_int16 value) Nonnull__(1);
extern bool libcdsb_vset_push_int32 (vtype_set* x, vtype_int32 value) Nonnull__(1);
extern bool libcdsb_vset_push_int64 (vtype_set* x, vtype_int64 value) Nonnull__(1);
extern bool libcdsb_vset_push_float (vtype_set* x, vtype_float value) Nonnull__(1);
extern bool libcdsb_vset_push_double (vtype_set* x, vtype_double value) Nonnull__(1);
extern bool libcdsb_vset_push_ldouble(vtype_set* x, vtype_ldouble value) Nonnull__(1);
extern int libcdsb_vset_find_pointer(vtype_set* x, const void* value, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_find_cstring(vtype_set* x, const char* value, void* data, vset_access_callback, bool cut) Nonnull__(1,2);
extern int libcdsb_vset_find_string (vtype_set* x, const vtype_string* value, void* data, vset_access_callback, bool cut) Nonnull__(1,2);
extern int libcdsb_vset_find_array (vtype_set* x, const vtype_array* value, void* data, vset_access_callback, bool cut) Nonnull__(1,2);
extern int libcdsb_vset_find_list (vtype_set* x, const vtype_list* value, void* data, vset_access_callback, bool cut) Nonnull__(1,2);
extern int libcdsb_vset_find_map (vtype_set* x, const vtype_map* value, void* data, vset_access_callback, bool cut) Nonnull__(1,2);
extern int libcdsb_vset_find_vset (vtype_set* x, const vtype_set* value, void* data, vset_access_callback, bool cut) Nonnull__(1,2);
extern int libcdsb_vset_find_dict (vtype_set* x, const vtype_dict* value, void* data, vset_access_callback, bool cut) Nonnull__(1,2);
extern int libcdsb_vset_find_boolean(vtype_set* x, vtype_bool value, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_find_uint8 (vtype_set* x, vtype_uint8 value, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_find_uint16 (vtype_set* x, vtype_uint16 value, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_find_uint32 (vtype_set* x, vtype_uint32 value, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_find_uint64 (vtype_set* x, vtype_uint64 value, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_find_int8 (vtype_set* x, vtype_int8 value, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_find_int16 (vtype_set* x, vtype_int16 value, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_find_int32 (vtype_set* x, vtype_int32 value, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_find_int64 (vtype_set* x, vtype_int64 value, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_find_float (vtype_set* x, vtype_float value, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_find_double (vtype_set* x, vtype_double value, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_find_ldouble(vtype_set* x, vtype_ldouble value, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern bool libcdsb_vset_insert (vtype_set* x, const void* value, vtype type) Nonnull__(1);
extern bool libcdsb_vset_attach (vtype_set* x, const void* value, vtype type) Nonnull__(1);
extern int libcdsb_vset_find (vtype_set* x, const void* value, vtype type, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_foreach(vtype_set* x, void* data, vset_access_callback, bool flush) Nonnull__(1,3);
#endif /* LIBCDSB_SET_H */