regex.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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/regex.hpp
  9. * \author Andrey Semashev
  10. * \date 18.07.2009
  11. *
  12. * This header enables Boost.Regex support for Boost.Log.
  13. */
  14. #ifndef BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_
  15. #define BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_
  16. #include <boost/regex.hpp>
  17. #include <boost/mpl/bool.hpp>
  18. #include <boost/log/detail/config.hpp>
  19. #include <boost/log/utility/functional/matches.hpp>
  20. #include <boost/log/detail/header.hpp>
  21. #ifdef BOOST_HAS_PRAGMA_ONCE
  22. #pragma once
  23. #endif
  24. namespace boost {
  25. BOOST_LOG_OPEN_NAMESPACE
  26. namespace aux {
  27. //! The trait verifies if the type can be converted to a Boost.Regex expression
  28. template< typename T >
  29. struct is_regex< T, true >
  30. {
  31. private:
  32. typedef char yes_type;
  33. struct no_type { char dummy[2]; };
  34. template< typename CharT, typename TraitsT >
  35. static yes_type check_regex(basic_regex< CharT, TraitsT > const&);
  36. static no_type check_regex(...);
  37. static T& get_T();
  38. public:
  39. enum { value = sizeof(check_regex(get_T())) == sizeof(yes_type) };
  40. typedef mpl::bool_< value > type;
  41. };
  42. //! The regex matching functor implementation
  43. template< >
  44. struct matches_fun_impl< boost_regex_expression_tag >
  45. {
  46. template< typename StringT, typename CharT, typename TraitsT >
  47. static bool matches(
  48. StringT const& str,
  49. basic_regex< CharT, TraitsT > const& expr,
  50. match_flag_type flags = match_default)
  51. {
  52. return boost::regex_match(str.begin(), str.end(), expr, flags);
  53. }
  54. };
  55. } // namespace aux
  56. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  57. } // namespace boost
  58. #include <boost/log/detail/footer.hpp>
  59. #endif // BOOST_LOG_SUPPORT_REGEX_HPP_INCLUDED_