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   is_in_range.hpp
0009  * \author Andrey Semashev
0010  * \date   02.09.2012
0011  *
0012  * The header contains implementation of an \c is_in_range predicate in template expressions.
0013  */
0014 
0015 #ifndef BOOST_LOG_EXPRESSIONS_PREDICATES_IS_IN_RANGE_HPP_INCLUDED_
0016 #define BOOST_LOG_EXPRESSIONS_PREDICATES_IS_IN_RANGE_HPP_INCLUDED_
0017 
0018 #include <utility>
0019 #include <boost/phoenix/core/actor.hpp>
0020 #include <boost/log/detail/config.hpp>
0021 #include <boost/log/detail/embedded_string_type.hpp>
0022 #include <boost/log/detail/unary_function_terminal.hpp>
0023 #include <boost/log/detail/attribute_predicate.hpp>
0024 #include <boost/log/expressions/attr_fwd.hpp>
0025 #include <boost/log/expressions/keyword_fwd.hpp>
0026 #include <boost/log/attributes/attribute_name.hpp>
0027 #include <boost/log/attributes/fallback_policy.hpp>
0028 #include <boost/log/utility/functional/in_range.hpp>
0029 #include <boost/log/detail/header.hpp>
0030 
0031 #ifdef BOOST_HAS_PRAGMA_ONCE
0032 #pragma once
0033 #endif
0034 
0035 namespace boost {
0036 
0037 BOOST_LOG_OPEN_NAMESPACE
0038 
0039 namespace expressions {
0040 
0041 /*!
0042  * The predicate checks if the attribute value contains a substring. The attribute value is assumed to be of a string type.
0043  */
0044 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
0045 
0046 template< typename T, typename BoundaryT, typename FallbackPolicyT = fallback_to_none >
0047 using attribute_is_in_range = aux::attribute_predicate< T, std::pair< BoundaryT, BoundaryT >, in_range_fun, FallbackPolicyT >;
0048 
0049 #else // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
0050 
0051 template< typename T, typename BoundaryT, typename FallbackPolicyT = fallback_to_none >
0052 class attribute_is_in_range :
0053     public aux::attribute_predicate< T, std::pair< BoundaryT, BoundaryT >, in_range_fun, FallbackPolicyT >
0054 {
0055     typedef aux::attribute_predicate< T, std::pair< BoundaryT, BoundaryT >, in_range_fun, FallbackPolicyT > base_type;
0056 
0057 public:
0058     /*!
0059      * Initializing constructor
0060      *
0061      * \param name Attribute name
0062      * \param boundaries The expected attribute value boundaries
0063      */
0064     attribute_is_in_range(attribute_name const& name, std::pair< BoundaryT, BoundaryT > const& boundaries) : base_type(name, boundaries)
0065     {
0066     }
0067 
0068     /*!
0069      * Initializing constructor
0070      *
0071      * \param name Attribute name
0072      * \param boundaries The expected attribute value boundaries
0073      * \param arg Additional parameter for the fallback policy
0074      */
0075     template< typename U >
0076     attribute_is_in_range(attribute_name const& name, std::pair< BoundaryT, BoundaryT > const& boundaries, U const& arg) : base_type(name, boundaries, arg)
0077     {
0078     }
0079 };
0080 
0081 #endif // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
0082 
0083 /*!
0084  * The function generates a terminal node in a template expression. The node will check if the attribute value
0085  * is in the specified range. The range must be half-open, that is the predicate will be equivalent to <tt>least <= attr < most</tt>.
0086  */
0087 template< typename T, typename FallbackPolicyT, typename TagT, template< typename > class ActorT, typename BoundaryT >
0088 BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< attribute_is_in_range< T, typename boost::log::aux::make_embedded_string_type< BoundaryT >::type, FallbackPolicyT > > >
0089 is_in_range(attribute_actor< T, FallbackPolicyT, TagT, ActorT > const& attr, BoundaryT const& least, BoundaryT const& most)
0090 {
0091     typedef typename boost::log::aux::make_embedded_string_type< BoundaryT >::type boundary_type;
0092     typedef aux::unary_function_terminal< attribute_is_in_range< T, boundary_type, FallbackPolicyT > > terminal_type;
0093     ActorT< terminal_type > act = {{ terminal_type(attr.get_name(), std::pair< boundary_type, boundary_type >(least, most), attr.get_fallback_policy()) }};
0094     return act;
0095 }
0096 
0097 /*!
0098  * The function generates a terminal node in a template expression. The node will check if the attribute value
0099  * is in the specified range. The range must be half-open, that is the predicate will be equivalent to <tt>least <= attr < most</tt>.
0100  */
0101 template< typename DescriptorT, template< typename > class ActorT, typename BoundaryT >
0102 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 > > >
0103 is_in_range(attribute_keyword< DescriptorT, ActorT > const&, BoundaryT const& least, BoundaryT const& most)
0104 {
0105     typedef typename boost::log::aux::make_embedded_string_type< BoundaryT >::type boundary_type;
0106     typedef aux::unary_function_terminal< attribute_is_in_range< typename DescriptorT::value_type, boundary_type > > terminal_type;
0107     ActorT< terminal_type > act = {{ terminal_type(DescriptorT::get_name(), std::pair< boundary_type, boundary_type >(least, most)) }};
0108     return act;
0109 }
0110 
0111 /*!
0112  * The function generates a terminal node in a template expression. The node will check if the attribute value
0113  * is in the specified range. The range must be half-open, that is the predicate will be equivalent to <tt>least <= attr < most</tt>.
0114  */
0115 template< typename T, typename BoundaryT >
0116 BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< attribute_is_in_range< T, typename boost::log::aux::make_embedded_string_type< BoundaryT >::type > > >
0117 is_in_range(attribute_name const& name, BoundaryT const& least, BoundaryT const& most)
0118 {
0119     typedef typename boost::log::aux::make_embedded_string_type< BoundaryT >::type boundary_type;
0120     typedef aux::unary_function_terminal< attribute_is_in_range< T, boundary_type > > terminal_type;
0121     phoenix::actor< terminal_type > act = {{ terminal_type(name, std::pair< boundary_type, boundary_type >(least, most)) }};
0122     return act;
0123 }
0124 
0125 } // namespace expressions
0126 
0127 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0128 
0129 } // namespace boost
0130 
0131 #include <boost/log/detail/footer.hpp>
0132 
0133 #endif // BOOST_LOG_EXPRESSIONS_PREDICATES_IS_IN_RANGE_HPP_INCLUDED_