Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file is_in_range.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 02.09.2012
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains implementation of an \c is_in_range predicate in template expressions.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_EXPRESSIONS_PREDICATES_IS_IN_RANGE_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_EXPRESSIONS_PREDICATES_IS_IN_RANGE_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <utility>
|
Chris@16
|
19 #include <boost/phoenix/core/actor.hpp>
|
Chris@16
|
20 #include <boost/log/detail/config.hpp>
|
Chris@16
|
21 #include <boost/log/detail/embedded_string_type.hpp>
|
Chris@16
|
22 #include <boost/log/detail/unary_function_terminal.hpp>
|
Chris@16
|
23 #include <boost/log/detail/attribute_predicate.hpp>
|
Chris@16
|
24 #include <boost/log/expressions/attr_fwd.hpp>
|
Chris@16
|
25 #include <boost/log/expressions/keyword_fwd.hpp>
|
Chris@16
|
26 #include <boost/log/attributes/attribute_name.hpp>
|
Chris@16
|
27 #include <boost/log/attributes/fallback_policy.hpp>
|
Chris@16
|
28 #include <boost/log/utility/functional/in_range.hpp>
|
Chris@16
|
29 #include <boost/log/detail/header.hpp>
|
Chris@16
|
30
|
Chris@16
|
31 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
32 #pragma once
|
Chris@16
|
33 #endif
|
Chris@16
|
34
|
Chris@16
|
35 namespace boost {
|
Chris@16
|
36
|
Chris@16
|
37 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
38
|
Chris@16
|
39 namespace expressions {
|
Chris@16
|
40
|
Chris@16
|
41 /*!
|
Chris@16
|
42 * The predicate checks if the attribute value contains a substring. The attribute value is assumed to be of a string type.
|
Chris@16
|
43 */
|
Chris@16
|
44 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
Chris@16
|
45
|
Chris@16
|
46 template< typename T, typename BoundaryT, typename FallbackPolicyT = fallback_to_none >
|
Chris@16
|
47 using attribute_is_in_range = aux::attribute_predicate< T, std::pair< BoundaryT, BoundaryT >, in_range_fun, FallbackPolicyT >;
|
Chris@16
|
48
|
Chris@16
|
49 #else // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
Chris@16
|
50
|
Chris@16
|
51 template< typename T, typename BoundaryT, typename FallbackPolicyT = fallback_to_none >
|
Chris@16
|
52 class attribute_is_in_range :
|
Chris@16
|
53 public aux::attribute_predicate< T, std::pair< BoundaryT, BoundaryT >, in_range_fun, FallbackPolicyT >
|
Chris@16
|
54 {
|
Chris@16
|
55 typedef aux::attribute_predicate< T, std::pair< BoundaryT, BoundaryT >, in_range_fun, FallbackPolicyT > base_type;
|
Chris@16
|
56
|
Chris@16
|
57 public:
|
Chris@16
|
58 /*!
|
Chris@16
|
59 * Initializing constructor
|
Chris@16
|
60 *
|
Chris@16
|
61 * \param name Attribute name
|
Chris@16
|
62 * \param boundaries The expected attribute value boundaries
|
Chris@16
|
63 */
|
Chris@16
|
64 attribute_is_in_range(attribute_name const& name, std::pair< BoundaryT, BoundaryT > const& boundaries) : base_type(name, boundaries)
|
Chris@16
|
65 {
|
Chris@16
|
66 }
|
Chris@16
|
67
|
Chris@16
|
68 /*!
|
Chris@16
|
69 * Initializing constructor
|
Chris@16
|
70 *
|
Chris@16
|
71 * \param name Attribute name
|
Chris@16
|
72 * \param boundaries The expected attribute value boundaries
|
Chris@16
|
73 * \param arg Additional parameter for the fallback policy
|
Chris@16
|
74 */
|
Chris@16
|
75 template< typename U >
|
Chris@16
|
76 attribute_is_in_range(attribute_name const& name, std::pair< BoundaryT, BoundaryT > const& boundaries, U const& arg) : base_type(name, boundaries, arg)
|
Chris@16
|
77 {
|
Chris@16
|
78 }
|
Chris@16
|
79 };
|
Chris@16
|
80
|
Chris@16
|
81 #endif // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
Chris@16
|
82
|
Chris@16
|
83 /*!
|
Chris@16
|
84 * The function generates a terminal node in a template expression. The node will check if the attribute value
|
Chris@16
|
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>.
|
Chris@16
|
86 */
|
Chris@16
|
87 template< typename T, typename FallbackPolicyT, typename TagT, template< typename > class ActorT, typename BoundaryT >
|
Chris@16
|
88 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
|
89 is_in_range(attribute_actor< T, FallbackPolicyT, TagT, ActorT > const& attr, BoundaryT const& least, BoundaryT const& most)
|
Chris@16
|
90 {
|
Chris@16
|
91 typedef typename boost::log::aux::make_embedded_string_type< BoundaryT >::type boundary_type;
|
Chris@16
|
92 typedef aux::unary_function_terminal< attribute_is_in_range< T, boundary_type, FallbackPolicyT > > terminal_type;
|
Chris@16
|
93 ActorT< terminal_type > act = {{ terminal_type(attr.get_name(), std::pair< boundary_type, boundary_type >(least, most), attr.get_fallback_policy()) }};
|
Chris@16
|
94 return act;
|
Chris@16
|
95 }
|
Chris@16
|
96
|
Chris@16
|
97 /*!
|
Chris@16
|
98 * The function generates a terminal node in a template expression. The node will check if the attribute value
|
Chris@16
|
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>.
|
Chris@16
|
100 */
|
Chris@16
|
101 template< typename DescriptorT, template< typename > class ActorT, typename BoundaryT >
|
Chris@16
|
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 > > >
|
Chris@16
|
103 is_in_range(attribute_keyword< DescriptorT, ActorT > const&, BoundaryT const& least, BoundaryT const& most)
|
Chris@16
|
104 {
|
Chris@16
|
105 typedef typename boost::log::aux::make_embedded_string_type< BoundaryT >::type boundary_type;
|
Chris@16
|
106 typedef aux::unary_function_terminal< attribute_is_in_range< typename DescriptorT::value_type, boundary_type > > terminal_type;
|
Chris@16
|
107 ActorT< terminal_type > act = {{ terminal_type(DescriptorT::get_name(), std::pair< boundary_type, boundary_type >(least, most)) }};
|
Chris@16
|
108 return act;
|
Chris@16
|
109 }
|
Chris@16
|
110
|
Chris@16
|
111 /*!
|
Chris@16
|
112 * The function generates a terminal node in a template expression. The node will check if the attribute value
|
Chris@16
|
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>.
|
Chris@16
|
114 */
|
Chris@16
|
115 template< typename T, typename BoundaryT >
|
Chris@16
|
116 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
|
117 is_in_range(attribute_name const& name, BoundaryT const& least, BoundaryT const& most)
|
Chris@16
|
118 {
|
Chris@16
|
119 typedef typename boost::log::aux::make_embedded_string_type< BoundaryT >::type boundary_type;
|
Chris@16
|
120 typedef aux::unary_function_terminal< attribute_is_in_range< T, boundary_type > > terminal_type;
|
Chris@16
|
121 phoenix::actor< terminal_type > act = {{ terminal_type(name, std::pair< boundary_type, boundary_type >(least, most)) }};
|
Chris@16
|
122 return act;
|
Chris@16
|
123 }
|
Chris@16
|
124
|
Chris@16
|
125 } // namespace expressions
|
Chris@16
|
126
|
Chris@16
|
127 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
128
|
Chris@16
|
129 } // namespace boost
|
Chris@16
|
130
|
Chris@16
|
131 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
132
|
Chris@16
|
133 #endif // BOOST_LOG_EXPRESSIONS_PREDICATES_IS_IN_RANGE_HPP_INCLUDED_
|