123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- // Copyright (c) 2001-2011 Hartmut Kaiser
- //
- // Distributed under the Boost Software License, Version 1.0. (See accompanying
- // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- #if !defined(BOOST_SPIRIT_KARMA_GENERATE_DEC_01_2009_0734PM)
- #define BOOST_SPIRIT_KARMA_GENERATE_DEC_01_2009_0734PM
- #if defined(_MSC_VER)
- #pragma once
- #endif
- #include <boost/spirit/home/support/context.hpp>
- #include <boost/spirit/home/support/nonterminal/locals.hpp>
- #include <boost/spirit/home/karma/detail/generate.hpp>
- namespace boost { namespace spirit { namespace karma
- {
- ///////////////////////////////////////////////////////////////////////////
- template <typename OutputIterator, typename Expr>
- inline bool
- generate(
- OutputIterator& sink
- , Expr const& expr)
- {
- return detail::generate_impl<Expr>::call(sink, expr);
- }
- template <typename OutputIterator, typename Expr>
- inline bool
- generate(
- OutputIterator const& sink_
- , Expr const& expr)
- {
- OutputIterator sink = sink_;
- return karma::generate(sink, expr);
- }
- ///////////////////////////////////////////////////////////////////////////
- namespace detail
- {
- template <typename T>
- struct make_context
- {
- typedef context<fusion::cons<T const&>, locals<> > type;
- };
- template <>
- struct make_context<unused_type>
- {
- typedef unused_type type;
- };
- }
- template <typename OutputIterator, typename Properties, typename Expr
- , typename Attr>
- inline bool
- generate(
- detail::output_iterator<OutputIterator, Properties>& sink
- , Expr const& expr
- , Attr const& attr)
- {
- // Report invalid expression error as early as possible.
- // If you got an error_invalid_expression error message here,
- // then the expression (expr) is not a valid spirit karma expression.
- BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
- typename detail::make_context<Attr>::type context(attr);
- return compile<karma::domain>(expr).generate(sink, context, unused, attr);
- }
- template <typename OutputIterator, typename Expr, typename Attr>
- inline bool
- generate(
- OutputIterator& sink_
- , Expr const& expr
- , Attr const& attr)
- {
- // Report invalid expression error as early as possible.
- // If you got an error_invalid_expression error message here,
- // then the expression (expr) is not a valid spirit karma expression.
- BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
- typedef traits::properties_of<
- typename result_of::compile<karma::domain, Expr>::type
- > properties;
- // wrap user supplied iterator into our own output iterator
- detail::output_iterator<OutputIterator
- , mpl::int_<properties::value> > sink(sink_);
- return karma::generate(sink, expr, attr);
- }
- template <typename OutputIterator, typename Expr, typename Attr>
- inline bool
- generate(
- OutputIterator const& sink_
- , Expr const& expr
- , Attr const& attr)
- {
- OutputIterator sink = sink_;
- return karma::generate(sink, expr, attr);
- }
- ///////////////////////////////////////////////////////////////////////////
- template <typename OutputIterator, typename Expr, typename Delimiter>
- inline bool
- generate_delimited(
- OutputIterator& sink
- , Expr const& expr
- , Delimiter const& delimiter
- , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit =
- delimit_flag::dont_predelimit)
- {
- return detail::generate_delimited_impl<Expr>::call(
- sink, expr, delimiter, pre_delimit);
- }
- template <typename OutputIterator, typename Expr, typename Delimiter>
- inline bool
- generate_delimited(
- OutputIterator const& sink_
- , Expr const& expr
- , Delimiter const& delimiter
- , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit =
- delimit_flag::dont_predelimit)
- {
- OutputIterator sink = sink_;
- return karma::generate_delimited(sink, expr, delimiter, pre_delimit);
- }
- ///////////////////////////////////////////////////////////////////////////
- template <typename OutputIterator, typename Properties, typename Expr
- , typename Delimiter, typename Attribute>
- inline bool
- generate_delimited(
- detail::output_iterator<OutputIterator, Properties>& sink
- , Expr const& expr
- , Delimiter const& delimiter
- , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit
- , Attribute const& attr)
- {
- // Report invalid expression error as early as possible.
- // If you got an error_invalid_expression error message here,
- // then either the expression (expr) or skipper is not a valid
- // spirit karma expression.
- BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
- BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
- typename result_of::compile<karma::domain, Delimiter>::type const
- delimiter_ = compile<karma::domain>(delimiter);
- if (pre_delimit == delimit_flag::predelimit &&
- !karma::delimit_out(sink, delimiter_))
- {
- return false;
- }
- typename detail::make_context<Attribute>::type context(attr);
- return compile<karma::domain>(expr).
- generate(sink, context, delimiter_, attr);
- }
- template <typename OutputIterator, typename Expr, typename Delimiter
- , typename Attribute>
- inline bool
- generate_delimited(
- OutputIterator& sink_
- , Expr const& expr
- , Delimiter const& delimiter
- , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit
- , Attribute const& attr)
- {
- typedef traits::properties_of<
- typename result_of::compile<karma::domain, Expr>::type
- > properties;
- typedef traits::properties_of<
- typename result_of::compile<karma::domain, Delimiter>::type
- > delimiter_properties;
- // wrap user supplied iterator into our own output iterator
- detail::output_iterator<OutputIterator
- , mpl::int_<properties::value | delimiter_properties::value>
- > sink(sink_);
- return karma::generate_delimited(sink, expr, delimiter, pre_delimit, attr);
- }
- template <typename OutputIterator, typename Expr, typename Delimiter
- , typename Attribute>
- inline bool
- generate_delimited(
- OutputIterator const& sink_
- , Expr const& expr
- , Delimiter const& delimiter
- , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit
- , Attribute const& attr)
- {
- OutputIterator sink = sink_;
- return karma::generate_delimited(sink, expr, delimiter, pre_delimit, attr);
- }
- ///////////////////////////////////////////////////////////////////////////
- template <typename OutputIterator, typename Expr, typename Delimiter
- , typename Attribute>
- inline bool
- generate_delimited(
- OutputIterator& sink
- , Expr const& expr
- , Delimiter const& delimiter
- , Attribute const& attr)
- {
- return karma::generate_delimited(sink, expr, delimiter
- , delimit_flag::dont_predelimit, attr);
- }
- template <typename OutputIterator, typename Expr, typename Delimiter
- , typename Attribute>
- inline bool
- generate_delimited(
- OutputIterator const& sink_
- , Expr const& expr
- , Delimiter const& delimiter
- , Attribute const& attr)
- {
- OutputIterator sink = sink_;
- return karma::generate_delimited(sink, expr, delimiter
- , delimit_flag::dont_predelimit, attr);
- }
- }}}
- #endif
|