Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:39

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_FORMAT_MANIP_MAY_03_2007_1424PM)
0007 #define BOOST_SPIRIT_KARMA_FORMAT_MANIP_MAY_03_2007_1424PM
0008 
0009 #if defined(_MSC_VER)
0010 #pragma once
0011 #endif
0012 
0013 #include <iosfwd>
0014 #include <iterator>
0015 #include <string>
0016 #include <boost/spirit/home/karma/generate.hpp>
0017 #include <boost/spirit/home/support/iterators/ostream_iterator.hpp>
0018 #include <boost/core/scoped_enum.hpp>
0019 #include <boost/mpl/bool.hpp>
0020 
0021 ///////////////////////////////////////////////////////////////////////////////
0022 namespace boost { namespace spirit { namespace karma { namespace detail
0023 {
0024     ///////////////////////////////////////////////////////////////////////////
0025 #ifdef _MSC_VER
0026 #  pragma warning(push)
0027 #  pragma warning(disable: 4512) // assignment operator could not be generated.
0028 #endif
0029     template <typename Expr
0030       , typename CopyExpr = mpl::false_, typename CopyAttr = mpl::false_
0031       , typename Delimiter = unused_type, typename Attribute = unused_type>
0032     struct format_manip 
0033     {
0034         // This assertion makes sure we don't hit the only code path which is 
0035         // not implemented (because it isn't needed), where both, the 
0036         // expression and the attribute need to be held as a copy.
0037         BOOST_SPIRIT_ASSERT_MSG(!CopyExpr::value || !CopyAttr::value
0038             , error_invalid_should_not_happen, ());
0039 
0040         format_manip(Expr const& xpr, Delimiter const& d, Attribute const& a) 
0041           : expr(xpr), delim(d), pre(delimit_flag::dont_predelimit), attr(a) {}
0042 
0043         format_manip(Expr const& xpr, Delimiter const& d
0044             , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit, Attribute const& a) 
0045           : expr(xpr), delim(d), pre(pre_delimit), attr(a) {}
0046 
0047         Expr const& expr;
0048         Delimiter const& delim;
0049         BOOST_SCOPED_ENUM(delimit_flag) const pre;
0050         Attribute const& attr;
0051     };
0052 
0053     template <typename Expr, typename Delimiter, typename Attribute>
0054     struct format_manip<Expr, mpl::false_, mpl::true_, Delimiter, Attribute>
0055     {
0056         format_manip(Expr const& xpr, Delimiter const& d, Attribute const& a) 
0057           : expr(xpr), delim(d), pre(delimit_flag::dont_predelimit), attr(a) {}
0058 
0059         format_manip(Expr const& xpr, Delimiter const& d
0060             , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit, Attribute const& a) 
0061           : expr(xpr), delim(d), pre(pre_delimit), attr(a) {}
0062 
0063         Expr const& expr;
0064         Delimiter const& delim;
0065         BOOST_SCOPED_ENUM(delimit_flag) const pre;
0066         Attribute attr;
0067     };
0068 
0069     template <typename Expr, typename Delimiter, typename Attribute>
0070     struct format_manip<Expr, mpl::true_, mpl::false_, Delimiter, Attribute>
0071     {
0072         format_manip(Expr const& xpr, Delimiter const& d, Attribute const& a) 
0073           : expr(xpr), delim(d), pre(delimit_flag::dont_predelimit), attr(a) {}
0074 
0075         format_manip(Expr const& xpr, Delimiter const& d
0076             , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit, Attribute const& a) 
0077           : expr(xpr), delim(d), pre(pre_delimit), attr(a) {}
0078 
0079         Expr expr;
0080         Delimiter const& delim;
0081         BOOST_SCOPED_ENUM(delimit_flag) const pre;
0082         Attribute const& attr;
0083     };
0084 #ifdef _MSC_VER
0085 #  pragma warning(pop)
0086 #endif
0087 
0088     ///////////////////////////////////////////////////////////////////////////
0089     template <typename Expr, typename Enable = void>
0090     struct format
0091     {
0092         // Report invalid expression error as early as possible.
0093         // If you got an error_invalid_expression error message here,
0094         // then the expression (Expr) is not a valid spirit karma expression.
0095         // Did you intend to use the auto_ facilities while forgetting to 
0096         // #include <boost/spirit/include/karma_format_auto.hpp>?
0097         BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
0098     };
0099 
0100     template <typename Expr>
0101     struct format<Expr
0102       , typename enable_if<traits::matches<karma::domain, Expr> >::type>
0103     {
0104         typedef format_manip<Expr> type;
0105 
0106         static type call(Expr const& expr)
0107         {
0108             return type(expr, unused, unused);
0109         }
0110     };
0111 
0112     ///////////////////////////////////////////////////////////////////////////
0113     template <typename Expr, typename Delimiter, typename Enable = void>
0114     struct format_delimited
0115     {
0116         // Report invalid expression error as early as possible.
0117         // If you got an error_invalid_expression error message here,
0118         // then the expression (Expr) is not a valid spirit karma expression.
0119         // Did you intend to use the auto_ facilities while forgetting to 
0120         // #include <boost/spirit/include/karma_format_auto.hpp>?
0121         BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
0122     };
0123 
0124     template <typename Expr, typename Delimiter>
0125     struct format_delimited<Expr, Delimiter
0126       , typename enable_if<traits::matches<karma::domain, Expr> >::type>
0127     {
0128         typedef format_manip<Expr, mpl::false_, mpl::false_, Delimiter> type;
0129 
0130         static type call(
0131             Expr const& expr
0132           , Delimiter const& delimiter
0133           , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit)
0134         {
0135             // Report invalid expression error as early as possible.
0136             // If you got an error_invalid_expression error message here,
0137             // then the delimiter is not a valid spirit karma expression.
0138             BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
0139             return type(expr, delimiter, pre_delimit, unused);
0140         }
0141     };
0142 
0143     ///////////////////////////////////////////////////////////////////////////
0144     template<typename Char, typename Traits, typename Expr
0145       , typename CopyExpr, typename CopyAttr> 
0146     inline std::basic_ostream<Char, Traits> & 
0147     operator<< (std::basic_ostream<Char, Traits> &os
0148       , format_manip<Expr, CopyExpr, CopyAttr> const& fm)
0149     {
0150         karma::ostream_iterator<Char, Char, Traits> sink(os);
0151         if (!karma::generate (sink, fm.expr))
0152         {
0153             os.setstate(std::basic_ostream<Char, Traits>::failbit);
0154         }
0155         return os;
0156     }
0157 
0158     ///////////////////////////////////////////////////////////////////////////
0159     template<typename Char, typename Traits, typename Expr
0160       , typename CopyExpr, typename CopyAttr, typename Attribute> 
0161     inline std::basic_ostream<Char, Traits> & 
0162     operator<< (std::basic_ostream<Char, Traits> &os
0163       , format_manip<Expr, CopyExpr, CopyAttr, unused_type, Attribute> const& fm)
0164     {
0165         karma::ostream_iterator<Char, Char, Traits> sink(os);
0166         if (!karma::generate(sink, fm.expr, fm.attr))
0167         {
0168             os.setstate(std::basic_ostream<Char, Traits>::failbit);
0169         }
0170         return os;
0171     }
0172 
0173     template<typename Char, typename Traits, typename Expr
0174       , typename CopyExpr, typename CopyAttr, typename Delimiter> 
0175     inline std::basic_ostream<Char, Traits> & 
0176     operator<< (std::basic_ostream<Char, Traits> &os
0177       , format_manip<Expr, CopyExpr, CopyAttr, Delimiter> const& fm)
0178     {
0179         karma::ostream_iterator<Char, Char, Traits> sink(os);
0180         if (!karma::generate_delimited(sink, fm.expr, fm.delim, fm.pre))
0181         {
0182             os.setstate(std::basic_ostream<Char, Traits>::failbit);
0183         }
0184         return os;
0185     }
0186 
0187     ///////////////////////////////////////////////////////////////////////////
0188     template<typename Char, typename Traits, typename Expr
0189       , typename CopyExpr, typename CopyAttr, typename Delimiter
0190       , typename Attribute> 
0191     inline std::basic_ostream<Char, Traits> & 
0192     operator<< (std::basic_ostream<Char, Traits> &os
0193       , format_manip<Expr, CopyExpr, CopyAttr, Delimiter, Attribute> const& fm)
0194     {
0195         karma::ostream_iterator<Char, Char, Traits> sink(os);
0196         if (!karma::generate_delimited(sink, fm.expr, fm.delim, fm.pre, fm.attr))
0197         {
0198             os.setstate(std::basic_ostream<Char, Traits>::failbit);
0199         }
0200         return os;
0201     }
0202 }}}}
0203 
0204 #endif