Chris@16: /* Chris@16: * Copyright Andrey Semashev 2007 - 2013. 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@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@16: #warning 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@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@16: //! The trait verifies if the type can be converted to a Boost.Spirit (classic) parser Chris@16: template< typename T > Chris@16: struct is_spirit_classic_parser< T, true > 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@16: //! The matching functor implementation Chris@16: template< > Chris@16: struct matches_fun_impl< boost_spirit_classic_expression_tag > Chris@16: { Chris@16: template< typename StringT, typename ParserT > Chris@16: static bool matches( Chris@16: StringT const& str, Chris@16: ParserT 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_