Back to home page

EIC code displayed by LXR

 
 

    


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

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   attribute_predicate.hpp
0009  * \author Andrey Semashev
0010  * \date   02.09.2012
0011  *
0012  * The header contains implementation of a generic predicate in template expressions.
0013  */
0014 
0015 #ifndef BOOST_LOG_DETAIL_ATTRIBUTE_PREDICATE_HPP_INCLUDED_
0016 #define BOOST_LOG_DETAIL_ATTRIBUTE_PREDICATE_HPP_INCLUDED_
0017 
0018 #include <boost/phoenix/core/actor.hpp>
0019 #include <boost/utility/result_of.hpp>
0020 #include <boost/log/detail/config.hpp>
0021 #include <boost/log/attributes/attribute_name.hpp>
0022 #include <boost/log/attributes/value_visitation.hpp>
0023 #include <boost/log/attributes/fallback_policy.hpp>
0024 #include <boost/log/utility/functional/bind.hpp>
0025 #include <boost/log/utility/functional/save_result.hpp>
0026 #include <boost/log/detail/header.hpp>
0027 
0028 #ifdef BOOST_HAS_PRAGMA_ONCE
0029 #pragma once
0030 #endif
0031 
0032 namespace boost {
0033 
0034 BOOST_LOG_OPEN_NAMESPACE
0035 
0036 namespace expressions {
0037 
0038 namespace aux {
0039 
0040 /*!
0041  * The predicate checks if the attribute value satisfies a predicate.
0042  */
0043 template< typename T, typename ArgT, typename PredicateT, typename FallbackPolicyT = fallback_to_none >
0044 class attribute_predicate
0045 {
0046 public:
0047     //! Function result_type
0048     typedef bool result_type;
0049     //! Expected attribute value type
0050     typedef T value_type;
0051     //! Predicate type
0052     typedef PredicateT predicate_type;
0053     //! Argument type for the predicate
0054     typedef ArgT argument_type;
0055     //! Fallback policy
0056     typedef FallbackPolicyT fallback_policy;
0057 
0058 private:
0059     //! Argument for the predicate
0060     const argument_type m_arg;
0061     //! Attribute value name
0062     const attribute_name m_name;
0063     //! Visitor invoker
0064     value_visitor_invoker< value_type, fallback_policy > m_visitor_invoker;
0065 
0066 public:
0067     /*!
0068      * Initializing constructor
0069      *
0070      * \param name Attribute name
0071      * \param pred_arg The predicate argument
0072      */
0073     attribute_predicate(attribute_name const& name, argument_type const& pred_arg) : m_arg(pred_arg), m_name(name)
0074     {
0075     }
0076 
0077     /*!
0078      * Initializing constructor
0079      *
0080      * \param name Attribute name
0081      * \param pred_arg The predicate argument
0082      * \param arg Additional parameter for the fallback policy
0083      */
0084     template< typename U >
0085     attribute_predicate(attribute_name const& name, argument_type const& pred_arg, U const& arg) : m_arg(pred_arg), m_name(name), m_visitor_invoker(arg)
0086     {
0087     }
0088 
0089     /*!
0090      * Checking operator
0091      *
0092      * \param arg A set of attribute values or a log record
0093      * \return \c true if the log record contains the sought attribute value, \c false otherwise
0094      */
0095     template< typename ArgumentT >
0096     result_type operator() (ArgumentT const& arg) const
0097     {
0098         typedef binder2nd< predicate_type, argument_type const& > visitor_type;
0099 
0100         bool res = false;
0101         m_visitor_invoker(m_name, arg, boost::log::save_result(visitor_type(predicate_type(), m_arg), res));
0102         return res;
0103     }
0104 };
0105 
0106 } // namespace aux
0107 
0108 } // namespace expressions
0109 
0110 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0111 
0112 } // namespace boost
0113 
0114 #include <boost/log/detail/footer.hpp>
0115 
0116 #endif // BOOST_LOG_DETAIL_ATTRIBUTE_PREDICATE_HPP_INCLUDED_