Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file attribute_predicate.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 02.09.2012
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains implementation of a generic predicate in template expressions.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_DETAIL_ATTRIBUTE_PREDICATE_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_DETAIL_ATTRIBUTE_PREDICATE_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/phoenix/core/actor.hpp>
|
Chris@16
|
19 #include <boost/utility/result_of.hpp>
|
Chris@16
|
20 #include <boost/log/detail/config.hpp>
|
Chris@16
|
21 #include <boost/log/attributes/attribute_name.hpp>
|
Chris@16
|
22 #include <boost/log/attributes/value_visitation.hpp>
|
Chris@16
|
23 #include <boost/log/attributes/fallback_policy.hpp>
|
Chris@16
|
24 #include <boost/log/utility/functional/bind.hpp>
|
Chris@16
|
25 #include <boost/log/utility/functional/save_result.hpp>
|
Chris@16
|
26 #include <boost/log/detail/header.hpp>
|
Chris@16
|
27
|
Chris@16
|
28 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
29 #pragma once
|
Chris@16
|
30 #endif
|
Chris@16
|
31
|
Chris@16
|
32 namespace boost {
|
Chris@16
|
33
|
Chris@16
|
34 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
35
|
Chris@16
|
36 namespace expressions {
|
Chris@16
|
37
|
Chris@16
|
38 namespace aux {
|
Chris@16
|
39
|
Chris@16
|
40 /*!
|
Chris@16
|
41 * The predicate checks if the attribute value satisfies a predicate.
|
Chris@16
|
42 */
|
Chris@16
|
43 template< typename T, typename ArgT, typename PredicateT, typename FallbackPolicyT = fallback_to_none >
|
Chris@16
|
44 class attribute_predicate
|
Chris@16
|
45 {
|
Chris@16
|
46 public:
|
Chris@16
|
47 //! Function result_type
|
Chris@16
|
48 typedef bool result_type;
|
Chris@16
|
49 //! Expected attribute value type
|
Chris@16
|
50 typedef T value_type;
|
Chris@16
|
51 //! Predicate type
|
Chris@16
|
52 typedef PredicateT predicate_type;
|
Chris@16
|
53 //! Argument type for the predicate
|
Chris@16
|
54 typedef ArgT argument_type;
|
Chris@16
|
55 //! Fallback policy
|
Chris@16
|
56 typedef FallbackPolicyT fallback_policy;
|
Chris@16
|
57
|
Chris@16
|
58 private:
|
Chris@16
|
59 //! Argument for the predicate
|
Chris@16
|
60 const argument_type m_arg;
|
Chris@16
|
61 //! Attribute value name
|
Chris@16
|
62 const attribute_name m_name;
|
Chris@16
|
63 //! Visitor invoker
|
Chris@16
|
64 value_visitor_invoker< value_type, fallback_policy > m_visitor_invoker;
|
Chris@16
|
65
|
Chris@16
|
66 public:
|
Chris@16
|
67 /*!
|
Chris@16
|
68 * Initializing constructor
|
Chris@16
|
69 *
|
Chris@16
|
70 * \param name Attribute name
|
Chris@16
|
71 * \param pred_arg The predicate argument
|
Chris@16
|
72 */
|
Chris@16
|
73 attribute_predicate(attribute_name const& name, argument_type const& pred_arg) : m_arg(pred_arg), m_name(name)
|
Chris@16
|
74 {
|
Chris@16
|
75 }
|
Chris@16
|
76
|
Chris@16
|
77 /*!
|
Chris@16
|
78 * Initializing constructor
|
Chris@16
|
79 *
|
Chris@16
|
80 * \param name Attribute name
|
Chris@16
|
81 * \param pred_arg The predicate argument
|
Chris@16
|
82 * \param arg Additional parameter for the fallback policy
|
Chris@16
|
83 */
|
Chris@16
|
84 template< typename U >
|
Chris@16
|
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)
|
Chris@16
|
86 {
|
Chris@16
|
87 }
|
Chris@16
|
88
|
Chris@16
|
89 /*!
|
Chris@16
|
90 * Checking operator
|
Chris@16
|
91 *
|
Chris@16
|
92 * \param arg A set of attribute values or a log record
|
Chris@16
|
93 * \return \c true if the log record contains the sought attribute value, \c false otherwise
|
Chris@16
|
94 */
|
Chris@16
|
95 template< typename ArgumentT >
|
Chris@16
|
96 result_type operator() (ArgumentT const& arg) const
|
Chris@16
|
97 {
|
Chris@16
|
98 typedef binder2nd< predicate_type, argument_type const& > visitor_type;
|
Chris@16
|
99
|
Chris@16
|
100 bool res = false;
|
Chris@16
|
101 m_visitor_invoker(m_name, arg, boost::log::save_result(visitor_type(predicate_type(), m_arg), res));
|
Chris@16
|
102 return res;
|
Chris@16
|
103 }
|
Chris@16
|
104 };
|
Chris@16
|
105
|
Chris@16
|
106 } // namespace aux
|
Chris@16
|
107
|
Chris@16
|
108 } // namespace expressions
|
Chris@16
|
109
|
Chris@16
|
110 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
111
|
Chris@16
|
112 } // namespace boost
|
Chris@16
|
113
|
Chris@16
|
114 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
115
|
Chris@16
|
116 #endif // BOOST_LOG_DETAIL_ATTRIBUTE_PREDICATE_HPP_INCLUDED_
|