Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:45:08

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   support/spirit_classic.hpp
0009  * \author Andrey Semashev
0010  * \date   19.07.2009
0011  *
0012  * This header enables Boost.Spirit (classic) support for Boost.Log.
0013  */
0014 
0015 #ifndef BOOST_LOG_SUPPORT_SPIRIT_CLASSIC_HPP_INCLUDED_
0016 #define BOOST_LOG_SUPPORT_SPIRIT_CLASSIC_HPP_INCLUDED_
0017 
0018 #include <boost/mpl/bool.hpp>
0019 #include <boost/core/enable_if.hpp>
0020 #include <boost/log/detail/config.hpp>
0021 #include <boost/log/utility/functional/matches.hpp>
0022 
0023 #ifdef BOOST_HAS_PRAGMA_ONCE
0024 #pragma once
0025 #endif
0026 
0027 #if !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_SPIRIT_THREADSAFE) && !defined(BOOST_LOG_DOXYGEN_PASS)
0028 /*
0029  * As Boost.Log filters may be called in multiple threads concurrently,
0030  * this may lead to using Boost.Spirit parsers in a multithreaded context.
0031  * In order to protect parsers properly, BOOST_SPIRIT_THREADSAFE macro should
0032  * be defined.
0033  *
0034  * If we got here, it means that the user did not define that macro and we
0035  * have to define it ourselves. However, it may also lead to ODR violations
0036  * or even total ignorance of this macro, if the user has included Boost.Spirit
0037  * headers before including this header, or uses Boost.Spirit without the macro
0038  * in other translation units. The only reliable way to settle this problem is to
0039  * define the macro for the whole project (i.e. all translation units).
0040  */
0041 #if defined(__GNUC__)
0042 #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."
0043 #elif defined(_MSC_VER)
0044 #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.")
0045 #endif
0046 #define BOOST_SPIRIT_THREADSAFE 1
0047 #endif // !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_SPIRIT_THREADSAFE)
0048 
0049 #include <boost/spirit/include/classic_parser.hpp>
0050 
0051 #include <boost/log/detail/header.hpp>
0052 
0053 namespace boost {
0054 
0055 BOOST_LOG_OPEN_NAMESPACE
0056 
0057 namespace aux {
0058 
0059 //! This tag type is used if an expression is recognized as a Boost.Spirit.Classic expression
0060 struct boost_spirit_classic_expression_tag;
0061 
0062 //! The trait verifies if the type can be converted to a Boost.Spirit (classic) parser
0063 template< typename T >
0064 struct is_spirit_classic_parser
0065 {
0066 private:
0067     typedef char yes_type;
0068     struct no_type { char dummy[2]; };
0069 
0070     template< typename U >
0071     static yes_type check_spirit_classic_parser(spirit::classic::parser< U > const&);
0072     static no_type check_spirit_classic_parser(...);
0073     static T& get_T();
0074 
0075 public:
0076     enum { value = sizeof(check_spirit_classic_parser(get_T())) == sizeof(yes_type) };
0077     typedef mpl::bool_< value > type;
0078 };
0079 
0080 //! The metafunction detects the matching expression kind and returns a tag that is used to specialize \c match_traits
0081 template< typename ExpressionT >
0082 struct matching_expression_kind< ExpressionT, typename boost::enable_if_c< is_spirit_classic_parser< ExpressionT >::value >::type >
0083 {
0084     typedef boost_spirit_classic_expression_tag type;
0085 };
0086 
0087 //! The matching function implementation
0088 template< typename ExpressionT >
0089 struct match_traits< ExpressionT, boost_spirit_classic_expression_tag >
0090 {
0091     typedef ExpressionT compiled_type;
0092     static compiled_type compile(ExpressionT const& expr) { return expr; }
0093 
0094     template< typename StringT >
0095     static bool matches(StringT const& str, ExpressionT const& expr)
0096     {
0097         typedef typename StringT::const_iterator const_iterator;
0098         spirit::classic::parse_info< const_iterator > info =
0099             spirit::classic::parse(str.begin(), str.end(), expr);
0100         return info.full;
0101     }
0102 };
0103 
0104 } // namespace aux
0105 
0106 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0107 
0108 } // namespace boost
0109 
0110 #include <boost/log/detail/footer.hpp>
0111 
0112 #endif // BOOST_LOG_SUPPORT_SPIRIT_CLASSIC_HPP_INCLUDED_