Add preprocessor FOR macro.
[bertos.git] / bertos / cfg / for.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2012 Develer S.r.l. (http://www.develer.com/)
30  * All Rights Reserved.
31  * -->
32  *
33  * \brief Preprocessor FOR macro.
34  *
35  * \author Francesco Sacchi <batt@develer.com>
36  */
37
38 #ifndef CFG_FOR_H
39 #define CFG_FOR_H
40
41 #define IDENTITY(x) x
42
43 #define FOR(body, ...) \
44                 PP_CAT(FOR_, COUNT_PARMS(__VA_ARGS__)) (body, __VA_ARGS__)
45
46 #define FOR_1(body, x) IDENTITY(body x)
47
48 #define FOR_2(body, x, ...) \
49                 IDENTITY(body x) \
50                 FOR_1(body, __VA_ARGS__)
51
52 #define FOR_3(body, x, ...) \
53                 IDENTITY(body x) \
54                 FOR_2(body, __VA_ARGS__)
55
56 #define FOR_4(body, x, ...) \
57                 IDENTITY(body x) \
58                 FOR_3(body, __VA_ARGS__)
59
60 #define FOR_5(body, x, ...) \
61                 IDENTITY(body x) \
62                 FOR_4(body, __VA_ARGS__)
63
64 #define FOR_6(body, x, ...) \
65                 IDENTITY(body x) \
66                 FOR_5(body, __VA_ARGS__)
67
68 #define FOR_7(body, x, ...) \
69                 IDENTITY(body x) \
70                 FOR_6(body, __VA_ARGS__)
71
72 #define FOR_8(body, x, ...) \
73                 IDENTITY(body x) \
74                 FOR_7(body, __VA_ARGS__)
75
76 #define FOR_9(body, x, ...) \
77                 IDENTITY(body x) \
78                 FOR_8(body, __VA_ARGS__)
79
80 #define FOR_10(body, x, ...) \
81                 IDENTITY(body x) \
82                 FOR_9(body, __VA_ARGS__)
83
84 #define FOR_11(body, x, ...) \
85                 IDENTITY(body x) \
86                 FOR_10(body, __VA_ARGS__)
87
88 #define FOR_12(body, x, ...) \
89                 IDENTITY(body x) \
90                 FOR_11(body, __VA_ARGS__)
91
92 #define FOR_13(body, x, ...) \
93                 IDENTITY(body x) \
94                 FOR_12(body, __VA_ARGS__)
95
96 #define FOR_14(body, x, ...) \
97                 IDENTITY(body x) \
98                 FOR_13(body, __VA_ARGS__)
99
100 #define FOR_15(body, x, ...) \
101                 IDENTITY(body x) \
102                 FOR_14(body, __VA_ARGS__)
103
104 #define FOR_16(body, x, ...) \
105                 IDENTITY(body x) \
106                 FOR_15(body, __VA_ARGS__)
107
108 #define FOR_17(body, x, ...) \
109                 IDENTITY(body x) \
110                 FOR_16(body, __VA_ARGS__)
111
112 #define FOR_18(body, x, ...) \
113                 IDENTITY(body x) \
114                 FOR_17(body, __VA_ARGS__)
115
116 #define FOR_19(body, x, ...) \
117                 IDENTITY(body x) \
118                 FOR_18(body, __VA_ARGS__)
119
120 #define FOR_20(body, x, ...) \
121                 IDENTITY(body x) \
122                 FOR_19(body, __VA_ARGS__)
123
124 #define FOR_21(body, x, ...) \
125                 IDENTITY(body x) \
126                 FOR_20(body, __VA_ARGS__)
127
128 #define FOR_22(body, x, ...) \
129                 IDENTITY(body x) \
130                 FOR_21(body, __VA_ARGS__)
131
132 #define FOR_23(body, x, ...) \
133                 IDENTITY(body x) \
134                 FOR_22(body, __VA_ARGS__)
135
136 #define FOR_24(body, x, ...) \
137                 IDENTITY(body x) \
138                 FOR_23(body, __VA_ARGS__)
139
140 #define FOR_25(body, x, ...) \
141                 IDENTITY(body x) \
142                 FOR_24(body, __VA_ARGS__)
143
144 #define FOR_26(body, x, ...) \
145                 IDENTITY(body x) \
146                 FOR_25(body, __VA_ARGS__)
147
148 #define FOR_27(body, x, ...) \
149                 IDENTITY(body x) \
150                 FOR_26(body, __VA_ARGS__)
151
152 #define FOR_28(body, x, ...) \
153                 IDENTITY(body x) \
154                 FOR_27(body, __VA_ARGS__)
155
156 #define FOR_29(body, x, ...) \
157                 IDENTITY(body x) \
158                 FOR_28(body, __VA_ARGS__)
159
160 #define FOR_30(body, x, ...) \
161                 IDENTITY(body x) \
162                 FOR_29(body, __VA_ARGS__)
163
164 #define FOR_31(body, x, ...) \
165                 IDENTITY(body x) \
166                 FOR_30(body, __VA_ARGS__)
167
168 #define FOR_32(body, x, ...) \
169                 IDENTITY(body x) \
170                 FOR_31(body, __VA_ARGS__)
171
172 #endif /* CFG_FOR_H */