Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file to_log.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 06.11.2012
|
Chris@16
|
11 *
|
Chris@16
|
12 * This header contains the \c to_log output manipulator.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_UTILITY_MANIPULATORS_TO_LOG_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_UTILITY_MANIPULATORS_TO_LOG_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <iosfwd>
|
Chris@16
|
19 #include <boost/mpl/bool.hpp>
|
Chris@16
|
20 #include <boost/log/detail/config.hpp>
|
Chris@16
|
21 #include <boost/log/utility/formatting_ostream_fwd.hpp>
|
Chris@16
|
22 #include <boost/log/detail/header.hpp>
|
Chris@16
|
23
|
Chris@16
|
24 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
25 #pragma once
|
Chris@16
|
26 #endif
|
Chris@16
|
27
|
Chris@16
|
28 namespace boost {
|
Chris@16
|
29
|
Chris@16
|
30 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
31
|
Chris@16
|
32 /*!
|
Chris@16
|
33 * \brief Generic manipulator for customizing output to log
|
Chris@16
|
34 */
|
Chris@16
|
35 template< typename T, typename TagT = void >
|
Chris@16
|
36 class to_log_manip
|
Chris@16
|
37 {
|
Chris@16
|
38 public:
|
Chris@16
|
39 //! Output value type
|
Chris@16
|
40 typedef T value_type;
|
Chris@16
|
41 //! Value tag type
|
Chris@16
|
42 typedef TagT tag_type;
|
Chris@16
|
43
|
Chris@16
|
44 private:
|
Chris@16
|
45 //! Reference to the value
|
Chris@16
|
46 value_type const& m_value;
|
Chris@16
|
47
|
Chris@16
|
48 public:
|
Chris@16
|
49 explicit to_log_manip(value_type const& value) : m_value(value) {}
|
Chris@16
|
50 to_log_manip(to_log_manip const& that) : m_value(that.m_value) {}
|
Chris@16
|
51
|
Chris@16
|
52 value_type const& get() const { return m_value; }
|
Chris@16
|
53 };
|
Chris@16
|
54
|
Chris@16
|
55 template< typename CharT, typename TraitsT, typename T, typename TagT >
|
Chris@16
|
56 inline std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, to_log_manip< T, TagT > manip)
|
Chris@16
|
57 {
|
Chris@16
|
58 strm << manip.get();
|
Chris@16
|
59 return strm;
|
Chris@16
|
60 }
|
Chris@16
|
61
|
Chris@16
|
62 template< typename CharT, typename TraitsT, typename AllocatorT, typename T, typename TagT >
|
Chris@16
|
63 inline basic_formatting_ostream< CharT, TraitsT, AllocatorT >& operator<< (basic_formatting_ostream< CharT, TraitsT, AllocatorT >& strm, to_log_manip< T, TagT > manip)
|
Chris@16
|
64 {
|
Chris@16
|
65 strm << manip.get();
|
Chris@16
|
66 return strm;
|
Chris@16
|
67 }
|
Chris@16
|
68
|
Chris@16
|
69 template< typename T >
|
Chris@16
|
70 inline to_log_manip< T > to_log(T const& value)
|
Chris@16
|
71 {
|
Chris@16
|
72 return to_log_manip< T >(value);
|
Chris@16
|
73 }
|
Chris@16
|
74
|
Chris@16
|
75 template< typename TagT, typename T >
|
Chris@16
|
76 inline to_log_manip< T, TagT > to_log(T const& value)
|
Chris@16
|
77 {
|
Chris@16
|
78 return to_log_manip< T, TagT >(value);
|
Chris@16
|
79 }
|
Chris@16
|
80
|
Chris@16
|
81 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
82
|
Chris@16
|
83 } // namespace boost
|
Chris@16
|
84
|
Chris@16
|
85 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
86
|
Chris@16
|
87 #endif // BOOST_LOG_UTILITY_MANIPULATORS_TO_LOG_HPP_INCLUDED_
|