| 1 | // Copyright (c) 2001-2011 Hartmut Kaiser |
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #if !defined(BOOST_PP_IS_ITERATING) |
| 7 | |
| 8 | #if !defined(BOOST_SPIRIT_KARMA_FORMAT_MANIP_ATTR_APR_24_2009_0734AM) |
| 9 | #define BOOST_SPIRIT_KARMA_FORMAT_MANIP_ATTR_APR_24_2009_0734AM |
| 10 | |
| 11 | #include <boost/spirit/home/karma/stream/format_manip.hpp> |
| 12 | |
| 13 | #include <boost/mpl/bool.hpp> |
| 14 | #include <boost/fusion/include/vector.hpp> |
| 15 | #include <boost/preprocessor/cat.hpp> |
| 16 | #include <boost/preprocessor/iterate.hpp> |
| 17 | #include <boost/preprocessor/repetition/enum.hpp> |
| 18 | #include <boost/preprocessor/repetition/enum_params.hpp> |
| 19 | #include <boost/preprocessor/repetition/enum_binary_params.hpp> |
| 20 | |
| 21 | #define BOOST_PP_FILENAME_1 \ |
| 22 | <boost/spirit/home/karma/stream/format_manip_attr.hpp> |
| 23 | #define BOOST_PP_ITERATION_LIMITS (2, SPIRIT_ARGUMENTS_LIMIT) |
| 24 | #include BOOST_PP_ITERATE() |
| 25 | |
| 26 | #endif |
| 27 | |
| 28 | /////////////////////////////////////////////////////////////////////////////// |
| 29 | // |
| 30 | // Preprocessor vertical repetition code |
| 31 | // |
| 32 | /////////////////////////////////////////////////////////////////////////////// |
| 33 | #else // defined(BOOST_PP_IS_ITERATING) |
| 34 | |
| 35 | #define N BOOST_PP_ITERATION() |
| 36 | #define BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE(z, n, A) \ |
| 37 | BOOST_PP_CAT(A, n) const& |
| 38 | |
| 39 | /////////////////////////////////////////////////////////////////////////////// |
| 40 | namespace boost { namespace spirit { namespace karma |
| 41 | { |
| 42 | /////////////////////////////////////////////////////////////////////////// |
| 43 | template <typename Expr, BOOST_PP_ENUM_PARAMS(N, typename A)> |
| 44 | inline detail::format_manip<Expr, mpl::false_, mpl::true_, unused_type |
| 45 | , fusion::vector< |
| 46 | BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A) |
| 47 | > > |
| 48 | format(Expr const& xpr, BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr)) |
| 49 | { |
| 50 | using karma::detail::format_manip; |
| 51 | |
| 52 | // Report invalid expression error as early as possible. |
| 53 | // If you got an error_invalid_expression error message here, |
| 54 | // then the expression (expr) is not a valid spirit karma expression. |
| 55 | BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr); |
| 56 | |
| 57 | typedef fusion::vector< |
| 58 | BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A) |
| 59 | > vector_type; |
| 60 | |
| 61 | vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr)); |
| 62 | return format_manip<Expr, mpl::false_, mpl::true_, unused_type, vector_type>( |
| 63 | xpr, unused, attr); |
| 64 | } |
| 65 | |
| 66 | /////////////////////////////////////////////////////////////////////////// |
| 67 | template <typename Expr, typename Delimiter |
| 68 | , BOOST_PP_ENUM_PARAMS(N, typename A)> |
| 69 | inline detail::format_manip<Expr, mpl::false_, mpl::true_, Delimiter |
| 70 | , fusion::vector< |
| 71 | BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A) |
| 72 | > > |
| 73 | format_delimited(Expr const& xpr, Delimiter const& d |
| 74 | , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit |
| 75 | , BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr)) |
| 76 | { |
| 77 | using karma::detail::format_manip; |
| 78 | |
| 79 | // Report invalid expression error as early as possible. |
| 80 | // If you got an error_invalid_expression error message here, |
| 81 | // then the expression (expr) is not a valid spirit karma expression. |
| 82 | BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr); |
| 83 | BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter); |
| 84 | |
| 85 | typedef fusion::vector< |
| 86 | BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A) |
| 87 | > vector_type; |
| 88 | |
| 89 | vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr)); |
| 90 | return format_manip<Expr, mpl::false_, mpl::true_, Delimiter, vector_type>( |
| 91 | xpr, d, pre_delimit, attr); |
| 92 | } |
| 93 | |
| 94 | template <typename Expr, typename Delimiter |
| 95 | , BOOST_PP_ENUM_PARAMS(N, typename A)> |
| 96 | inline detail::format_manip<Expr, mpl::false_, mpl::true_, Delimiter |
| 97 | , fusion::vector< |
| 98 | BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A) |
| 99 | > > |
| 100 | format_delimited(Expr const& xpr, Delimiter const& d |
| 101 | , BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr)) |
| 102 | { |
| 103 | using karma::detail::format_manip; |
| 104 | |
| 105 | // Report invalid expression error as early as possible. |
| 106 | // If you got an error_invalid_expression error message here, |
| 107 | // then the expression (expr) is not a valid spirit karma expression. |
| 108 | BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr); |
| 109 | BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter); |
| 110 | |
| 111 | typedef fusion::vector< |
| 112 | BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A) |
| 113 | > vector_type; |
| 114 | |
| 115 | vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr)); |
| 116 | return format_manip<Expr, mpl::false_, mpl::true_, Delimiter, vector_type>( |
| 117 | xpr, d, delimit_flag::dont_predelimit, attr); |
| 118 | } |
| 119 | }}} |
| 120 | |
| 121 | #undef BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE |
| 122 | #undef N |
| 123 | |
| 124 | #endif |
| 125 | |
| 126 | |