Chris@16
|
1 // Copyright (c) 2001-2011 Hartmut Kaiser
|
Chris@16
|
2 //
|
Chris@16
|
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5
|
Chris@16
|
6 #if !defined(SPIRIT_KARMA_OMIT_JUL_20_2009_1008AM)
|
Chris@16
|
7 #define SPIRIT_KARMA_OMIT_JUL_20_2009_1008AM
|
Chris@16
|
8
|
Chris@16
|
9 #if defined(_MSC_VER)
|
Chris@16
|
10 #pragma once
|
Chris@16
|
11 #endif
|
Chris@16
|
12
|
Chris@16
|
13 #include <boost/spirit/home/karma/meta_compiler.hpp>
|
Chris@16
|
14 #include <boost/spirit/home/karma/generator.hpp>
|
Chris@16
|
15 #include <boost/spirit/home/karma/domain.hpp>
|
Chris@16
|
16 #include <boost/spirit/home/support/unused.hpp>
|
Chris@16
|
17 #include <boost/spirit/home/support/info.hpp>
|
Chris@16
|
18 #include <boost/spirit/home/support/common_terminals.hpp>
|
Chris@16
|
19 #include <boost/spirit/home/support/has_semantic_action.hpp>
|
Chris@16
|
20 #include <boost/spirit/home/support/handles_container.hpp>
|
Chris@16
|
21 #include <boost/spirit/home/karma/detail/attributes.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 namespace boost { namespace spirit
|
Chris@16
|
24 {
|
Chris@16
|
25 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
26 // Enablers
|
Chris@16
|
27 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
28 template <>
|
Chris@16
|
29 struct use_directive<karma::domain, tag::omit> // enables omit
|
Chris@16
|
30 : mpl::true_ {};
|
Chris@16
|
31
|
Chris@16
|
32 template <>
|
Chris@16
|
33 struct use_directive<karma::domain, tag::skip> // enables skip
|
Chris@16
|
34 : mpl::true_ {};
|
Chris@16
|
35 }}
|
Chris@16
|
36
|
Chris@16
|
37 namespace boost { namespace spirit { namespace karma
|
Chris@16
|
38 {
|
Chris@16
|
39 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
|
Chris@16
|
40 using spirit::omit;
|
Chris@16
|
41 using spirit::skip;
|
Chris@16
|
42 #endif
|
Chris@16
|
43 using spirit::omit_type;
|
Chris@16
|
44 using spirit::skip_type;
|
Chris@16
|
45
|
Chris@16
|
46 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
47 // omit_directive consumes the attribute of subject generator without
|
Chris@16
|
48 // generating anything
|
Chris@16
|
49 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
50 template <typename Subject, bool Execute>
|
Chris@16
|
51 struct omit_directive : unary_generator<omit_directive<Subject, Execute> >
|
Chris@16
|
52 {
|
Chris@16
|
53 typedef Subject subject_type;
|
Chris@16
|
54
|
Chris@16
|
55 typedef mpl::int_<
|
Chris@16
|
56 generator_properties::disabling | subject_type::properties::value
|
Chris@16
|
57 > properties;
|
Chris@16
|
58
|
Chris@16
|
59 omit_directive(Subject const& subject)
|
Chris@16
|
60 : subject(subject) {}
|
Chris@16
|
61
|
Chris@16
|
62 template <typename Context, typename Iterator = unused_type>
|
Chris@16
|
63 struct attribute
|
Chris@16
|
64 : traits::attribute_of<subject_type, Context, Iterator>
|
Chris@16
|
65 {};
|
Chris@16
|
66
|
Chris@16
|
67 template <typename OutputIterator, typename Context, typename Delimiter
|
Chris@16
|
68 , typename Attribute>
|
Chris@16
|
69 bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
|
Chris@16
|
70 , Attribute const& attr) const
|
Chris@16
|
71 {
|
Chris@16
|
72 // We need to actually compile the output operation as we don't
|
Chris@16
|
73 // have any other means to verify, whether the passed attribute is
|
Chris@16
|
74 // compatible with the subject.
|
Chris@16
|
75
|
Chris@16
|
76 // omit[] will execute the code, while skip[] doesn't execute it
|
Chris@16
|
77 if (Execute) {
|
Chris@16
|
78 // wrap the given output iterator to avoid output
|
Chris@16
|
79 detail::disable_output<OutputIterator> disable(sink);
|
Chris@16
|
80 return subject.generate(sink, ctx, d, attr);
|
Chris@16
|
81 }
|
Chris@16
|
82 return true;
|
Chris@16
|
83 }
|
Chris@16
|
84
|
Chris@16
|
85 template <typename Context>
|
Chris@16
|
86 info what(Context& context) const
|
Chris@16
|
87 {
|
Chris@16
|
88 return info(Execute ? "omit" : "skip", subject.what(context));
|
Chris@16
|
89 }
|
Chris@16
|
90
|
Chris@16
|
91 Subject subject;
|
Chris@16
|
92 };
|
Chris@16
|
93
|
Chris@16
|
94 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
95 // Generator generators: make_xxx function (objects)
|
Chris@16
|
96 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
97 template <typename Subject, typename Modifiers>
|
Chris@16
|
98 struct make_directive<tag::omit, Subject, Modifiers>
|
Chris@16
|
99 {
|
Chris@16
|
100 typedef omit_directive<Subject, true> result_type;
|
Chris@16
|
101 result_type operator()(unused_type, Subject const& subject
|
Chris@16
|
102 , unused_type) const
|
Chris@16
|
103 {
|
Chris@16
|
104 return result_type(subject);
|
Chris@16
|
105 }
|
Chris@16
|
106 };
|
Chris@16
|
107
|
Chris@16
|
108 template <typename Subject, typename Modifiers>
|
Chris@16
|
109 struct make_directive<tag::skip, Subject, Modifiers>
|
Chris@16
|
110 {
|
Chris@16
|
111 typedef omit_directive<Subject, false> result_type;
|
Chris@16
|
112 result_type operator()(unused_type, Subject const& subject
|
Chris@16
|
113 , unused_type) const
|
Chris@16
|
114 {
|
Chris@16
|
115 return result_type(subject);
|
Chris@16
|
116 }
|
Chris@16
|
117 };
|
Chris@16
|
118 }}}
|
Chris@16
|
119
|
Chris@16
|
120 namespace boost { namespace spirit { namespace traits
|
Chris@16
|
121 {
|
Chris@16
|
122 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
123 template <typename Subject, bool Execute>
|
Chris@16
|
124 struct has_semantic_action<karma::omit_directive<Subject, Execute> >
|
Chris@16
|
125 : unary_has_semantic_action<Subject> {};
|
Chris@16
|
126
|
Chris@16
|
127 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
128 template <typename Subject, bool Execute, typename Attribute
|
Chris@16
|
129 , typename Context, typename Iterator>
|
Chris@16
|
130 struct handles_container<karma::omit_directive<Subject, Execute>, Attribute
|
Chris@16
|
131 , Context, Iterator>
|
Chris@16
|
132 : unary_handles_container<Subject, Attribute, Context, Iterator> {};
|
Chris@16
|
133 }}}
|
Chris@16
|
134
|
Chris@16
|
135 #endif
|