ends_with.hpp 5.2 KB

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