]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/include/boost/spirit/repository/home/karma/directive/confix.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / include / boost / spirit / repository / home / karma / directive / confix.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_REPOSITORY_KARMA_CONFIX_AUG_19_2008_1041AM)
7 #define BOOST_SPIRIT_REPOSITORY_KARMA_CONFIX_AUG_19_2008_1041AM
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/support/unused.hpp>
16 #include <boost/spirit/home/karma/detail/attributes.hpp>
17 #include <boost/spirit/home/karma/domain.hpp>
18 #include <boost/spirit/home/karma/meta_compiler.hpp>
19
20 #include <boost/spirit/repository/home/support/confix.hpp>
21
22 #include <boost/fusion/include/vector.hpp>
23 #include <boost/mpl/or.hpp>
24
25 ///////////////////////////////////////////////////////////////////////////////
26 namespace boost { namespace spirit
27 {
28 ///////////////////////////////////////////////////////////////////////////
29 // Enablers
30 ///////////////////////////////////////////////////////////////////////////
31
32 // enables confix(..., ...)[]
33 template <typename Prefix, typename Suffix>
34 struct use_directive<karma::domain
35 , terminal_ex<repository::tag::confix, fusion::vector2<Prefix, Suffix> > >
36 : mpl::true_ {};
37
38 // enables *lazy* confix(..., ...)[g]
39 template <>
40 struct use_lazy_directive<karma::domain, repository::tag::confix, 2>
41 : mpl::true_ {};
42
43 }}
44
45 ///////////////////////////////////////////////////////////////////////////////
46 namespace boost { namespace spirit { namespace repository { namespace karma
47 {
48 using repository::confix_type;
49 using repository::confix;
50
51 ///////////////////////////////////////////////////////////////////////////
52 template <typename Subject, typename Prefix, typename Suffix>
53 struct confix_generator
54 : spirit::karma::primitive_generator<confix_generator<Subject, Prefix, Suffix> >
55 {
56 typedef Subject subject_type;
57
58 template <typename Context, typename Iterator>
59 struct attribute
60 : traits::attribute_of<subject_type, Context, Iterator>
61 {};
62
63 confix_generator(Subject const& subject, Prefix const& prefix
64 , Suffix const& suffix)
65 : subject(subject), prefix(prefix), suffix(suffix) {}
66
67 ///////////////////////////////////////////////////////////////////////
68 template <typename OutputIterator, typename Context, typename Delimiter
69 , typename Attribute>
70 bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
71 , Attribute const& attr) const
72 {
73 // generate the prefix, the embedded item and the suffix
74 return prefix.generate(sink, ctx, d, unused) &&
75 subject.generate(sink, ctx, d, attr) &&
76 suffix.generate(sink, ctx, d, unused);
77 }
78
79 template <typename Context>
80 info what(Context const& ctx) const
81 {
82 return info("confix", subject.what(ctx));
83 }
84
85 Subject subject;
86 Prefix prefix;
87 Suffix suffix;
88 };
89
90 }}}}
91
92 ///////////////////////////////////////////////////////////////////////////////
93 namespace boost { namespace spirit { namespace karma
94 {
95 ///////////////////////////////////////////////////////////////////////////
96 // Generator generators: make_xxx function (objects)
97 ///////////////////////////////////////////////////////////////////////////
98
99 // creates confix(..., ...)[] directive generator
100 template <typename Prefix, typename Suffix, typename Subject
101 , typename Modifiers>
102 struct make_directive<
103 terminal_ex<repository::tag::confix, fusion::vector2<Prefix, Suffix> >
104 , Subject, Modifiers>
105 {
106 typedef typename
107 result_of::compile<karma::domain, Prefix, Modifiers>::type
108 prefix_type;
109 typedef typename
110 result_of::compile<karma::domain, Suffix, Modifiers>::type
111 suffix_type;
112
113 typedef repository::karma::confix_generator<
114 Subject, prefix_type, suffix_type> result_type;
115
116 template <typename Terminal>
117 result_type operator()(Terminal const& term, Subject const& subject
118 , Modifiers const& modifiers) const
119 {
120 return result_type(subject
121 , compile<karma::domain>(fusion::at_c<0>(term.args), modifiers)
122 , compile<karma::domain>(fusion::at_c<1>(term.args), modifiers));
123 }
124 };
125
126 }}}
127
128 namespace boost { namespace spirit { namespace traits
129 {
130 template <typename Subject, typename Prefix, typename Suffix>
131 struct has_semantic_action<
132 repository::karma::confix_generator<Subject, Prefix, Suffix> >
133 : mpl::or_<
134 has_semantic_action<Subject>
135 , has_semantic_action<Prefix>
136 , has_semantic_action<Suffix>
137 > {};
138 }}}
139
140 #endif