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)
9 * \author Andrey Semashev
12 * The header contains implementation of a generic attribute presence checker in template expressions.
15 #ifndef BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_
16 #define BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_
18 #include <boost/phoenix/core/actor.hpp>
19 #include <boost/log/detail/config.hpp>
20 #include <boost/log/core/record_view.hpp>
21 #include <boost/log/attributes/attribute_name.hpp>
22 #include <boost/log/attributes/attribute_value_set.hpp>
23 #include <boost/log/attributes/value_visitation.hpp>
24 #include <boost/log/expressions/keyword_fwd.hpp>
25 #include <boost/log/detail/unary_function_terminal.hpp>
26 #include <boost/log/utility/functional/nop.hpp>
27 #include <boost/log/detail/header.hpp>
29 #ifdef BOOST_HAS_PRAGMA_ONCE
35 BOOST_LOG_OPEN_NAMESPACE
37 namespace expressions {
40 * An attribute value presence checker.
42 template< typename T >
46 //! Function result_type
47 typedef bool result_type;
48 //! Expected attribute value type
52 //! Attribute value name
53 const attribute_name m_name;
55 value_visitor_invoker< value_type > m_visitor_invoker;
59 * Initializing constructor
61 * \param name Attribute name
63 explicit has_attribute(attribute_name const& name) : m_name(name)
70 * \param arg A set of attribute values or a log record
71 * \return \c true if the log record contains the sought attribute value, \c false otherwise
73 template< typename ArgT >
74 result_type operator() (ArgT const& arg) const
76 return m_visitor_invoker(m_name, arg, nop()).code() == visitation_result::ok;
81 * An attribute value presence checker. This specialization does not check the type of the attribute value.
84 class has_attribute< void >
87 //! Function result_type
88 typedef bool result_type;
89 //! Expected attribute value type
90 typedef void value_type;
94 const attribute_name m_name;
98 * Initializing constructor
100 * \param name Attribute name
102 explicit has_attribute(attribute_name const& name) : m_name(name)
109 * \param attrs A set of attribute values
110 * \return \c true if the log record contains the sought attribute value, \c false otherwise
112 result_type operator() (attribute_value_set const& attrs) const
114 return attrs.find(m_name) != attrs.end();
120 * \param rec A log record
121 * \return \c true if the log record contains the sought attribute value, \c false otherwise
123 result_type operator() (boost::log::record_view const& rec) const
125 return operator()(rec.attribute_values());
130 * The function generates a terminal node in a template expression. The node will check for the attribute value
131 * presence in a log record. The node will also check that the attribute value has the specified type, if present.
133 template< typename AttributeValueT >
134 BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< has_attribute< AttributeValueT > > > has_attr(attribute_name const& name)
136 typedef aux::unary_function_terminal< has_attribute< AttributeValueT > > terminal_type;
137 phoenix::actor< terminal_type > act = {{ terminal_type(name) }};
142 * The function generates a terminal node in a template expression. The node will check for the attribute value
143 * presence in a log record.
145 BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< has_attribute< void > > > has_attr(attribute_name const& name)
147 typedef aux::unary_function_terminal< has_attribute< void > > terminal_type;
148 phoenix::actor< terminal_type > act = {{ terminal_type(name) }};
153 * The function generates a terminal node in a template expression. The node will check for the attribute value
154 * presence in a log record. The node will also check that the attribute value has the specified type, if present.
156 template< typename DescriptorT, template< typename > class ActorT >
157 BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< has_attribute< typename DescriptorT::value_type > > > has_attr(attribute_keyword< DescriptorT, ActorT > const&)
159 typedef aux::unary_function_terminal< has_attribute< typename DescriptorT::value_type > > terminal_type;
160 ActorT< terminal_type > act = {{ terminal_type(DescriptorT::get_name()) }};
164 } // namespace expressions
166 BOOST_LOG_CLOSE_NAMESPACE // namespace log
170 #include <boost/log/detail/footer.hpp>
172 #endif // BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_