]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/spirit/home/karma/auxiliary/eps.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / spirit / home / karma / auxiliary / eps.hpp
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(BOOST_SPIRIT_KARMA_EPS_APRIL_21_2007_0246PM)
7 #define BOOST_SPIRIT_KARMA_EPS_APRIL_21_2007_0246PM
8
9 #if defined(_MSC_VER)
10 #pragma once
11 #endif
12
13 #include <boost/spirit/home/support/common_terminals.hpp>
14 #include <boost/spirit/home/support/info.hpp>
15 #include <boost/spirit/home/karma/domain.hpp>
16 #include <boost/spirit/home/karma/meta_compiler.hpp>
17 #include <boost/spirit/home/karma/delimit_out.hpp>
18 #include <boost/spirit/home/support/unused.hpp>
19 #include <boost/fusion/include/at.hpp>
20
21 namespace boost { namespace spirit
22 {
23 ///////////////////////////////////////////////////////////////////////////
24 // Enablers
25 ///////////////////////////////////////////////////////////////////////////
26
27 // enables eps
28 template <>
29 struct use_terminal<karma::domain, tag::eps>
30 : mpl::true_ {};
31
32 // enables eps(bool-condition)
33 template <typename A0>
34 struct use_terminal<karma::domain
35 , terminal_ex<tag::eps, fusion::vector1<A0> > >
36 : is_convertible<A0, bool> {};
37
38 // enables lazy eps(f)
39 template <>
40 struct use_lazy_terminal<karma::domain, tag::eps, 1>
41 : mpl::true_ {};
42
43 }}
44
45 ///////////////////////////////////////////////////////////////////////////////
46 namespace boost { namespace spirit { namespace karma
47 {
48 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
49 using boost::spirit::eps;
50 #endif
51 using boost::spirit::eps_type;
52
53 struct eps_generator : primitive_generator<eps_generator>
54 {
55 template <typename Context, typename Unused>
56 struct attribute
57 {
58 typedef unused_type type;
59 };
60
61 template <
62 typename OutputIterator, typename Context, typename Delimiter
63 , typename Attribute>
64 static bool generate(OutputIterator& sink, Context&, Delimiter const& d
65 , Attribute const& /*attr*/)
66 {
67 return karma::delimit_out(sink, d); // always do post-delimiting
68 }
69
70 template <typename Context>
71 info what(Context const& /*context*/) const
72 {
73 return info("eps");
74 }
75 };
76
77 struct semantic_predicate : primitive_generator<semantic_predicate>
78 {
79 template <typename Context, typename Unused>
80 struct attribute
81 {
82 typedef unused_type type;
83 };
84
85 semantic_predicate(bool predicate)
86 : predicate_(predicate)
87 {}
88
89 template <
90 typename OutputIterator, typename Context, typename Delimiter
91 , typename Attribute>
92 bool generate(OutputIterator& sink, Context&, Delimiter const& d
93 , Attribute const& /*attr*/) const
94 {
95 // only do post-delimiting when predicate is true
96 return predicate_ && karma::delimit_out(sink, d);
97 }
98
99 template <typename Context>
100 info what(Context const& /*context*/) const
101 {
102 return info("semantic-predicate");
103 }
104
105 bool predicate_;
106 };
107
108 ///////////////////////////////////////////////////////////////////////////
109 // Generator generators: make_xxx function (objects)
110 ///////////////////////////////////////////////////////////////////////////
111 template <typename Modifiers>
112 struct make_primitive<tag::eps, Modifiers>
113 {
114 typedef eps_generator result_type;
115 result_type operator()(unused_type, unused_type) const
116 {
117 return result_type();
118 }
119 };
120
121 template <typename Modifiers, typename A0>
122 struct make_primitive<
123 terminal_ex<tag::eps, fusion::vector1<A0> >
124 , Modifiers>
125 {
126 typedef semantic_predicate result_type;
127
128 template <typename Terminal>
129 result_type operator()(Terminal const& term, unused_type) const
130 {
131 return result_type(fusion::at_c<0>(term.args));
132 }
133 };
134
135 }}}
136
137 #endif