1 // Copyright (c) 2001-2011 Hartmut Kaiser
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)
6 #if !defined(BOOST_PP_IS_ITERATING)
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
11 #include <boost/spirit/home/karma/stream/format_manip.hpp>
13 #include <boost/fusion/include/vector.hpp>
14 #include <boost/preprocessor/iterate.hpp>
15 #include <boost/preprocessor/repetition/enum.hpp>
16 #include <boost/preprocessor/repetition/enum_params.hpp>
17 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
19 #define BOOST_PP_FILENAME_1 \
20 <boost/spirit/home/karma/stream/format_manip_attr.hpp>
21 #define BOOST_PP_ITERATION_LIMITS (2, SPIRIT_ARGUMENTS_LIMIT)
22 #include BOOST_PP_ITERATE()
26 ///////////////////////////////////////////////////////////////////////////////
28 // Preprocessor vertical repetition code
30 ///////////////////////////////////////////////////////////////////////////////
31 #else // defined(BOOST_PP_IS_ITERATING)
33 #define N BOOST_PP_ITERATION()
34 #define BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE(z, n, A) \
35 BOOST_PP_CAT(A, n) const&
37 ///////////////////////////////////////////////////////////////////////////////
38 namespace boost { namespace spirit { namespace karma
40 ///////////////////////////////////////////////////////////////////////////
41 template <typename Expr, BOOST_PP_ENUM_PARAMS(N, typename A)>
42 inline detail::format_manip<Expr, mpl::false_, mpl::true_, unused_type
44 BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
46 format(Expr const& xpr, BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
48 using karma::detail::format_manip;
50 // Report invalid expression error as early as possible.
51 // If you got an error_invalid_expression error message here,
52 // then the expression (expr) is not a valid spirit karma expression.
53 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
55 typedef fusion::vector<
56 BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
59 vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
60 return format_manip<Expr, mpl::false_, mpl::true_, unused_type, vector_type>(
64 ///////////////////////////////////////////////////////////////////////////
65 template <typename Expr, typename Delimiter
66 , BOOST_PP_ENUM_PARAMS(N, typename A)>
67 inline detail::format_manip<Expr, mpl::false_, mpl::true_, Delimiter
69 BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
71 format_delimited(Expr const& xpr, Delimiter const& d
72 , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit
73 , BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
75 using karma::detail::format_manip;
77 // Report invalid expression error as early as possible.
78 // If you got an error_invalid_expression error message here,
79 // then the expression (expr) is not a valid spirit karma expression.
80 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
81 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
83 typedef fusion::vector<
84 BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
87 vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
88 return format_manip<Expr, mpl::false_, mpl::true_, Delimiter, vector_type>(
89 xpr, d, pre_delimit, attr);
92 template <typename Expr, typename Delimiter
93 , BOOST_PP_ENUM_PARAMS(N, typename A)>
94 inline detail::format_manip<Expr, mpl::false_, mpl::true_, Delimiter
96 BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
98 format_delimited(Expr const& xpr, Delimiter const& d
99 , BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
101 using karma::detail::format_manip;
103 // Report invalid expression error as early as possible.
104 // If you got an error_invalid_expression error message here,
105 // then the expression (expr) is not a valid spirit karma expression.
106 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
107 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
109 typedef fusion::vector<
110 BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
113 vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
114 return format_manip<Expr, mpl::false_, mpl::true_, Delimiter, vector_type>(
115 xpr, d, delimit_flag::dont_predelimit, attr);
119 #undef BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE