]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/spirit/home/x3/support/traits/print_token.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / spirit / home / x3 / support / traits / print_token.hpp
1 /*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
3 Copyright (c) 2001-2011 Hartmut Kaiser
4
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ================================================_==============================*/
8 #if !defined(BOOST_SPIRIT_X3_PRINT_TOKEN_JANUARY_20_2013_0814AM)
9 #define BOOST_SPIRIT_X3_PRINT_TOKEN_JANUARY_20_2013_0814AM
10
11 #include <boost/mpl/if.hpp>
12 #include <boost/mpl/and.hpp>
13 #include <boost/type_traits/is_convertible.hpp>
14 #include <cctype>
15 #include <ios>
16
17 namespace boost { namespace spirit { namespace x3 { namespace traits
18 {
19 ///////////////////////////////////////////////////////////////////////////
20 // generate debug output for lookahead token (character) stream
21 namespace detail
22 {
23 struct token_printer_debug_for_chars
24 {
25 template<typename Out, typename Char>
26 static void print(Out& o, Char c)
27 {
28 using namespace std; // allow for ADL to find the proper iscntrl
29
30 switch (c)
31 {
32 case '\a': o << "\\a"; break;
33 case '\b': o << "\\b"; break;
34 case '\f': o << "\\f"; break;
35 case '\n': o << "\\n"; break;
36 case '\r': o << "\\r"; break;
37 case '\t': o << "\\t"; break;
38 case '\v': o << "\\v"; break;
39 default:
40 if (c >= 0 && c < 127)
41 {
42 if (iscntrl(c))
43 o << "\\" << std::oct << int(c);
44 else if (isprint(c))
45 o << char(c);
46 else
47 o << "\\x" << std::hex << int(c);
48 }
49 else
50 o << "\\x" << std::hex << int(c);
51 }
52 }
53 };
54
55 // for token types where the comparison with char constants wouldn't work
56 struct token_printer_debug
57 {
58 template<typename Out, typename T>
59 static void print(Out& o, T const& val)
60 {
61 o << val;
62 }
63 };
64 }
65
66 template <typename T, typename Enable = void>
67 struct token_printer_debug
68 : mpl::if_<
69 mpl::and_<
70 is_convertible<T, char>, is_convertible<char, T> >
71 , detail::token_printer_debug_for_chars
72 , detail::token_printer_debug>::type
73 {};
74
75 template <typename Out, typename T>
76 inline void print_token(Out& out, T const& val)
77 {
78 // allow to customize the token printer routine
79 token_printer_debug<T>::print(out, val);
80 }
81 }}}}
82
83 #endif