-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.c
96 lines (79 loc) · 2.88 KB
/
sample.c
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
All types starts with 'dt', followed by its name (e.g. 'Vector'), and a suffix
that hints what the name refers to. Any suffix starting with an underline '_'
is a definition, else, it's a declaration. Suffixes are generally a single
upper case letter (or two, when in use for iterators).
All types with a suffix, as described above, are macros in C. All of the macros
receive a type as its argument.
Possible letters:
N - Container's base data typename
T - Container's complete data typename
D - Container's base data structure, only data.
S - Container's complete data structure, with data and helper fields.
A - Container's API typename (roughly, the container's class)
C - Recovers the container's API
U - An utility structure used on macro's algorithms.
M - Starter for an aliased container's function (a 'method'). You need to
declare the container's functions for them to work.
F - Starter for a container's macro function. Macro functions works on
Base data structures, not on complete ones.
All letter sequences starting with 'I' are markers for iterators. All the
above markers apply for iterators (e.g. IN, IT, ID, etc).
There's also two basic "post-suffixes" used on any of the above types:
_decl - Emits a declaration. It's generally used in header files or
inside functions.
_defn - Emits a definition. It's generally used on source files. MUST be put
outside functions, as it emits code.
_decm - Same as _decl, but emit markers, according to the build type used.
_defm - Same as _defn, but emit markers, according to the build type used.
There's also the following raw types' typedefs (observing availability)
- dtptrdiff: ptrdiff_t
- dtoffset: offset_t
- dtsize: size_t
- dtwchar: wchar_t
- dtchar: char
- dtuchar: unsigned char
- dtshort: short
- dtushort: unsigned short
- dtint: int
- dtuint: unsigned int
- dtlong: long
- dtulong: unsigned long
- dtllong: long long
- dtullong: unsigned long long
- dtfloat: float
- dtdouble: double
- dtldouble: long double
- dtcharp: char*
- dtwcharp: wchar_t*
- dtsizep: size_t*
- dtvoidp: void*
Basically, for this library to work, any C type comprised of more than one
token or of punctuation needs to be typedef'd (aliased) to a single token, to
circumvent the pre-processor limitations.
*/
#define dtVectorN(RT) dtVector__ ## RT ## __data
#define dtVectorT(RT) dtVector__ ## RT ## __ctnr
#define dtVectorA(RT) dtVector__ ## RT ## __api
#define dtVectorU(RT) \
struct { \
RT ret; \
}
#define dtVectorD(RT) \
struct dtVectorN(RT) ## _ { \
size_t cap; \
size_t len; \
union { \
RT *ptr; \
void *vptr; \
} \
}
#define dtVectorS(RT) \
struct dtVectorT(RT) ## _ { \
dtCtnr base; \
dtVectorD(RT) data; \
}
#define dtVectorC(RT, c) ((dtVectorA(RT)) ((c) ? ((c)->base).api : NULL))
dtVectorF_push(RT, c, aux, {/*success*/}, {/*failure*/})
dtVectorM_push(RT, c, value) | dtVectorA(RT)->
dtVectorM_pop(RT, c)