1 | /*
|
---|
2 | * TemplatePowerSetGenerator.hpp
|
---|
3 | *
|
---|
4 | * Created on: Dec 31, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef TEMPLATEPOWERSETGENERATOR_HPP_
|
---|
9 | #define TEMPLATEPOWERSETGENERATOR_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 |
|
---|
17 | // this include is needed for BOOST_PP_LOCAL_ITERATE()
|
---|
18 | #include <boost/preprocessor/iteration/local.hpp>
|
---|
19 |
|
---|
20 | // this include is needed for BOOST_PP_REPEAT
|
---|
21 | #include <boost/preprocessor/repetition/repeat.hpp>
|
---|
22 |
|
---|
23 | #include <boost/preprocessor/punctuation/comma_if.hpp>
|
---|
24 | #include <boost/preprocessor/seq/elem.hpp>
|
---|
25 | #include <boost/preprocessor/seq/enum.hpp>
|
---|
26 | #include <boost/preprocessor/seq/for_each.hpp>
|
---|
27 | #include <boost/preprocessor/seq/for_each_i.hpp>
|
---|
28 | #include <boost/preprocessor/stringize.hpp>
|
---|
29 | #include <boost/preprocessor/tuple/elem.hpp>
|
---|
30 |
|
---|
31 | /** Functions that prints the given elem as [elem].
|
---|
32 | *
|
---|
33 | * Use the funcione as follows:
|
---|
34 | * SquareBracketize(~,~,test)
|
---|
35 | *
|
---|
36 | * which would output:
|
---|
37 | * [test]
|
---|
38 | */
|
---|
39 | #define SquareBracketize(r, data, i, elem) \
|
---|
40 | [ \
|
---|
41 | BOOST_PP_SEQ_ELEM(i, data) \
|
---|
42 | elem \
|
---|
43 | ]
|
---|
44 |
|
---|
45 | /** Functions that allows to print a given seq of elements in the way of
|
---|
46 | * enumeration declaration.
|
---|
47 | *
|
---|
48 | * Use the functions as follows:
|
---|
49 | * #define BOOST_PP_REPEAT(BOOST_PP_SEQ_SIZE(seq), n, seqitems_as_struct)
|
---|
50 | *
|
---|
51 | * where "seq" is your defined list, e.g.
|
---|
52 | * #define seq (1)(2)(3)(4)
|
---|
53 | *
|
---|
54 | * which would output:
|
---|
55 | * 1,
|
---|
56 | * 2,
|
---|
57 | * 3,
|
---|
58 | * 4
|
---|
59 | *
|
---|
60 | */
|
---|
61 | #define seqitems_as_enum(z,n,seq_with_elements) \
|
---|
62 | BOOST_PP_COMMA_IF (n) \
|
---|
63 | BOOST_PP_SEQ_ELEM(n, seq_with_elements)
|
---|
64 |
|
---|
65 | /** Functions that allows to print a given seq of elements in the way of
|
---|
66 | * variable declaration.
|
---|
67 | *
|
---|
68 | * Use the functions as follows:
|
---|
69 | * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum(seqsize, n, seq)
|
---|
70 | * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 )
|
---|
71 | * #include BOOST_PP_LOCAL_ITERATE()
|
---|
72 | *
|
---|
73 | * where "seq" is your defined list, e.g.
|
---|
74 | * #define seq (1)(2)(3)(4)
|
---|
75 | *
|
---|
76 | * which would output:
|
---|
77 | * 1;
|
---|
78 | * 2;
|
---|
79 | * 3;
|
---|
80 | * 4;
|
---|
81 | *
|
---|
82 | */
|
---|
83 | #define seqitems_as_struct(z,n,seq_with_elements ) \
|
---|
84 | BOOST_PP_SEQ_ELEM(n, seq_with_elements) ;
|
---|
85 |
|
---|
86 | /** Functions that allows to print a given seq of elements in the way of
|
---|
87 | * std::map from strings to enums.
|
---|
88 | *
|
---|
89 | * e.g. let "seq" be defined as
|
---|
90 | * #define seq (one)(two)(three)(four)
|
---|
91 | *
|
---|
92 | * then we use
|
---|
93 | * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_string_enum_map(seqsize, n, seq, EnumMap, name_space)
|
---|
94 | * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 )
|
---|
95 | * #include BOOST_PP_LOCAL_ITERATE()
|
---|
96 | *
|
---|
97 | * which expands by the preprocessor to:
|
---|
98 | * EnumMap["one"] = test:: one;
|
---|
99 | * EnumMap["two"] = test:: two;
|
---|
100 | * EnumMap["three"] = test:: three;
|
---|
101 | * EnumMap["four"] = test:: four;
|
---|
102 |
|
---|
103 | */
|
---|
104 | #define seqitems_as_string_enum_map(z,n,seq_with_elements, map, name_space) \
|
---|
105 | map [BOOST_PP_STRINGIZE( \
|
---|
106 | BOOST_PP_SEQ_ELEM(n, seq_with_elements) \
|
---|
107 | )] = name_space BOOST_PP_SEQ_ELEM(n, seq_with_elements) \
|
---|
108 | ;
|
---|
109 |
|
---|
110 | /** Functions that allows to print a given seq of elements in the way of
|
---|
111 | * std::map from strings to enums.
|
---|
112 | *
|
---|
113 | * e.g. let "seq" be defined as
|
---|
114 | * #define seq (one)(two)(three)(four)
|
---|
115 | *
|
---|
116 | * then we use
|
---|
117 | * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(seqsize, n, seq, EnumMap, test::)
|
---|
118 | * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 )
|
---|
119 | * #include BOOST_PP_LOCAL_ITERATE()
|
---|
120 | *
|
---|
121 | * which expands by the preprocessor to:
|
---|
122 | * EnumMap[one] = test::one;
|
---|
123 | * EnumMap[two] = test::two;
|
---|
124 | * EnumMap[three] = test::three;
|
---|
125 | * EnumMap[four] = test::four;
|
---|
126 |
|
---|
127 | */
|
---|
128 | #define seqitems_as_enum_key_map(z,n,seq_with_elements, map, keytype, name_space, suffix) \
|
---|
129 | map [ \
|
---|
130 | BOOST_PP_SEQ_ELEM(n, seq_with_elements) \
|
---|
131 | ] = keytype< name_space BOOST_PP_SEQ_ELEM(n, seq_with_elements) suffix > ();
|
---|
132 |
|
---|
133 | #define tupel_in_square_brackets(z,n,tupelelement) \
|
---|
134 | [ \
|
---|
135 | tupelelement \
|
---|
136 | ]\
|
---|
137 |
|
---|
138 | /** Functions that allows to print a given seq of elements in the way of
|
---|
139 | * std::map from strings to enums.
|
---|
140 | *
|
---|
141 | * e.g. let "seqseq" be defined as
|
---|
142 | * #define seqseq ((d)(eins)(zwei)(drei))((e)(one)(two)(three))((f)(un)(deux)(troix))
|
---|
143 | *
|
---|
144 | * then we use
|
---|
145 | * #define tableprinter(z,n,seq) BOOST_PP_SEQ_ELEM(n,seq)
|
---|
146 | * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(seqsize, n, seqseq, bla::, MultiMap, test::testfunction, test_printer, tableprinter)
|
---|
147 | * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seqseq)-1 )
|
---|
148 | * #include BOOST_PP_LOCAL_ITERATE()
|
---|
149 | *
|
---|
150 | * which expands by the preprocessor to:
|
---|
151 | * MultiMap[eins][zwei][drei] = test:: d;
|
---|
152 | * MultiMap[one][two][three] = test:: e;
|
---|
153 | * MultiMap[un][deux][troix] = test:: f;
|
---|
154 |
|
---|
155 | */
|
---|
156 | #define seqitems_as_enum_key_multidimmap(z,n, size_tupels, seq_of_tupels, map, tableitems_arg_printer, template_function, template_arg_printer, param_arg_printer) \
|
---|
157 | map \
|
---|
158 | BOOST_PP_REPEAT (size_tupels, tableitems_arg_printer, BOOST_PP_SEQ_ELEM(n, seq_of_tupels) ) \
|
---|
159 | = template_function \
|
---|
160 | < BOOST_PP_REPEAT(size_tupels, template_arg_printer, BOOST_PP_SEQ_ELEM(n, seq_of_tupels) ) > (\
|
---|
161 | BOOST_PP_REPEAT(size_tupels, param_arg_printer, BOOST_PP_SEQ_ELEM(n, seq_of_tupels) ) );
|
---|
162 |
|
---|
163 |
|
---|
164 | #endif /* TEMPLATEPOWERSETGENERATOR_HPP_ */
|
---|