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_NO_DELIMIT_JAN_19_2010_0920AM)
7 #define BOOST_SPIRIT_KARMA_NO_DELIMIT_JAN_19_2010_0920AM
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/karma/detail/unused_delimiter.hpp>
17 #include <boost/spirit/home/karma/auxiliary/lazy.hpp>
18 #include <boost/spirit/home/support/unused.hpp>
19 #include <boost/spirit/home/support/common_terminals.hpp>
20 #include <boost/spirit/home/support/has_semantic_action.hpp>
21 #include <boost/spirit/home/support/handles_container.hpp>
22 #include <boost/spirit/home/karma/detail/attributes.hpp>
23 #include <boost/spirit/home/support/info.hpp>
24 
25 namespace boost { namespace spirit
26 {
27     ///////////////////////////////////////////////////////////////////////////
28     // Enablers
29     ///////////////////////////////////////////////////////////////////////////
30     template <>
31     struct use_directive<karma::domain, tag::no_delimit>   // enables no_delimit[]
32       : mpl::true_ {};
33 
34 }}
35 
36 namespace boost { namespace spirit { namespace karma
37 {
38 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
39     using spirit::no_delimit;
40 #endif
41     using spirit::no_delimit_type;
42 
43     ///////////////////////////////////////////////////////////////////////////
44     //  The no_delimit generator is used for no_delimit[...] directives.
45     ///////////////////////////////////////////////////////////////////////////
46     template <typename Subject>
47     struct no_delimit_generator
48       : unary_generator<no_delimit_generator<Subject> >
49     {
50         typedef Subject subject_type;
51         typedef typename subject_type::properties properties;
52 
53         template <typename Context, typename Iterator>
54         struct attribute
55           : traits::attribute_of<subject_type, Context, Iterator>
56         {};
57 
no_delimit_generatorboost::spirit::karma::no_delimit_generator58         no_delimit_generator(Subject const& subject)
59           : subject(subject) {}
60 
61         template <typename OutputIterator, typename Context, typename Delimiter
62           , typename Attribute>
generateboost::spirit::karma::no_delimit_generator63         bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
64           , Attribute const& attr) const
65         {
66             //  the no_delimit generator simply dispatches to the embedded
67             //  generator while supplying unused_delimiter as the new delimiter
68             //  to avoid delimiting down the generator stream
69             typedef detail::unused_delimiter<Delimiter> unused_delimiter;
70 
71             // the difference to verbatim[] is that this does not post-delimit
72             return subject.generate(sink, ctx, unused_delimiter(d), attr);
73         }
74 
75         template <typename Context>
whatboost::spirit::karma::no_delimit_generator76         info what(Context& context) const
77         {
78             return info("no_delimit", subject.what(context));
79         }
80 
81         Subject subject;
82     };
83 
84     ///////////////////////////////////////////////////////////////////////////
85     // Generator generators: make_xxx function (objects)
86     ///////////////////////////////////////////////////////////////////////////
87     template <typename Subject, typename Modifiers>
88     struct make_directive<tag::no_delimit, Subject, Modifiers>
89     {
90         typedef no_delimit_generator<Subject> result_type;
91 
92         result_type
operator ()boost::spirit::karma::make_directive93         operator()(unused_type, Subject const& subject, unused_type) const
94         {
95             return result_type(subject);
96         }
97     };
98 
99 }}}
100 
101 namespace boost { namespace spirit { namespace traits
102 {
103     ///////////////////////////////////////////////////////////////////////////
104     template <typename Subject>
105     struct has_semantic_action<karma::no_delimit_generator<Subject> >
106       : unary_has_semantic_action<Subject> {};
107 
108     ///////////////////////////////////////////////////////////////////////////
109     template <typename Subject, typename Attribute, typename Context
110         , typename Iterator>
111     struct handles_container<karma::no_delimit_generator<Subject>, Attribute
112         , Context, Iterator>
113       : unary_handles_container<Subject, Attribute, Context, Iterator> {};
114 }}}
115 
116 #endif
117