Chris@16: /* Chris@101: * Copyright Andrey Semashev 2007 - 2015. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: /*! Chris@16: * \file attribute_predicate.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 02.09.2012 Chris@16: * Chris@16: * The header contains implementation of a generic predicate in template expressions. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_DETAIL_ATTRIBUTE_PREDICATE_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_DETAIL_ATTRIBUTE_PREDICATE_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: BOOST_LOG_OPEN_NAMESPACE Chris@16: Chris@16: namespace expressions { Chris@16: Chris@16: namespace aux { Chris@16: Chris@16: /*! Chris@16: * The predicate checks if the attribute value satisfies a predicate. Chris@16: */ Chris@16: template< typename T, typename ArgT, typename PredicateT, typename FallbackPolicyT = fallback_to_none > Chris@16: class attribute_predicate Chris@16: { Chris@16: public: Chris@16: //! Function result_type Chris@16: typedef bool result_type; Chris@16: //! Expected attribute value type Chris@16: typedef T value_type; Chris@16: //! Predicate type Chris@16: typedef PredicateT predicate_type; Chris@16: //! Argument type for the predicate Chris@16: typedef ArgT argument_type; Chris@16: //! Fallback policy Chris@16: typedef FallbackPolicyT fallback_policy; Chris@16: Chris@16: private: Chris@16: //! Argument for the predicate Chris@16: const argument_type m_arg; Chris@16: //! Attribute value name Chris@16: const attribute_name m_name; Chris@16: //! Visitor invoker Chris@16: value_visitor_invoker< value_type, fallback_policy > m_visitor_invoker; Chris@16: Chris@16: public: Chris@16: /*! Chris@16: * Initializing constructor Chris@16: * Chris@16: * \param name Attribute name Chris@16: * \param pred_arg The predicate argument Chris@16: */ Chris@16: attribute_predicate(attribute_name const& name, argument_type const& pred_arg) : m_arg(pred_arg), m_name(name) Chris@16: { Chris@16: } Chris@16: Chris@16: /*! Chris@16: * Initializing constructor Chris@16: * Chris@16: * \param name Attribute name Chris@16: * \param pred_arg The predicate argument Chris@16: * \param arg Additional parameter for the fallback policy Chris@16: */ Chris@16: template< typename U > Chris@16: 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: { Chris@16: } Chris@16: Chris@16: /*! Chris@16: * Checking operator Chris@16: * Chris@16: * \param arg A set of attribute values or a log record Chris@16: * \return \c true if the log record contains the sought attribute value, \c false otherwise Chris@16: */ Chris@16: template< typename ArgumentT > Chris@16: result_type operator() (ArgumentT const& arg) const Chris@16: { Chris@16: typedef binder2nd< predicate_type, argument_type const& > visitor_type; Chris@16: Chris@16: bool res = false; Chris@16: m_visitor_invoker(m_name, arg, boost::log::save_result(visitor_type(predicate_type(), m_arg), res)); Chris@16: return res; Chris@16: } Chris@16: }; Chris@16: Chris@16: } // namespace aux Chris@16: Chris@16: } // namespace expressions Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_LOG_DETAIL_ATTRIBUTE_PREDICATE_HPP_INCLUDED_