// Copyright (c) 2001-2010 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_FORMAT_MANIP_MAY_03_2007_1424PM) #define BOOST_SPIRIT_KARMA_FORMAT_MANIP_MAY_03_2007_1424PM #if defined(_MSC_VER) #pragma once #endif #include #include #include #include #include /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { namespace karma { namespace detail { /////////////////////////////////////////////////////////////////////////// template struct format_manip { // This assertion makes sure we don't hit the only code path which is // not implemented (because it isn't needed), where both, the // expression and the attribute need to be held as a copy. BOOST_SPIRIT_ASSERT_MSG(!CopyExpr::value || !CopyAttr::value , error_invalid_should_not_happen, ()); format_manip(Expr const& xpr, Delimiter const& d, Attribute const& a) : expr(xpr), delim(d), pre(delimit_flag::dont_predelimit), attr(a) {} format_manip(Expr const& xpr, Delimiter const& d , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit, Attribute const& a) : expr(xpr), delim(d), pre(pre_delimit), attr(a) {} Expr const& expr; Delimiter const& delim; BOOST_SCOPED_ENUM(delimit_flag) const pre; Attribute const& attr; private: // silence MSVC warning C4512: assignment operator could not be generated format_manip& operator= (format_manip const&); }; template struct format_manip { format_manip(Expr const& xpr, Delimiter const& d, Attribute const& a) : expr(xpr), delim(d), pre(delimit_flag::dont_predelimit), attr(a) {} format_manip(Expr const& xpr, Delimiter const& d , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit, Attribute const& a) : expr(xpr), delim(d), pre(pre_delimit), attr(a) {} Expr const& expr; Delimiter const& delim; BOOST_SCOPED_ENUM(delimit_flag) const pre; Attribute attr; private: // silence MSVC warning C4512: assignment operator could not be generated format_manip& operator= (format_manip const&); }; template struct format_manip { format_manip(Expr const& xpr, Delimiter const& d, Attribute const& a) : expr(xpr), delim(d), pre(delimit_flag::dont_predelimit), attr(a) {} format_manip(Expr const& xpr, Delimiter const& d , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit, Attribute const& a) : expr(xpr), delim(d), pre(pre_delimit), attr(a) {} Expr expr; Delimiter const& delim; BOOST_SCOPED_ENUM(delimit_flag) const pre; Attribute const& attr; private: // silence MSVC warning C4512: assignment operator could not be generated format_manip& operator= (format_manip const&); }; /////////////////////////////////////////////////////////////////////////// template struct format { // 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. // Did you intend to use the auto_ facilities while forgetting to // #include ? BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr); }; template struct format >::type> { typedef format_manip type; static type call(Expr const& expr) { return type(expr, unused, unused); } }; /////////////////////////////////////////////////////////////////////////// template struct format_delimited { // 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. // Did you intend to use the auto_ facilities while forgetting to // #include ? BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr); }; template struct format_delimited >::type> { typedef format_manip type; static type call( Expr const& expr , Delimiter const& delimiter , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit) { // Report invalid expression error as early as possible. // If you got an error_invalid_expression error message here, // then the delimiter is not a valid spirit karma expression. BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter); return type(expr, delimiter, pre_delimit, unused); } }; /////////////////////////////////////////////////////////////////////////// template inline std::basic_ostream & operator<< (std::basic_ostream &os , format_manip const& fm) { karma::ostream_iterator sink(os); if (!karma::generate (sink, fm.expr)) { os.setstate(std::ios_base::failbit); } return os; } /////////////////////////////////////////////////////////////////////////// template inline std::basic_ostream & operator<< (std::basic_ostream &os , format_manip const& fm) { karma::ostream_iterator sink(os); if (!karma::generate(sink, fm.expr, fm.attr)) { os.setstate(std::ios_base::failbit); } return os; } template inline std::basic_ostream & operator<< (std::basic_ostream &os , format_manip const& fm) { karma::ostream_iterator sink(os); if (!karma::generate_delimited(sink, fm.expr, fm.delim, fm.pre)) { os.setstate(std::ios_base::failbit); } return os; } /////////////////////////////////////////////////////////////////////////// template inline std::basic_ostream & operator<< (std::basic_ostream &os , format_manip const& fm) { karma::ostream_iterator sink(os); if (!karma::generate_delimited(sink, fm.expr, fm.delim, fm.pre, fm.attr)) { os.setstate(std::ios_base::failbit); } return os; } }}}} #endif