/*============================================================================= 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_MATCH_MANIP_MAY_05_2007_1203PM) #define BOOST_SPIRIT_MATCH_MANIP_MAY_05_2007_1203PM #if defined(_MSC_VER) #pragma once #endif #include #include #include #include #include #include /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { namespace qi { namespace detail { /////////////////////////////////////////////////////////////////////////// template struct match_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, ()); match_manip(Expr const& xpr, Skipper const& s, Attribute& a) : expr(xpr), skipper(s), attr(a), post_skip(skip_flag::postskip) {} match_manip(Expr const& xpr, Skipper const& s , BOOST_SCOPED_ENUM(skip_flag) ps, Attribute& a) : expr(xpr), skipper(s), attr(a), post_skip(ps) {} Expr const& expr; Skipper const& skipper; Attribute& attr; BOOST_SCOPED_ENUM(skip_flag) const post_skip; private: // silence MSVC warning C4512: assignment operator could not be generated match_manip& operator= (match_manip const&); }; template struct match_manip { match_manip(Expr const& xpr, Skipper const& s, Attribute& a) : expr(xpr), skipper(s), attr(a), post_skip(skip_flag::postskip) {} match_manip(Expr const& xpr, Skipper const& s , BOOST_SCOPED_ENUM(skip_flag) ps, Attribute& a) : expr(xpr), skipper(s), attr(a), post_skip(ps) {} Expr const& expr; Skipper const& skipper; Attribute attr; BOOST_SCOPED_ENUM(skip_flag) const post_skip; private: // silence MSVC warning C4512: assignment operator could not be generated match_manip& operator= (match_manip const&); }; template struct match_manip { match_manip(Expr const& xpr, Skipper const& s, Attribute& a) : expr(xpr), skipper(s), attr(a), post_skip(skip_flag::postskip) {} match_manip(Expr const& xpr, Skipper const& s , BOOST_SCOPED_ENUM(skip_flag) ps, Attribute& a) : expr(xpr), skipper(s), attr(a), post_skip(ps) {} Expr expr; Skipper const& skipper; Attribute& attr; BOOST_SCOPED_ENUM(skip_flag) const post_skip; private: // silence MSVC warning C4512: assignment operator could not be generated match_manip& operator= (match_manip const&); }; /////////////////////////////////////////////////////////////////////////// template struct match { // 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 qi expression. // Did you intend to use the auto_ facilities while forgetting to // #include ? BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr); }; template struct match >::type> { typedef match_manip type; static type call(Expr const& expr) { return type(expr, unused, unused); } }; /////////////////////////////////////////////////////////////////////////// template struct phrase_match { // 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 qi expression. // Did you intend to use the auto_ facilities while forgetting to // #include ? BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr); }; template struct phrase_match >::type> { typedef match_manip type; static type call( Expr const& expr , Skipper const& skipper , BOOST_SCOPED_ENUM(skip_flag) post_skip) { // 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(qi::domain, Skipper); return type(expr, skipper, post_skip, unused); } }; /////////////////////////////////////////////////////////////////////////// template inline std::basic_istream & operator>>(std::basic_istream &is, match_manip const& fm) { typedef spirit::basic_istream_iterator input_iterator; input_iterator f(is); input_iterator l; if (!qi::parse(f, l, fm.expr)) { is.setstate(std::ios_base::failbit); } return is; } /////////////////////////////////////////////////////////////////////////// template inline std::basic_istream & operator>>(std::basic_istream &is, match_manip const& fm) { typedef spirit::basic_istream_iterator input_iterator; input_iterator f(is); input_iterator l; if (!qi::parse(f, l, fm.expr, fm.attr)) { is.setstate(std::ios_base::failbit); } return is; } /////////////////////////////////////////////////////////////////////////// template inline std::basic_istream & operator>>(std::basic_istream &is, match_manip const& fm) { typedef spirit::basic_istream_iterator input_iterator; input_iterator f(is); input_iterator l; if (!qi::phrase_parse( f, l, fm.expr, fm.skipper, fm.post_skip)) { is.setstate(std::ios_base::failbit); } return is; } /////////////////////////////////////////////////////////////////////////// template inline std::basic_istream & operator>>( std::basic_istream &is, match_manip const& fm) { typedef spirit::basic_istream_iterator input_iterator; input_iterator f(is); input_iterator l; if (!qi::phrase_parse( f, l, fm.expr, fm.skipper, fm.post_skip, fm.attr)) { is.setstate(std::ios_base::failbit); } return is; } }}}} #endif