format_manip_attr.hpp 4.8 KB

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