New doc system done for core
[io.git] / libs / basekit / source / List.h
blobbc03ec3882514e8c686890f83654413da310b327
1 //metadoc List copyright Steve Dekorte 2002
2 //metadoc List license BSD revised
3 /*metadoc List description
4 List - an array of void pointers
5 User is responsible for io_freeing items
6 */
8 #ifndef LIST_DEFINED
9 #define LIST_DEFINED 1
11 #include "Common.h"
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <string.h>
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
20 #ifdef LOW_MEMORY_SYSTEM
21 #define LIST_START_SIZE 1
22 #define LIST_RESIZE_FACTOR 2
23 #else
24 #define LIST_START_SIZE 1
25 #define LIST_RESIZE_FACTOR 2
26 #endif
28 #define LIST_AT_(self, n) self->items[n]
31 typedef void (ListDoCallback)(void *);
32 typedef void (ListDoWithCallback)(void *, void *);
33 typedef void *(ListCollectCallback)(void *);
34 typedef int (ListSelectCallback)(void *);
35 typedef int (ListDetectCallback)(void *);
36 typedef int (ListSortCallback)(const void *, const void *);
37 typedef int (ListCompareFunc)(const void *, const void *);
39 typedef struct
41 void **items;
42 size_t size;
43 size_t memSize;
44 } List;
46 typedef struct
48 List *list;
49 size_t index;
50 } ListCursor;
52 BASEKIT_API List *List_new(void);
53 BASEKIT_API List *List_clone(const List *self);
54 BASEKIT_API List *List_cloneSlice(const List *self, long startIndex, long endIndex);
56 BASEKIT_API void List_free(List *self);
57 BASEKIT_API void List_removeAll(List *self);
58 BASEKIT_API void List_copy_(List *self, const List *otherList);
59 BASEKIT_API int List_equals_(const List *self, const List *otherList);
60 BASEKIT_API size_t List_memorySize(const List *self);
62 #include "UArray.h"
64 BASEKIT_API UArray List_asStackAllocatedUArray(List *self);
66 // sizing
68 BASEKIT_API void List_preallocateToSize_(List *self, size_t index);
69 BASEKIT_API void List_setSize_(List *self, size_t index);
70 BASEKIT_API void List_compact(List *self);
72 // utility
74 BASEKIT_API void List_print(const List *self);
75 BASEKIT_API void List_sliceInPlace(List *self, long startIndex, long endIndex);
77 // enumeration
79 BASEKIT_API void List_do_(List *self, ListDoCallback *callback);
80 BASEKIT_API void List_do_with_(List *self, ListDoWithCallback *callback, void *arg);
82 BASEKIT_API List *List_map_(List *self, ListCollectCallback *callback);
83 BASEKIT_API void List_mapInPlace_(List *self, ListCollectCallback *callback);
84 BASEKIT_API void *List_detect_(List *self, ListDetectCallback *callback);
85 BASEKIT_API List *List_select_(List *self, ListSelectCallback *callback);
87 BASEKIT_API void *List_anyOne(const List *self);
88 BASEKIT_API void List_shuffle(List *self);
89 BASEKIT_API void *List_removeLast(List *self);
91 #include "List_inline.h"
93 #ifdef __cplusplus
95 #endif
96 #endif