]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/include/boost/spirit/home/karma/detail/generate.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / spirit / include / boost / spirit / home / karma / detail / generate.hpp
CommitLineData
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_DETAIL_GENERATE_FEB_20_2007_0959AM)
7#define BOOST_SPIRIT_KARMA_DETAIL_GENERATE_FEB_20_2007_0959AM
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/delimit_out.hpp>
15#include <boost/spirit/home/karma/delimit_flag.hpp>
16#include <boost/spirit/home/karma/detail/output_iterator.hpp>
17#include <boost/spirit/home/support/unused.hpp>
18#include <boost/mpl/assert.hpp>
19#include <boost/mpl/bool.hpp>
20
21namespace boost { namespace spirit { namespace karma { namespace detail
22{
23 ///////////////////////////////////////////////////////////////////////////
24 template <typename Expr, typename Enable = void>
25 struct generate_impl
26 {
27 // Report invalid expression error as early as possible.
28 // If you got an error_invalid_expression error message here,
29 // then the expression (Expr) is not a valid spirit karma expression.
30 // Did you intend to use the auto_ facilities while forgetting to
31 // #include <boost/spirit/include/karma_auto.hpp>?
32 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
33 };
34
35 template <typename Expr>
36 struct generate_impl<Expr
37 , typename enable_if<traits::matches<karma::domain, Expr> >::type>
38 {
39 template <typename OutputIterator>
40 static bool call(
41 OutputIterator& target_sink
42 , Expr const& expr)
43 {
44 typedef traits::properties_of<
45 typename result_of::compile<karma::domain, Expr>::type
46 > properties;
47
48 // wrap user supplied iterator into our own output iterator
49 output_iterator<OutputIterator
50 , mpl::int_<properties::value> > sink(target_sink);
51 return compile<karma::domain>(expr).
52 generate(sink, unused, unused, unused);
53 }
54
55 template <typename OutputIterator, typename Properties>
56 static bool call(
57 detail::output_iterator<OutputIterator, Properties>& sink
58 , Expr const& expr)
59 {
60 return compile<karma::domain>(expr).
61 generate(sink, unused, unused, unused);
62 }
63 };
64
65 ///////////////////////////////////////////////////////////////////////////
66 template <typename Expr, typename Enable = void>
67 struct generate_delimited_impl
68 {
69 // Report invalid expression error as early as possible.
70 // If you got an error_invalid_expression error message here,
71 // then the expression (Expr) is not a valid spirit karma expression.
72 // Did you intend to use the auto_ facilities while forgetting to
73 // #include <boost/spirit/include/karma_auto.hpp>?
74 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
75 };
76
77 template <typename Expr>
78 struct generate_delimited_impl<Expr
79 , typename enable_if<traits::matches<karma::domain, Expr> >::type>
80 {
81 template <typename OutputIterator, typename Delimiter>
82 static bool call(
83 OutputIterator& target_sink
84 , Expr const& expr
85 , Delimiter const& delimiter
86 , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit)
87 {
88 typedef traits::properties_of<
89 typename result_of::compile<karma::domain, Expr>::type
90 > properties;
91 typedef traits::properties_of<
92 typename result_of::compile<karma::domain, Delimiter>::type
93 > delimiter_properties;
94
95 // wrap user supplied iterator into our own output iterator
96 detail::output_iterator<OutputIterator
97 , mpl::int_<properties::value | delimiter_properties::value>
98 > sink(target_sink);
99 return call(sink, expr, delimiter, pre_delimit);
100 }
101
102 template <typename OutputIterator, typename Properties
103 , typename Delimiter>
104 static bool call(
105 detail::output_iterator<OutputIterator, Properties>& sink
106 , Expr const& expr
107 , Delimiter const& delimiter
108 , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit)
109 {
110 // Report invalid expression error as early as possible.
111 // If you got an error_invalid_expression error message here,
112 // then the delimiter is not a valid spirit karma expression.
113 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
114
115 typename result_of::compile<karma::domain, Delimiter>::type const
116 delimiter_ = compile<karma::domain>(delimiter);
117
118 if (pre_delimit == delimit_flag::predelimit &&
119 !karma::delimit_out(sink, delimiter_))
120 {
121 return false;
122 }
123 return compile<karma::domain>(expr).
124 generate(sink, unused, delimiter_, unused);
125 }
126 };
127
128}}}}
129
130#endif
131