Zycore 1.4.0.0
Loading...
Searching...
No Matches
List.h
Go to the documentation of this file.
1/***************************************************************************************************
2
3 Zyan Core Library (Zycore-C)
4
5 Original Author : Florian Bernd
6
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24
25***************************************************************************************************/
26
32#ifndef ZYCORE_LIST_H
33#define ZYCORE_LIST_H
34
35#include <Zycore/Allocator.h>
36#include <Zycore/Object.h>
37#include <Zycore/Status.h>
38#include <Zycore/Types.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/* ============================================================================================== */
45/* Enums and types */
46/* ============================================================================================== */
47
65
126
127/* ============================================================================================== */
128/* Macros */
129/* ============================================================================================== */
130
131/* ---------------------------------------------------------------------------------------------- */
132/* General */
133/* ---------------------------------------------------------------------------------------------- */
134
138#define ZYAN_LIST_INITIALIZER \
139 { \
140 /* allocator */ ZYAN_NULL, \
141 /* size */ 0, \
142 /* element_size */ 0, \
143 /* head */ ZYAN_NULL, \
144 /* destructor */ ZYAN_NULL, \
145 /* tail */ ZYAN_NULL, \
146 /* buffer */ ZYAN_NULL, \
147 /* capacity */ 0, \
148 /* first_unused */ ZYAN_NULL \
149 }
150
151/* ---------------------------------------------------------------------------------------------- */
152/* Helper macros */
153/* ---------------------------------------------------------------------------------------------- */
154
165#ifdef __cplusplus
166#define ZYAN_LIST_GET(type, node) \
167 (*reinterpret_cast<const type*>(ZyanListGetNodeData(node)))
168#else
169#define ZYAN_LIST_GET(type, node) \
170 (*(const type*)ZyanListGetNodeData(node))
171#endif
172
173/* ---------------------------------------------------------------------------------------------- */
174
175/* ============================================================================================== */
176/* Exported functions */
177/* ============================================================================================== */
178
179/* ---------------------------------------------------------------------------------------------- */
180/* Constructor and destructor */
181/* ---------------------------------------------------------------------------------------------- */
182
183#ifndef ZYAN_NO_LIBC
184
200 ZyanMemberProcedure destructor);
201
202#endif // ZYAN_NO_LIBC
203
217ZYCORE_EXPORT ZyanStatus ZyanListInitEx(ZyanList* list, ZyanUSize element_size,
218 ZyanMemberProcedure destructor, ZyanAllocator* allocator);
219
240 ZyanMemberProcedure destructor, void* buffer, ZyanUSize capacity);
241
250
251/* ---------------------------------------------------------------------------------------------- */
252/* Duplication */
253/* ---------------------------------------------------------------------------------------------- */
254
255#ifndef ZYAN_NO_LIBC
256
270 const ZyanList* source);
271
272#endif // ZYAN_NO_LIBC
273
287 ZyanAllocator* allocator);
288
310 const ZyanList* source, void* buffer, ZyanUSize capacity);
311
312/* ---------------------------------------------------------------------------------------------- */
313/* Item access */
314/* ---------------------------------------------------------------------------------------------- */
315
325
335
345
354
366
378
391
404
415 const void* value);
416
417/* ---------------------------------------------------------------------------------------------- */
418/* Insertion */
419/* ---------------------------------------------------------------------------------------------- */
420
430
440
452 ZyanMemberFunction constructor);
453
465 ZyanMemberFunction constructor);
466
467/* ---------------------------------------------------------------------------------------------- */
468/* Deletion */
469/* ---------------------------------------------------------------------------------------------- */
470
479
488
498
509 const ZyanListNode* last);
510
519
520/* ---------------------------------------------------------------------------------------------- */
521/* Searching */
522/* ---------------------------------------------------------------------------------------------- */
523
524// TODO:
525
526/* ---------------------------------------------------------------------------------------------- */
527/* Memory management */
528/* ---------------------------------------------------------------------------------------------- */
529
539
549ZYCORE_EXPORT ZyanStatus ZyanListResizeEx(ZyanList* list, ZyanUSize size, const void* initializer);
550
551/* ---------------------------------------------------------------------------------------------- */
552/* Information */
553/* ---------------------------------------------------------------------------------------------- */
554
563ZYCORE_EXPORT ZyanStatus ZyanListGetSize(const ZyanList* list, ZyanUSize* size);
564
565/* ---------------------------------------------------------------------------------------------- */
566
567/* ============================================================================================== */
568
569#ifdef __cplusplus
570}
571#endif
572
573#endif /* ZYCORE_VECTOR_H */
#define ZYAN_REQUIRES_LIBC
Definition Defines.h:358
#define ZYCORE_EXPORT
Definition Defines.h:227
ZYCORE_EXPORT ZyanStatus ZyanListInitEx(ZyanList *list, ZyanUSize element_size, ZyanMemberProcedure destructor, ZyanAllocator *allocator)
ZYCORE_EXPORT ZyanStatus ZyanListPushFront(ZyanList *list, const void *item)
struct ZyanList_ ZyanList
ZYCORE_EXPORT ZyanStatus ZyanListDestroy(ZyanList *list)
ZYCORE_EXPORT ZyanStatus ZyanListGetNodeDataMutableEx(const ZyanListNode *node, void **value)
ZYCORE_EXPORT ZyanStatus ZyanListPopBack(ZyanList *list)
ZYCORE_EXPORT ZyanStatus ZyanListRemove(ZyanList *list, const ZyanListNode *node)
ZYCORE_EXPORT ZyanStatus ZyanListPushBack(ZyanList *list, const void *item)
ZYCORE_EXPORT ZyanStatus ZyanListEmplaceBack(ZyanList *list, void **item, ZyanMemberFunction constructor)
struct ZyanListNode_ ZyanListNode
ZYCORE_EXPORT ZyanStatus ZyanListEmplaceFront(ZyanList *list, void **item, ZyanMemberFunction constructor)
ZYCORE_EXPORT ZyanStatus ZyanListInitCustomBuffer(ZyanList *list, ZyanUSize element_size, ZyanMemberProcedure destructor, void *buffer, ZyanUSize capacity)
ZYCORE_EXPORT ZyanStatus ZyanListPopFront(ZyanList *list)
ZYCORE_EXPORT ZyanStatus ZyanListSetNodeData(const ZyanList *list, const ZyanListNode *node, const void *value)
ZYCORE_EXPORT ZyanStatus ZyanListGetTailNode(const ZyanList *list, const ZyanListNode **node)
ZYCORE_EXPORT const void * ZyanListGetNodeData(const ZyanListNode *node)
ZYCORE_EXPORT ZyanStatus ZyanListGetNextNode(const ZyanListNode **node)
ZYCORE_EXPORT ZyanStatus ZyanListDuplicateEx(ZyanList *destination, const ZyanList *source, ZyanAllocator *allocator)
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanListDuplicate(ZyanList *destination, const ZyanList *source)
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanListInit(ZyanList *list, ZyanUSize element_size, ZyanMemberProcedure destructor)
ZYCORE_EXPORT ZyanStatus ZyanListGetHeadNode(const ZyanList *list, const ZyanListNode **node)
ZYCORE_EXPORT ZyanStatus ZyanListRemoveRange(ZyanList *list, const ZyanListNode *first, const ZyanListNode *last)
ZYCORE_EXPORT ZyanStatus ZyanListResize(ZyanList *list, ZyanUSize size)
ZYCORE_EXPORT ZyanStatus ZyanListDuplicateCustomBuffer(ZyanList *destination, const ZyanList *source, void *buffer, ZyanUSize capacity)
ZYCORE_EXPORT ZyanStatus ZyanListGetPrevNode(const ZyanListNode **node)
ZYCORE_EXPORT ZyanStatus ZyanListResizeEx(ZyanList *list, ZyanUSize size, const void *initializer)
ZYCORE_EXPORT ZyanStatus ZyanListGetSize(const ZyanList *list, ZyanUSize *size)
ZYCORE_EXPORT ZyanStatus ZyanListClear(ZyanList *list)
ZYCORE_EXPORT ZyanStatus ZyanListGetNodeDataEx(const ZyanListNode *node, const void **value)
ZYCORE_EXPORT void * ZyanListGetNodeDataMutable(const ZyanListNode *node)
void(* ZyanMemberProcedure)(void *object)
Definition Object.h:51
ZyanStatus(* ZyanMemberFunction)(void *object)
Definition Object.h:67
ZyanU32 ZyanStatus
Definition Status.h:48
Definition Allocator.h:89
Definition List.h:55
struct ZyanListNode_ * next
Definition List.h:63
struct ZyanListNode_ * prev
Definition List.h:59
Definition List.h:73
ZyanListNode * head
Definition List.h:93
ZyanUSize element_size
Definition List.h:85
ZyanMemberProcedure destructor
Definition List.h:89
ZyanListNode * tail
Definition List.h:97
ZyanUSize capacity
Definition List.h:109
void * buffer
Definition List.h:103
ZyanUSize size
Definition List.h:81
ZyanAllocator * allocator
Definition List.h:77
ZyanListNode * first_unused
Definition List.h:124