parameterized.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (c) 2001-2011 Joel de Guzman
  2. // Copyright (c) 2001-2011 Hartmut Kaiser
  3. // Copyright (c) 2009 Francois Barel
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #if !defined(BOOST_SPIRIT_KARMA_PARAMETERIZED_AUGUST_09_2009_0601AM)
  8. #define BOOST_SPIRIT_KARMA_PARAMETERIZED_AUGUST_09_2009_0601AM
  9. #if defined(_MSC_VER)
  10. #pragma once
  11. #endif
  12. #include <boost/ref.hpp>
  13. #include <boost/spirit/home/support/handles_container.hpp>
  14. #include <boost/spirit/home/karma/generator.hpp>
  15. namespace boost { namespace spirit { namespace karma
  16. {
  17. ///////////////////////////////////////////////////////////////////////////
  18. // parameterized_nonterminal: generator representing the invocation of a
  19. // nonterminal, passing inherited attributes
  20. ///////////////////////////////////////////////////////////////////////////
  21. template <typename Subject, typename Params>
  22. struct parameterized_nonterminal
  23. : generator<parameterized_nonterminal<Subject, Params> >
  24. {
  25. typedef mpl::int_<generator_properties::all_properties> properties;
  26. parameterized_nonterminal(Subject const& subject, Params const& params)
  27. : ref(subject), params(params)
  28. {
  29. }
  30. template <typename Context, typename Unused>
  31. struct attribute
  32. // Forward to subject.
  33. : Subject::template attribute<Context, Unused> {};
  34. template <typename OutputIterator, typename Context, typename Delimiter
  35. , typename Attribute>
  36. bool generate(OutputIterator& sink, Context& context
  37. , Delimiter const& delim, Attribute const& attr) const
  38. {
  39. // Forward to subject, passing the additional
  40. // params argument to generate.
  41. return ref.get().generate(sink, context, delim, attr, params);
  42. }
  43. template <typename Context>
  44. info what(Context& context) const
  45. {
  46. // Forward to subject.
  47. return ref.get().what(context);
  48. }
  49. boost::reference_wrapper<Subject const> ref;
  50. Params params;
  51. };
  52. }}}
  53. namespace boost { namespace spirit { namespace traits
  54. {
  55. ///////////////////////////////////////////////////////////////////////////
  56. template <typename Subject, typename Params, typename Attribute
  57. , typename Context, typename Iterator>
  58. struct handles_container<karma::parameterized_nonterminal<Subject, Params>
  59. , Attribute, Context, Iterator>
  60. : handles_container<typename remove_const<Subject>::type
  61. , Attribute, Context, Iterator>
  62. {};
  63. }}}
  64. #endif