-
Notifications
You must be signed in to change notification settings - Fork 0
/
abarrayx.h
66 lines (56 loc) · 2.42 KB
/
abarrayx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/***************************************************************************
* Copyright (c) 2009-2009, Aaron Brady
* All Rights Reserved
*
* Module Description:
* crazy xmacro header
*
***************************************************************************/
#ifndef TYPE_T
#error "TYPE_T not defined"
#endif
#ifndef TYPE_FUNC_PREFIX
#define TYPE_FUNC_PREFIX TYPE_T
#endif
// don't ask, but:
// 1. TYPE_FUNC_PREFIX => TFP (an argument)
// 2. pass TFP into 3 evals the argument, turning it into e.g. foo
// 3. foo concatted with func
#ifndef ADECL
#define ADECL3(FUNC,PREFIX) PREFIX ## _ ## FUNC
#define ADECL2(FUNC,PREFIX) ADECL3(FUNC,PREFIX)
#define ADECL(FUNC) ADECL2(FUNC,TYPE_FUNC_PREFIX)
#define S_ADECL(FUNC) ADECL(FUNC) ## _s
#endif
typedef void ADECL(destroyelt_fp)(TYPE_T *helt);
typedef int ADECL(cmp_fp)(TYPE_T *hlhs,TYPE_T *hrhs, void *ctxt);
typedef void ADECL(foreach_ctxt_fp)(TYPE_T *ht, void *ctxt);
typedef void ADECL(foreach_fp)(TYPE_T *ht);
TYPE_T* ADECL(init)(void *mem, size_t mem_size, U32 flags);
TYPE_T* ADECL(create)(int capacity);
void ADECL(destroy)(TYPE_T** ha, ADECL(destroyelt_fp) *fp);
int ADECL(size)(TYPE_T const * const * ha);
void ADECL(setsize)(TYPE_T** ha, int size);
// push is interesting semantically. most people expect it to take a param, but
// having push take a struct as a param and doing a memcpy is problematic
// but copying a pointer is okay. so if you have an array of Foo structs, use push
// if you have an array of pointers to Foo (Foo*), you may want to use the preprocessor:
// #define pfoo_push pfoo_push_by_cp
TYPE_T* ADECL(push)(TYPE_T **ha);
TYPE_T* ADECL(pushn)(TYPE_T **ha, int n);
TYPE_T* ADECL(pushfront)(TYPE_T **ha);
int ADECL(push_by_cp)(TYPE_T **ha, TYPE_T b);
TYPE_T* ADECL(pop)(TYPE_T **ha);
TYPE_T* ADECL(top)(TYPE_T **ha);
void ADECL(cp)(TYPE_T **hdest,TYPE_T const * const *hsrc,int n);
void ADECL(cp_raw)(TYPE_T **hdest,TYPE_T const *s,int n); // second arg may not be an Array
void ADECL(insert)(TYPE_T **hdest, TYPE_T *src, int i, int n);
void ADECL(append)(TYPE_T **hdest, TYPE_T *src, int n);
void ADECL(rm)(TYPE_T **ha, int offset, int n);
int ADECL(find)(TYPE_T **ha, TYPE_T *b, ADECL(cmp_fp) *cmp, void *ctxt);
void ADECL(foreach_ctxt)(TYPE_T **ha, ADECL(foreach_ctxt_fp) *fp, void *ctxt);
void ADECL(foreach)(TYPE_T **ha, ADECL(foreach_fp) *fp);
#ifdef ABARRAY_SERIALIZE
int ADECL(binwrite)(File *fp, TYPE_T **ha);
int ADECL(binread)(File *fp, TYPE_T **ha);
#endif