Refactor map, add attaching functional

This commit is contained in:
2022-08-19 18:46:51 +03:00
parent b789b133e2
commit 36f03d3d23
15 changed files with 353 additions and 1242 deletions
+27
View File
@@ -2,6 +2,7 @@
/* Copyright © 2022 Gregory Lirent */
#include "include.h"
#include "assert.h"
#ifndef LIBCDSB_SRC_INTERNAL_VNODE_H
#define LIBCDSB_SRC_INTERNAL_VNODE_H
@@ -24,6 +25,32 @@ extern vnode_t libcdsb_vnode_create_target(vtype target_type, const void* value,
extern void libcdsb_vnode_free(vnode_t* x, vtype type) Nonnull__(1);
extern void* libcdsb_vnode_peek(const vnode_t* x, vtype type) pure__ wur__ Nonnull__(1);
ainline(void vnode_attach(vnode_t* node, const void* value, vtype type)) {
if (type < VTYPE_STRING) {
*node = libcdsb_vnode_create(value, type);
} else if (sizeof(str_t) == sizeof(void*) && type == VTYPE_STRING) {
*node = *(char**)value;
} else {
*node = malloc(vtype_size(type));
memcpy(*node, value, vtype_size(type));
}
}
ainline(void vnode_tattach(vnode_t* node, vtype target_type, const void* value, vtype type)) {
if (type < VTYPE_STRING) {
*node = libcdsb_vnode_create_target(target_type, value, type);
} else {
type_assert(target_type, type);
if (sizeof(str_t) == sizeof(void*) && type == VTYPE_STRING) {
*node = *(char**)value;
} else {
*node = malloc(vtype_size(type));
memcpy(*node, value, vtype_size(type));
}
}
}
#define vnode_create libcdsb_vnode_create
#define vnode_tcreate libcdsb_vnode_create_target
#define vnode_peek libcdsb_vnode_peek