matches.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2015.
  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 matches.hpp
  9. * \author Andrey Semashev
  10. * \date 02.09.2012
  11. *
  12. * The header contains implementation of a \c matches predicate in template expressions.
  13. */
  14. #ifndef BOOST_LOG_EXPRESSIONS_PREDICATES_MATCHES_HPP_INCLUDED_
  15. #define BOOST_LOG_EXPRESSIONS_PREDICATES_MATCHES_HPP_INCLUDED_
  16. #include <boost/phoenix/core/actor.hpp>
  17. #include <boost/log/detail/config.hpp>
  18. #include <boost/log/detail/unary_function_terminal.hpp>
  19. #include <boost/log/detail/attribute_predicate.hpp>
  20. #include <boost/log/expressions/attr_fwd.hpp>
  21. #include <boost/log/expressions/keyword_fwd.hpp>
  22. #include <boost/log/attributes/attribute_name.hpp>
  23. #include <boost/log/attributes/fallback_policy.hpp>
  24. #include <boost/log/utility/functional/matches.hpp>
  25. #include <boost/log/detail/header.hpp>
  26. #ifdef BOOST_HAS_PRAGMA_ONCE
  27. #pragma once
  28. #endif
  29. namespace boost {
  30. BOOST_LOG_OPEN_NAMESPACE
  31. namespace expressions {
  32. /*!
  33. * The predicate checks if the attribute value matches a regular expression. The attribute value is assumed to be of a string type.
  34. */
  35. template< typename T, typename RegexT, typename FallbackPolicyT = fallback_to_none >
  36. class attribute_matches :
  37. public aux::attribute_predicate< T, typename boost::log::aux::match_traits< RegexT >::compiled_type, matches_fun, FallbackPolicyT >
  38. {
  39. typedef aux::attribute_predicate< T, typename boost::log::aux::match_traits< RegexT >::compiled_type, matches_fun, FallbackPolicyT > base_type;
  40. public:
  41. /*!
  42. * Initializing constructor
  43. *
  44. * \param name Attribute name
  45. * \param rex The regular expression to match the attribute value against
  46. */
  47. attribute_matches(attribute_name const& name, RegexT const& rex) : base_type(name, boost::log::aux::match_traits< RegexT >::compile(rex))
  48. {
  49. }
  50. /*!
  51. * Initializing constructor
  52. *
  53. * \param name Attribute name
  54. * \param rex The regular expression to match the attribute value against
  55. * \param arg Additional parameter for the fallback policy
  56. */
  57. template< typename U >
  58. attribute_matches(attribute_name const& name, RegexT const& rex, U const& arg) : base_type(name, boost::log::aux::match_traits< RegexT >::compile(rex), arg)
  59. {
  60. }
  61. };
  62. /*!
  63. * The function generates a terminal node in a template expression. The node will check if the attribute value,
  64. * which is assumed to be a string, matches the specified regular expression.
  65. */
  66. template< typename T, typename FallbackPolicyT, typename TagT, template< typename > class ActorT, typename RegexT >
  67. BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< attribute_matches< T, RegexT, FallbackPolicyT > > >
  68. matches(attribute_actor< T, FallbackPolicyT, TagT, ActorT > const& attr, RegexT const& rex)
  69. {
  70. typedef aux::unary_function_terminal< attribute_matches< T, RegexT, FallbackPolicyT > > terminal_type;
  71. ActorT< terminal_type > act = {{ terminal_type(attr.get_name(), rex, attr.get_fallback_policy()) }};
  72. return act;
  73. }
  74. /*!
  75. * The function generates a terminal node in a template expression. The node will check if the attribute value,
  76. * which is assumed to be a string, matches the specified regular expression.
  77. */
  78. template< typename DescriptorT, template< typename > class ActorT, typename RegexT >
  79. BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< attribute_matches< typename DescriptorT::value_type, RegexT > > >
  80. matches(attribute_keyword< DescriptorT, ActorT > const&, RegexT const& rex)
  81. {
  82. typedef aux::unary_function_terminal< attribute_matches< typename DescriptorT::value_type, RegexT > > terminal_type;
  83. ActorT< terminal_type > act = {{ terminal_type(DescriptorT::get_name(), rex) }};
  84. return act;
  85. }
  86. /*!
  87. * The function generates a terminal node in a template expression. The node will check if the attribute value,
  88. * which is assumed to be a string, matches the specified regular expression.
  89. */
  90. template< typename T, typename RegexT >
  91. BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< attribute_matches< T, RegexT > > >
  92. matches(attribute_name const& name, RegexT const& rex)
  93. {
  94. typedef aux::unary_function_terminal< attribute_matches< T, RegexT > > terminal_type;
  95. phoenix::actor< terminal_type > act = {{ terminal_type(name, rex) }};
  96. return act;
  97. }
  98. } // namespace expressions
  99. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  100. } // namespace boost
  101. #include <boost/log/detail/footer.hpp>
  102. #endif // BOOST_LOG_EXPRESSIONS_PREDICATES_MATCHES_HPP_INCLUDED_