Chris@16
|
1 // Copyright (c) 2001-2011 Hartmut Kaiser
|
Chris@16
|
2 //
|
Chris@16
|
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5
|
Chris@16
|
6 #if !defined(BOOST_SPIRIT_KARMA_DETAIL_GENERATE_FEB_20_2007_0959AM)
|
Chris@16
|
7 #define BOOST_SPIRIT_KARMA_DETAIL_GENERATE_FEB_20_2007_0959AM
|
Chris@16
|
8
|
Chris@16
|
9 #if defined(_MSC_VER)
|
Chris@16
|
10 #pragma once
|
Chris@16
|
11 #endif
|
Chris@16
|
12
|
Chris@16
|
13 #include <boost/spirit/home/karma/meta_compiler.hpp>
|
Chris@16
|
14 #include <boost/spirit/home/karma/delimit_out.hpp>
|
Chris@16
|
15 #include <boost/spirit/home/karma/delimit_flag.hpp>
|
Chris@16
|
16 #include <boost/spirit/home/karma/detail/output_iterator.hpp>
|
Chris@16
|
17 #include <boost/spirit/home/support/unused.hpp>
|
Chris@16
|
18 #include <boost/mpl/assert.hpp>
|
Chris@16
|
19 #include <boost/mpl/bool.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 namespace boost { namespace spirit { namespace karma { namespace detail
|
Chris@16
|
22 {
|
Chris@16
|
23 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
24 template <typename Expr, typename Enable = void>
|
Chris@16
|
25 struct generate_impl
|
Chris@16
|
26 {
|
Chris@16
|
27 // Report invalid expression error as early as possible.
|
Chris@16
|
28 // If you got an error_invalid_expression error message here,
|
Chris@16
|
29 // then the expression (Expr) is not a valid spirit karma expression.
|
Chris@16
|
30 // Did you intend to use the auto_ facilities while forgetting to
|
Chris@16
|
31 // #include <boost/spirit/include/karma_auto.hpp>?
|
Chris@16
|
32 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
|
Chris@16
|
33 };
|
Chris@16
|
34
|
Chris@16
|
35 template <typename Expr>
|
Chris@16
|
36 struct generate_impl<Expr
|
Chris@16
|
37 , typename enable_if<traits::matches<karma::domain, Expr> >::type>
|
Chris@16
|
38 {
|
Chris@16
|
39 template <typename OutputIterator>
|
Chris@16
|
40 static bool call(
|
Chris@16
|
41 OutputIterator& target_sink
|
Chris@16
|
42 , Expr const& expr)
|
Chris@16
|
43 {
|
Chris@16
|
44 typedef traits::properties_of<
|
Chris@16
|
45 typename result_of::compile<karma::domain, Expr>::type
|
Chris@16
|
46 > properties;
|
Chris@16
|
47
|
Chris@16
|
48 // wrap user supplied iterator into our own output iterator
|
Chris@16
|
49 output_iterator<OutputIterator
|
Chris@16
|
50 , mpl::int_<properties::value> > sink(target_sink);
|
Chris@16
|
51 return compile<karma::domain>(expr).
|
Chris@16
|
52 generate(sink, unused, unused, unused);
|
Chris@16
|
53 }
|
Chris@16
|
54
|
Chris@16
|
55 template <typename OutputIterator, typename Properties>
|
Chris@16
|
56 static bool call(
|
Chris@16
|
57 detail::output_iterator<OutputIterator, Properties>& sink
|
Chris@16
|
58 , Expr const& expr)
|
Chris@16
|
59 {
|
Chris@16
|
60 return compile<karma::domain>(expr).
|
Chris@16
|
61 generate(sink, unused, unused, unused);
|
Chris@16
|
62 }
|
Chris@16
|
63 };
|
Chris@16
|
64
|
Chris@16
|
65 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
66 template <typename Expr, typename Enable = void>
|
Chris@16
|
67 struct generate_delimited_impl
|
Chris@16
|
68 {
|
Chris@16
|
69 // Report invalid expression error as early as possible.
|
Chris@16
|
70 // If you got an error_invalid_expression error message here,
|
Chris@16
|
71 // then the expression (Expr) is not a valid spirit karma expression.
|
Chris@16
|
72 // Did you intend to use the auto_ facilities while forgetting to
|
Chris@16
|
73 // #include <boost/spirit/include/karma_auto.hpp>?
|
Chris@16
|
74 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
|
Chris@16
|
75 };
|
Chris@16
|
76
|
Chris@16
|
77 template <typename Expr>
|
Chris@16
|
78 struct generate_delimited_impl<Expr
|
Chris@16
|
79 , typename enable_if<traits::matches<karma::domain, Expr> >::type>
|
Chris@16
|
80 {
|
Chris@16
|
81 template <typename OutputIterator, typename Delimiter>
|
Chris@16
|
82 static bool call(
|
Chris@16
|
83 OutputIterator& target_sink
|
Chris@16
|
84 , Expr const& expr
|
Chris@16
|
85 , Delimiter const& delimiter
|
Chris@16
|
86 , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit)
|
Chris@16
|
87 {
|
Chris@16
|
88 typedef traits::properties_of<
|
Chris@16
|
89 typename result_of::compile<karma::domain, Expr>::type
|
Chris@16
|
90 > properties;
|
Chris@16
|
91 typedef traits::properties_of<
|
Chris@16
|
92 typename result_of::compile<karma::domain, Delimiter>::type
|
Chris@16
|
93 > delimiter_properties;
|
Chris@16
|
94
|
Chris@16
|
95 // wrap user supplied iterator into our own output iterator
|
Chris@16
|
96 detail::output_iterator<OutputIterator
|
Chris@16
|
97 , mpl::int_<properties::value | delimiter_properties::value>
|
Chris@16
|
98 > sink(target_sink);
|
Chris@16
|
99 return call(sink, expr, delimiter, pre_delimit);
|
Chris@16
|
100 }
|
Chris@16
|
101
|
Chris@16
|
102 template <typename OutputIterator, typename Properties
|
Chris@16
|
103 , typename Delimiter>
|
Chris@16
|
104 static bool call(
|
Chris@16
|
105 detail::output_iterator<OutputIterator, Properties>& sink
|
Chris@16
|
106 , Expr const& expr
|
Chris@16
|
107 , Delimiter const& delimiter
|
Chris@16
|
108 , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit)
|
Chris@16
|
109 {
|
Chris@16
|
110 // Report invalid expression error as early as possible.
|
Chris@16
|
111 // If you got an error_invalid_expression error message here,
|
Chris@16
|
112 // then the delimiter is not a valid spirit karma expression.
|
Chris@16
|
113 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
|
Chris@16
|
114
|
Chris@16
|
115 typename result_of::compile<karma::domain, Delimiter>::type const
|
Chris@16
|
116 delimiter_ = compile<karma::domain>(delimiter);
|
Chris@16
|
117
|
Chris@16
|
118 if (pre_delimit == delimit_flag::predelimit &&
|
Chris@16
|
119 !karma::delimit_out(sink, delimiter_))
|
Chris@16
|
120 {
|
Chris@16
|
121 return false;
|
Chris@16
|
122 }
|
Chris@16
|
123 return compile<karma::domain>(expr).
|
Chris@16
|
124 generate(sink, unused, delimiter_, unused);
|
Chris@16
|
125 }
|
Chris@16
|
126 };
|
Chris@16
|
127
|
Chris@16
|
128 }}}}
|
Chris@16
|
129
|
Chris@16
|
130 #endif
|
Chris@16
|
131
|