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)
8 * \file is_in_range.hpp
9 * \author Andrey Semashev
12 * The header contains implementation of an \c is_in_range predicate in template expressions.
15 #ifndef BOOST_LOG_EXPRESSIONS_PREDICATES_IS_IN_RANGE_HPP_INCLUDED_
16 #define BOOST_LOG_EXPRESSIONS_PREDICATES_IS_IN_RANGE_HPP_INCLUDED_
19 #include <boost/phoenix/core/actor.hpp>
20 #include <boost/log/detail/config.hpp>
21 #include <boost/log/detail/embedded_string_type.hpp>
22 #include <boost/log/detail/unary_function_terminal.hpp>
23 #include <boost/log/detail/attribute_predicate.hpp>
24 #include <boost/log/expressions/attr_fwd.hpp>
25 #include <boost/log/expressions/keyword_fwd.hpp>
26 #include <boost/log/attributes/attribute_name.hpp>
27 #include <boost/log/attributes/fallback_policy.hpp>
28 #include <boost/log/utility/functional/in_range.hpp>
29 #include <boost/log/detail/header.hpp>
31 #ifdef BOOST_HAS_PRAGMA_ONCE
37 BOOST_LOG_OPEN_NAMESPACE
39 namespace expressions {
42 * The predicate checks if the attribute value contains a substring. The attribute value is assumed to be of a string type.
44 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
46 template< typename T, typename BoundaryT, typename FallbackPolicyT = fallback_to_none >
47 using attribute_is_in_range = aux::attribute_predicate< T, std::pair< BoundaryT, BoundaryT >, in_range_fun, FallbackPolicyT >;
49 #else // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
51 template< typename T, typename BoundaryT, typename FallbackPolicyT = fallback_to_none >
52 class attribute_is_in_range :
53 public aux::attribute_predicate< T, std::pair< BoundaryT, BoundaryT >, in_range_fun, FallbackPolicyT >
55 typedef aux::attribute_predicate< T, std::pair< BoundaryT, BoundaryT >, in_range_fun, FallbackPolicyT > base_type;
59 * Initializing constructor
61 * \param name Attribute name
62 * \param boundaries The expected attribute value boundaries
64 attribute_is_in_range(attribute_name const& name, std::pair< BoundaryT, BoundaryT > const& boundaries) : base_type(name, boundaries)
69 * Initializing constructor
71 * \param name Attribute name
72 * \param boundaries The expected attribute value boundaries
73 * \param arg Additional parameter for the fallback policy
75 template< typename U >
76 attribute_is_in_range(attribute_name const& name, std::pair< BoundaryT, BoundaryT > const& boundaries, U const& arg) : base_type(name, boundaries, arg)
81 #endif // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
84 * The function generates a terminal node in a template expression. The node will check if the attribute value
85 * is in the specified range. The range must be half-open, that is the predicate will be equivalent to <tt>least <= attr < most</tt>.
87 template< typename T, typename FallbackPolicyT, typename TagT, template< typename > class ActorT, typename BoundaryT >
88 BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< attribute_is_in_range< T, typename boost::log::aux::make_embedded_string_type< BoundaryT >::type, FallbackPolicyT > > >
89 is_in_range(attribute_actor< T, FallbackPolicyT, TagT, ActorT > const& attr, BoundaryT const& least, BoundaryT const& most)
91 typedef typename boost::log::aux::make_embedded_string_type< BoundaryT >::type boundary_type;
92 typedef aux::unary_function_terminal< attribute_is_in_range< T, boundary_type, FallbackPolicyT > > terminal_type;
93 ActorT< terminal_type > act = {{ terminal_type(attr.get_name(), std::pair< boundary_type, boundary_type >(least, most), attr.get_fallback_policy()) }};
98 * The function generates a terminal node in a template expression. The node will check if the attribute value
99 * is in the specified range. The range must be half-open, that is the predicate will be equivalent to <tt>least <= attr < most</tt>.
101 template< typename DescriptorT, template< typename > class ActorT, typename BoundaryT >
102 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 > > >
103 is_in_range(attribute_keyword< DescriptorT, ActorT > const&, BoundaryT const& least, BoundaryT const& most)
105 typedef typename boost::log::aux::make_embedded_string_type< BoundaryT >::type boundary_type;
106 typedef aux::unary_function_terminal< attribute_is_in_range< typename DescriptorT::value_type, boundary_type > > terminal_type;
107 ActorT< terminal_type > act = {{ terminal_type(DescriptorT::get_name(), std::pair< boundary_type, boundary_type >(least, most)) }};
112 * The function generates a terminal node in a template expression. The node will check if the attribute value
113 * is in the specified range. The range must be half-open, that is the predicate will be equivalent to <tt>least <= attr < most</tt>.
115 template< typename T, typename BoundaryT >
116 BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< attribute_is_in_range< T, typename boost::log::aux::make_embedded_string_type< BoundaryT >::type > > >
117 is_in_range(attribute_name const& name, BoundaryT const& least, BoundaryT const& most)
119 typedef typename boost::log::aux::make_embedded_string_type< BoundaryT >::type boundary_type;
120 typedef aux::unary_function_terminal< attribute_is_in_range< T, boundary_type > > terminal_type;
121 phoenix::actor< terminal_type > act = {{ terminal_type(name, std::pair< boundary_type, boundary_type >(least, most)) }};
125 } // namespace expressions
127 BOOST_LOG_CLOSE_NAMESPACE // namespace log
131 #include <boost/log/detail/footer.hpp>
133 #endif // BOOST_LOG_EXPRESSIONS_PREDICATES_IS_IN_RANGE_HPP_INCLUDED_