Chris@16: /* Chris@101: * Copyright Andrey Semashev 2007 - 2015. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: /*! Chris@16: * \file matches.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 02.09.2012 Chris@16: * Chris@16: * The header contains implementation of a \c matches predicate in template expressions. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_EXPRESSIONS_PREDICATES_MATCHES_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_EXPRESSIONS_PREDICATES_MATCHES_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: BOOST_LOG_OPEN_NAMESPACE Chris@16: Chris@16: namespace expressions { Chris@16: Chris@16: /*! Chris@16: * The predicate checks if the attribute value matches a regular expression. The attribute value is assumed to be of a string type. Chris@16: */ Chris@16: template< typename T, typename RegexT, typename FallbackPolicyT = fallback_to_none > Chris@16: class attribute_matches : Chris@101: public aux::attribute_predicate< T, typename boost::log::aux::match_traits< RegexT >::compiled_type, matches_fun, FallbackPolicyT > Chris@16: { Chris@101: typedef aux::attribute_predicate< T, typename boost::log::aux::match_traits< RegexT >::compiled_type, matches_fun, FallbackPolicyT > base_type; Chris@16: Chris@16: public: Chris@16: /*! Chris@16: * Initializing constructor Chris@16: * Chris@16: * \param name Attribute name Chris@16: * \param rex The regular expression to match the attribute value against Chris@16: */ Chris@101: attribute_matches(attribute_name const& name, RegexT const& rex) : base_type(name, boost::log::aux::match_traits< RegexT >::compile(rex)) Chris@16: { Chris@16: } Chris@16: Chris@16: /*! Chris@16: * Initializing constructor Chris@16: * Chris@16: * \param name Attribute name Chris@16: * \param rex The regular expression to match the attribute value against Chris@16: * \param arg Additional parameter for the fallback policy Chris@16: */ Chris@16: template< typename U > Chris@101: attribute_matches(attribute_name const& name, RegexT const& rex, U const& arg) : base_type(name, boost::log::aux::match_traits< RegexT >::compile(rex), arg) Chris@16: { Chris@16: } Chris@16: }; Chris@16: Chris@16: /*! Chris@16: * The function generates a terminal node in a template expression. The node will check if the attribute value, Chris@16: * which is assumed to be a string, matches the specified regular expression. Chris@16: */ Chris@16: template< typename T, typename FallbackPolicyT, typename TagT, template< typename > class ActorT, typename RegexT > Chris@16: BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< attribute_matches< T, RegexT, FallbackPolicyT > > > Chris@16: matches(attribute_actor< T, FallbackPolicyT, TagT, ActorT > const& attr, RegexT const& rex) Chris@16: { Chris@16: typedef aux::unary_function_terminal< attribute_matches< T, RegexT, FallbackPolicyT > > terminal_type; Chris@16: ActorT< terminal_type > act = {{ terminal_type(attr.get_name(), rex, attr.get_fallback_policy()) }}; Chris@16: return act; Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function generates a terminal node in a template expression. The node will check if the attribute value, Chris@16: * which is assumed to be a string, matches the specified regular expression. Chris@16: */ Chris@16: template< typename DescriptorT, template< typename > class ActorT, typename RegexT > Chris@16: BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< attribute_matches< typename DescriptorT::value_type, RegexT > > > Chris@16: matches(attribute_keyword< DescriptorT, ActorT > const&, RegexT const& rex) Chris@16: { Chris@16: typedef aux::unary_function_terminal< attribute_matches< typename DescriptorT::value_type, RegexT > > terminal_type; Chris@16: ActorT< terminal_type > act = {{ terminal_type(DescriptorT::get_name(), rex) }}; Chris@16: return act; Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function generates a terminal node in a template expression. The node will check if the attribute value, Chris@16: * which is assumed to be a string, matches the specified regular expression. Chris@16: */ Chris@16: template< typename T, typename RegexT > Chris@16: BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< attribute_matches< T, RegexT > > > Chris@16: matches(attribute_name const& name, RegexT const& rex) Chris@16: { Chris@16: typedef aux::unary_function_terminal< attribute_matches< T, RegexT > > terminal_type; Chris@16: phoenix::actor< terminal_type > act = {{ terminal_type(name, rex) }}; Chris@16: return act; Chris@16: } Chris@16: Chris@16: } // namespace expressions Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_LOG_EXPRESSIONS_PREDICATES_MATCHES_HPP_INCLUDED_