Alchemy  1.0
A framework to robustly process network messages and structured data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
meta_macros.h
Go to the documentation of this file.
1 /// @file meta_macros.h
2 ///
3 /// @brief Utility MACROS used to simplify the definitions for
4 /// many of the TMP constructs.
5 ///
6 /// MACROS: TMP_ARRAY_X To simplify multiple repetitive declarations
7 /// TMP_REPEAT_X Repeats in the input the number of times specified
8 ///
9 /// The MIT License(MIT)
10 /// @copyright 2014 Paul M Watt
11 ///
12 // ****************************************************************************
13 /// Additional copyright information:
14 ///
15 /// This MACRO was adapted from the BOOST Preprocessing library.
16 /// Copyright Housemarque Oy 2002
17 /// Copyright Paul Mensonides 2002
18 ///
19 /// Distributed under the Boost Software License, Version 1.0.
20 /// (See at www.boost.org/LICENSE_1_0.txt
21 ///
22 // ****************************************************************************
23 // ****************************************************************************
24 #ifndef META_MACROS_H_INCLUDED
25 #define META_MACROS_H_INCLUDED
26 // Includes *******************************************************************
27 #include <Pb/detail/boost_preprocessor.h>
28 
29 // ****************************************************************************
30 #define BEGIN_NAMESPACE(NS) namespace NS {
31 #define END_NAMESPACE(NS) }
32 
33 // ****************************************************************************
34 // Evaluates the two input expressions,
35 // then uses the token paste operator to fuse them together.
36 #define TMP_PASTE(A,B) TMP_PASTE_DO(A,B)
37 #define TMP_PASTE_DO(A,B) A ## B
38 
39 // ****************************************************************************
40 // TODO: Include a pruned version of the BOOST_PP MACROS that are used here.
41 //#include <Pb/meta_variadic_macros.h>
42 
43 // ****************************************************************************
44 /** MACRO set to simplify the declaration of many array entries **************/
45 #define TMP_ARRAY_1(T) T##0
46 #define TMP_ARRAY_2(T) TMP_ARRAY_1(T), T##1
47 #define TMP_ARRAY_3(T) TMP_ARRAY_2(T), T##2
48 #define TMP_ARRAY_4(T) TMP_ARRAY_3(T), T##3
49 #define TMP_ARRAY_5(T) TMP_ARRAY_4(T), T##4
50 #define TMP_ARRAY_6(T) TMP_ARRAY_5(T), T##5
51 #define TMP_ARRAY_7(T) TMP_ARRAY_6(T), T##6
52 #define TMP_ARRAY_8(T) TMP_ARRAY_7(T), T##7
53 #define TMP_ARRAY_9(T) TMP_ARRAY_8(T), T##8
54 #define TMP_ARRAY_10(T) TMP_ARRAY_9(T), T##9
55 #define TMP_ARRAY_11(T) TMP_ARRAY_10(T), T##10
56 #define TMP_ARRAY_12(T) TMP_ARRAY_11(T), T##11
57 #define TMP_ARRAY_13(T) TMP_ARRAY_12(T), T##12
58 #define TMP_ARRAY_14(T) TMP_ARRAY_13(T), T##13
59 #define TMP_ARRAY_15(T) TMP_ARRAY_14(T), T##14
60 #define TMP_ARRAY_16(T) TMP_ARRAY_15(T), T##15
61 #define TMP_ARRAY_17(T) TMP_ARRAY_16(T), T##16
62 #define TMP_ARRAY_18(T) TMP_ARRAY_17(T), T##17
63 #define TMP_ARRAY_19(T) TMP_ARRAY_18(T), T##18
64 #define TMP_ARRAY_20(T) TMP_ARRAY_19(T), T##19
65 #define TMP_ARRAY_21(T) TMP_ARRAY_20(T), T##20
66 #define TMP_ARRAY_22(T) TMP_ARRAY_21(T), T##21
67 #define TMP_ARRAY_23(T) TMP_ARRAY_22(T), T##22
68 #define TMP_ARRAY_24(T) TMP_ARRAY_23(T), T##23
69 #define TMP_ARRAY_25(T) TMP_ARRAY_24(T), T##24
70 #define TMP_ARRAY_26(T) TMP_ARRAY_25(T), T##25
71 #define TMP_ARRAY_27(T) TMP_ARRAY_26(T), T##26
72 #define TMP_ARRAY_28(T) TMP_ARRAY_27(T), T##27
73 #define TMP_ARRAY_29(T) TMP_ARRAY_28(T), T##28
74 #define TMP_ARRAY_30(T) TMP_ARRAY_29(T), T##29
75 #define TMP_ARRAY_31(T) TMP_ARRAY_30(T), T##30
76 #define TMP_ARRAY_32(T) TMP_ARRAY_31(T), T##31
77 
78 // Repeats a specified number of times, 32 is the current maximum.
79 // Note: The value N passed in must be a literal number.
80 #define TMP_ARRAY_N(N,T) TMP_ARRAY_##N(T)
81 
82 /** MACROS used to simplify the replication of an item ********************/
83 #define TMP_REPEAT_1(T) T
84 #define TMP_REPEAT_2(T) TMP_REPEAT_1(T) T
85 #define TMP_REPEAT_3(T) TMP_REPEAT_2(T) T
86 #define TMP_REPEAT_4(T) TMP_REPEAT_3(T) T
87 #define TMP_REPEAT_5(T) TMP_REPEAT_4(T) T
88 #define TMP_REPEAT_6(T) TMP_REPEAT_5(T) T
89 #define TMP_REPEAT_7(T) TMP_REPEAT_6(T) T
90 #define TMP_REPEAT_8(T) TMP_REPEAT_7(T) T
91 #define TMP_REPEAT_9(T) TMP_REPEAT_8(T) T
92 #define TMP_REPEAT_10(T) TMP_REPEAT_9(T) T
93 #define TMP_REPEAT_11(T) TMP_REPEAT_10(T) T
94 #define TMP_REPEAT_12(T) TMP_REPEAT_11(T) T
95 #define TMP_REPEAT_13(T) TMP_REPEAT_12(T) T
96 #define TMP_REPEAT_14(T) TMP_REPEAT_13(T) T
97 #define TMP_REPEAT_15(T) TMP_REPEAT_14(T) T
98 #define TMP_REPEAT_16(T) TMP_REPEAT_15(T) T
99 #define TMP_REPEAT_17(T) TMP_REPEAT_16(T) T
100 #define TMP_REPEAT_18(T) TMP_REPEAT_17(T) T
101 #define TMP_REPEAT_19(T) TMP_REPEAT_18(T) T
102 #define TMP_REPEAT_20(T) TMP_REPEAT_19(T) T
103 #define TMP_REPEAT_21(T) TMP_REPEAT_20(T) T
104 #define TMP_REPEAT_22(T) TMP_REPEAT_21(T) T
105 #define TMP_REPEAT_23(T) TMP_REPEAT_22(T) T
106 #define TMP_REPEAT_24(T) TMP_REPEAT_23(T) T
107 #define TMP_REPEAT_25(T) TMP_REPEAT_24(T) T
108 #define TMP_REPEAT_26(T) TMP_REPEAT_25(T) T
109 #define TMP_REPEAT_27(T) TMP_REPEAT_26(T) T
110 #define TMP_REPEAT_28(T) TMP_REPEAT_27(T) T
111 #define TMP_REPEAT_29(T) TMP_REPEAT_28(T) T
112 #define TMP_REPEAT_30(T) TMP_REPEAT_29(T) T
113 #define TMP_REPEAT_31(T) TMP_REPEAT_30(T) T
114 #define TMP_REPEAT_32(T) TMP_REPEAT_31(T) T
115 
116 // Repeats a specified number of times, 32 is the current maximum.
117 // Note: The value N passed in must be a literal number.
118 #define TMP_REPEAT_N(N,T) TMP_REPEAT_##N(T)
119 
120 // Increments 1 to the supplied number, 0 to 16 are supported
121 #define TMP_INC(x) TMP_INC_DO(x)
122 #define TMP_INC_DO(x) TMP_INC_ ## x
123 
124 #define TMP_INC_0 1
125 #define TMP_INC_1 2
126 #define TMP_INC_2 3
127 #define TMP_INC_3 4
128 #define TMP_INC_4 5
129 #define TMP_INC_5 6
130 #define TMP_INC_6 7
131 #define TMP_INC_7 8
132 #define TMP_INC_8 9
133 #define TMP_INC_9 10
134 #define TMP_INC_10 11
135 #define TMP_INC_11 12
136 #define TMP_INC_12 13
137 #define TMP_INC_13 14
138 #define TMP_INC_14 15
139 #define TMP_INC_15 16
140 #define TMP_INC_16 15
141 #define TMP_INC_17 16
142 #define TMP_INC_18 17
143 #define TMP_INC_19 18
144 #define TMP_INC_20 19
145 #define TMP_INC_21 20
146 #define TMP_INC_22 21
147 #define TMP_INC_23 22
148 #define TMP_INC_24 23
149 #define TMP_INC_25 24
150 #define TMP_INC_26 25
151 #define TMP_INC_27 26
152 #define TMP_INC_28 27
153 #define TMP_INC_29 28
154 #define TMP_INC_30 29
155 #define TMP_INC_31 30
156 #define TMP_INC_32 31
157 
158 
159 // Decrements 1 from the supplied number, 32 to 1 are supported.
160 #define TMP_DEC(x) TMP_DEC_DO(x)
161 #define TMP_DEC_DO(x) TMP_DEC_ ## x
162 
163 #define TMP_DEC_1 0
164 #define TMP_DEC_2 1
165 #define TMP_DEC_3 2
166 #define TMP_DEC_4 3
167 #define TMP_DEC_5 4
168 #define TMP_DEC_6 5
169 #define TMP_DEC_7 6
170 #define TMP_DEC_8 7
171 #define TMP_DEC_9 8
172 #define TMP_DEC_10 9
173 #define TMP_DEC_11 10
174 #define TMP_DEC_12 11
175 #define TMP_DEC_13 12
176 #define TMP_DEC_14 13
177 #define TMP_DEC_15 14
178 #define TMP_DEC_16 15
179 #define TMP_DEC_17 16
180 #define TMP_DEC_18 17
181 #define TMP_DEC_19 18
182 #define TMP_DEC_20 19
183 #define TMP_DEC_21 20
184 #define TMP_DEC_22 21
185 #define TMP_DEC_23 22
186 #define TMP_DEC_24 23
187 #define TMP_DEC_25 24
188 #define TMP_DEC_26 25
189 #define TMP_DEC_27 26
190 #define TMP_DEC_28 27
191 #define TMP_DEC_29 28
192 #define TMP_DEC_30 29
193 #define TMP_DEC_31 30
194 #define TMP_DEC_32 31
195 
196 #endif