annotate DEPENDENCIES/generic/include/boost/log/support/spirit_classic.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 /*
Chris@101 2 * Copyright Andrey Semashev 2007 - 2015.
Chris@16 3 * Distributed under the Boost Software License, Version 1.0.
Chris@16 4 * (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 5 * http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6 */
Chris@16 7 /*!
Chris@16 8 * \file support/spirit_classic.hpp
Chris@16 9 * \author Andrey Semashev
Chris@16 10 * \date 19.07.2009
Chris@16 11 *
Chris@16 12 * This header enables Boost.Spirit (classic) support for Boost.Log.
Chris@16 13 */
Chris@16 14
Chris@16 15 #ifndef BOOST_LOG_SUPPORT_SPIRIT_CLASSIC_HPP_INCLUDED_
Chris@16 16 #define BOOST_LOG_SUPPORT_SPIRIT_CLASSIC_HPP_INCLUDED_
Chris@16 17
Chris@16 18 #include <boost/mpl/bool.hpp>
Chris@101 19 #include <boost/utility/enable_if.hpp>
Chris@16 20 #include <boost/log/detail/config.hpp>
Chris@16 21 #include <boost/log/utility/functional/matches.hpp>
Chris@16 22
Chris@16 23 #ifdef BOOST_HAS_PRAGMA_ONCE
Chris@16 24 #pragma once
Chris@16 25 #endif
Chris@16 26
Chris@16 27 #if !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_SPIRIT_THREADSAFE) && !defined(BOOST_LOG_DOXYGEN_PASS)
Chris@16 28 /*
Chris@16 29 * As Boost.Log filters may be called in multiple threads concurrently,
Chris@16 30 * this may lead to using Boost.Spirit parsers in a multithreaded context.
Chris@16 31 * In order to protect parsers properly, BOOST_SPIRIT_THREADSAFE macro should
Chris@16 32 * be defined.
Chris@16 33 *
Chris@16 34 * If we got here, it means that the user did not define that macro and we
Chris@16 35 * have to define it ourselves. However, it may also lead to ODR violations
Chris@16 36 * or even total ignorance of this macro, if the user has included Boost.Spirit
Chris@16 37 * headers before including this header, or uses Boost.Spirit without the macro
Chris@16 38 * in other translation units. The only reliable way to settle this problem is to
Chris@16 39 * define the macro for the whole project (i.e. all translation units).
Chris@16 40 */
Chris@101 41 #if defined(__GNUC__)
Chris@101 42 #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 43 #elif defined(_MSC_VER)
Chris@101 44 #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 45 #endif
Chris@16 46 #define BOOST_SPIRIT_THREADSAFE 1
Chris@16 47 #endif // !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_SPIRIT_THREADSAFE)
Chris@16 48
Chris@16 49 #include <boost/spirit/include/classic_parser.hpp>
Chris@16 50
Chris@16 51 #include <boost/log/detail/header.hpp>
Chris@16 52
Chris@16 53 namespace boost {
Chris@16 54
Chris@16 55 BOOST_LOG_OPEN_NAMESPACE
Chris@16 56
Chris@16 57 namespace aux {
Chris@16 58
Chris@101 59 //! This tag type is used if an expression is recognized as a Boost.Spirit.Classic expression
Chris@101 60 struct boost_spirit_classic_expression_tag;
Chris@101 61
Chris@16 62 //! The trait verifies if the type can be converted to a Boost.Spirit (classic) parser
Chris@16 63 template< typename T >
Chris@101 64 struct is_spirit_classic_parser
Chris@16 65 {
Chris@16 66 private:
Chris@16 67 typedef char yes_type;
Chris@16 68 struct no_type { char dummy[2]; };
Chris@16 69
Chris@16 70 template< typename U >
Chris@16 71 static yes_type check_spirit_classic_parser(spirit::classic::parser< U > const&);
Chris@16 72 static no_type check_spirit_classic_parser(...);
Chris@16 73 static T& get_T();
Chris@16 74
Chris@16 75 public:
Chris@16 76 enum { value = sizeof(check_spirit_classic_parser(get_T())) == sizeof(yes_type) };
Chris@16 77 typedef mpl::bool_< value > type;
Chris@16 78 };
Chris@16 79
Chris@101 80 //! The metafunction detects the matching expression kind and returns a tag that is used to specialize \c match_traits
Chris@101 81 template< typename ExpressionT >
Chris@101 82 struct matching_expression_kind< ExpressionT, typename boost::enable_if_c< is_spirit_classic_parser< ExpressionT >::value >::type >
Chris@16 83 {
Chris@101 84 typedef boost_spirit_classic_expression_tag type;
Chris@101 85 };
Chris@101 86
Chris@101 87 //! The matching function implementation
Chris@101 88 template< typename ExpressionT >
Chris@101 89 struct match_traits< ExpressionT, boost_spirit_classic_expression_tag >
Chris@101 90 {
Chris@101 91 typedef ExpressionT compiled_type;
Chris@101 92 static compiled_type compile(ExpressionT const& expr) { return expr; }
Chris@101 93
Chris@101 94 template< typename StringT >
Chris@101 95 static bool matches(StringT const& str, ExpressionT const& expr)
Chris@16 96 {
Chris@16 97 typedef typename StringT::const_iterator const_iterator;
Chris@16 98 spirit::classic::parse_info< const_iterator > info =
Chris@16 99 spirit::classic::parse(str.begin(), str.end(), expr);
Chris@16 100 return info.full;
Chris@16 101 }
Chris@16 102 };
Chris@16 103
Chris@16 104 } // namespace aux
Chris@16 105
Chris@16 106 BOOST_LOG_CLOSE_NAMESPACE // namespace log
Chris@16 107
Chris@16 108 } // namespace boost
Chris@16 109
Chris@16 110 #include <boost/log/detail/footer.hpp>
Chris@16 111
Chris@16 112 #endif // BOOST_LOG_SUPPORT_SPIRIT_CLASSIC_HPP_INCLUDED_