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)
8 * \file attribute_predicate.hpp
9 * \author Andrey Semashev
12 * The header contains implementation of a generic predicate in template expressions.
15 #ifndef BOOST_LOG_DETAIL_ATTRIBUTE_PREDICATE_HPP_INCLUDED_
16 #define BOOST_LOG_DETAIL_ATTRIBUTE_PREDICATE_HPP_INCLUDED_
18 #include <boost/phoenix/core/actor.hpp>
19 #include <boost/utility/result_of.hpp>
20 #include <boost/log/detail/config.hpp>
21 #include <boost/log/attributes/attribute_name.hpp>
22 #include <boost/log/attributes/value_visitation.hpp>
23 #include <boost/log/attributes/fallback_policy.hpp>
24 #include <boost/log/utility/functional/bind.hpp>
25 #include <boost/log/utility/functional/save_result.hpp>
26 #include <boost/log/detail/header.hpp>
28 #ifdef BOOST_HAS_PRAGMA_ONCE
34 BOOST_LOG_OPEN_NAMESPACE
36 namespace expressions {
41 * The predicate checks if the attribute value satisfies a predicate.
43 template< typename T, typename ArgT, typename PredicateT, typename FallbackPolicyT = fallback_to_none >
44 class attribute_predicate
47 //! Function result_type
48 typedef bool result_type;
49 //! Expected attribute value type
52 typedef PredicateT predicate_type;
53 //! Argument type for the predicate
54 typedef ArgT argument_type;
56 typedef FallbackPolicyT fallback_policy;
59 //! Argument for the predicate
60 const argument_type m_arg;
61 //! Attribute value name
62 const attribute_name m_name;
64 value_visitor_invoker< value_type, fallback_policy > m_visitor_invoker;
68 * Initializing constructor
70 * \param name Attribute name
71 * \param pred_arg The predicate argument
73 attribute_predicate(attribute_name const& name, argument_type const& pred_arg) : m_arg(pred_arg), m_name(name)
78 * Initializing constructor
80 * \param name Attribute name
81 * \param pred_arg The predicate argument
82 * \param arg Additional parameter for the fallback policy
84 template< typename U >
85 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)
92 * \param arg A set of attribute values or a log record
93 * \return \c true if the log record contains the sought attribute value, \c false otherwise
95 template< typename ArgumentT >
96 result_type operator() (ArgumentT const& arg) const
98 typedef binder2nd< predicate_type, argument_type const& > visitor_type;
101 m_visitor_invoker(m_name, arg, boost::log::save_result(visitor_type(predicate_type(), m_arg), res));
108 } // namespace expressions
110 BOOST_LOG_CLOSE_NAMESPACE // namespace log
114 #include <boost/log/detail/footer.hpp>
116 #endif // BOOST_LOG_DETAIL_ATTRIBUTE_PREDICATE_HPP_INCLUDED_