caller_context.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // (C) Copyright 2013,2015 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. #ifndef BOOST_THREAD_CALL_CONTEXT_HPP
  6. #define BOOST_THREAD_CALL_CONTEXT_HPP
  7. #include <boost/thread/detail/config.hpp>
  8. #if defined BOOST_THREAD_USES_LOG_THREAD_ID
  9. #include <boost/thread/thread.hpp>
  10. #endif
  11. #include <boost/current_function.hpp>
  12. #include <boost/io/ios_state.hpp>
  13. #include <iomanip>
  14. #include <boost/config/abi_prefix.hpp>
  15. namespace boost
  16. {
  17. struct caller_context_t
  18. {
  19. const char * filename;
  20. unsigned lineno;
  21. const char * func;
  22. caller_context_t(const char * filename, unsigned lineno, const char * func) :
  23. filename(filename), lineno(lineno), func(func)
  24. {
  25. }
  26. };
  27. #define BOOST_CONTEXTOF boost::caller_context_t(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
  28. template <typename OStream>
  29. OStream& operator<<(OStream& os, caller_context_t const& ctx)
  30. {
  31. #if defined BOOST_THREAD_USES_LOG_THREAD_ID
  32. {
  33. io::ios_flags_saver ifs( os );
  34. os << std::left << std::setw(14) << boost::this_thread::get_id() << " ";
  35. }
  36. #endif
  37. {
  38. io::ios_flags_saver ifs(os);
  39. os << std::setw(50) << ctx.filename << "["
  40. << std::setw(4) << std::right << std::dec<< ctx.lineno << "] ";
  41. #if defined BOOST_THREAD_USES_LOG_CURRENT_FUNCTION
  42. os << ctx.func << " " ;
  43. #endif
  44. }
  45. return os;
  46. }
  47. }
  48. #include <boost/config/abi_suffix.hpp>
  49. #endif // header