1 // Copyright (c) 2001-2011 Hartmut Kaiser
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)
6 #if !defined(SPIRIT_KARMA_OMIT_JUL_20_2009_1008AM)
7 #define SPIRIT_KARMA_OMIT_JUL_20_2009_1008AM
13 #include <boost/spirit/home/karma/meta_compiler.hpp>
14 #include <boost/spirit/home/karma/generator.hpp>
15 #include <boost/spirit/home/karma/domain.hpp>
16 #include <boost/spirit/home/support/unused.hpp>
17 #include <boost/spirit/home/support/info.hpp>
18 #include <boost/spirit/home/support/common_terminals.hpp>
19 #include <boost/spirit/home/support/has_semantic_action.hpp>
20 #include <boost/spirit/home/support/handles_container.hpp>
21 #include <boost/spirit/home/karma/detail/attributes.hpp>
23 namespace boost { namespace spirit
25 ///////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////
29 struct use_directive<karma::domain, tag::omit> // enables omit
33 struct use_directive<karma::domain, tag::skip> // enables skip
37 namespace boost { namespace spirit { namespace karma
39 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
43 using spirit::omit_type;
44 using spirit::skip_type;
46 ///////////////////////////////////////////////////////////////////////////
47 // omit_directive consumes the attribute of subject generator without
48 // generating anything
49 ///////////////////////////////////////////////////////////////////////////
50 template <typename Subject, bool Execute>
51 struct omit_directive : unary_generator<omit_directive<Subject, Execute> >
53 typedef Subject subject_type;
56 generator_properties::disabling | subject_type::properties::value
59 omit_directive(Subject const& subject)
62 template <typename Context, typename Iterator = unused_type>
64 : traits::attribute_of<subject_type, Context, Iterator>
67 template <typename OutputIterator, typename Context, typename Delimiter
69 bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
70 , Attribute const& attr) const
72 // We need to actually compile the output operation as we don't
73 // have any other means to verify, whether the passed attribute is
74 // compatible with the subject.
76 // omit[] will execute the code, while skip[] doesn't execute it
78 // wrap the given output iterator to avoid output
79 detail::disable_output<OutputIterator> disable(sink);
80 return subject.generate(sink, ctx, d, attr);
85 template <typename Context>
86 info what(Context& context) const
88 return info(Execute ? "omit" : "skip", subject.what(context));
94 ///////////////////////////////////////////////////////////////////////////
95 // Generator generators: make_xxx function (objects)
96 ///////////////////////////////////////////////////////////////////////////
97 template <typename Subject, typename Modifiers>
98 struct make_directive<tag::omit, Subject, Modifiers>
100 typedef omit_directive<Subject, true> result_type;
101 result_type operator()(unused_type, Subject const& subject
104 return result_type(subject);
108 template <typename Subject, typename Modifiers>
109 struct make_directive<tag::skip, Subject, Modifiers>
111 typedef omit_directive<Subject, false> result_type;
112 result_type operator()(unused_type, Subject const& subject
115 return result_type(subject);
120 namespace boost { namespace spirit { namespace traits
122 ///////////////////////////////////////////////////////////////////////////
123 template <typename Subject, bool Execute>
124 struct has_semantic_action<karma::omit_directive<Subject, Execute> >
125 : unary_has_semantic_action<Subject> {};
127 ///////////////////////////////////////////////////////////////////////////
128 template <typename Subject, bool Execute, typename Attribute
129 , typename Context, typename Iterator>
130 struct handles_container<karma::omit_directive<Subject, Execute>, Attribute
132 : unary_handles_container<Subject, Attribute, Context, Iterator> {};