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 has_attr.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 23.07.2012
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains implementation of a generic attribute presence checker in template expressions.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/phoenix/core/actor.hpp>
|
Chris@16
|
19 #include <boost/log/detail/config.hpp>
|
Chris@16
|
20 #include <boost/log/core/record_view.hpp>
|
Chris@16
|
21 #include <boost/log/attributes/attribute_name.hpp>
|
Chris@16
|
22 #include <boost/log/attributes/attribute_value_set.hpp>
|
Chris@16
|
23 #include <boost/log/attributes/value_visitation.hpp>
|
Chris@16
|
24 #include <boost/log/expressions/keyword_fwd.hpp>
|
Chris@16
|
25 #include <boost/log/detail/unary_function_terminal.hpp>
|
Chris@16
|
26 #include <boost/log/utility/functional/nop.hpp>
|
Chris@16
|
27 #include <boost/log/detail/header.hpp>
|
Chris@16
|
28
|
Chris@16
|
29 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
30 #pragma once
|
Chris@16
|
31 #endif
|
Chris@16
|
32
|
Chris@16
|
33 namespace boost {
|
Chris@16
|
34
|
Chris@16
|
35 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
36
|
Chris@16
|
37 namespace expressions {
|
Chris@16
|
38
|
Chris@16
|
39 /*!
|
Chris@16
|
40 * An attribute value presence checker.
|
Chris@16
|
41 */
|
Chris@16
|
42 template< typename T >
|
Chris@16
|
43 class has_attribute
|
Chris@16
|
44 {
|
Chris@16
|
45 public:
|
Chris@16
|
46 //! Function result_type
|
Chris@16
|
47 typedef bool result_type;
|
Chris@16
|
48 //! Expected attribute value type
|
Chris@16
|
49 typedef T value_type;
|
Chris@16
|
50
|
Chris@16
|
51 private:
|
Chris@16
|
52 //! Attribute value name
|
Chris@16
|
53 const attribute_name m_name;
|
Chris@16
|
54 //! Visitor invoker
|
Chris@16
|
55 value_visitor_invoker< value_type > m_visitor_invoker;
|
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 */
|
Chris@16
|
63 explicit has_attribute(attribute_name const& name) : m_name(name)
|
Chris@16
|
64 {
|
Chris@16
|
65 }
|
Chris@16
|
66
|
Chris@16
|
67 /*!
|
Chris@16
|
68 * Checking operator
|
Chris@16
|
69 *
|
Chris@16
|
70 * \param arg A set of attribute values or a log record
|
Chris@16
|
71 * \return \c true if the log record contains the sought attribute value, \c false otherwise
|
Chris@16
|
72 */
|
Chris@16
|
73 template< typename ArgT >
|
Chris@16
|
74 result_type operator() (ArgT const& arg) const
|
Chris@16
|
75 {
|
Chris@16
|
76 return m_visitor_invoker(m_name, arg, nop()).code() == visitation_result::ok;
|
Chris@16
|
77 }
|
Chris@16
|
78 };
|
Chris@16
|
79
|
Chris@16
|
80 /*!
|
Chris@16
|
81 * An attribute value presence checker. This specialization does not check the type of the attribute value.
|
Chris@16
|
82 */
|
Chris@16
|
83 template< >
|
Chris@16
|
84 class has_attribute< void >
|
Chris@16
|
85 {
|
Chris@16
|
86 public:
|
Chris@16
|
87 //! Function result_type
|
Chris@16
|
88 typedef bool result_type;
|
Chris@16
|
89 //! Expected attribute value type
|
Chris@16
|
90 typedef void value_type;
|
Chris@16
|
91
|
Chris@16
|
92 private:
|
Chris@16
|
93 //! Attribute name
|
Chris@16
|
94 const attribute_name m_name;
|
Chris@16
|
95
|
Chris@16
|
96 public:
|
Chris@16
|
97 /*!
|
Chris@16
|
98 * Initializing constructor
|
Chris@16
|
99 *
|
Chris@16
|
100 * \param name Attribute name
|
Chris@16
|
101 */
|
Chris@16
|
102 explicit has_attribute(attribute_name const& name) : m_name(name)
|
Chris@16
|
103 {
|
Chris@16
|
104 }
|
Chris@16
|
105
|
Chris@16
|
106 /*!
|
Chris@16
|
107 * Checking operator
|
Chris@16
|
108 *
|
Chris@16
|
109 * \param attrs A set of attribute values
|
Chris@16
|
110 * \return \c true if the log record contains the sought attribute value, \c false otherwise
|
Chris@16
|
111 */
|
Chris@16
|
112 result_type operator() (attribute_value_set const& attrs) const
|
Chris@16
|
113 {
|
Chris@16
|
114 return attrs.find(m_name) != attrs.end();
|
Chris@16
|
115 }
|
Chris@16
|
116
|
Chris@16
|
117 /*!
|
Chris@16
|
118 * Checking operator
|
Chris@16
|
119 *
|
Chris@16
|
120 * \param rec A log record
|
Chris@16
|
121 * \return \c true if the log record contains the sought attribute value, \c false otherwise
|
Chris@16
|
122 */
|
Chris@16
|
123 result_type operator() (boost::log::record_view const& rec) const
|
Chris@16
|
124 {
|
Chris@16
|
125 return operator()(rec.attribute_values());
|
Chris@16
|
126 }
|
Chris@16
|
127 };
|
Chris@16
|
128
|
Chris@16
|
129 /*!
|
Chris@16
|
130 * The function generates a terminal node in a template expression. The node will check for the attribute value
|
Chris@16
|
131 * presence in a log record. The node will also check that the attribute value has the specified type, if present.
|
Chris@16
|
132 */
|
Chris@16
|
133 template< typename AttributeValueT >
|
Chris@16
|
134 BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< has_attribute< AttributeValueT > > > has_attr(attribute_name const& name)
|
Chris@16
|
135 {
|
Chris@16
|
136 typedef aux::unary_function_terminal< has_attribute< AttributeValueT > > terminal_type;
|
Chris@16
|
137 phoenix::actor< terminal_type > act = {{ terminal_type(name) }};
|
Chris@16
|
138 return act;
|
Chris@16
|
139 }
|
Chris@16
|
140
|
Chris@16
|
141 /*!
|
Chris@16
|
142 * The function generates a terminal node in a template expression. The node will check for the attribute value
|
Chris@16
|
143 * presence in a log record.
|
Chris@16
|
144 */
|
Chris@16
|
145 BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< has_attribute< void > > > has_attr(attribute_name const& name)
|
Chris@16
|
146 {
|
Chris@16
|
147 typedef aux::unary_function_terminal< has_attribute< void > > terminal_type;
|
Chris@16
|
148 phoenix::actor< terminal_type > act = {{ terminal_type(name) }};
|
Chris@16
|
149 return act;
|
Chris@16
|
150 }
|
Chris@16
|
151
|
Chris@16
|
152 /*!
|
Chris@16
|
153 * The function generates a terminal node in a template expression. The node will check for the attribute value
|
Chris@16
|
154 * presence in a log record. The node will also check that the attribute value has the specified type, if present.
|
Chris@16
|
155 */
|
Chris@16
|
156 template< typename DescriptorT, template< typename > class ActorT >
|
Chris@16
|
157 BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< has_attribute< typename DescriptorT::value_type > > > has_attr(attribute_keyword< DescriptorT, ActorT > const&)
|
Chris@16
|
158 {
|
Chris@16
|
159 typedef aux::unary_function_terminal< has_attribute< typename DescriptorT::value_type > > terminal_type;
|
Chris@16
|
160 ActorT< terminal_type > act = {{ terminal_type(DescriptorT::get_name()) }};
|
Chris@16
|
161 return act;
|
Chris@16
|
162 }
|
Chris@16
|
163
|
Chris@16
|
164 } // namespace expressions
|
Chris@16
|
165
|
Chris@16
|
166 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
167
|
Chris@16
|
168 } // namespace boost
|
Chris@16
|
169
|
Chris@16
|
170 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
171
|
Chris@16
|
172 #endif // BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_
|