Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:02:15

0001 //  Copyright (c) 2001-2011 Hartmut Kaiser
0002 // 
0003 //  Distributed under the Boost Software License, Version 1.0. (See accompanying 
0004 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #if !defined(BOOST_SPIRIT_KARMA_GENERATE_DEC_01_2009_0734PM)
0007 #define BOOST_SPIRIT_KARMA_GENERATE_DEC_01_2009_0734PM
0008 
0009 #if defined(_MSC_VER)
0010 #pragma once
0011 #endif
0012 
0013 #include <boost/spirit/home/support/context.hpp>
0014 #include <boost/spirit/home/support/nonterminal/locals.hpp>
0015 #include <boost/spirit/home/karma/detail/generate.hpp>
0016 
0017 namespace boost { namespace spirit { namespace karma
0018 {
0019     ///////////////////////////////////////////////////////////////////////////
0020     template <typename OutputIterator, typename Expr>
0021     inline bool
0022     generate(
0023         OutputIterator& sink
0024       , Expr const& expr)
0025     {
0026         return detail::generate_impl<Expr>::call(sink, expr);
0027     }
0028 
0029     template <typename OutputIterator, typename Expr>
0030     inline bool
0031     generate(
0032         OutputIterator const& sink_
0033       , Expr const& expr)
0034     {
0035         OutputIterator sink = sink_;
0036         return karma::generate(sink, expr);
0037     }
0038 
0039     ///////////////////////////////////////////////////////////////////////////
0040     namespace detail
0041     {
0042         template <typename T>
0043         struct make_context
0044         {
0045             typedef context<fusion::cons<T const&>, locals<> > type;
0046         };
0047 
0048         template <>
0049         struct make_context<unused_type>
0050         {
0051             typedef unused_type type;
0052         };
0053     }
0054 
0055     template <typename OutputIterator, typename Properties, typename Expr
0056       , typename Attr>
0057     inline bool
0058     generate(
0059         detail::output_iterator<OutputIterator, Properties>& sink
0060       , Expr const& expr
0061       , Attr const& attr)
0062     {
0063         // Report invalid expression error as early as possible.
0064         // If you got an error_invalid_expression error message here,
0065         // then the expression (expr) is not a valid spirit karma expression.
0066         BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
0067 
0068         typename detail::make_context<Attr>::type context(attr);
0069         return compile<karma::domain>(expr).generate(sink, context, unused, attr);
0070     }
0071 
0072     template <typename OutputIterator, typename Expr, typename Attr>
0073     inline bool
0074     generate(
0075         OutputIterator& sink_
0076       , Expr const& expr
0077       , Attr const& attr)
0078     {
0079         // Report invalid expression error as early as possible.
0080         // If you got an error_invalid_expression error message here,
0081         // then the expression (expr) is not a valid spirit karma expression.
0082         BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
0083 
0084         typedef traits::properties_of<
0085             typename result_of::compile<karma::domain, Expr>::type
0086         > properties;
0087 
0088         // wrap user supplied iterator into our own output iterator
0089         detail::output_iterator<OutputIterator
0090           , mpl::int_<properties::value> > sink(sink_);
0091         return karma::generate(sink, expr, attr);
0092     }
0093 
0094     template <typename OutputIterator, typename Expr, typename Attr>
0095     inline bool
0096     generate(
0097         OutputIterator const& sink_
0098       , Expr const& expr
0099       , Attr const& attr)
0100     {
0101         OutputIterator sink = sink_;
0102         return karma::generate(sink, expr, attr);
0103     }
0104 
0105     ///////////////////////////////////////////////////////////////////////////
0106     template <typename OutputIterator, typename Expr, typename Delimiter>
0107     inline bool
0108     generate_delimited(
0109         OutputIterator& sink
0110       , Expr const& expr
0111       , Delimiter const& delimiter
0112       , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit = 
0113             delimit_flag::dont_predelimit)
0114     {
0115         return detail::generate_delimited_impl<Expr>::call(
0116             sink, expr, delimiter, pre_delimit);
0117     }
0118 
0119     template <typename OutputIterator, typename Expr, typename Delimiter>
0120     inline bool
0121     generate_delimited(
0122         OutputIterator const& sink_
0123       , Expr const& expr
0124       , Delimiter const& delimiter
0125       , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit = 
0126             delimit_flag::dont_predelimit)
0127     {
0128         OutputIterator sink = sink_;
0129         return karma::generate_delimited(sink, expr, delimiter, pre_delimit);
0130     }
0131 
0132     ///////////////////////////////////////////////////////////////////////////
0133     template <typename OutputIterator, typename Properties, typename Expr
0134       , typename Delimiter, typename Attribute>
0135     inline bool
0136     generate_delimited(
0137         detail::output_iterator<OutputIterator, Properties>& sink
0138       , Expr const& expr
0139       , Delimiter const& delimiter
0140       , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit
0141       , Attribute const& attr)
0142     {
0143         // Report invalid expression error as early as possible.
0144         // If you got an error_invalid_expression error message here,
0145         // then either the expression (expr) or skipper is not a valid
0146         // spirit karma expression.
0147         BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
0148         BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
0149 
0150         typename result_of::compile<karma::domain, Delimiter>::type const 
0151             delimiter_ = compile<karma::domain>(delimiter);
0152 
0153         if (pre_delimit == delimit_flag::predelimit &&
0154             !karma::delimit_out(sink, delimiter_))
0155         {
0156             return false;
0157         }
0158 
0159         typename detail::make_context<Attribute>::type context(attr);
0160         return compile<karma::domain>(expr).
0161             generate(sink, context, delimiter_, attr);
0162     }
0163 
0164     template <typename OutputIterator, typename Expr, typename Delimiter
0165       , typename Attribute>
0166     inline bool
0167     generate_delimited(
0168         OutputIterator& sink_
0169       , Expr const& expr
0170       , Delimiter const& delimiter
0171       , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit
0172       , Attribute const& attr)
0173     {
0174         typedef traits::properties_of<
0175             typename result_of::compile<karma::domain, Expr>::type
0176         > properties;
0177         typedef traits::properties_of<
0178             typename result_of::compile<karma::domain, Delimiter>::type
0179         > delimiter_properties;
0180 
0181         // wrap user supplied iterator into our own output iterator
0182         detail::output_iterator<OutputIterator
0183           , mpl::int_<properties::value | delimiter_properties::value>
0184         > sink(sink_);
0185         return karma::generate_delimited(sink, expr, delimiter, pre_delimit, attr);
0186     }
0187 
0188     template <typename OutputIterator, typename Expr, typename Delimiter
0189       , typename Attribute>
0190     inline bool
0191     generate_delimited(
0192         OutputIterator const& sink_
0193       , Expr const& expr
0194       , Delimiter const& delimiter
0195       , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit
0196       , Attribute const& attr)
0197     {
0198         OutputIterator sink = sink_;
0199         return karma::generate_delimited(sink, expr, delimiter, pre_delimit, attr);
0200     }
0201 
0202     ///////////////////////////////////////////////////////////////////////////
0203     template <typename OutputIterator, typename Expr, typename Delimiter
0204       , typename Attribute>
0205     inline bool
0206     generate_delimited(
0207         OutputIterator& sink
0208       , Expr const& expr
0209       , Delimiter const& delimiter
0210       , Attribute const& attr)
0211     {
0212         return karma::generate_delimited(sink, expr, delimiter
0213           , delimit_flag::dont_predelimit, attr);
0214     }
0215 
0216     template <typename OutputIterator, typename Expr, typename Delimiter
0217       , typename Attribute>
0218     inline bool
0219     generate_delimited(
0220         OutputIterator const& sink_
0221       , Expr const& expr
0222       , Delimiter const& delimiter
0223       , Attribute const& attr)
0224     {
0225         OutputIterator sink = sink_;
0226         return karma::generate_delimited(sink, expr, delimiter
0227           , delimit_flag::dont_predelimit, attr);
0228     }
0229 }}}
0230 
0231 #endif
0232