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 #ifndef BOOST_SPIRIT_KARMA_DIRECTIVE_OMIT_HPP
7 #define BOOST_SPIRIT_KARMA_DIRECTIVE_OMIT_HPP
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 #if defined(_MSC_VER) && _MSC_VER < 1900
77 # pragma warning(push)
78 # pragma warning(disable: 4127) // conditional expression is constant
80 // omit[] will execute the code, while skip[] doesn't execute it
82 #if defined(_MSC_VER) && _MSC_VER < 1900
85 // wrap the given output iterator to avoid output
86 detail::disable_output<OutputIterator> disable(sink);
87 return subject.generate(sink, ctx, d, attr);
92 template <typename Context>
93 info what(Context& context) const
95 return info(Execute ? "omit" : "skip", subject.what(context));
101 ///////////////////////////////////////////////////////////////////////////
102 // Generator generators: make_xxx function (objects)
103 ///////////////////////////////////////////////////////////////////////////
104 template <typename Subject, typename Modifiers>
105 struct make_directive<tag::omit, Subject, Modifiers>
107 typedef omit_directive<Subject, true> result_type;
108 result_type operator()(unused_type, Subject const& subject
111 return result_type(subject);
115 template <typename Subject, typename Modifiers>
116 struct make_directive<tag::skip, Subject, Modifiers>
118 typedef omit_directive<Subject, false> result_type;
119 result_type operator()(unused_type, Subject const& subject
122 return result_type(subject);
127 namespace boost { namespace spirit { namespace traits
129 ///////////////////////////////////////////////////////////////////////////
130 template <typename Subject, bool Execute>
131 struct has_semantic_action<karma::omit_directive<Subject, Execute> >
132 : unary_has_semantic_action<Subject> {};
134 ///////////////////////////////////////////////////////////////////////////
135 template <typename Subject, bool Execute, typename Attribute
136 , typename Context, typename Iterator>
137 struct handles_container<karma::omit_directive<Subject, Execute>, Attribute
139 : unary_handles_container<Subject, Attribute, Context, Iterator> {};