]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 <boost/log/detail/setup_config.hpp> | |
20 | #include <cstddef> | |
21 | #include <boost/log/attributes/attribute_name.hpp> | |
22 | #include <boost/log/attributes/value_visitation.hpp> | |
23 | #include <boost/log/utility/setup/filter_parser.hpp> | |
24 | #include <boost/log/utility/functional/save_result.hpp> | |
25 | #include <boost/log/detail/header.hpp> | |
26 | ||
27 | namespace boost { | |
28 | ||
29 | BOOST_LOG_OPEN_NAMESPACE | |
30 | ||
31 | namespace aux { | |
32 | ||
33 | //! Relation predicate wrapper | |
34 | template< typename ValueT, typename PredicateT > | |
35 | struct predicate_wrapper | |
36 | { | |
37 | typedef typename PredicateT::result_type result_type; | |
38 | ||
39 | explicit predicate_wrapper(attribute_name const& name, PredicateT const& pred) : m_name(name), m_visitor(pred) | |
40 | { | |
41 | } | |
42 | ||
43 | template< typename T > | |
44 | result_type operator() (T const& arg) const | |
45 | { | |
46 | bool res = false; | |
47 | boost::log::visit< ValueT >(m_name, arg, save_result_wrapper< PredicateT const&, bool >(m_visitor, res)); | |
48 | return res; | |
49 | } | |
50 | ||
51 | private: | |
52 | attribute_name m_name; | |
53 | const PredicateT m_visitor; | |
54 | }; | |
55 | ||
56 | //! The default filter factory that supports creating filters for the standard types (see utility/type_dispatch/standard_types.hpp) | |
57 | template< typename CharT > | |
58 | class default_filter_factory : | |
59 | public filter_factory< CharT > | |
60 | { | |
61 | private: | |
62 | //! Base type | |
63 | typedef filter_factory< CharT > base_type; | |
64 | //! Self type | |
65 | typedef default_filter_factory< CharT > this_type; | |
66 | ||
67 | public: | |
68 | // Type imports | |
69 | typedef typename base_type::char_type char_type; | |
70 | typedef typename base_type::string_type string_type; | |
71 | ||
72 | //! The callback for equality relation filter | |
20effc67 | 73 | filter on_equality_relation(attribute_name const& name, string_type const& arg) BOOST_OVERRIDE; |
7c673cae | 74 | //! The callback for inequality relation filter |
20effc67 | 75 | filter on_inequality_relation(attribute_name const& name, string_type const& arg) BOOST_OVERRIDE; |
7c673cae | 76 | //! The callback for less relation filter |
20effc67 | 77 | filter on_less_relation(attribute_name const& name, string_type const& arg) BOOST_OVERRIDE; |
7c673cae | 78 | //! The callback for greater relation filter |
20effc67 | 79 | filter on_greater_relation(attribute_name const& name, string_type const& arg) BOOST_OVERRIDE; |
7c673cae | 80 | //! The callback for less or equal relation filter |
20effc67 | 81 | filter on_less_or_equal_relation(attribute_name const& name, string_type const& arg) BOOST_OVERRIDE; |
7c673cae | 82 | //! The callback for greater or equal relation filter |
20effc67 | 83 | filter on_greater_or_equal_relation(attribute_name const& name, string_type const& arg) BOOST_OVERRIDE; |
7c673cae FG |
84 | |
85 | //! The callback for custom relation filter | |
20effc67 | 86 | filter on_custom_relation(attribute_name const& name, string_type const& rel, string_type const& arg) BOOST_OVERRIDE; |
7c673cae FG |
87 | |
88 | private: | |
89 | //! The function parses the argument value for a binary relation and constructs the corresponding filter | |
90 | template< typename RelationT > | |
91 | static filter parse_argument(attribute_name const& name, string_type const& arg); | |
92 | }; | |
93 | ||
94 | //! The function parses the "matches" relation | |
95 | template< typename CharT > | |
96 | filter parse_matches_relation(attribute_name const& name, std::basic_string< CharT > const& operand); | |
97 | ||
98 | } // namespace aux | |
99 | ||
100 | BOOST_LOG_CLOSE_NAMESPACE // namespace log | |
101 | ||
102 | } // namespace boost | |
103 | ||
104 | #include <boost/log/detail/footer.hpp> | |
105 | ||
106 | #endif // BOOST_DEFAULT_FILTER_FACTORY_HPP_INCLUDED_ |