2016-03-19 15:14:35 +00:00
|
|
|
#include "first.h"
|
|
|
|
|
2009-10-11 14:31:42 +00:00
|
|
|
#include "array.h"
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2019-10-02 06:16:08 +00:00
|
|
|
__attribute_cold__
|
2005-08-08 16:36:51 +00:00
|
|
|
static data_unset *data_array_copy(const data_unset *s) {
|
2005-08-08 14:40:47 +00:00
|
|
|
data_array *src = (data_array *)s;
|
|
|
|
data_array *ds = data_array_init();
|
|
|
|
|
2019-10-13 07:37:59 +00:00
|
|
|
if (!buffer_is_empty(&src->key)) buffer_copy_buffer(&ds->key, &src->key);
|
2019-10-13 21:06:05 +00:00
|
|
|
array_copy_array(&ds->value, &src->value);
|
2005-08-08 14:40:47 +00:00
|
|
|
return (data_unset *)ds;
|
|
|
|
}
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
static void data_array_free(data_unset *d) {
|
|
|
|
data_array *ds = (data_array *)d;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2019-10-13 07:37:59 +00:00
|
|
|
free(ds->key.ptr);
|
2019-10-13 21:06:05 +00:00
|
|
|
array_free_data(&ds->value);
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
free(d);
|
|
|
|
}
|
|
|
|
|
2019-10-02 06:16:08 +00:00
|
|
|
__attribute_cold__
|
2005-02-20 14:27:00 +00:00
|
|
|
static int data_array_insert_dup(data_unset *dst, data_unset *src) {
|
|
|
|
UNUSED(dst);
|
|
|
|
|
2018-09-23 02:12:51 +00:00
|
|
|
src->fn->free(src);
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-02 06:16:08 +00:00
|
|
|
__attribute_cold__
|
2005-08-08 16:36:51 +00:00
|
|
|
static void data_array_print(const data_unset *d, int depth) {
|
2005-02-20 14:27:00 +00:00
|
|
|
data_array *ds = (data_array *)d;
|
2005-08-08 10:16:53 +00:00
|
|
|
|
2019-10-13 21:06:05 +00:00
|
|
|
array_print(&ds->value, depth);
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data_array *data_array_init(void) {
|
2018-09-23 02:12:51 +00:00
|
|
|
static const struct data_methods fn = {
|
|
|
|
data_array_copy,
|
|
|
|
data_array_free,
|
|
|
|
data_array_insert_dup,
|
|
|
|
data_array_print,
|
|
|
|
};
|
2005-02-20 14:27:00 +00:00
|
|
|
data_array *ds;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
ds = calloc(1, sizeof(*ds));
|
2016-01-30 13:59:07 +00:00
|
|
|
force_assert(NULL != ds);
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
ds->type = TYPE_ARRAY;
|
2018-09-23 02:12:51 +00:00
|
|
|
ds->fn = &fn;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
return ds;
|
|
|
|
}
|