]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/log/support/spirit_qi.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / log / support / spirit_qi.hpp
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 support/spirit_qi.hpp
9 * \author Andrey Semashev
10 * \date 19.07.2009
11 *
12 * This header enables Boost.Spirit.Qi support for Boost.Log.
13 */
14
15 #ifndef BOOST_LOG_SUPPORT_SPIRIT_QI_HPP_INCLUDED_
16 #define BOOST_LOG_SUPPORT_SPIRIT_QI_HPP_INCLUDED_
17
18 #include <boost/core/enable_if.hpp>
19 #include <boost/spirit/include/qi_parse.hpp>
20 #include <boost/spirit/include/qi_domain.hpp>
21 #include <boost/spirit/include/support_unused.hpp>
22 #include <boost/spirit/home/support/meta_compiler.hpp> // spirit::compile()
23 #include <boost/spirit/home/qi/nonterminal/nonterminal_fwd.hpp> // rule forward declaration
24 #include <boost/log/detail/config.hpp>
25 #include <boost/log/utility/functional/matches.hpp>
26 #include <boost/log/detail/header.hpp>
27
28 #ifdef BOOST_HAS_PRAGMA_ONCE
29 #pragma once
30 #endif
31
32 namespace boost {
33
34 BOOST_LOG_OPEN_NAMESPACE
35
36 namespace aux {
37
38 //! This tag type is used if an expression is recognized as a Boost.Spirit.Qi expression
39 struct boost_spirit_qi_expression_tag;
40
41 //! The metafunction detects the matching expression kind and returns a tag that is used to specialize \c match_traits
42 template< typename ExpressionT >
43 struct matching_expression_kind< ExpressionT, typename boost::enable_if_c< spirit::traits::matches< spirit::qi::domain, ExpressionT >::value >::type >
44 {
45 typedef boost_spirit_qi_expression_tag type;
46 };
47
48 //! The matching function implementation
49 template< typename ExpressionT >
50 struct match_traits< ExpressionT, boost_spirit_qi_expression_tag >
51 {
52 typedef typename spirit::result_of::compile< spirit::qi::domain, ExpressionT, spirit::unused_type >::type compiled_type;
53
54 static compiled_type compile(ExpressionT const& expr)
55 {
56 return spirit::compile< spirit::qi::domain >(expr);
57 }
58
59 template< typename StringT >
60 static bool matches(StringT const& str, ExpressionT const& expr)
61 {
62 typedef typename StringT::const_iterator const_iterator;
63 const_iterator it = str.begin(), end = str.end();
64 return (spirit::qi::parse(it, end, expr) && it == end);
65 }
66 };
67
68 //! The matching function implementation
69 template< typename IteratorT, typename T1, typename T2, typename T3, typename T4 >
70 struct match_traits< spirit::qi::rule< IteratorT, T1, T2, T3, T4 >, boost_spirit_qi_expression_tag >
71 {
72 typedef spirit::qi::rule< IteratorT, T1, T2, T3, T4 > compiled_type;
73 static compiled_type compile(compiled_type const& expr) { return expr; }
74
75 template< typename StringT >
76 static bool matches(StringT const& str, compiled_type const& expr)
77 {
78 typedef typename StringT::const_iterator const_iterator;
79 const_iterator it = str.begin(), end = str.end();
80 return (spirit::qi::parse(it, end, expr) && it == end);
81 }
82 };
83
84 } // namespace aux
85
86 BOOST_LOG_CLOSE_NAMESPACE // namespace log
87
88 } // namespace boost
89
90 #include <boost/log/detail/footer.hpp>
91
92 #endif // BOOST_LOG_SUPPORT_SPIRIT_QI_HPP_INCLUDED_