1 /* 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) 6 */ 7 /*! 8 * \file default_filter_factory.hpp 9 * \author Andrey Semashev 10 * \date 29.05.2010 11 * 12 * \brief This header is the Boost.Log library implementation, see the library documentation 13 * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html. 14 */ 15 16 #ifndef BOOST_DEFAULT_FILTER_FACTORY_HPP_INCLUDED_ 17 #define BOOST_DEFAULT_FILTER_FACTORY_HPP_INCLUDED_ 18 19 #include <cstddef> 20 #include <boost/log/attributes/attribute_name.hpp> 21 #include <boost/log/attributes/value_visitation.hpp> 22 #include <boost/log/utility/setup/filter_parser.hpp> 23 #include <boost/log/utility/functional/save_result.hpp> 24 #include <boost/log/detail/header.hpp> 25 26 namespace boost { 27 28 BOOST_LOG_OPEN_NAMESPACE 29 30 namespace aux { 31 32 //! Relation predicate wrapper 33 template< typename ValueT, typename PredicateT > 34 struct predicate_wrapper 35 { 36 typedef typename PredicateT::result_type result_type; 37 predicate_wrapperboost::aux::predicate_wrapper38 explicit predicate_wrapper(attribute_name const& name, PredicateT const& pred) : m_name(name), m_visitor(pred) 39 { 40 } 41 42 template< typename T > operator ()boost::aux::predicate_wrapper43 result_type operator() (T const& arg) const 44 { 45 bool res = false; 46 boost::log::visit< ValueT >(m_name, arg, save_result_wrapper< PredicateT const&, bool >(m_visitor, res)); 47 return res; 48 } 49 50 private: 51 attribute_name m_name; 52 const PredicateT m_visitor; 53 }; 54 55 //! The default filter factory that supports creating filters for the standard types (see utility/type_dispatch/standard_types.hpp) 56 template< typename CharT > 57 class default_filter_factory : 58 public filter_factory< CharT > 59 { 60 private: 61 //! Base type 62 typedef filter_factory< CharT > base_type; 63 //! Self type 64 typedef default_filter_factory< CharT > this_type; 65 66 public: 67 // Type imports 68 typedef typename base_type::char_type char_type; 69 typedef typename base_type::string_type string_type; 70 71 //! The callback for equality relation filter 72 virtual filter on_equality_relation(attribute_name const& name, string_type const& arg); 73 //! The callback for inequality relation filter 74 virtual filter on_inequality_relation(attribute_name const& name, string_type const& arg); 75 //! The callback for less relation filter 76 virtual filter on_less_relation(attribute_name const& name, string_type const& arg); 77 //! The callback for greater relation filter 78 virtual filter on_greater_relation(attribute_name const& name, string_type const& arg); 79 //! The callback for less or equal relation filter 80 virtual filter on_less_or_equal_relation(attribute_name const& name, string_type const& arg); 81 //! The callback for greater or equal relation filter 82 virtual filter on_greater_or_equal_relation(attribute_name const& name, string_type const& arg); 83 84 //! The callback for custom relation filter 85 virtual filter on_custom_relation(attribute_name const& name, string_type const& rel, string_type const& arg); 86 87 private: 88 //! The function parses the argument value for a binary relation and constructs the corresponding filter 89 template< typename RelationT > 90 static filter parse_argument(attribute_name const& name, string_type const& arg); 91 }; 92 93 //! The function parses the "matches" relation 94 template< typename CharT > 95 filter parse_matches_relation(attribute_name const& name, std::basic_string< CharT > const& operand); 96 97 } // namespace aux 98 99 BOOST_LOG_CLOSE_NAMESPACE // namespace log 100 101 } // namespace boost 102 103 #include <boost/log/detail/footer.hpp> 104 105 #endif // BOOST_DEFAULT_FILTER_FACTORY_HPP_INCLUDED_ 106