Sample: cleaning up Inheritance
[io/quag.git] / libs / basekit / source / Stack.h
blobf6aa2f6cd7dfddbe63888c7d11b2c34bbb00b40a
1 /*#io
2 docCopyright("Steve Dekorte", 2002)
3 docLicense("BSD revised")
4 docDescription("""
5 Stack - array of void pointers
6 supports setting marks - when a mark is popped,
7 all stack items above it are popped as well
9 Designed to optimize push, pushMark and popMark
10 at the expense of pop (since pop requires a mark check)
11 """)
14 #ifndef STACK_DEFINED
15 #define STACK_DEFINED 1
17 #include "Common.h"
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <stddef.h>
22 #include "List.h"
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 #ifdef LOW_MEMORY_SYSTEM
29 #define STACK_START_SIZE 512
30 #define STACK_RESIZE_FACTOR 2
31 #else
32 #define STACK_START_SIZE 512
33 #define STACK_RESIZE_FACTOR 2
34 #endif
36 typedef void (StackDoCallback)(void *);
37 typedef void (StackDoOnCallback)(void *, void *);
39 //#define STACK_POP_CALLBACK
41 #ifdef STACK_POP_CALLBACK
42 typedef void (StackPopCallback)(void *);
43 #endif
45 typedef struct
47 void **items;
48 void **memEnd;
49 void **top;
50 intptr_t lastMark;
52 #ifdef STACK_POP_CALLBACK
53 StackPopCallback *popCallback;
54 #endif
55 } Stack;
57 #define Stack_popCallback_(self, callback) self->popCallback = callback;
59 BASEKIT_API Stack *Stack_new(void);
60 BASEKIT_API void Stack_free(Stack *self);
61 BASEKIT_API Stack *Stack_clone(const Stack *self);
62 BASEKIT_API void Stack_copy_(Stack *self, const Stack *other);
64 BASEKIT_API size_t Stack_memorySize(const Stack *self);
65 BASEKIT_API void Stack_compact(Stack *self);
67 BASEKIT_API void Stack_resize(Stack *self);
69 BASEKIT_API void Stack_popToMark_(Stack *self, intptr_t mark);
71 // not high performance
73 BASEKIT_API void Stack_makeMarksNull(Stack *self);
74 BASEKIT_API Stack *Stack_newCopyWithNullMarks(const Stack *self);
75 BASEKIT_API void Stack_do_on_(const Stack *self, StackDoOnCallback *callback, void *target);
77 BASEKIT_API List *Stack_asList(const Stack *self);
79 #include "Stack_inline.h"
81 #ifdef __cplusplus
83 #endif
84 #endif