1 /* Copyright (C) 2010-2020 The RetroArch team
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (vector_list.c).
5 * ---------------------------------------------------------------------------------------
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 /* default type is void*, override by defining VECTOR_LIST_TYPE before inclusion */
28 #ifndef VECTOR_LIST_TYPE
29 #define VECTOR_LIST_TYPE void*
30 #define VECTOR_LIST_TYPE_DEFINED
33 /* default name is void, override by defining VECTOR_LIST_NAME before inclusion */
34 #ifndef VECTOR_LIST_NAME
35 #define VECTOR_LIST_NAME void
36 #define VECTOR_LIST_NAME_DEFINED
39 #define CAT_I(a,b) a##b
40 #define CAT(a,b) CAT_I(a, b)
41 #define MAKE_TYPE_NAME() CAT(VECTOR_LIST_NAME, _vector_list)
42 #define TYPE_NAME() MAKE_TYPE_NAME()
46 /* VECTOR_LIST_TYPE for pointers will expand to a pointer-to-pointer */
47 VECTOR_LIST_TYPE *data;
52 static struct TYPE_NAME()* CAT(TYPE_NAME(), _new(void))
54 struct TYPE_NAME() *list = (struct TYPE_NAME()*)calloc(1, sizeof(*list));
57 list->data = (VECTOR_LIST_TYPE*)calloc(list->size, sizeof(*list->data));
62 static bool CAT(TYPE_NAME(), _append(struct TYPE_NAME() *list, VECTOR_LIST_TYPE elem))
64 if (list->size == list->count)
67 list->data = (VECTOR_LIST_TYPE*)realloc(list->data, list->size * sizeof(*list->data));
73 list->data[list->count] = elem;
79 static void CAT(TYPE_NAME(), _free(struct TYPE_NAME() *list))
89 #ifdef VECTOR_LIST_TYPE_DEFINED
90 #undef VECTOR_LIST_TYPE
93 #ifdef VECTOR_LIST_NAME_DEFINED
94 #undef VECTOR_LIST_NAME