/* * This file is part of corelibs. (https://git.redxen.eu/corelibs) * Copyright (c) 2021-2022 Alex-David Denes * * corelibs is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * corelibs is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with corelibs. If not, see . */ #include "types/error/error.h" #include // bool #include // size_t #include // uintmax_t #ifndef CORELIBS_GUARD_DYNARRAY #define CORELIBS_GUARD_DYNARRAY typedef struct cl_dynarray_t cl_dynarray_t; struct corelibs_dynarray_interface { // Makers const struct { cl_error_t (*const new) (size_t sbyte, cl_dynarray_t **ptr), // New - allocate new array (*const slice) (const cl_dynarray_t *arr, uintmax_t pos, uintmax_t len, cl_dynarray_t **ssave); // Slicer - gets a slice of a array } make; // Free cl_error_t (*const free) (cl_dynarray_t *arr); // Modifiers const struct { const struct { cl_error_t (*const app) (cl_dynarray_t *arr, uintmax_t cnt, const void *elem), // Appender - Adds element at end of array (*const ins) (cl_dynarray_t *arr, uintmax_t pos, uintmax_t cnt, const void *elem), // Inserter - Adds element at position, pushing next element 1 position further (*const rep) (cl_dynarray_t *arr, uintmax_t pos, uintmax_t cnt, const void *elem), // Replacer - Replaces array item or creates it if not existent (*const rm) (cl_dynarray_t *arr, uintmax_t pos, uintmax_t cnt); // Remover - removes element from array } dat; const struct { cl_error_t (*const cap) (cl_dynarray_t *ptr, uintmax_t len), // Capacity (*const lock) (cl_dynarray_t *ptr, bool cap); // Capacity lock (dynamic / static capacity) } arr; } mod; // Fetchers const struct { cl_error_t (*const len) (const cl_dynarray_t *arr, uintmax_t *save), (*const size) (const cl_dynarray_t *arr, size_t *save); const struct { cl_error_t (*const len) (const cl_dynarray_t *arr, uintmax_t *save), (*const lock) (const cl_dynarray_t *arr, bool *save); } cap; } get; // Comparers const struct { cl_error_t (*const data) (const cl_dynarray_t *a, const cl_dynarray_t *b, bool *eq); } cmp; // Exporter const struct { cl_error_t (*const slice) (const cl_dynarray_t *arr, uintmax_t pos, uintmax_t cnt, void *save); } export; }; extern const struct corelibs_dynarray_interface cl_dynarray; #endif /* CORELIBS_GUARD_DYNARRAY */