Chris@16
|
1 // Copyright (c) 2001-2011 Joel de Guzman
|
Chris@16
|
2 // Copyright (c) 2001-2011 Hartmut Kaiser
|
Chris@16
|
3 //
|
Chris@16
|
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6
|
Chris@16
|
7 #if !defined(BOOST_SPIRIT_KARMA_REFERENCE_APR_17_2009_1057PM)
|
Chris@16
|
8 #define BOOST_SPIRIT_KARMA_REFERENCE_APR_17_2009_1057PM
|
Chris@16
|
9
|
Chris@16
|
10 #if defined(_MSC_VER)
|
Chris@16
|
11 #pragma once
|
Chris@16
|
12 #endif
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/spirit/home/karma/meta_compiler.hpp>
|
Chris@16
|
15 #include <boost/spirit/home/karma/generator.hpp>
|
Chris@16
|
16 #include <boost/spirit/home/support/info.hpp>
|
Chris@16
|
17 #include <boost/spirit/home/support/handles_container.hpp>
|
Chris@16
|
18 #include <boost/type_traits/remove_const.hpp>
|
Chris@16
|
19 #include <boost/ref.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 namespace boost { namespace spirit { namespace karma
|
Chris@16
|
22 {
|
Chris@16
|
23 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
24 // reference is a generator that references another generator (its Subject)
|
Chris@16
|
25 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
26 template <typename Subject>
|
Chris@16
|
27 struct reference : generator<reference<Subject> >
|
Chris@16
|
28 {
|
Chris@16
|
29 typedef mpl::int_<generator_properties::all_properties> properties;
|
Chris@16
|
30
|
Chris@16
|
31 typedef Subject subject_type;
|
Chris@16
|
32
|
Chris@16
|
33 reference(Subject& subject)
|
Chris@16
|
34 : ref(subject) {}
|
Chris@16
|
35
|
Chris@16
|
36 template <typename Context, typename Unused>
|
Chris@16
|
37 struct attribute : Subject::template attribute<Context, Unused> {};
|
Chris@16
|
38
|
Chris@16
|
39 // Default overload, used whenever the attribute is not unused and not
|
Chris@16
|
40 // used from an aliased rule.
|
Chris@16
|
41 template <typename OutputIterator, typename Context
|
Chris@16
|
42 , typename Delimiter, typename Attribute>
|
Chris@16
|
43 bool generate(OutputIterator& sink, Context& context
|
Chris@16
|
44 , Delimiter const& delim, Attribute const& attr) const
|
Chris@16
|
45 {
|
Chris@16
|
46 return ref.get().generate(sink, context, delim, attr);
|
Chris@16
|
47 }
|
Chris@16
|
48
|
Chris@16
|
49 // This overload gets called from an aliased rule only, we take the
|
Chris@16
|
50 // attribute from the context provided from the wrapper rule.
|
Chris@16
|
51 template <typename OutputIterator, typename Context
|
Chris@16
|
52 , typename Delimiter>
|
Chris@16
|
53 bool generate(OutputIterator& sink, Context& context
|
Chris@16
|
54 , Delimiter const& delim, unused_type) const
|
Chris@16
|
55 {
|
Chris@16
|
56 return ref.get().generate(sink, context, delim, context.attributes);
|
Chris@16
|
57 }
|
Chris@16
|
58
|
Chris@16
|
59 // This overload is used whenever no attribute is given and it is used
|
Chris@16
|
60 // not from an aliased rule.
|
Chris@16
|
61 template <typename OutputIterator, typename Delimiter>
|
Chris@16
|
62 bool generate(OutputIterator& sink, unused_type
|
Chris@16
|
63 , Delimiter const& delim, unused_type) const
|
Chris@16
|
64 {
|
Chris@16
|
65 return ref.get().generate(sink, unused, delim, unused);
|
Chris@16
|
66 }
|
Chris@16
|
67
|
Chris@16
|
68 template <typename Context>
|
Chris@16
|
69 info what(Context& context) const
|
Chris@16
|
70 {
|
Chris@16
|
71 // the reference is transparent (does not add any info)
|
Chris@16
|
72 return ref.get().what(context);
|
Chris@16
|
73 }
|
Chris@16
|
74
|
Chris@16
|
75 boost::reference_wrapper<Subject> ref;
|
Chris@16
|
76 };
|
Chris@16
|
77 }}}
|
Chris@16
|
78
|
Chris@16
|
79 namespace boost { namespace spirit { namespace traits
|
Chris@16
|
80 {
|
Chris@16
|
81 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
82 template <typename Subject, typename Attribute, typename Context
|
Chris@16
|
83 , typename Iterator>
|
Chris@16
|
84 struct handles_container<karma::reference<Subject>, Attribute
|
Chris@16
|
85 , Context, Iterator>
|
Chris@16
|
86 : handles_container<typename remove_const<Subject>::type, Attribute
|
Chris@16
|
87 , Context, Iterator>
|
Chris@16
|
88 {};
|
Chris@16
|
89 }}}
|
Chris@16
|
90
|
Chris@16
|
91 #endif
|