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)
8 * \file id_formatting.hpp
9 * \author Andrey Semashev
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.
16 #ifndef BOOST_LOG_ID_FORMATTING_HPP_INCLUDED_
17 #define BOOST_LOG_ID_FORMATTING_HPP_INCLUDED_
19 #include <boost/log/detail/config.hpp>
21 #include <boost/log/detail/header.hpp>
25 BOOST_LOG_OPEN_NAMESPACE
29 // Defined in dump.cpp
30 extern const char g_hex_char_table[2][16];
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
35 const char* const char_table = g_hex_char_table[uppercase];
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'
41 size -= 3; // reserve space for the terminating 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)
46 buf[i] = static_cast< CharT >(char_table[(id >> shift) & 15u]);
49 buf[i] = static_cast< CharT >('\0');
54 BOOST_LOG_CLOSE_NAMESPACE // namespace log
58 #include <boost/log/detail/footer.hpp>
60 #endif // BOOST_LOG_ID_FORMATTING_HPP_INCLUDED_