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_classic.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 19.07.2009 Chris@16: * Chris@16: * This header enables Boost.Spirit (classic) support for Boost.Log. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_SUPPORT_SPIRIT_CLASSIC_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_SUPPORT_SPIRIT_CLASSIC_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@101: #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: #if !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_SPIRIT_THREADSAFE) && !defined(BOOST_LOG_DOXYGEN_PASS) Chris@16: /* Chris@16: * As Boost.Log filters may be called in multiple threads concurrently, Chris@16: * this may lead to using Boost.Spirit parsers in a multithreaded context. Chris@16: * In order to protect parsers properly, BOOST_SPIRIT_THREADSAFE macro should Chris@16: * be defined. Chris@16: * Chris@16: * If we got here, it means that the user did not define that macro and we Chris@16: * have to define it ourselves. However, it may also lead to ODR violations Chris@16: * or even total ignorance of this macro, if the user has included Boost.Spirit Chris@16: * headers before including this header, or uses Boost.Spirit without the macro Chris@16: * in other translation units. The only reliable way to settle this problem is to Chris@16: * define the macro for the whole project (i.e. all translation units). Chris@16: */ Chris@101: #if defined(__GNUC__) Chris@101: #pragma message "Boost.Log: Boost.Spirit requires BOOST_SPIRIT_THREADSAFE macro to be defined if parsers are used in a multithreaded context. It is strongly recommended to define this macro project-wide." Chris@101: #elif defined(_MSC_VER) Chris@101: #pragma message("Boost.Log: Boost.Spirit requires BOOST_SPIRIT_THREADSAFE macro to be defined if parsers are used in a multithreaded context. It is strongly recommended to define this macro project-wide.") Chris@101: #endif Chris@16: #define BOOST_SPIRIT_THREADSAFE 1 Chris@16: #endif // !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_SPIRIT_THREADSAFE) Chris@16: Chris@16: #include Chris@16: Chris@16: #include 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.Classic expression Chris@101: struct boost_spirit_classic_expression_tag; Chris@101: Chris@16: //! The trait verifies if the type can be converted to a Boost.Spirit (classic) parser Chris@16: template< typename T > Chris@101: struct is_spirit_classic_parser Chris@16: { Chris@16: private: Chris@16: typedef char yes_type; Chris@16: struct no_type { char dummy[2]; }; Chris@16: Chris@16: template< typename U > Chris@16: static yes_type check_spirit_classic_parser(spirit::classic::parser< U > const&); Chris@16: static no_type check_spirit_classic_parser(...); Chris@16: static T& get_T(); Chris@16: Chris@16: public: Chris@16: enum { value = sizeof(check_spirit_classic_parser(get_T())) == sizeof(yes_type) }; Chris@16: typedef mpl::bool_< value > type; Chris@16: }; Chris@16: 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_c< is_spirit_classic_parser< ExpressionT >::value >::type > Chris@16: { Chris@101: typedef boost_spirit_classic_expression_tag type; Chris@101: }; Chris@101: Chris@101: //! The matching function implementation Chris@101: template< typename ExpressionT > Chris@101: struct match_traits< ExpressionT, boost_spirit_classic_expression_tag > Chris@101: { Chris@101: typedef ExpressionT compiled_type; Chris@101: static compiled_type compile(ExpressionT const& expr) { return expr; } Chris@101: Chris@101: template< typename StringT > Chris@101: static bool matches(StringT const& str, ExpressionT const& expr) Chris@16: { Chris@16: typedef typename StringT::const_iterator const_iterator; Chris@16: spirit::classic::parse_info< const_iterator > info = Chris@16: spirit::classic::parse(str.begin(), str.end(), expr); Chris@16: return info.full; 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_CLASSIC_HPP_INCLUDED_