1 // Copyright (c) 2001-2011 Hartmut Kaiser
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_KARMA_GENERATE_DEC_01_2009_0734PM)
7 #define BOOST_SPIRIT_KARMA_GENERATE_DEC_01_2009_0734PM
13 #include <boost/spirit/home/support/context.hpp>
14 #include <boost/spirit/home/support/nonterminal/locals.hpp>
15 #include <boost/spirit/home/karma/detail/generate.hpp>
17 namespace boost { namespace spirit { namespace karma
19 ///////////////////////////////////////////////////////////////////////////
20 template <typename OutputIterator, typename Expr>
26 return detail::generate_impl<Expr>::call(sink, expr);
29 template <typename OutputIterator, typename Expr>
32 OutputIterator const& sink_
35 OutputIterator sink = sink_;
36 return karma::generate(sink, expr);
39 ///////////////////////////////////////////////////////////////////////////
45 typedef context<fusion::cons<T const&>, locals<> > type;
49 struct make_context<unused_type>
51 typedef unused_type type;
55 template <typename OutputIterator, typename Properties, typename Expr
59 detail::output_iterator<OutputIterator, Properties>& sink
63 // Report invalid expression error as early as possible.
64 // If you got an error_invalid_expression error message here,
65 // then the expression (expr) is not a valid spirit karma expression.
66 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
68 typename detail::make_context<Attr>::type context(attr);
69 return compile<karma::domain>(expr).generate(sink, context, unused, attr);
72 template <typename OutputIterator, typename Expr, typename Attr>
79 // Report invalid expression error as early as possible.
80 // If you got an error_invalid_expression error message here,
81 // then the expression (expr) is not a valid spirit karma expression.
82 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
84 typedef traits::properties_of<
85 typename result_of::compile<karma::domain, Expr>::type
88 // wrap user supplied iterator into our own output iterator
89 detail::output_iterator<OutputIterator
90 , mpl::int_<properties::value> > sink(sink_);
91 return karma::generate(sink, expr, attr);
94 template <typename OutputIterator, typename Expr, typename Attr>
97 OutputIterator const& sink_
101 OutputIterator sink = sink_;
102 return karma::generate(sink, expr, attr);
105 ///////////////////////////////////////////////////////////////////////////
106 template <typename OutputIterator, typename Expr, typename Delimiter>
111 , Delimiter const& delimiter
112 , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit =
113 delimit_flag::dont_predelimit)
115 return detail::generate_delimited_impl<Expr>::call(
116 sink, expr, delimiter, pre_delimit);
119 template <typename OutputIterator, typename Expr, typename Delimiter>
122 OutputIterator const& sink_
124 , Delimiter const& delimiter
125 , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit =
126 delimit_flag::dont_predelimit)
128 OutputIterator sink = sink_;
129 return karma::generate_delimited(sink, expr, delimiter, pre_delimit);
132 ///////////////////////////////////////////////////////////////////////////
133 template <typename OutputIterator, typename Properties, typename Expr
134 , typename Delimiter, typename Attribute>
137 detail::output_iterator<OutputIterator, Properties>& sink
139 , Delimiter const& delimiter
140 , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit
141 , Attribute const& attr)
143 // Report invalid expression error as early as possible.
144 // If you got an error_invalid_expression error message here,
145 // then either the expression (expr) or skipper is not a valid
146 // spirit karma expression.
147 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
148 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
150 typename result_of::compile<karma::domain, Delimiter>::type const
151 delimiter_ = compile<karma::domain>(delimiter);
153 if (pre_delimit == delimit_flag::predelimit &&
154 !karma::delimit_out(sink, delimiter_))
159 typename detail::make_context<Attribute>::type context(attr);
160 return compile<karma::domain>(expr).
161 generate(sink, context, delimiter_, attr);
164 template <typename OutputIterator, typename Expr, typename Delimiter
165 , typename Attribute>
168 OutputIterator& sink_
170 , Delimiter const& delimiter
171 , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit
172 , Attribute const& attr)
174 typedef traits::properties_of<
175 typename result_of::compile<karma::domain, Expr>::type
177 typedef traits::properties_of<
178 typename result_of::compile<karma::domain, Delimiter>::type
179 > delimiter_properties;
181 // wrap user supplied iterator into our own output iterator
182 detail::output_iterator<OutputIterator
183 , mpl::int_<properties::value | delimiter_properties::value>
185 return karma::generate_delimited(sink, expr, delimiter, pre_delimit, attr);
188 template <typename OutputIterator, typename Expr, typename Delimiter
189 , typename Attribute>
192 OutputIterator const& sink_
194 , Delimiter const& delimiter
195 , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit
196 , Attribute const& attr)
198 OutputIterator sink = sink_;
199 return karma::generate_delimited(sink, expr, delimiter, pre_delimit, attr);
202 ///////////////////////////////////////////////////////////////////////////
203 template <typename OutputIterator, typename Expr, typename Delimiter
204 , typename Attribute>
209 , Delimiter const& delimiter
210 , Attribute const& attr)
212 return karma::generate_delimited(sink, expr, delimiter
213 , delimit_flag::dont_predelimit, attr);
216 template <typename OutputIterator, typename Expr, typename Delimiter
217 , typename Attribute>
220 OutputIterator const& sink_
222 , Delimiter const& delimiter
223 , Attribute const& attr)
225 OutputIterator sink = sink_;
226 return karma::generate_delimited(sink, expr, delimiter
227 , delimit_flag::dont_predelimit, attr);