summaryrefslogtreecommitdiff
path: root/libs/log/src/spirit_encoding.hpp
blob: e1b8db7a26ed48613309672d1bc27979c488e31c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 *          Copyright Andrey Semashev 2007 - 2014.
 * Distributed under the Boost Software License, Version 1.0.
 *    (See accompanying file LICENSE_1_0.txt or copy at
 *          http://www.boost.org/LICENSE_1_0.txt)
 */
/*!
 * \file   spirit_encoding.hpp
 * \author Andrey Semashev
 * \date   20.07.2012
 *
 * \brief  This header is the Boost.Log library implementation, see the library documentation
 *         at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
 */

#ifndef BOOST_LOG_SPIRIT_ENCODING_HPP_INCLUDED_
#define BOOST_LOG_SPIRIT_ENCODING_HPP_INCLUDED_

#include <boost/preprocessor/tuple/elem.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/spirit/include/support_standard.hpp>
#include <boost/spirit/include/support_standard_wide.hpp>
#include <boost/spirit/home/support/common_terminals.hpp>
#include <boost/log/detail/config.hpp>
#include <boost/log/detail/header.hpp>

#ifdef BOOST_HAS_PRAGMA_ONCE
#pragma once
#endif

namespace boost {

BOOST_LOG_OPEN_NAMESPACE

namespace aux {

template< typename >
struct encoding;

template< >
struct encoding< char >
{
    typedef spirit::char_encoding::standard type;
};
template< >
struct encoding< wchar_t >
{
    typedef spirit::char_encoding::standard_wide type;
};

//! A simple trait that allows to use charset-specific Qi parsers in a generic way
template< typename EncodingT >
struct encoding_specific;

#define BOOST_LOG_CHARSET_PARSERS\
    ((char_type, char_))\
    ((string_type, string))\
    ((alnum_type, alnum))\
    ((alpha_type, alpha))\
    ((blank_type, blank))\
    ((cntrl_type, cntrl))\
    ((digit_type, digit))\
    ((graph_type, graph))\
    ((print_type, print))\
    ((punct_type, punct))\
    ((space_type, space))\
    ((xdigit_type, xdigit))\
    ((no_case_type, no_case))\
    ((lower_type, lower))\
    ((upper_type, upper))\
    ((lowernum_type, lowernum))\
    ((uppernum_type, uppernum))

#define BOOST_LOG_DECLARE_CHARSET_PARSER(r, charset, parser)\
    typedef spirit::charset::BOOST_PP_TUPLE_ELEM(2, 0, parser) BOOST_PP_TUPLE_ELEM(2, 0, parser);\
    BOOST_LOG_API static BOOST_PP_TUPLE_ELEM(2, 0, parser) const& BOOST_PP_TUPLE_ELEM(2, 1, parser);

#define BOOST_LOG_DECLARE_CHARSET_PARSERS(charset)\
    BOOST_PP_SEQ_FOR_EACH(BOOST_LOG_DECLARE_CHARSET_PARSER, charset, BOOST_LOG_CHARSET_PARSERS)

template< >
struct encoding_specific< spirit::char_encoding::standard >
{
    BOOST_LOG_DECLARE_CHARSET_PARSERS(standard)
};

template< >
struct encoding_specific< spirit::char_encoding::standard_wide >
{
    BOOST_LOG_DECLARE_CHARSET_PARSERS(standard_wide)
};

#undef BOOST_LOG_DECLARE_CHARSET_PARSERS
#undef BOOST_LOG_DECLARE_CHARSET_PARSER

} // namespace aux

BOOST_LOG_CLOSE_NAMESPACE // namespace log

} // namespace boost

#include <boost/log/detail/footer.hpp>

#endif // BOOST_LOG_SPIRIT_ENCODING_HPP_INCLUDED_