]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/log/include/boost/log/expressions/predicates/has_attr.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / log / include / boost / log / expressions / predicates / has_attr.hpp
CommitLineData
7c673cae
FG
1/*
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)
6 */
7/*!
8 * \file has_attr.hpp
9 * \author Andrey Semashev
10 * \date 23.07.2012
11 *
12 * The header contains implementation of a generic attribute presence checker in template expressions.
13 */
14
15#ifndef BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_
16#define BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_
17
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>
28
29#ifdef BOOST_HAS_PRAGMA_ONCE
30#pragma once
31#endif
32
33namespace boost {
34
35BOOST_LOG_OPEN_NAMESPACE
36
37namespace expressions {
38
39/*!
40 * An attribute value presence checker.
41 */
42template< typename T >
43class has_attribute
44{
45public:
46 //! Function result_type
47 typedef bool result_type;
48 //! Expected attribute value type
49 typedef T value_type;
50
51private:
52 //! Attribute value name
53 const attribute_name m_name;
54 //! Visitor invoker
55 value_visitor_invoker< value_type > m_visitor_invoker;
56
57public:
58 /*!
59 * Initializing constructor
60 *
61 * \param name Attribute name
62 */
63 explicit has_attribute(attribute_name const& name) : m_name(name)
64 {
65 }
66
67 /*!
68 * Checking operator
69 *
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
72 */
73 template< typename ArgT >
74 result_type operator() (ArgT const& arg) const
75 {
76 return m_visitor_invoker(m_name, arg, nop()).code() == visitation_result::ok;
77 }
78};
79
80/*!
81 * An attribute value presence checker. This specialization does not check the type of the attribute value.
82 */
83template< >
84class has_attribute< void >
85{
86public:
87 //! Function result_type
88 typedef bool result_type;
89 //! Expected attribute value type
90 typedef void value_type;
91
92private:
93 //! Attribute name
94 const attribute_name m_name;
95
96public:
97 /*!
98 * Initializing constructor
99 *
100 * \param name Attribute name
101 */
102 explicit has_attribute(attribute_name const& name) : m_name(name)
103 {
104 }
105
106 /*!
107 * Checking operator
108 *
109 * \param attrs A set of attribute values
110 * \return \c true if the log record contains the sought attribute value, \c false otherwise
111 */
112 result_type operator() (attribute_value_set const& attrs) const
113 {
114 return attrs.find(m_name) != attrs.end();
115 }
116
117 /*!
118 * Checking operator
119 *
120 * \param rec A log record
121 * \return \c true if the log record contains the sought attribute value, \c false otherwise
122 */
123 result_type operator() (boost::log::record_view const& rec) const
124 {
125 return operator()(rec.attribute_values());
126 }
127};
128
129/*!
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.
132 */
133template< typename AttributeValueT >
134BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< has_attribute< AttributeValueT > > > has_attr(attribute_name const& name)
135{
136 typedef aux::unary_function_terminal< has_attribute< AttributeValueT > > terminal_type;
137 phoenix::actor< terminal_type > act = {{ terminal_type(name) }};
138 return act;
139}
140
141/*!
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.
144 */
145BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< has_attribute< void > > > has_attr(attribute_name const& name)
146{
147 typedef aux::unary_function_terminal< has_attribute< void > > terminal_type;
148 phoenix::actor< terminal_type > act = {{ terminal_type(name) }};
149 return act;
150}
151
152/*!
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.
155 */
156template< typename DescriptorT, template< typename > class ActorT >
157BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< has_attribute< typename DescriptorT::value_type > > > has_attr(attribute_keyword< DescriptorT, ActorT > const&)
158{
159 typedef aux::unary_function_terminal< has_attribute< typename DescriptorT::value_type > > terminal_type;
160 ActorT< terminal_type > act = {{ terminal_type(DescriptorT::get_name()) }};
161 return act;
162}
163
164} // namespace expressions
165
166BOOST_LOG_CLOSE_NAMESPACE // namespace log
167
168} // namespace boost
169
170#include <boost/log/detail/footer.hpp>
171
172#endif // BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_