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
|
#ifndef _TEMPLATE_H_
#define _TEMPLATE_H_
/*--------------------------------------------------------------------------------*/
/* Looping and Iteration */
/*--------------------------------------------------------------------------------*/
/**
* Template for the general structure of a loop.
*/
#define TEMPLATE_LOOP(setup, loop_def, body) \
do \
{ \
setup; \
loop_def { \
body; \
} \
} while (0)
/**
* Template for looping over an array-like sequence.
*/
#define TEMPLATE_DO_ARR_LIKE(iter_idx, type, \
arr, arr_length, \
iter_elem_setup, \
body) \
do \
{ \
TEMPLATE_LOOP( \
int iter_idx, \
for(iter_idx = 0; iter_idx < (arr_length); ++iter_idx), \
iter_elem_setup; \
body); \
} while (0)
/**
* Template for looping over the contents of an array.
*/
#define TEMPLATE_DO_ARR(iter_idx, type, iter_elem, arr, arr_length, body) \
do \
{ \
TEMPLATE_DO_ARR_LIKE( \
iter_idx, type, arr, arr_length, \
type iter_elem = (arr)[iter_idx], \
body); \
} while (0)
/**
* Template for looping over the contents of an #ARR_DESC.
*/
#define TEMPLATE_DO_ARR_DESC(iter_idx, type, iter_elem, arr_desc, body) \
do \
{ \
TEMPLATE_DO_ARR_LIKE( \
iter_idx, type, arr_desc, (arr_desc).element_count, \
type iter_elem = ARR_DESC_ELT(type, iter_idx, &(arr_desc)), \
body); \
} while (0)
/*--------------------------------------------------------------------------------*/
/* Test Definition */
/*--------------------------------------------------------------------------------*/
/**
* Template for the general structure of a test.
*/
#define TEMPLATE_TEST(setup, body, teardown) \
do \
{ \
setup; \
body; \
teardown; \
} while (0)
/**
* Template for calling a function.
*
* @note Surround function arguments with the #PAREN() macro.
*
* @example
* void my_func(int arg1, int arg2);
*
* TEMPLATE_CALL_FN(my_func, PAREN(3, 7));
*/
#define TEMPLATE_CALL_FN(fn, fn_args) \
fn fn_args
#endif /* _TEMPLATE_H_ */
|