Chris@16: /* Chris@101: * Copyright Andrey Semashev 2007 - 2015. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: /*! Chris@16: * \file support/spirit_qi.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 19.07.2009 Chris@16: * Chris@16: * This header enables Boost.Spirit.Qi support for Boost.Log. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_SUPPORT_SPIRIT_QI_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_SUPPORT_SPIRIT_QI_HPP_INCLUDED_ Chris@16: Chris@101: #include Chris@101: #include Chris@101: #include Chris@101: #include Chris@101: #include // spirit::compile() Chris@101: #include // rule forward declaration Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: BOOST_LOG_OPEN_NAMESPACE Chris@16: Chris@16: namespace aux { Chris@16: Chris@101: //! This tag type is used if an expression is recognized as a Boost.Spirit.Qi expression Chris@101: struct boost_spirit_qi_expression_tag; Chris@101: Chris@101: //! The metafunction detects the matching expression kind and returns a tag that is used to specialize \c match_traits Chris@101: template< typename ExpressionT > Chris@101: struct matching_expression_kind< ExpressionT, typename boost::enable_if< spirit::traits::matches< spirit::qi::domain, ExpressionT > >::type > Chris@16: { Chris@101: typedef boost_spirit_qi_expression_tag type; Chris@16: }; Chris@16: Chris@101: //! The matching function implementation Chris@101: template< typename ExpressionT > Chris@101: struct match_traits< ExpressionT, boost_spirit_qi_expression_tag > Chris@16: { Chris@101: typedef typename spirit::result_of::compile< spirit::qi::domain, ExpressionT, spirit::unused_type >::type compiled_type; Chris@101: Chris@101: static compiled_type compile(ExpressionT const& expr) Chris@101: { Chris@101: return spirit::compile< spirit::qi::domain >(expr); Chris@101: } Chris@101: Chris@101: template< typename StringT > Chris@101: static bool matches(StringT const& str, ExpressionT const& expr) Chris@101: { Chris@101: typedef typename StringT::const_iterator const_iterator; Chris@101: const_iterator it = str.begin(), end = str.end(); Chris@101: return (spirit::qi::parse(it, end, expr) && it == end); Chris@101: } Chris@101: }; Chris@101: Chris@101: //! The matching function implementation Chris@101: template< typename IteratorT, typename T1, typename T2, typename T3, typename T4 > Chris@101: struct match_traits< spirit::qi::rule< IteratorT, T1, T2, T3, T4 >, boost_spirit_qi_expression_tag > Chris@101: { Chris@101: typedef spirit::qi::rule< IteratorT, T1, T2, T3, T4 > compiled_type; Chris@101: static compiled_type compile(compiled_type const& expr) { return expr; } Chris@101: Chris@101: template< typename StringT > Chris@101: static bool matches(StringT const& str, compiled_type const& expr) Chris@16: { Chris@16: typedef typename StringT::const_iterator const_iterator; Chris@16: const_iterator it = str.begin(), end = str.end(); Chris@16: return (spirit::qi::parse(it, end, expr) && it == end); Chris@16: } Chris@16: }; Chris@16: Chris@16: } // namespace aux Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_LOG_SUPPORT_SPIRIT_QI_HPP_INCLUDED_