]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/log/src/id_formatting.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / log / src / id_formatting.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 id_formatting.hpp
9 * \author Andrey Semashev
10 * \date 25.01.2015
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_LOG_ID_FORMATTING_HPP_INCLUDED_
17 #define BOOST_LOG_ID_FORMATTING_HPP_INCLUDED_
18
19 #include <boost/log/detail/config.hpp>
20 #include <cstddef>
21 #include <boost/log/detail/header.hpp>
22
23 namespace boost {
24
25 BOOST_LOG_OPEN_NAMESPACE
26
27 namespace aux {
28
29 // Defined in dump.cpp
30 extern const char g_hex_char_table[2][16];
31
32 template< std::size_t IdSize, typename CharT, typename IdT >
33 inline void format_id(CharT* buf, std::size_t size, IdT id, bool uppercase) BOOST_NOEXCEPT
34 {
35 const char* const char_table = g_hex_char_table[uppercase];
36
37 // Input buffer is assumed to be always larger than 2 chars
38 *buf++ = static_cast< CharT >(char_table[0]); // '0'
39 *buf++ = static_cast< CharT >(char_table[10] + ('x' - 'a')); // 'x'
40
41 size -= 3; // reserve space for the terminating 0
42 std::size_t i = 0;
43 const std::size_t n = (size > (IdSize * 2u)) ? IdSize * 2u : size;
44 for (std::size_t shift = n * 4u - 4u; i < n; ++i, shift -= 4u)
45 {
46 buf[i] = static_cast< CharT >(char_table[(id >> shift) & 15u]);
47 }
48
49 buf[i] = static_cast< CharT >('\0');
50 }
51
52 } // namespace aux
53
54 BOOST_LOG_CLOSE_NAMESPACE // namespace log
55
56 } // namespace boost
57
58 #include <boost/log/detail/footer.hpp>
59
60 #endif // BOOST_LOG_ID_FORMATTING_HPP_INCLUDED_
61