Chris@16
|
1 /*
|
Chris@16
|
2 * Copyright Andrey Semashev 2007 - 2013.
|
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 filter.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 13.07.2012
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains a filter function object definition.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_EXPRESSIONS_FILTER_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_EXPRESSIONS_FILTER_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/move/core.hpp>
|
Chris@16
|
19 #include <boost/move/utility.hpp>
|
Chris@16
|
20 #include <boost/utility/enable_if.hpp>
|
Chris@16
|
21 #include <boost/log/detail/config.hpp>
|
Chris@16
|
22 #include <boost/log/attributes/attribute_value_set.hpp>
|
Chris@16
|
23 #include <boost/log/detail/light_function.hpp>
|
Chris@16
|
24 #include <boost/log/detail/header.hpp>
|
Chris@16
|
25
|
Chris@16
|
26 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
27 #pragma once
|
Chris@16
|
28 #endif
|
Chris@16
|
29
|
Chris@16
|
30 namespace boost {
|
Chris@16
|
31
|
Chris@16
|
32 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
33
|
Chris@16
|
34 /*!
|
Chris@16
|
35 * Log record filter function wrapper.
|
Chris@16
|
36 */
|
Chris@16
|
37 class filter
|
Chris@16
|
38 {
|
Chris@16
|
39 BOOST_COPYABLE_AND_MOVABLE(filter)
|
Chris@16
|
40
|
Chris@16
|
41 public:
|
Chris@16
|
42 //! Result type
|
Chris@16
|
43 typedef bool result_type;
|
Chris@16
|
44
|
Chris@16
|
45 private:
|
Chris@16
|
46 //! Filter function type
|
Chris@16
|
47 typedef boost::log::aux::light_function< bool (attribute_value_set const&) > filter_type;
|
Chris@16
|
48
|
Chris@16
|
49 //! Default filter, always returns \c true
|
Chris@16
|
50 struct default_filter
|
Chris@16
|
51 {
|
Chris@16
|
52 typedef bool result_type;
|
Chris@16
|
53 result_type operator() (attribute_value_set const&) const { return true; }
|
Chris@16
|
54 };
|
Chris@16
|
55
|
Chris@16
|
56 private:
|
Chris@16
|
57 //! Filter function
|
Chris@16
|
58 filter_type m_Filter;
|
Chris@16
|
59
|
Chris@16
|
60 public:
|
Chris@16
|
61 /*!
|
Chris@16
|
62 * Default constructor. Creates a filter that always returns \c true.
|
Chris@16
|
63 */
|
Chris@16
|
64 filter() : m_Filter(default_filter())
|
Chris@16
|
65 {
|
Chris@16
|
66 }
|
Chris@16
|
67 /*!
|
Chris@16
|
68 * Copy constructor
|
Chris@16
|
69 */
|
Chris@16
|
70 filter(filter const& that) : m_Filter(that.m_Filter)
|
Chris@16
|
71 {
|
Chris@16
|
72 }
|
Chris@16
|
73 /*!
|
Chris@16
|
74 * Move constructor. The moved-from filter is left in an unspecified state.
|
Chris@16
|
75 */
|
Chris@16
|
76 filter(BOOST_RV_REF(filter) that) BOOST_NOEXCEPT : m_Filter(boost::move(that.m_Filter))
|
Chris@16
|
77 {
|
Chris@16
|
78 }
|
Chris@16
|
79
|
Chris@16
|
80 /*!
|
Chris@16
|
81 * Initializing constructor. Creates a filter which will invoke the specified function object.
|
Chris@16
|
82 */
|
Chris@16
|
83 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
84 template< typename FunT >
|
Chris@16
|
85 filter(FunT const& fun)
|
Chris@16
|
86 #else
|
Chris@16
|
87 template< typename FunT >
|
Chris@16
|
88 filter(FunT const& fun, typename disable_if< move_detail::is_rv< FunT >, int >::type = 0)
|
Chris@16
|
89 #endif
|
Chris@16
|
90 : m_Filter(fun)
|
Chris@16
|
91 {
|
Chris@16
|
92 }
|
Chris@16
|
93
|
Chris@16
|
94 /*!
|
Chris@16
|
95 * Move assignment. The moved-from filter is left in an unspecified state.
|
Chris@16
|
96 */
|
Chris@16
|
97 filter& operator= (BOOST_RV_REF(filter) that) BOOST_NOEXCEPT
|
Chris@16
|
98 {
|
Chris@16
|
99 m_Filter.swap(that.m_Filter);
|
Chris@16
|
100 return *this;
|
Chris@16
|
101 }
|
Chris@16
|
102 /*!
|
Chris@16
|
103 * Copy assignment.
|
Chris@16
|
104 */
|
Chris@16
|
105 filter& operator= (BOOST_COPY_ASSIGN_REF(filter) that)
|
Chris@16
|
106 {
|
Chris@16
|
107 m_Filter = that.m_Filter;
|
Chris@16
|
108 return *this;
|
Chris@16
|
109 }
|
Chris@16
|
110 /*!
|
Chris@16
|
111 * Initializing assignment. Sets the specified function object to the filter.
|
Chris@16
|
112 */
|
Chris@16
|
113 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
114 template< typename FunT >
|
Chris@16
|
115 filter& operator= (FunT const& fun)
|
Chris@16
|
116 #else
|
Chris@16
|
117 template< typename FunT >
|
Chris@16
|
118 typename disable_if< is_same< typename remove_cv< FunT >::type, filter >, filter& >::type
|
Chris@16
|
119 operator= (FunT const& fun)
|
Chris@16
|
120 #endif
|
Chris@16
|
121 {
|
Chris@16
|
122 filter(fun).swap(*this);
|
Chris@16
|
123 return *this;
|
Chris@16
|
124 }
|
Chris@16
|
125
|
Chris@16
|
126 /*!
|
Chris@16
|
127 * Filtering operator.
|
Chris@16
|
128 *
|
Chris@16
|
129 * \param values Attribute values of the log record.
|
Chris@16
|
130 * \return \c true if the log record passes the filter, \c false otherwise.
|
Chris@16
|
131 */
|
Chris@16
|
132 result_type operator() (attribute_value_set const& values) const
|
Chris@16
|
133 {
|
Chris@16
|
134 return m_Filter(values);
|
Chris@16
|
135 }
|
Chris@16
|
136
|
Chris@16
|
137 /*!
|
Chris@16
|
138 * Resets the filter to the default. The default filter always returns \c true.
|
Chris@16
|
139 */
|
Chris@16
|
140 void reset()
|
Chris@16
|
141 {
|
Chris@16
|
142 m_Filter = default_filter();
|
Chris@16
|
143 }
|
Chris@16
|
144
|
Chris@16
|
145 /*!
|
Chris@16
|
146 * Swaps two filters
|
Chris@16
|
147 */
|
Chris@16
|
148 void swap(filter& that) BOOST_NOEXCEPT
|
Chris@16
|
149 {
|
Chris@16
|
150 m_Filter.swap(that.m_Filter);
|
Chris@16
|
151 }
|
Chris@16
|
152 };
|
Chris@16
|
153
|
Chris@16
|
154 inline void swap(filter& left, filter& right) BOOST_NOEXCEPT
|
Chris@16
|
155 {
|
Chris@16
|
156 left.swap(right);
|
Chris@16
|
157 }
|
Chris@16
|
158
|
Chris@16
|
159 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
160
|
Chris@16
|
161 } // namespace boost
|
Chris@16
|
162
|
Chris@16
|
163 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
164
|
Chris@16
|
165 #endif // BOOST_LOG_EXPRESSIONS_FILTER_HPP_INCLUDED_
|