• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 #ifndef BOOST_LOG_UTILITY_MANIPULATORS_TO_LOG_HPP_INCLUDED_
16 #define BOOST_LOG_UTILITY_MANIPULATORS_TO_LOG_HPP_INCLUDED_
17 
18 #include <iosfwd>
19 #include <boost/core/enable_if.hpp>
20 #include <boost/log/detail/config.hpp>
21 #include <boost/log/detail/is_ostream.hpp>
22 #include <boost/log/utility/formatting_ostream_fwd.hpp>
23 #include <boost/log/detail/header.hpp>
24 
25 #ifdef BOOST_HAS_PRAGMA_ONCE
26 #pragma once
27 #endif
28 
29 namespace boost {
30 
31 BOOST_LOG_OPEN_NAMESPACE
32 
33 /*!
34  * \brief Generic manipulator for customizing output to log
35  */
36 template< typename T, typename TagT = void >
37 class to_log_manip
38 {
39 public:
40     //! Output value type
41     typedef T value_type;
42     //! Value tag type
43     typedef TagT tag_type;
44 
45 private:
46     //! Reference to the value
47     value_type const& m_value;
48 
49 public:
to_log_manip(value_type const & value)50     explicit to_log_manip(value_type const& value) BOOST_NOEXCEPT : m_value(value) {}
to_log_manip(to_log_manip const & that)51     to_log_manip(to_log_manip const& that) BOOST_NOEXCEPT : m_value(that.m_value) {}
52 
get() const53     value_type const& get() const BOOST_NOEXCEPT { return m_value; }
54 };
55 
56 template< typename StreamT, typename T, typename TagT >
operator <<(StreamT & strm,to_log_manip<T,TagT> manip)57 inline typename enable_if_c< log::aux::is_ostream< StreamT >::value, StreamT& >::type operator<< (StreamT& strm, to_log_manip< T, TagT > manip)
58 {
59     strm << manip.get();
60     return strm;
61 }
62 
63 template< typename T >
to_log(T const & value)64 inline to_log_manip< T > to_log(T const& value) BOOST_NOEXCEPT
65 {
66     return to_log_manip< T >(value);
67 }
68 
69 template< typename TagT, typename T >
to_log(T const & value)70 inline to_log_manip< T, TagT > to_log(T const& value) BOOST_NOEXCEPT
71 {
72     return to_log_manip< T, TagT >(value);
73 }
74 
75 BOOST_LOG_CLOSE_NAMESPACE // namespace log
76 
77 } // namespace boost
78 
79 #include <boost/log/detail/footer.hpp>
80 
81 #endif // BOOST_LOG_UTILITY_MANIPULATORS_TO_LOG_HPP_INCLUDED_
82