| 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 bind_to_log.hpp |
| 9 | * \author Andrey Semashev |
| 10 | * \date 06.11.2012 |
| 11 | * |
| 12 | * This header contains a function object that puts the received value to the bound stream using the \c to_log manipulator. |
| 13 | * This is a lightweight alternative to what Boost.Phoenix and Boost.Lambda provides. |
| 14 | */ |
| 15 | |
| 16 | #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_BIND_TO_LOG_HPP_INCLUDED_ |
| 17 | #define BOOST_LOG_UTILITY_FUNCTIONAL_BIND_TO_LOG_HPP_INCLUDED_ |
| 18 | |
| 19 | #include <boost/log/detail/config.hpp> |
| 20 | #include <boost/log/utility/functional/bind.hpp> |
| 21 | #include <boost/log/utility/manipulators/to_log.hpp> |
| 22 | #include <boost/log/detail/header.hpp> |
| 23 | |
| 24 | #ifdef BOOST_HAS_PRAGMA_ONCE |
| 25 | #pragma once |
| 26 | #endif |
| 27 | |
| 28 | namespace boost { |
| 29 | |
| 30 | BOOST_LOG_OPEN_NAMESPACE |
| 31 | |
| 32 | //! The function object that outputs its second operand to the first one |
| 33 | template< typename TagT = void > |
| 34 | struct to_log_fun |
| 35 | { |
| 36 | typedef void result_type; |
| 37 | |
| 38 | template< typename StreamT, typename T > |
| 39 | void operator() (StreamT& strm, T const& val) const |
| 40 | { |
| 41 | strm << boost::log::to_log< TagT >(val); |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | //! The function object that outputs its second operand to the first one |
| 46 | template< > |
| 47 | struct to_log_fun< void > |
| 48 | { |
| 49 | typedef void result_type; |
| 50 | |
| 51 | template< typename StreamT, typename T > |
| 52 | void operator() (StreamT& strm, T const& val) const |
| 53 | { |
| 54 | strm << boost::log::to_log(val); |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | template< typename StreamT > |
| 59 | BOOST_FORCEINLINE binder1st< to_log_fun< >, StreamT& > bind_to_log(StreamT& strm) |
| 60 | { |
| 61 | return binder1st< to_log_fun< >, StreamT& >(to_log_fun< >(), strm); |
| 62 | } |
| 63 | |
| 64 | template< typename TagT, typename StreamT > |
| 65 | BOOST_FORCEINLINE binder1st< to_log_fun< TagT >, StreamT& > bind_to_log(StreamT& strm) |
| 66 | { |
| 67 | return binder1st< to_log_fun< TagT >, StreamT& >(to_log_fun< TagT >(), strm); |
| 68 | } |
| 69 | |
| 70 | BOOST_LOG_CLOSE_NAMESPACE // namespace log |
| 71 | |
| 72 | } // namespace boost |
| 73 | |
| 74 | #include <boost/log/detail/footer.hpp> |
| 75 | |
| 76 | #endif // BOOST_LOG_UTILITY_FUNCTIONAL_BIND_TO_LOG_HPP_INCLUDED_ |
| 77 | |