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