matches.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 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. #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  36. template< typename T, typename RegexT, typename FallbackPolicyT = fallback_to_none >
  37. using attribute_matches = aux::attribute_predicate< T, RegexT, matches_fun, FallbackPolicyT >;
  38. #else // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  39. template< typename T, typename RegexT, typename FallbackPolicyT = fallback_to_none >
  40. class attribute_matches :
  41. public aux::attribute_predicate< T, RegexT, matches_fun, FallbackPolicyT >
  42. {
  43. typedef aux::attribute_predicate< T, RegexT, matches_fun, FallbackPolicyT > base_type;
  44. public:
  45. /*!
  46. * Initializing constructor
  47. *
  48. * \param name Attribute name
  49. * \param rex The regular expression to match the attribute value against
  50. */
  51. attribute_matches(attribute_name const& name, RegexT const& rex) : base_type(name, rex)
  52. {
  53. }
  54. /*!
  55. * Initializing constructor
  56. *
  57. * \param name Attribute name
  58. * \param rex The regular expression to match the attribute value against
  59. * \param arg Additional parameter for the fallback policy
  60. */
  61. template< typename U >
  62. attribute_matches(attribute_name const& name, RegexT const& rex, U const& arg) : base_type(name, rex, arg)
  63. {
  64. }
  65. };
  66. #endif // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  67. /*!
  68. * The function generates a terminal node in a template expression. The node will check if the attribute value,
  69. * which is assumed to be a string, matches the specified regular expression.
  70. */
  71. template< typename T, typename FallbackPolicyT, typename TagT, template< typename > class ActorT, typename RegexT >
  72. BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< attribute_matches< T, RegexT, FallbackPolicyT > > >
  73. matches(attribute_actor< T, FallbackPolicyT, TagT, ActorT > const& attr, RegexT const& rex)
  74. {
  75. typedef aux::unary_function_terminal< attribute_matches< T, RegexT, FallbackPolicyT > > terminal_type;
  76. ActorT< terminal_type > act = {{ terminal_type(attr.get_name(), rex, attr.get_fallback_policy()) }};
  77. return act;
  78. }
  79. /*!
  80. * The function generates a terminal node in a template expression. The node will check if the attribute value,
  81. * which is assumed to be a string, matches the specified regular expression.
  82. */
  83. template< typename DescriptorT, template< typename > class ActorT, typename RegexT >
  84. BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< attribute_matches< typename DescriptorT::value_type, RegexT > > >
  85. matches(attribute_keyword< DescriptorT, ActorT > const&, RegexT const& rex)
  86. {
  87. typedef aux::unary_function_terminal< attribute_matches< typename DescriptorT::value_type, RegexT > > terminal_type;
  88. ActorT< terminal_type > act = {{ terminal_type(DescriptorT::get_name(), rex) }};
  89. return act;
  90. }
  91. /*!
  92. * The function generates a terminal node in a template expression. The node will check if the attribute value,
  93. * which is assumed to be a string, matches the specified regular expression.
  94. */
  95. template< typename T, typename RegexT >
  96. BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< attribute_matches< T, RegexT > > >
  97. matches(attribute_name const& name, RegexT const& rex)
  98. {
  99. typedef aux::unary_function_terminal< attribute_matches< T, RegexT > > terminal_type;
  100. phoenix::actor< terminal_type > act = {{ terminal_type(name, rex) }};
  101. return act;
  102. }
  103. } // namespace expressions
  104. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  105. } // namespace boost
  106. #include <boost/log/detail/footer.hpp>
  107. #endif // BOOST_LOG_EXPRESSIONS_PREDICATES_MATCHES_HPP_INCLUDED_