generate_to.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_DETAIL_GENERATE_TO_FEB_20_2007_0417PM)
  6. #define BOOST_SPIRIT_KARMA_DETAIL_GENERATE_TO_FEB_20_2007_0417PM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #include <boost/spirit/home/support/unused.hpp>
  11. #include <boost/spirit/home/support/char_class.hpp>
  12. #include <boost/spirit/home/karma/detail/output_iterator.hpp>
  13. namespace boost { namespace spirit { namespace karma { namespace detail
  14. {
  15. ///////////////////////////////////////////////////////////////////////////
  16. // These utility functions insert the given parameter into the supplied
  17. // output iterator.
  18. // If the attribute is spirit's unused_type, this is a no_op.
  19. ///////////////////////////////////////////////////////////////////////////
  20. template <
  21. typename OutputIterator, typename Attribute, typename CharEncoding
  22. , typename Tag>
  23. inline bool
  24. generate_to(OutputIterator& sink, Attribute const& p, CharEncoding, Tag)
  25. {
  26. *sink = spirit::char_class::convert<CharEncoding>::to(Tag(), p);
  27. ++sink;
  28. return detail::sink_is_good(sink);
  29. }
  30. template <typename OutputIterator, typename Attribute>
  31. inline bool
  32. generate_to(OutputIterator& sink, Attribute const& p, unused_type, unused_type)
  33. {
  34. *sink = p;
  35. ++sink;
  36. return detail::sink_is_good(sink);
  37. }
  38. template <typename OutputIterator, typename CharEncoding, typename Tag>
  39. inline bool generate_to(OutputIterator&, unused_type, CharEncoding, Tag)
  40. {
  41. return true;
  42. }
  43. template <typename OutputIterator, typename Attribute>
  44. inline bool
  45. generate_to(OutputIterator& sink, Attribute const& p)
  46. {
  47. *sink = p;
  48. ++sink;
  49. return detail::sink_is_good(sink);
  50. }
  51. template <typename OutputIterator>
  52. inline bool generate_to(OutputIterator&, unused_type)
  53. {
  54. return true;
  55. }
  56. }}}} // namespace boost::spirit::karma::detail
  57. #endif // KARMA_CORE_DETAIL_INSERT_TO_HPP