format_manip_attr.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #if !defined(BOOST_PP_IS_ITERATING)
  6. #if !defined(BOOST_SPIRIT_KARMA_FORMAT_MANIP_ATTR_APR_24_2009_0734AM)
  7. #define BOOST_SPIRIT_KARMA_FORMAT_MANIP_ATTR_APR_24_2009_0734AM
  8. #include <boost/spirit/home/karma/stream/format_manip.hpp>
  9. #include <boost/mpl/bool.hpp>
  10. #include <boost/fusion/include/vector.hpp>
  11. #include <boost/preprocessor/cat.hpp>
  12. #include <boost/preprocessor/iterate.hpp>
  13. #include <boost/preprocessor/repetition/enum.hpp>
  14. #include <boost/preprocessor/repetition/enum_params.hpp>
  15. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  16. #define BOOST_PP_FILENAME_1 \
  17. <boost/spirit/home/karma/stream/format_manip_attr.hpp>
  18. #define BOOST_PP_ITERATION_LIMITS (2, SPIRIT_ARGUMENTS_LIMIT)
  19. #include BOOST_PP_ITERATE()
  20. #endif
  21. ///////////////////////////////////////////////////////////////////////////////
  22. //
  23. // Preprocessor vertical repetition code
  24. //
  25. ///////////////////////////////////////////////////////////////////////////////
  26. #else // defined(BOOST_PP_IS_ITERATING)
  27. #define N BOOST_PP_ITERATION()
  28. #define BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE(z, n, A) \
  29. BOOST_PP_CAT(A, n) const&
  30. ///////////////////////////////////////////////////////////////////////////////
  31. namespace boost { namespace spirit { namespace karma
  32. {
  33. ///////////////////////////////////////////////////////////////////////////
  34. template <typename Expr, BOOST_PP_ENUM_PARAMS(N, typename A)>
  35. inline detail::format_manip<Expr, mpl::false_, mpl::true_, unused_type
  36. , fusion::vector<
  37. BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
  38. > >
  39. format(Expr const& xpr, BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
  40. {
  41. using karma::detail::format_manip;
  42. // Report invalid expression error as early as possible.
  43. // If you got an error_invalid_expression error message here,
  44. // then the expression (expr) is not a valid spirit karma expression.
  45. BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
  46. typedef fusion::vector<
  47. BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
  48. > vector_type;
  49. vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
  50. return format_manip<Expr, mpl::false_, mpl::true_, unused_type, vector_type>(
  51. xpr, unused, attr);
  52. }
  53. ///////////////////////////////////////////////////////////////////////////
  54. template <typename Expr, typename Delimiter
  55. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  56. inline detail::format_manip<Expr, mpl::false_, mpl::true_, Delimiter
  57. , fusion::vector<
  58. BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
  59. > >
  60. format_delimited(Expr const& xpr, Delimiter const& d
  61. , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit
  62. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
  63. {
  64. using karma::detail::format_manip;
  65. // Report invalid expression error as early as possible.
  66. // If you got an error_invalid_expression error message here,
  67. // then the expression (expr) is not a valid spirit karma expression.
  68. BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
  69. BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
  70. typedef fusion::vector<
  71. BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
  72. > vector_type;
  73. vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
  74. return format_manip<Expr, mpl::false_, mpl::true_, Delimiter, vector_type>(
  75. xpr, d, pre_delimit, attr);
  76. }
  77. template <typename Expr, typename Delimiter
  78. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  79. inline detail::format_manip<Expr, mpl::false_, mpl::true_, Delimiter
  80. , fusion::vector<
  81. BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
  82. > >
  83. format_delimited(Expr const& xpr, Delimiter const& d
  84. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
  85. {
  86. using karma::detail::format_manip;
  87. // Report invalid expression error as early as possible.
  88. // If you got an error_invalid_expression error message here,
  89. // then the expression (expr) is not a valid spirit karma expression.
  90. BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
  91. BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
  92. typedef fusion::vector<
  93. BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
  94. > vector_type;
  95. vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
  96. return format_manip<Expr, mpl::false_, mpl::true_, Delimiter, vector_type>(
  97. xpr, d, delimit_flag::dont_predelimit, attr);
  98. }
  99. }}}
  100. #undef BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE
  101. #undef N
  102. #endif