Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:45:05

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   filter.hpp
0009  * \author Andrey Semashev
0010  * \date   13.07.2012
0011  *
0012  * The header contains a filter function object definition.
0013  */
0014 
0015 #ifndef BOOST_LOG_EXPRESSIONS_FILTER_HPP_INCLUDED_
0016 #define BOOST_LOG_EXPRESSIONS_FILTER_HPP_INCLUDED_
0017 
0018 #include <boost/move/core.hpp>
0019 #include <boost/move/utility_core.hpp>
0020 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0021 #include <boost/type_traits/is_same.hpp>
0022 #include <boost/type_traits/remove_cv.hpp>
0023 #include <boost/log/detail/sfinae_tools.hpp>
0024 #endif
0025 #include <boost/log/detail/config.hpp>
0026 #include <boost/log/attributes/attribute_value_set.hpp>
0027 #include <boost/log/detail/light_function.hpp>
0028 #include <boost/log/detail/header.hpp>
0029 
0030 #ifdef BOOST_HAS_PRAGMA_ONCE
0031 #pragma once
0032 #endif
0033 
0034 namespace boost {
0035 
0036 BOOST_LOG_OPEN_NAMESPACE
0037 
0038 /*!
0039  * Log record filter function wrapper.
0040  */
0041 class filter
0042 {
0043     BOOST_COPYABLE_AND_MOVABLE(filter)
0044 
0045 public:
0046     //! Result type
0047     typedef bool result_type;
0048 
0049 private:
0050     //! Filter function type
0051     typedef boost::log::aux::light_function< bool (attribute_value_set const&) > filter_type;
0052 
0053     //! Default filter, always returns \c true
0054     struct default_filter
0055     {
0056         typedef bool result_type;
0057         result_type operator() (attribute_value_set const&) const { return true; }
0058     };
0059 
0060 private:
0061     //! Filter function
0062     filter_type m_Filter;
0063 
0064 public:
0065     /*!
0066      * Default constructor. Creates a filter that always returns \c true.
0067      */
0068     filter() : m_Filter(default_filter())
0069     {
0070     }
0071     /*!
0072      * Copy constructor
0073      */
0074     filter(filter const& that) : m_Filter(that.m_Filter)
0075     {
0076     }
0077     /*!
0078      * Move constructor. The moved-from filter is left in an unspecified state.
0079      */
0080     filter(BOOST_RV_REF(filter) that) BOOST_NOEXCEPT : m_Filter(boost::move(that.m_Filter))
0081     {
0082     }
0083 
0084     /*!
0085      * Initializing constructor. Creates a filter which will invoke the specified function object.
0086      */
0087 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0088     template< typename FunT >
0089     filter(FunT&& fun) : m_Filter(boost::forward< FunT >(fun))
0090     {
0091     }
0092 #elif !defined(BOOST_MSVC) || BOOST_MSVC >= 1600
0093     template< typename FunT >
0094     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)
0095     {
0096     }
0097 #else
0098     // MSVC 9 and older blows up in unexpected ways if we use SFINAE to disable constructor instantiation
0099     template< typename FunT >
0100     filter(FunT const& fun) : m_Filter(fun)
0101     {
0102     }
0103     template< typename FunT >
0104     filter(rv< FunT >& fun) : m_Filter(fun)
0105     {
0106     }
0107     template< typename FunT >
0108     filter(rv< FunT > const& fun) : m_Filter(static_cast< FunT const& >(fun))
0109     {
0110     }
0111     filter(rv< filter > const& that) : m_Filter(that.m_Filter)
0112     {
0113     }
0114 #endif
0115 
0116     /*!
0117      * Move assignment. The moved-from filter is left in an unspecified state.
0118      */
0119     filter& operator= (BOOST_RV_REF(filter) that) BOOST_NOEXCEPT
0120     {
0121         m_Filter.swap(that.m_Filter);
0122         return *this;
0123     }
0124     /*!
0125      * Copy assignment.
0126      */
0127     filter& operator= (BOOST_COPY_ASSIGN_REF(filter) that)
0128     {
0129         m_Filter = that.m_Filter;
0130         return *this;
0131     }
0132     /*!
0133      * Initializing assignment. Sets the specified function object to the filter.
0134      */
0135 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0136     template< typename FunT >
0137     filter& operator= (FunT const& fun)
0138 #else
0139     template< typename FunT >
0140     typename boost::disable_if_c< is_same< typename remove_cv< FunT >::type, filter >::value, filter& >::type
0141     operator= (FunT const& fun)
0142 #endif
0143     {
0144         filter(fun).swap(*this);
0145         return *this;
0146     }
0147 
0148     /*!
0149      * Filtering operator.
0150      *
0151      * \param values Attribute values of the log record.
0152      * \return \c true if the log record passes the filter, \c false otherwise.
0153      */
0154     result_type operator() (attribute_value_set const& values) const
0155     {
0156         return m_Filter(values);
0157     }
0158 
0159     /*!
0160      * Resets the filter to the default. The default filter always returns \c true.
0161      */
0162     void reset()
0163     {
0164         m_Filter = default_filter();
0165     }
0166 
0167     /*!
0168      * Swaps two filters
0169      */
0170     void swap(filter& that) BOOST_NOEXCEPT
0171     {
0172         m_Filter.swap(that.m_Filter);
0173     }
0174 };
0175 
0176 inline void swap(filter& left, filter& right) BOOST_NOEXCEPT
0177 {
0178     left.swap(right);
0179 }
0180 
0181 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0182 
0183 } // namespace boost
0184 
0185 #include <boost/log/detail/footer.hpp>
0186 
0187 #endif // BOOST_LOG_EXPRESSIONS_FILTER_HPP_INCLUDED_