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)
9 * \author Andrey Semashev
12 * The header contains implementation of a \c matches predicate in template expressions.
15 #ifndef BOOST_LOG_EXPRESSIONS_PREDICATES_MATCHES_HPP_INCLUDED_
16 #define BOOST_LOG_EXPRESSIONS_PREDICATES_MATCHES_HPP_INCLUDED_
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>
29 #ifdef BOOST_HAS_PRAGMA_ONCE
35 BOOST_LOG_OPEN_NAMESPACE
37 namespace expressions {
40 * The predicate checks if the attribute value matches a regular expression. The attribute value is assumed to be of a string type.
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 >
46 typedef aux::attribute_predicate< T, typename boost::log::aux::match_traits< RegexT >::compiled_type, matches_fun, FallbackPolicyT > base_type;
50 * Initializing constructor
52 * \param name Attribute name
53 * \param rex The regular expression to match the attribute value against
55 attribute_matches(attribute_name const& name, RegexT const& rex) : base_type(name, boost::log::aux::match_traits< RegexT >::compile(rex))
60 * Initializing constructor
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
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)
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.
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)
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()) }};
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.
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)
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) }};
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.
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)
106 typedef aux::unary_function_terminal< attribute_matches< T, RegexT > > terminal_type;
107 phoenix::actor< terminal_type > act = {{ terminal_type(name, rex) }};
111 } // namespace expressions
113 BOOST_LOG_CLOSE_NAMESPACE // namespace log
117 #include <boost/log/detail/footer.hpp>
119 #endif // BOOST_LOG_EXPRESSIONS_PREDICATES_MATCHES_HPP_INCLUDED_