Project revived from Feb2017
[EroSomnia.git] / deps / boost_1_63_0 / boost / spirit / repository / home / karma / directive / confix.hpp
blobcc7bd99898db0338a66f00ac8bbfa305e0ac7b2a
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)
6 #if !defined(BOOST_SPIRIT_REPOSITORY_KARMA_CONFIX_AUG_19_2008_1041AM)
7 #define BOOST_SPIRIT_REPOSITORY_KARMA_CONFIX_AUG_19_2008_1041AM
9 #if defined(_MSC_VER)
10 #pragma once
11 #endif
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>
20 #include <boost/spirit/repository/home/support/confix.hpp>
22 #include <boost/fusion/include/vector.hpp>
23 #include <boost/mpl/or.hpp>
25 ///////////////////////////////////////////////////////////////////////////////
26 namespace boost { namespace spirit
28 ///////////////////////////////////////////////////////////////////////////
29 // Enablers
30 ///////////////////////////////////////////////////////////////////////////
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_ {};
38 // enables *lazy* confix(..., ...)[g]
39 template <>
40 struct use_lazy_directive<karma::domain, repository::tag::confix, 2>
41 : mpl::true_ {};
45 ///////////////////////////////////////////////////////////////////////////////
46 namespace boost { namespace spirit { namespace repository { namespace karma
48 using repository::confix_type;
49 using repository::confix;
51 ///////////////////////////////////////////////////////////////////////////
52 template <typename Subject, typename Prefix, typename Suffix>
53 struct confix_generator
54 : spirit::karma::primitive_generator<confix_generator<Subject, Prefix, Suffix> >
56 typedef Subject subject_type;
58 template <typename Context, typename Iterator>
59 struct attribute
60 : traits::attribute_of<subject_type, Context, Iterator>
61 {};
63 confix_generator(Subject const& subject, Prefix const& prefix
64 , Suffix const& suffix)
65 : subject(subject), prefix(prefix), suffix(suffix) {}
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
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);
79 template <typename Context>
80 info what(Context const& ctx) const
82 return info("confix", subject.what(ctx));
85 Subject subject;
86 Prefix prefix;
87 Suffix suffix;
90 }}}}
92 ///////////////////////////////////////////////////////////////////////////////
93 namespace boost { namespace spirit { namespace karma
95 ///////////////////////////////////////////////////////////////////////////
96 // Generator generators: make_xxx function (objects)
97 ///////////////////////////////////////////////////////////////////////////
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>
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;
113 typedef repository::karma::confix_generator<
114 Subject, prefix_type, suffix_type> result_type;
116 template <typename Terminal>
117 result_type operator()(Terminal const& term, Subject const& subject
118 , Modifiers const& modifiers) const
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));
128 namespace boost { namespace spirit { namespace traits
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 > {};
140 #endif