Chris@16: /* Chris@101: * Copyright Andrey Semashev 2007 - 2015. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: /*! Chris@16: * \file has_attr.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 23.07.2012 Chris@16: * Chris@16: * The header contains implementation of a generic attribute presence checker in template expressions. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: BOOST_LOG_OPEN_NAMESPACE Chris@16: Chris@16: namespace expressions { Chris@16: Chris@16: /*! Chris@16: * An attribute value presence checker. Chris@16: */ Chris@16: template< typename T > Chris@16: class has_attribute Chris@16: { Chris@16: public: Chris@16: //! Function result_type Chris@16: typedef bool result_type; Chris@16: //! Expected attribute value type Chris@16: typedef T value_type; Chris@16: Chris@16: private: Chris@16: //! Attribute value name Chris@16: const attribute_name m_name; Chris@16: //! Visitor invoker Chris@16: value_visitor_invoker< value_type > m_visitor_invoker; Chris@16: Chris@16: public: Chris@16: /*! Chris@16: * Initializing constructor Chris@16: * Chris@16: * \param name Attribute name Chris@16: */ Chris@16: explicit has_attribute(attribute_name const& name) : m_name(name) Chris@16: { Chris@16: } Chris@16: Chris@16: /*! Chris@16: * Checking operator Chris@16: * Chris@16: * \param arg A set of attribute values or a log record Chris@16: * \return \c true if the log record contains the sought attribute value, \c false otherwise Chris@16: */ Chris@16: template< typename ArgT > Chris@16: result_type operator() (ArgT const& arg) const Chris@16: { Chris@16: return m_visitor_invoker(m_name, arg, nop()).code() == visitation_result::ok; Chris@16: } Chris@16: }; Chris@16: Chris@16: /*! Chris@16: * An attribute value presence checker. This specialization does not check the type of the attribute value. Chris@16: */ Chris@16: template< > Chris@16: class has_attribute< void > Chris@16: { Chris@16: public: Chris@16: //! Function result_type Chris@16: typedef bool result_type; Chris@16: //! Expected attribute value type Chris@16: typedef void value_type; Chris@16: Chris@16: private: Chris@16: //! Attribute name Chris@16: const attribute_name m_name; Chris@16: Chris@16: public: Chris@16: /*! Chris@16: * Initializing constructor Chris@16: * Chris@16: * \param name Attribute name Chris@16: */ Chris@16: explicit has_attribute(attribute_name const& name) : m_name(name) Chris@16: { Chris@16: } Chris@16: Chris@16: /*! Chris@16: * Checking operator Chris@16: * Chris@16: * \param attrs A set of attribute values Chris@16: * \return \c true if the log record contains the sought attribute value, \c false otherwise Chris@16: */ Chris@16: result_type operator() (attribute_value_set const& attrs) const Chris@16: { Chris@16: return attrs.find(m_name) != attrs.end(); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * Checking operator Chris@16: * Chris@16: * \param rec A log record Chris@16: * \return \c true if the log record contains the sought attribute value, \c false otherwise Chris@16: */ Chris@16: result_type operator() (boost::log::record_view const& rec) const Chris@16: { Chris@16: return operator()(rec.attribute_values()); Chris@16: } Chris@16: }; Chris@16: Chris@16: /*! Chris@16: * The function generates a terminal node in a template expression. The node will check for the attribute value Chris@16: * presence in a log record. The node will also check that the attribute value has the specified type, if present. Chris@16: */ Chris@16: template< typename AttributeValueT > Chris@16: BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< has_attribute< AttributeValueT > > > has_attr(attribute_name const& name) Chris@16: { Chris@16: typedef aux::unary_function_terminal< has_attribute< AttributeValueT > > terminal_type; Chris@16: phoenix::actor< terminal_type > act = {{ terminal_type(name) }}; Chris@16: return act; Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function generates a terminal node in a template expression. The node will check for the attribute value Chris@16: * presence in a log record. Chris@16: */ Chris@16: BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< has_attribute< void > > > has_attr(attribute_name const& name) Chris@16: { Chris@16: typedef aux::unary_function_terminal< has_attribute< void > > terminal_type; Chris@16: phoenix::actor< terminal_type > act = {{ terminal_type(name) }}; Chris@16: return act; Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function generates a terminal node in a template expression. The node will check for the attribute value Chris@16: * presence in a log record. The node will also check that the attribute value has the specified type, if present. Chris@16: */ Chris@16: template< typename DescriptorT, template< typename > class ActorT > Chris@16: BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< has_attribute< typename DescriptorT::value_type > > > has_attr(attribute_keyword< DescriptorT, ActorT > const&) Chris@16: { Chris@16: typedef aux::unary_function_terminal< has_attribute< typename DescriptorT::value_type > > terminal_type; Chris@16: ActorT< terminal_type > act = {{ terminal_type(DescriptorT::get_name()) }}; Chris@16: return act; Chris@16: } Chris@16: Chris@16: } // namespace expressions Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_LOG_EXPRESSIONS_PREDICATES_HAS_ATTR_HPP_INCLUDED_