eol.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_SPIRIT_KARMA_EOL_JUL_08_2008_1014AM)
  6. #define BOOST_SPIRIT_KARMA_EOL_JUL_08_2008_1014AM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #include <boost/spirit/home/support/common_terminals.hpp>
  11. #include <boost/spirit/home/support/info.hpp>
  12. #include <boost/spirit/home/support/unused.hpp>
  13. #include <boost/spirit/home/karma/detail/attributes.hpp>
  14. #include <boost/spirit/home/karma/domain.hpp>
  15. #include <boost/spirit/home/karma/meta_compiler.hpp>
  16. #include <boost/spirit/home/karma/delimit_out.hpp>
  17. #include <boost/spirit/home/karma/detail/generate_to.hpp>
  18. namespace boost { namespace spirit
  19. {
  20. ///////////////////////////////////////////////////////////////////////////
  21. // Enablers
  22. ///////////////////////////////////////////////////////////////////////////
  23. template <>
  24. struct use_terminal<karma::domain, tag::eol> // enables eol
  25. : mpl::true_ {};
  26. }}
  27. ///////////////////////////////////////////////////////////////////////////////
  28. namespace boost { namespace spirit { namespace karma
  29. {
  30. #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
  31. using boost::spirit::eol;
  32. #endif
  33. using boost::spirit::eol_type;
  34. struct eol_generator : primitive_generator<eol_generator>
  35. {
  36. template <typename Context, typename Unused>
  37. struct attribute
  38. {
  39. typedef unused_type type;
  40. };
  41. template <
  42. typename OutputIterator, typename Context, typename Delimiter
  43. , typename Attribute>
  44. static bool generate(OutputIterator& sink, Context&, Delimiter const& d
  45. , Attribute const& /*attr*/)
  46. {
  47. return detail::generate_to(sink, '\n') &&
  48. karma::delimit_out(sink, d); // always do post-delimiting
  49. }
  50. template <typename Context>
  51. info what(Context const& /*context*/) const
  52. {
  53. return info("eol");
  54. }
  55. };
  56. ///////////////////////////////////////////////////////////////////////////
  57. // Generator generators: make_xxx function (objects)
  58. ///////////////////////////////////////////////////////////////////////////
  59. template <typename Modifiers>
  60. struct make_primitive<tag::eol, Modifiers>
  61. {
  62. typedef eol_generator result_type;
  63. result_type operator()(unused_type, unused_type) const
  64. {
  65. return result_type();
  66. }
  67. };
  68. }}}
  69. #endif