Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:23

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   has_attr.hpp
0009  * \author Andrey Semashev
0010  * \date   23.07.2012
0011  *
0012  * The header contains implementation of a generic attribute presence checker in template expressions.
0013  */
0014 
0015 #ifndef BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_
0016 #define BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_
0017 
0018 #include <boost/phoenix/core/actor.hpp>
0019 #include <boost/log/detail/config.hpp>
0020 #include <boost/log/core/record_view.hpp>
0021 #include <boost/log/attributes/attribute_name.hpp>
0022 #include <boost/log/attributes/attribute_value_set.hpp>
0023 #include <boost/log/attributes/value_visitation.hpp>
0024 #include <boost/log/expressions/keyword_fwd.hpp>
0025 #include <boost/log/detail/unary_function_terminal.hpp>
0026 #include <boost/log/utility/functional/nop.hpp>
0027 #include <boost/log/detail/header.hpp>
0028 
0029 #ifdef BOOST_HAS_PRAGMA_ONCE
0030 #pragma once
0031 #endif
0032 
0033 namespace boost {
0034 
0035 BOOST_LOG_OPEN_NAMESPACE
0036 
0037 namespace expressions {
0038 
0039 /*!
0040  * An attribute value presence checker.
0041  */
0042 template< typename T >
0043 class has_attribute
0044 {
0045 public:
0046     //! Function result_type
0047     typedef bool result_type;
0048     //! Expected attribute value type
0049     typedef T value_type;
0050 
0051 private:
0052     //! Attribute value name
0053     const attribute_name m_name;
0054     //! Visitor invoker
0055     value_visitor_invoker< value_type > m_visitor_invoker;
0056 
0057 public:
0058     /*!
0059      * Initializing constructor
0060      *
0061      * \param name Attribute name
0062      */
0063     explicit has_attribute(attribute_name const& name) : m_name(name)
0064     {
0065     }
0066 
0067     /*!
0068      * Checking operator
0069      *
0070      * \param arg A set of attribute values or a log record
0071      * \return \c true if the log record contains the sought attribute value, \c false otherwise
0072      */
0073     template< typename ArgT >
0074     result_type operator() (ArgT const& arg) const
0075     {
0076         return m_visitor_invoker(m_name, arg, nop()).code() == visitation_result::ok;
0077     }
0078 };
0079 
0080 /*!
0081  * An attribute value presence checker. This specialization does not check the type of the attribute value.
0082  */
0083 template< >
0084 class has_attribute< void >
0085 {
0086 public:
0087     //! Function result_type
0088     typedef bool result_type;
0089     //! Expected attribute value type
0090     typedef void value_type;
0091 
0092 private:
0093     //! Attribute name
0094     const attribute_name m_name;
0095 
0096 public:
0097     /*!
0098      * Initializing constructor
0099      *
0100      * \param name Attribute name
0101      */
0102     explicit has_attribute(attribute_name const& name) : m_name(name)
0103     {
0104     }
0105 
0106     /*!
0107      * Checking operator
0108      *
0109      * \param attrs A set of attribute values
0110      * \return \c true if the log record contains the sought attribute value, \c false otherwise
0111      */
0112     result_type operator() (attribute_value_set const& attrs) const
0113     {
0114         return attrs.find(m_name) != attrs.end();
0115     }
0116 
0117     /*!
0118      * Checking operator
0119      *
0120      * \param rec A log record
0121      * \return \c true if the log record contains the sought attribute value, \c false otherwise
0122      */
0123     result_type operator() (boost::log::record_view const& rec) const
0124     {
0125         return operator()(rec.attribute_values());
0126     }
0127 };
0128 
0129 /*!
0130  * The function generates a terminal node in a template expression. The node will check for the attribute value
0131  * presence in a log record. The node will also check that the attribute value has the specified type, if present.
0132  */
0133 template< typename AttributeValueT >
0134 BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< has_attribute< AttributeValueT > > > has_attr(attribute_name const& name)
0135 {
0136     typedef aux::unary_function_terminal< has_attribute< AttributeValueT > > terminal_type;
0137     phoenix::actor< terminal_type > act = {{ terminal_type(name) }};
0138     return act;
0139 }
0140 
0141 /*!
0142  * The function generates a terminal node in a template expression. The node will check for the attribute value
0143  * presence in a log record.
0144  */
0145 BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< has_attribute< void > > > has_attr(attribute_name const& name)
0146 {
0147     typedef aux::unary_function_terminal< has_attribute< void > > terminal_type;
0148     phoenix::actor< terminal_type > act = {{ terminal_type(name) }};
0149     return act;
0150 }
0151 
0152 /*!
0153  * The function generates a terminal node in a template expression. The node will check for the attribute value
0154  * presence in a log record. The node will also check that the attribute value has the specified type, if present.
0155  */
0156 template< typename DescriptorT, template< typename > class ActorT >
0157 BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< has_attribute< typename DescriptorT::value_type > > > has_attr(attribute_keyword< DescriptorT, ActorT > const&)
0158 {
0159     typedef aux::unary_function_terminal< has_attribute< typename DescriptorT::value_type > > terminal_type;
0160     ActorT< terminal_type > act = {{ terminal_type(DescriptorT::get_name()) }};
0161     return act;
0162 }
0163 
0164 } // namespace expressions
0165 
0166 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0167 
0168 } // namespace boost
0169 
0170 #include <boost/log/detail/footer.hpp>
0171 
0172 #endif // BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_