]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_FORMAT_MANIP_MAY_01_2007_1211PM) | |
7 | #define BOOST_SPIRIT_KARMA_FORMAT_MANIP_MAY_01_2007_1211PM | |
8 | ||
9 | #if defined(_MSC_VER) | |
10 | #pragma once | |
11 | #endif | |
12 | ||
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> | |
18 | ||
19 | /////////////////////////////////////////////////////////////////////////////// | |
20 | namespace boost { namespace spirit { namespace karma | |
21 | { | |
22 | /////////////////////////////////////////////////////////////////////////// | |
23 | template <typename Expr> | |
24 | inline typename detail::format<Expr>::type | |
25 | format(Expr const& expr) | |
26 | { | |
27 | return detail::format<Expr>::call(expr); | |
28 | } | |
29 | ||
30 | template <typename Expr, typename Attribute> | |
31 | inline detail::format_manip<Expr, mpl::false_, mpl::false_, unused_type, Attribute> | |
32 | format( | |
33 | Expr const& expr | |
34 | , Attribute const& attr) | |
35 | { | |
36 | using karma::detail::format_manip; | |
37 | ||
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>( | |
43 | expr, unused, attr); | |
44 | } | |
45 | ||
46 | /////////////////////////////////////////////////////////////////////////// | |
47 | template <typename Expr, typename Delimiter> | |
48 | inline typename detail::format_delimited<Expr, Delimiter>::type | |
49 | format_delimited( | |
50 | Expr const& expr | |
51 | , Delimiter const& d | |
52 | , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit = | |
53 | delimit_flag::dont_predelimit) | |
54 | { | |
55 | return detail::format_delimited<Expr, Delimiter>::call(expr, d, pre_delimit); | |
56 | } | |
57 | ||
58 | template <typename Expr, typename Delimiter, typename Attribute> | |
59 | inline detail::format_manip<Expr, mpl::false_, mpl::false_, Delimiter, Attribute> | |
60 | format_delimited( | |
61 | Expr const& xpr | |
62 | , Delimiter const& d | |
63 | , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit | |
64 | , Attribute const& attr) | |
65 | { | |
66 | using karma::detail::format_manip; | |
67 | ||
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); | |
75 | } | |
76 | ||
77 | template <typename Expr, typename Delimiter, typename Attribute> | |
78 | inline detail::format_manip<Expr, mpl::false_, mpl::false_, Delimiter, Attribute> | |
79 | format_delimited( | |
80 | Expr const& xpr | |
81 | , Delimiter const& d | |
82 | , Attribute const& attr) | |
83 | { | |
84 | using karma::detail::format_manip; | |
85 | ||
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); | |
93 | } | |
94 | ||
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) | |
99 | { | |
100 | typedef traits::properties_of< | |
101 | typename result_of::compile<karma::domain, Derived>::type | |
102 | > properties; | |
103 | typedef karma::ostream_iterator<Char, Char, Traits> outiter_type; | |
104 | ||
105 | outiter_type target_sink(os); | |
106 | karma::detail::output_iterator<outiter_type, properties> sink(target_sink); | |
107 | ||
108 | if (!g.derived().generate(sink, unused, unused, unused)) | |
109 | { | |
110 | os.setstate(std::ios_base::failbit); | |
111 | } | |
112 | return os; | |
113 | } | |
114 | }}} | |
115 | ||
116 | #endif | |
117 |