Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:23

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   matches.hpp
0009  * \author Andrey Semashev
0010  * \date   02.09.2012
0011  *
0012  * The header contains implementation of a \c matches predicate in template expressions.
0013  */
0014 
0015 #ifndef BOOST_LOG_EXPRESSIONS_PREDICATES_MATCHES_HPP_INCLUDED_
0016 #define BOOST_LOG_EXPRESSIONS_PREDICATES_MATCHES_HPP_INCLUDED_
0017 
0018 #include <boost/phoenix/core/actor.hpp>
0019 #include <boost/log/detail/config.hpp>
0020 #include <boost/log/detail/unary_function_terminal.hpp>
0021 #include <boost/log/detail/attribute_predicate.hpp>
0022 #include <boost/log/expressions/attr_fwd.hpp>
0023 #include <boost/log/expressions/keyword_fwd.hpp>
0024 #include <boost/log/attributes/attribute_name.hpp>
0025 #include <boost/log/attributes/fallback_policy.hpp>
0026 #include <boost/log/utility/functional/matches.hpp>
0027 #include <boost/log/detail/header.hpp>
0028 
0029 #ifdef BOOST_HAS_PRAGMA_ONCE
0030 #pragma once
0031 #endif
0032 
0033 namespace boost {
0034 
0035 BOOST_LOG_OPEN_NAMESPACE
0036 
0037 namespace expressions {
0038 
0039 /*!
0040  * The predicate checks if the attribute value matches a regular expression. The attribute value is assumed to be of a string type.
0041  */
0042 template< typename T, typename RegexT, typename FallbackPolicyT = fallback_to_none >
0043 class attribute_matches :
0044     public aux::attribute_predicate< T, typename boost::log::aux::match_traits< RegexT >::compiled_type, matches_fun, FallbackPolicyT >
0045 {
0046     typedef aux::attribute_predicate< T, typename boost::log::aux::match_traits< RegexT >::compiled_type, matches_fun, FallbackPolicyT > base_type;
0047 
0048 public:
0049     /*!
0050      * Initializing constructor
0051      *
0052      * \param name Attribute name
0053      * \param rex The regular expression to match the attribute value against
0054      */
0055     attribute_matches(attribute_name const& name, RegexT const& rex) : base_type(name, boost::log::aux::match_traits< RegexT >::compile(rex))
0056     {
0057     }
0058 
0059     /*!
0060      * Initializing constructor
0061      *
0062      * \param name Attribute name
0063      * \param rex The regular expression to match the attribute value against
0064      * \param arg Additional parameter for the fallback policy
0065      */
0066     template< typename U >
0067     attribute_matches(attribute_name const& name, RegexT const& rex, U const& arg) : base_type(name, boost::log::aux::match_traits< RegexT >::compile(rex), arg)
0068     {
0069     }
0070 };
0071 
0072 #if defined(BOOST_MSVC) && BOOST_MSVC == 1925
0073 // MSVC 14.2 has a codegen bug that makes inlined `matches` functions below crash on copy constructing the phoenix::actor on return.
0074 // https://developercommunity.visualstudio.com/content/problem/982738/bad-code-generated-in-boostlogboostregex-test-case.html
0075 #define BOOST_LOG_AUX_FORCEINLINE_MSVC_BUG982738 inline BOOST_NOINLINE
0076 #else
0077 #define BOOST_LOG_AUX_FORCEINLINE_MSVC_BUG982738 BOOST_FORCEINLINE
0078 #endif
0079 
0080 /*!
0081  * The function generates a terminal node in a template expression. The node will check if the attribute value,
0082  * which is assumed to be a string, matches the specified regular expression.
0083  */
0084 template< typename T, typename FallbackPolicyT, typename TagT, template< typename > class ActorT, typename RegexT >
0085 BOOST_LOG_AUX_FORCEINLINE_MSVC_BUG982738 ActorT< aux::unary_function_terminal< attribute_matches< T, RegexT, FallbackPolicyT > > >
0086 matches(attribute_actor< T, FallbackPolicyT, TagT, ActorT > const& attr, RegexT const& rex)
0087 {
0088     typedef aux::unary_function_terminal< attribute_matches< T, RegexT, FallbackPolicyT > > terminal_type;
0089     ActorT< terminal_type > act = {{ terminal_type(attr.get_name(), rex, attr.get_fallback_policy()) }};
0090     return act;
0091 }
0092 
0093 /*!
0094  * The function generates a terminal node in a template expression. The node will check if the attribute value,
0095  * which is assumed to be a string, matches the specified regular expression.
0096  */
0097 template< typename DescriptorT, template< typename > class ActorT, typename RegexT >
0098 BOOST_LOG_AUX_FORCEINLINE_MSVC_BUG982738 ActorT< aux::unary_function_terminal< attribute_matches< typename DescriptorT::value_type, RegexT > > >
0099 matches(attribute_keyword< DescriptorT, ActorT > const&, RegexT const& rex)
0100 {
0101     typedef aux::unary_function_terminal< attribute_matches< typename DescriptorT::value_type, RegexT > > terminal_type;
0102     ActorT< terminal_type > act = {{ terminal_type(DescriptorT::get_name(), rex) }};
0103     return act;
0104 }
0105 
0106 /*!
0107  * The function generates a terminal node in a template expression. The node will check if the attribute value,
0108  * which is assumed to be a string, matches the specified regular expression.
0109  */
0110 template< typename T, typename RegexT >
0111 BOOST_LOG_AUX_FORCEINLINE_MSVC_BUG982738 phoenix::actor< aux::unary_function_terminal< attribute_matches< T, RegexT > > >
0112 matches(attribute_name const& name, RegexT const& rex)
0113 {
0114     typedef aux::unary_function_terminal< attribute_matches< T, RegexT > > terminal_type;
0115     phoenix::actor< terminal_type > act = {{ terminal_type(name, rex) }};
0116     return act;
0117 }
0118 
0119 #undef BOOST_LOG_AUX_FORCEINLINE_MSVC_BUG982738
0120 
0121 } // namespace expressions
0122 
0123 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0124 
0125 } // namespace boost
0126 
0127 #include <boost/log/detail/footer.hpp>
0128 
0129 #endif // BOOST_LOG_EXPRESSIONS_PREDICATES_MATCHES_HPP_INCLUDED_