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_FORMAT_MANIP_MAY_01_2007_1211PM)
7 #define BOOST_SPIRIT_KARMA_FORMAT_MANIP_MAY_01_2007_1211PM
13 #include <boost/spirit/home/karma/generate.hpp>
14 #include <boost/spirit/home/karma/generator.hpp>
15 #include <boost/spirit/home/karma/detail/output_iterator.hpp>
16 #include <boost/spirit/home/karma/stream/detail/format_manip.hpp>
17 #include <boost/spirit/home/support/unused.hpp>
19 ///////////////////////////////////////////////////////////////////////////////
20 namespace boost { namespace spirit { namespace karma
22 ///////////////////////////////////////////////////////////////////////////
23 template <typename Expr>
24 inline typename detail::format<Expr>::type
25 format(Expr const& expr)
27 return detail::format<Expr>::call(expr);
30 template <typename Expr, typename Attribute>
31 inline detail::format_manip<Expr, mpl::false_, mpl::false_, unused_type, Attribute>
34 , Attribute const& attr)
36 using karma::detail::format_manip;
38 // Report invalid expression error as early as possible.
39 // If you got an error_invalid_expression error message here,
40 // then the expression (expr) is not a valid spirit karma expression.
41 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
42 return format_manip<Expr, mpl::false_, mpl::false_, unused_type, Attribute>(
46 ///////////////////////////////////////////////////////////////////////////
47 template <typename Expr, typename Delimiter>
48 inline typename detail::format_delimited<Expr, Delimiter>::type
52 , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit =
53 delimit_flag::dont_predelimit)
55 return detail::format_delimited<Expr, Delimiter>::call(expr, d, pre_delimit);
58 template <typename Expr, typename Delimiter, typename Attribute>
59 inline detail::format_manip<Expr, mpl::false_, mpl::false_, Delimiter, Attribute>
63 , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit
64 , Attribute const& attr)
66 using karma::detail::format_manip;
68 // Report invalid expression error as early as possible.
69 // If you got an error_invalid_expression error message here,
70 // then the expression (expr) is not a valid spirit karma expression.
71 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
72 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
73 return format_manip<Expr, mpl::false_, mpl::false_, Delimiter, Attribute>(
74 xpr, d, pre_delimit, attr);
77 template <typename Expr, typename Delimiter, typename Attribute>
78 inline detail::format_manip<Expr, mpl::false_, mpl::false_, Delimiter, Attribute>
82 , Attribute const& attr)
84 using karma::detail::format_manip;
86 // Report invalid expression error as early as possible.
87 // If you got an error_invalid_expression error message here,
88 // then the expression (expr) is not a valid spirit karma expression.
89 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
90 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
91 return format_manip<Expr, mpl::false_, mpl::false_, Delimiter, Attribute>(
92 xpr, d, delimit_flag::dont_predelimit, attr);
95 ///////////////////////////////////////////////////////////////////////////
96 template<typename Char, typename Traits, typename Derived>
97 inline std::basic_ostream<Char, Traits> &
98 operator<< (std::basic_ostream<Char, Traits> &os, generator<Derived> const& g)
100 typedef traits::properties_of<
101 typename result_of::compile<karma::domain, Derived>::type
103 typedef karma::ostream_iterator<Char, Char, Traits> outiter_type;
105 outiter_type target_sink(os);
106 karma::detail::output_iterator<outiter_type, properties> sink(target_sink);
108 if (!g.derived().generate(sink, unused, unused, unused))
110 os.setstate(std::ios_base::failbit);