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)
9 * \author Andrey Semashev
12 * The header contains a filter function object definition.
15 #ifndef BOOST_LOG_EXPRESSIONS_FILTER_HPP_INCLUDED_
16 #define BOOST_LOG_EXPRESSIONS_FILTER_HPP_INCLUDED_
18 #include <boost/move/core.hpp>
19 #include <boost/move/utility_core.hpp>
20 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
21 #include <boost/type_traits/is_same.hpp>
22 #include <boost/type_traits/remove_cv.hpp>
23 #include <boost/log/detail/sfinae_tools.hpp>
25 #include <boost/log/detail/config.hpp>
26 #include <boost/log/attributes/attribute_value_set.hpp>
27 #include <boost/log/detail/light_function.hpp>
28 #include <boost/log/detail/header.hpp>
30 #ifdef BOOST_HAS_PRAGMA_ONCE
36 BOOST_LOG_OPEN_NAMESPACE
39 * Log record filter function wrapper.
43 BOOST_COPYABLE_AND_MOVABLE(filter)
47 typedef bool result_type;
50 //! Filter function type
51 typedef boost::log::aux::light_function< bool (attribute_value_set const&) > filter_type;
53 //! Default filter, always returns \c true
56 typedef bool result_type;
57 result_type operator() (attribute_value_set const&) const { return true; }
66 * Default constructor. Creates a filter that always returns \c true.
68 filter() : m_Filter(default_filter())
74 filter(filter const& that) : m_Filter(that.m_Filter)
78 * Move constructor. The moved-from filter is left in an unspecified state.
80 filter(BOOST_RV_REF(filter) that) BOOST_NOEXCEPT : m_Filter(boost::move(that.m_Filter))
85 * Initializing constructor. Creates a filter which will invoke the specified function object.
87 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
88 template< typename FunT >
89 filter(FunT&& fun) : m_Filter(boost::forward< FunT >(fun))
92 #elif !defined(BOOST_MSVC) || BOOST_MSVC >= 1600
93 template< typename FunT >
94 filter(FunT const& fun, typename boost::disable_if_c< move_detail::is_rv< FunT >::value, boost::log::aux::sfinae_dummy >::type = boost::log::aux::sfinae_dummy()) : m_Filter(fun)
98 // MSVC 9 and older blows up in unexpected ways if we use SFINAE to disable constructor instantiation
99 template< typename FunT >
100 filter(FunT const& fun) : m_Filter(fun)
103 template< typename FunT >
104 filter(rv< FunT >& fun) : m_Filter(fun)
107 template< typename FunT >
108 filter(rv< FunT > const& fun) : m_Filter(static_cast< FunT const& >(fun))
111 filter(rv< filter > const& that) : m_Filter(that.m_Filter)
117 * Move assignment. The moved-from filter is left in an unspecified state.
119 filter& operator= (BOOST_RV_REF(filter) that) BOOST_NOEXCEPT
121 m_Filter.swap(that.m_Filter);
127 filter& operator= (BOOST_COPY_ASSIGN_REF(filter) that)
129 m_Filter = that.m_Filter;
133 * Initializing assignment. Sets the specified function object to the filter.
135 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
136 template< typename FunT >
137 filter& operator= (FunT const& fun)
139 template< typename FunT >
140 typename boost::disable_if_c< is_same< typename remove_cv< FunT >::type, filter >::value, filter& >::type
141 operator= (FunT const& fun)
144 filter(fun).swap(*this);
149 * Filtering operator.
151 * \param values Attribute values of the log record.
152 * \return \c true if the log record passes the filter, \c false otherwise.
154 result_type operator() (attribute_value_set const& values) const
156 return m_Filter(values);
160 * Resets the filter to the default. The default filter always returns \c true.
164 m_Filter = default_filter();
170 void swap(filter& that) BOOST_NOEXCEPT
172 m_Filter.swap(that.m_Filter);
176 inline void swap(filter& left, filter& right) BOOST_NOEXCEPT
181 BOOST_LOG_CLOSE_NAMESPACE // namespace log
185 #include <boost/log/detail/footer.hpp>
187 #endif // BOOST_LOG_EXPRESSIONS_FILTER_HPP_INCLUDED_