Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / thread / caller_context.hpp
1 // (C) Copyright 2013 Vicente J. Botet Escriba
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6
7 #ifndef BOOST_THREAD_CALL_CONTEXT_HPP
8 #define BOOST_THREAD_CALL_CONTEXT_HPP
9
10 #include <boost/thread/detail/config.hpp>
11 #if defined BOOST_THREAD_USES_LOG_THREAD_ID
12 #include <boost/thread/thread.hpp>
13 #endif
14 #include <boost/current_function.hpp>
15 #include <iomanip>
16
17 #include <boost/config/abi_prefix.hpp>
18
19 namespace boost
20 {
21
22   struct caller_context_t
23   {
24     const char * filename;
25     unsigned lineno;
26     const char * func;
27     caller_context_t(const char * filename, unsigned lineno, const char * func) :
28       filename(filename), lineno(lineno), func(func)
29     {
30     }
31   };
32
33 #define BOOST_CONTEXTOF boost::caller_context_t(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
34
35   template <typename OStream>
36   OStream& operator<<(OStream& os, caller_context_t const& ctx)
37   {
38 #if defined BOOST_THREAD_USES_LOG_THREAD_ID
39     {
40       io::ios_flags_saver ifs( os );
41       os << std::left << std::setw(14) << boost::this_thread::get_id() << " ";
42     }
43 #endif
44     {
45       io::ios_flags_saver ifs(os);
46       os << ctx.filename << "["
47          << std::setw(4) << std::right << std::dec<< ctx.lineno << "] ";
48       os << ctx.func << " " ;
49     }
50     return os;
51   }
52 }
53
54 #include <boost/config/abi_suffix.hpp>
55
56 #endif // header