/* * TemplatePowerSetGenerator.hpp * * Created on: Dec 31, 2010 * Author: heber */ #ifndef TEMPLATEPOWERSETGENERATOR_HPP_ #define TEMPLATEPOWERSETGENERATOR_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif // this include is needed for BOOST_PP_LOCAL_ITERATE() #include // this include is needed for BOOST_PP_REPEAT #include #include #include #include #include #include #include #include /** Functions that prints the given elem as [elem]. * * Use the funcione as follows: * SquareBracketize(~,~,test) * * which would output: * [test] */ #define SquareBracketize(r, data, i, elem) \ [ \ BOOST_PP_SEQ_ELEM(i, data) \ elem \ ] /** Functions that allows to print a given seq of elements in the way of * enumeration declaration. * * Use the functions as follows: * #define BOOST_PP_REPEAT(BOOST_PP_SEQ_SIZE(seq), n, seqitems_as_struct) * * where "seq" is your defined list, e.g. * #define seq (1)(2)(3)(4) * * which would output: * 1, * 2, * 3, * 4 * */ #define seqitems_as_enum(z,n,seq_with_elements) \ BOOST_PP_COMMA_IF (n) \ BOOST_PP_SEQ_ELEM(n, seq_with_elements) /** Functions that allows to print a given seq of elements in the way of * variable declaration. * * Use the functions as follows: * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum(seqsize, n, seq) * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 ) * #include BOOST_PP_LOCAL_ITERATE() * * where "seq" is your defined list, e.g. * #define seq (1)(2)(3)(4) * * which would output: * 1; * 2; * 3; * 4; * */ #define seqitems_as_struct(z,n,seq_with_elements ) \ BOOST_PP_SEQ_ELEM(n, seq_with_elements) ; /** Functions that allows to print a given seq of elements in the way of * std::map from strings to enums. * * e.g. let "seq" be defined as * #define seq (one)(two)(three)(four) * * then we use * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_string_enum_map(seqsize, n, seq, EnumMap, name_space) * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 ) * #include BOOST_PP_LOCAL_ITERATE() * * which expands by the preprocessor to: * EnumMap["one"] = test:: one; * EnumMap["two"] = test:: two; * EnumMap["three"] = test:: three; * EnumMap["four"] = test:: four; */ #define seqitems_as_string_enum_map(z,n,seq_with_elements, map, name_space) \ map [BOOST_PP_STRINGIZE( \ BOOST_PP_SEQ_ELEM(n, seq_with_elements) \ )] = name_space BOOST_PP_SEQ_ELEM(n, seq_with_elements) \ ; /** Functions that allows to print a given seq of elements in the way of * std::map from strings to enums. * * e.g. let "seq" be defined as * #define seq (one)(two)(three)(four) * * then we use * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(seqsize, n, seq, EnumMap, test::) * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 ) * #include BOOST_PP_LOCAL_ITERATE() * * which expands by the preprocessor to: * EnumMap[one] = test::one; * EnumMap[two] = test::two; * EnumMap[three] = test::three; * EnumMap[four] = test::four; */ #define seqitems_as_enum_key_map(z,n,seq_with_elements, map, keytype, name_space, suffix) \ map [ \ BOOST_PP_SEQ_ELEM(n, seq_with_elements) \ ] = keytype< name_space BOOST_PP_SEQ_ELEM(n, seq_with_elements) suffix > (); #define tupel_in_square_brackets(z,n,tupelelement) \ [ \ tupelelement \ ]\ /** Functions that allows to print a given seq of elements in the way of * std::map from strings to enums. * * e.g. let "seqseq" be defined as * #define seqseq ((d)(eins)(zwei)(drei))((e)(one)(two)(three))((f)(un)(deux)(troix)) * * then we use * #define tableprinter(z,n,seq) BOOST_PP_SEQ_ELEM(n,seq) * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(seqsize, n, seqseq, bla::, MultiMap, test::testfunction, test_printer, tableprinter) * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seqseq)-1 ) * #include BOOST_PP_LOCAL_ITERATE() * * which expands by the preprocessor to: * MultiMap[eins][zwei][drei] = test:: d; * MultiMap[one][two][three] = test:: e; * MultiMap[un][deux][troix] = test:: f; */ #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) \ map \ BOOST_PP_REPEAT (size_tupels, tableitems_arg_printer, BOOST_PP_SEQ_ELEM(n, seq_of_tupels) ) \ = template_function \ < BOOST_PP_REPEAT(size_tupels, template_arg_printer, BOOST_PP_SEQ_ELEM(n, seq_of_tupels) ) > (\ BOOST_PP_REPEAT(size_tupels, param_arg_printer, BOOST_PP_SEQ_ELEM(n, seq_of_tupels) ) ); #endif /* TEMPLATEPOWERSETGENERATOR_HPP_ */