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