Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/spirit/home/karma/directive/omit.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // Copyright (c) 2001-2011 Hartmut Kaiser | |
2 // | |
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) | |
5 | |
6 #if !defined(SPIRIT_KARMA_OMIT_JUL_20_2009_1008AM) | |
7 #define SPIRIT_KARMA_OMIT_JUL_20_2009_1008AM | |
8 | |
9 #if defined(_MSC_VER) | |
10 #pragma once | |
11 #endif | |
12 | |
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> | |
22 | |
23 namespace boost { namespace spirit | |
24 { | |
25 /////////////////////////////////////////////////////////////////////////// | |
26 // Enablers | |
27 /////////////////////////////////////////////////////////////////////////// | |
28 template <> | |
29 struct use_directive<karma::domain, tag::omit> // enables omit | |
30 : mpl::true_ {}; | |
31 | |
32 template <> | |
33 struct use_directive<karma::domain, tag::skip> // enables skip | |
34 : mpl::true_ {}; | |
35 }} | |
36 | |
37 namespace boost { namespace spirit { namespace karma | |
38 { | |
39 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS | |
40 using spirit::omit; | |
41 using spirit::skip; | |
42 #endif | |
43 using spirit::omit_type; | |
44 using spirit::skip_type; | |
45 | |
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> > | |
52 { | |
53 typedef Subject subject_type; | |
54 | |
55 typedef mpl::int_< | |
56 generator_properties::disabling | subject_type::properties::value | |
57 > properties; | |
58 | |
59 omit_directive(Subject const& subject) | |
60 : subject(subject) {} | |
61 | |
62 template <typename Context, typename Iterator = unused_type> | |
63 struct attribute | |
64 : traits::attribute_of<subject_type, Context, Iterator> | |
65 {}; | |
66 | |
67 template <typename OutputIterator, typename Context, typename Delimiter | |
68 , typename Attribute> | |
69 bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d | |
70 , Attribute const& attr) const | |
71 { | |
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. | |
75 | |
76 // omit[] will execute the code, while skip[] doesn't execute it | |
77 if (Execute) { | |
78 // wrap the given output iterator to avoid output | |
79 detail::disable_output<OutputIterator> disable(sink); | |
80 return subject.generate(sink, ctx, d, attr); | |
81 } | |
82 return true; | |
83 } | |
84 | |
85 template <typename Context> | |
86 info what(Context& context) const | |
87 { | |
88 return info(Execute ? "omit" : "skip", subject.what(context)); | |
89 } | |
90 | |
91 Subject subject; | |
92 }; | |
93 | |
94 /////////////////////////////////////////////////////////////////////////// | |
95 // Generator generators: make_xxx function (objects) | |
96 /////////////////////////////////////////////////////////////////////////// | |
97 template <typename Subject, typename Modifiers> | |
98 struct make_directive<tag::omit, Subject, Modifiers> | |
99 { | |
100 typedef omit_directive<Subject, true> result_type; | |
101 result_type operator()(unused_type, Subject const& subject | |
102 , unused_type) const | |
103 { | |
104 return result_type(subject); | |
105 } | |
106 }; | |
107 | |
108 template <typename Subject, typename Modifiers> | |
109 struct make_directive<tag::skip, Subject, Modifiers> | |
110 { | |
111 typedef omit_directive<Subject, false> result_type; | |
112 result_type operator()(unused_type, Subject const& subject | |
113 , unused_type) const | |
114 { | |
115 return result_type(subject); | |
116 } | |
117 }; | |
118 }}} | |
119 | |
120 namespace boost { namespace spirit { namespace traits | |
121 { | |
122 /////////////////////////////////////////////////////////////////////////// | |
123 template <typename Subject, bool Execute> | |
124 struct has_semantic_action<karma::omit_directive<Subject, Execute> > | |
125 : unary_has_semantic_action<Subject> {}; | |
126 | |
127 /////////////////////////////////////////////////////////////////////////// | |
128 template <typename Subject, bool Execute, typename Attribute | |
129 , typename Context, typename Iterator> | |
130 struct handles_container<karma::omit_directive<Subject, Execute>, Attribute | |
131 , Context, Iterator> | |
132 : unary_handles_container<Subject, Attribute, Context, Iterator> {}; | |
133 }}} | |
134 | |
135 #endif |