SystemCall run(block) can now exit the run if it returns false
[io/quag.git] / libs / basekit / source / List.h
blob2942338c23583a40fd0c7cba132f505046d9b41e
1 /*#io
2 docCopyright("Steve Dekorte", 2002)
3 docLicense("BSD revised")
4 docDescription("""
5 List - an array of void pointers
6 User is responsible for io_freeing items
7 """)
8 */
10 #ifndef LIST_DEFINED
11 #define LIST_DEFINED 1
13 #include "Common.h"
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <string.h>
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
22 #ifdef LOW_MEMORY_SYSTEM
23 #define LIST_START_SIZE 1
24 #define LIST_RESIZE_FACTOR 2
25 #else
26 #define LIST_START_SIZE 1
27 #define LIST_RESIZE_FACTOR 2
28 #endif
30 #define LIST_AT_(self, n) self->items[n]
33 typedef void (ListDoCallback)(void *);
34 typedef void (ListDoWithCallback)(void *, void *);
35 typedef void *(ListCollectCallback)(void *);
36 typedef int (ListSelectCallback)(void *);
37 typedef int (ListDetectCallback)(void *);
38 typedef int (ListSortCallback)(const void *, const void *);
39 typedef int (ListCompareFunc)(const void *, const void *);
41 typedef struct
43 void **items;
44 size_t size;
45 size_t memSize;
46 } List;
48 typedef struct
50 List *list;
51 size_t index;
52 } ListCursor;
54 BASEKIT_API List *List_new(void);
55 BASEKIT_API List *List_clone(const List *self);
56 BASEKIT_API List *List_cloneSlice(const List *self, long startIndex, long endIndex);
58 BASEKIT_API void List_free(List *self);
59 BASEKIT_API void List_removeAll(List *self);
60 BASEKIT_API void List_copy_(List *self, const List *otherList);
61 BASEKIT_API int List_equals_(const List *self, const List *otherList);
62 BASEKIT_API size_t List_memorySize(const List *self);
64 #include "UArray.h"
66 BASEKIT_API UArray List_asStackAllocatedUArray(List *self);
68 // sizing
70 BASEKIT_API void List_preallocateToSize_(List *self, size_t index);
71 BASEKIT_API void List_setSize_(List *self, size_t index);
72 BASEKIT_API void List_compact(List *self);
74 // utility
76 BASEKIT_API void List_print(const List *self);
77 BASEKIT_API void List_sliceInPlace(List *self, long startIndex, long endIndex);
79 // enumeration
81 BASEKIT_API void List_do_(List *self, ListDoCallback *callback);
82 BASEKIT_API void List_do_with_(List *self, ListDoWithCallback *callback, void *arg);
84 BASEKIT_API List *List_map_(List *self, ListCollectCallback *callback);
85 BASEKIT_API void List_mapInPlace_(List *self, ListCollectCallback *callback);
86 BASEKIT_API void *List_detect_(List *self, ListDetectCallback *callback);
87 BASEKIT_API List *List_select_(List *self, ListSelectCallback *callback);
89 BASEKIT_API void *List_anyOne(const List *self);
90 BASEKIT_API void List_shuffle(List *self);
91 BASEKIT_API void *List_removeLast(List *self);
93 #include "List_inline.h"
95 #ifdef __cplusplus
97 #endif
98 #endif