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 is_in_range.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 02.09.2012 Chris@16: * Chris@16: * The header contains implementation of an \c is_in_range predicate in template expressions. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_EXPRESSIONS_PREDICATES_IS_IN_RANGE_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_EXPRESSIONS_PREDICATES_IS_IN_RANGE_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: #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 contains a substring. The attribute value is assumed to be of a string type. Chris@16: */ Chris@16: #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) Chris@16: Chris@16: template< typename T, typename BoundaryT, typename FallbackPolicyT = fallback_to_none > Chris@16: using attribute_is_in_range = aux::attribute_predicate< T, std::pair< BoundaryT, BoundaryT >, in_range_fun, FallbackPolicyT >; Chris@16: Chris@16: #else // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) Chris@16: Chris@16: template< typename T, typename BoundaryT, typename FallbackPolicyT = fallback_to_none > Chris@16: class attribute_is_in_range : Chris@16: public aux::attribute_predicate< T, std::pair< BoundaryT, BoundaryT >, in_range_fun, FallbackPolicyT > Chris@16: { Chris@16: typedef aux::attribute_predicate< T, std::pair< BoundaryT, BoundaryT >, in_range_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 boundaries The expected attribute value boundaries Chris@16: */ Chris@16: attribute_is_in_range(attribute_name const& name, std::pair< BoundaryT, BoundaryT > const& boundaries) : base_type(name, boundaries) Chris@16: { Chris@16: } Chris@16: Chris@16: /*! Chris@16: * Initializing constructor Chris@16: * Chris@16: * \param name Attribute name Chris@16: * \param boundaries The expected attribute value boundaries Chris@16: * \param arg Additional parameter for the fallback policy Chris@16: */ Chris@16: template< typename U > Chris@16: attribute_is_in_range(attribute_name const& name, std::pair< BoundaryT, BoundaryT > const& boundaries, U const& arg) : base_type(name, boundaries, arg) Chris@16: { Chris@16: } Chris@16: }; Chris@16: Chris@16: #endif // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) 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: * is in the specified range. The range must be half-open, that is the predicate will be equivalent to least <= attr < most. Chris@16: */ Chris@16: template< typename T, typename FallbackPolicyT, typename TagT, template< typename > class ActorT, typename BoundaryT > Chris@16: BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< attribute_is_in_range< T, typename boost::log::aux::make_embedded_string_type< BoundaryT >::type, FallbackPolicyT > > > Chris@16: is_in_range(attribute_actor< T, FallbackPolicyT, TagT, ActorT > const& attr, BoundaryT const& least, BoundaryT const& most) Chris@16: { Chris@16: typedef typename boost::log::aux::make_embedded_string_type< BoundaryT >::type boundary_type; Chris@16: typedef aux::unary_function_terminal< attribute_is_in_range< T, boundary_type, FallbackPolicyT > > terminal_type; Chris@16: ActorT< terminal_type > act = {{ terminal_type(attr.get_name(), std::pair< boundary_type, boundary_type >(least, most), 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: * is in the specified range. The range must be half-open, that is the predicate will be equivalent to least <= attr < most. Chris@16: */ Chris@16: template< typename DescriptorT, template< typename > class ActorT, typename BoundaryT > Chris@16: BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< attribute_is_in_range< typename DescriptorT::value_type, typename boost::log::aux::make_embedded_string_type< BoundaryT >::type > > > Chris@16: is_in_range(attribute_keyword< DescriptorT, ActorT > const&, BoundaryT const& least, BoundaryT const& most) Chris@16: { Chris@16: typedef typename boost::log::aux::make_embedded_string_type< BoundaryT >::type boundary_type; Chris@16: typedef aux::unary_function_terminal< attribute_is_in_range< typename DescriptorT::value_type, boundary_type > > terminal_type; Chris@16: ActorT< terminal_type > act = {{ terminal_type(DescriptorT::get_name(), std::pair< boundary_type, boundary_type >(least, most)) }}; 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: * is in the specified range. The range must be half-open, that is the predicate will be equivalent to least <= attr < most. Chris@16: */ Chris@16: template< typename T, typename BoundaryT > Chris@16: BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< attribute_is_in_range< T, typename boost::log::aux::make_embedded_string_type< BoundaryT >::type > > > Chris@16: is_in_range(attribute_name const& name, BoundaryT const& least, BoundaryT const& most) Chris@16: { Chris@16: typedef typename boost::log::aux::make_embedded_string_type< BoundaryT >::type boundary_type; Chris@16: typedef aux::unary_function_terminal< attribute_is_in_range< T, boundary_type > > terminal_type; Chris@16: phoenix::actor< terminal_type > act = {{ terminal_type(name, std::pair< boundary_type, boundary_type >(least, most)) }}; 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_IS_IN_RANGE_HPP_INCLUDED_