spirit_classic.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2013.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*!
  8. * \file support/spirit_classic.hpp
  9. * \author Andrey Semashev
  10. * \date 19.07.2009
  11. *
  12. * This header enables Boost.Spirit (classic) support for Boost.Log.
  13. */
  14. #ifndef BOOST_LOG_SUPPORT_SPIRIT_CLASSIC_HPP_INCLUDED_
  15. #define BOOST_LOG_SUPPORT_SPIRIT_CLASSIC_HPP_INCLUDED_
  16. #include <boost/mpl/bool.hpp>
  17. #include <boost/log/detail/config.hpp>
  18. #include <boost/log/utility/functional/matches.hpp>
  19. #ifdef BOOST_HAS_PRAGMA_ONCE
  20. #pragma once
  21. #endif
  22. #if !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_SPIRIT_THREADSAFE) && !defined(BOOST_LOG_DOXYGEN_PASS)
  23. /*
  24. * As Boost.Log filters may be called in multiple threads concurrently,
  25. * this may lead to using Boost.Spirit parsers in a multithreaded context.
  26. * In order to protect parsers properly, BOOST_SPIRIT_THREADSAFE macro should
  27. * be defined.
  28. *
  29. * If we got here, it means that the user did not define that macro and we
  30. * have to define it ourselves. However, it may also lead to ODR violations
  31. * or even total ignorance of this macro, if the user has included Boost.Spirit
  32. * headers before including this header, or uses Boost.Spirit without the macro
  33. * in other translation units. The only reliable way to settle this problem is to
  34. * define the macro for the whole project (i.e. all translation units).
  35. */
  36. #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.
  37. #define BOOST_SPIRIT_THREADSAFE 1
  38. #endif // !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_SPIRIT_THREADSAFE)
  39. #include <boost/spirit/include/classic_parser.hpp>
  40. #include <boost/log/detail/header.hpp>
  41. namespace boost {
  42. BOOST_LOG_OPEN_NAMESPACE
  43. namespace aux {
  44. //! The trait verifies if the type can be converted to a Boost.Spirit (classic) parser
  45. template< typename T >
  46. struct is_spirit_classic_parser< T, true >
  47. {
  48. private:
  49. typedef char yes_type;
  50. struct no_type { char dummy[2]; };
  51. template< typename U >
  52. static yes_type check_spirit_classic_parser(spirit::classic::parser< U > const&);
  53. static no_type check_spirit_classic_parser(...);
  54. static T& get_T();
  55. public:
  56. enum { value = sizeof(check_spirit_classic_parser(get_T())) == sizeof(yes_type) };
  57. typedef mpl::bool_< value > type;
  58. };
  59. //! The matching functor implementation
  60. template< >
  61. struct matches_fun_impl< boost_spirit_classic_expression_tag >
  62. {
  63. template< typename StringT, typename ParserT >
  64. static bool matches(
  65. StringT const& str,
  66. ParserT const& expr)
  67. {
  68. typedef typename StringT::const_iterator const_iterator;
  69. spirit::classic::parse_info< const_iterator > info =
  70. spirit::classic::parse(str.begin(), str.end(), expr);
  71. return info.full;
  72. }
  73. };
  74. } // namespace aux
  75. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  76. } // namespace boost
  77. #include <boost/log/detail/footer.hpp>
  78. #endif // BOOST_LOG_SUPPORT_SPIRIT_CLASSIC_HPP_INCLUDED_