xpressive.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/xpressive.hpp
  9. * \author Andrey Semashev
  10. * \date 18.07.2009
  11. *
  12. * This header enables Boost.Xpressive support for Boost.Log.
  13. */
  14. #ifndef BOOST_LOG_SUPPORT_XPRESSIVE_HPP_INCLUDED_
  15. #define BOOST_LOG_SUPPORT_XPRESSIVE_HPP_INCLUDED_
  16. #include <boost/mpl/bool.hpp>
  17. #include <boost/xpressive/basic_regex.hpp>
  18. #include <boost/xpressive/regex_constants.hpp>
  19. #include <boost/xpressive/regex_algorithms.hpp>
  20. #include <boost/log/detail/config.hpp>
  21. #include <boost/log/utility/functional/matches.hpp>
  22. #include <boost/log/detail/header.hpp>
  23. #ifdef BOOST_HAS_PRAGMA_ONCE
  24. #pragma once
  25. #endif
  26. namespace boost {
  27. BOOST_LOG_OPEN_NAMESPACE
  28. namespace aux {
  29. //! The trait verifies if the type can be converted to a Boost.Xpressive regex
  30. template< typename T >
  31. struct is_xpressive_regex< T, true >
  32. {
  33. private:
  34. typedef char yes_type;
  35. struct no_type { char dummy[2]; };
  36. template< typename U >
  37. static yes_type check_xpressive_regex(xpressive::basic_regex< U > const&);
  38. static no_type check_xpressive_regex(...);
  39. static T& get_T();
  40. public:
  41. enum { value = sizeof(check_xpressive_regex(get_T())) == sizeof(yes_type) };
  42. typedef mpl::bool_< value > type;
  43. };
  44. //! The regex matching functor implementation
  45. template< >
  46. struct matches_fun_impl< boost_xpressive_expression_tag >
  47. {
  48. template< typename StringT, typename T >
  49. static bool matches(
  50. StringT const& str,
  51. xpressive::basic_regex< T > const& expr,
  52. xpressive::regex_constants::match_flag_type flags = xpressive::regex_constants::match_default)
  53. {
  54. return xpressive::regex_match(str, expr, flags);
  55. }
  56. template< typename StringT >
  57. static bool matches(
  58. StringT const& str,
  59. xpressive::basic_regex< typename StringT::value_type* > const& expr,
  60. xpressive::regex_constants::match_flag_type flags = xpressive::regex_constants::match_default)
  61. {
  62. return xpressive::regex_match(str.c_str(), expr, flags);
  63. }
  64. template< typename StringT >
  65. static bool matches(
  66. StringT const& str,
  67. xpressive::basic_regex< typename StringT::value_type const* > const& expr,
  68. xpressive::regex_constants::match_flag_type flags = xpressive::regex_constants::match_default)
  69. {
  70. return xpressive::regex_match(str.c_str(), expr, flags);
  71. }
  72. };
  73. } // namespace aux
  74. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  75. } // namespace boost
  76. #include <boost/log/detail/footer.hpp>
  77. #endif // BOOST_LOG_SUPPORT_XPRESSIVE_HPP_INCLUDED_