to_log.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 to_log.hpp
  9. * \author Andrey Semashev
  10. * \date 06.11.2012
  11. *
  12. * This header contains the \c to_log output manipulator.
  13. */
  14. #ifndef BOOST_LOG_UTILITY_MANIPULATORS_TO_LOG_HPP_INCLUDED_
  15. #define BOOST_LOG_UTILITY_MANIPULATORS_TO_LOG_HPP_INCLUDED_
  16. #include <iosfwd>
  17. #include <boost/core/enable_if.hpp>
  18. #include <boost/log/detail/config.hpp>
  19. #include <boost/log/detail/is_ostream.hpp>
  20. #include <boost/log/utility/formatting_ostream_fwd.hpp>
  21. #include <boost/log/detail/header.hpp>
  22. #ifdef BOOST_HAS_PRAGMA_ONCE
  23. #pragma once
  24. #endif
  25. namespace boost {
  26. BOOST_LOG_OPEN_NAMESPACE
  27. /*!
  28. * \brief Generic manipulator for customizing output to log
  29. */
  30. template< typename T, typename TagT = void >
  31. class to_log_manip
  32. {
  33. public:
  34. //! Output value type
  35. typedef T value_type;
  36. //! Value tag type
  37. typedef TagT tag_type;
  38. private:
  39. //! Reference to the value
  40. value_type const& m_value;
  41. public:
  42. explicit to_log_manip(value_type const& value) BOOST_NOEXCEPT : m_value(value) {}
  43. to_log_manip(to_log_manip const& that) BOOST_NOEXCEPT : m_value(that.m_value) {}
  44. value_type const& get() const BOOST_NOEXCEPT { return m_value; }
  45. };
  46. template< typename StreamT, typename T, typename TagT >
  47. inline typename enable_if_c< log::aux::is_ostream< StreamT >::value, StreamT& >::type operator<< (StreamT& strm, to_log_manip< T, TagT > manip)
  48. {
  49. strm << manip.get();
  50. return strm;
  51. }
  52. template< typename T >
  53. inline to_log_manip< T > to_log(T const& value) BOOST_NOEXCEPT
  54. {
  55. return to_log_manip< T >(value);
  56. }
  57. template< typename TagT, typename T >
  58. inline to_log_manip< T, TagT > to_log(T const& value) BOOST_NOEXCEPT
  59. {
  60. return to_log_manip< T, TagT >(value);
  61. }
  62. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  63. } // namespace boost
  64. #include <boost/log/detail/footer.hpp>
  65. #endif // BOOST_LOG_UTILITY_MANIPULATORS_TO_LOG_HPP_INCLUDED_