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)
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 #include <boost/log/detail/config.hpp>
18 #include <boost/log/detail/process_id.hpp>
19 #include "id_formatting.hpp"
21 #if defined(BOOST_WINDOWS)
24 #include <boost/log/detail/header.hpp>
28 BOOST_LOG_OPEN_NAMESPACE
32 enum { pid_size
= sizeof(GetCurrentProcessId()) };
34 namespace this_process
{
36 //! The function returns current process identifier
37 BOOST_LOG_API
process::id
get_id()
39 return process::id(GetCurrentProcessId());
42 } // namespace this_process
46 BOOST_LOG_CLOSE_NAMESPACE
// namespace log
50 #else // defined(BOOST_WINDOWS)
53 #include <boost/log/detail/header.hpp>
57 BOOST_LOG_OPEN_NAMESPACE
61 namespace this_process
{
63 //! The function returns current process identifier
64 BOOST_LOG_API
process::id
get_id()
66 // According to POSIX, pid_t should always be an integer type:
67 // http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html
68 return process::id(getpid());
71 } // namespace this_process
73 enum { pid_size
= sizeof(pid_t
) };
77 BOOST_LOG_CLOSE_NAMESPACE
// namespace log
81 #endif // defined(BOOST_WINDOWS)
86 BOOST_LOG_OPEN_NAMESPACE
90 template< typename CharT
, typename TraitsT
>
91 BOOST_LOG_API
std::basic_ostream
< CharT
, TraitsT
>&
92 operator<< (std::basic_ostream
< CharT
, TraitsT
>& strm
, process::id
const& pid
)
96 CharT buf
[pid_size
* 2 + 3]; // 2 chars per byte + 3 chars for the leading 0x and terminating zero
97 format_id
< pid_size
>(buf
, sizeof(buf
) / sizeof(*buf
), pid
.native_id(), (strm
.flags() & std::ios_base::uppercase
) != 0);
105 #if defined(BOOST_LOG_USE_CHAR)
106 template BOOST_LOG_API
107 std::basic_ostream
< char, std::char_traits
< char > >&
108 operator<< (std::basic_ostream
< char, std::char_traits
< char > >& strm
, process::id
const& pid
);
109 #endif // defined(BOOST_LOG_USE_CHAR)
111 #if defined(BOOST_LOG_USE_WCHAR_T)
112 template BOOST_LOG_API
113 std::basic_ostream
< wchar_t, std::char_traits
< wchar_t > >&
114 operator<< (std::basic_ostream
< wchar_t, std::char_traits
< wchar_t > >& strm
, process::id
const& pid
);
115 #endif // defined(BOOST_LOG_USE_WCHAR_T)
119 BOOST_LOG_CLOSE_NAMESPACE
// namespace log
123 #include <boost/log/detail/footer.hpp>