annotate DEPENDENCIES/generic/include/boost/log/utility/manipulators/add_value.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
rev   line source
Chris@16 1 /*
Chris@16 2 * Copyright Andrey Semashev 2007 - 2013.
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 add_value.hpp
Chris@16 9 * \author Andrey Semashev
Chris@16 10 * \date 26.11.2012
Chris@16 11 *
Chris@16 12 * This header contains the \c add_value manipulator.
Chris@16 13 */
Chris@16 14
Chris@16 15 #ifndef BOOST_LOG_UTILITY_MANIPULATORS_ADD_VALUE_HPP_INCLUDED_
Chris@16 16 #define BOOST_LOG_UTILITY_MANIPULATORS_ADD_VALUE_HPP_INCLUDED_
Chris@16 17
Chris@16 18 #include <boost/type_traits/remove_cv.hpp>
Chris@16 19 #include <boost/type_traits/remove_reference.hpp>
Chris@16 20 #include <boost/log/detail/config.hpp>
Chris@16 21 #include <boost/log/detail/embedded_string_type.hpp>
Chris@16 22 #include <boost/log/attributes/attribute_name.hpp>
Chris@16 23 #include <boost/log/attributes/attribute_value_impl.hpp>
Chris@16 24 #include <boost/log/expressions/keyword_fwd.hpp>
Chris@16 25 #include <boost/log/sources/record_ostream.hpp>
Chris@16 26 #include <boost/log/detail/header.hpp>
Chris@16 27
Chris@16 28 #ifdef BOOST_HAS_PRAGMA_ONCE
Chris@16 29 #pragma once
Chris@16 30 #endif
Chris@16 31
Chris@16 32 #ifdef _MSC_VER
Chris@16 33 #pragma warning(push)
Chris@16 34 // 'boost::log::v2s_mt_nt6::add_value_manip<RefT>::m_value' : reference member is initialized to a temporary that doesn't persist after the constructor exits
Chris@16 35 // This is intentional since the manipulator can be used with a temporary, which will be used before the streaming expression ends and it is destroyed.
Chris@16 36 #pragma warning(disable: 4413)
Chris@16 37 // returning address of local variable or temporary
Chris@16 38 // This warning refers to add_value_manip<RefT>::get_value() when RefT is an rvalue reference. We store the reference in the manipulator and we intend to return it as is.
Chris@16 39 #pragma warning(disable: 4172)
Chris@16 40 #endif
Chris@16 41
Chris@16 42 namespace boost {
Chris@16 43
Chris@16 44 BOOST_LOG_OPEN_NAMESPACE
Chris@16 45
Chris@16 46 //! Attribute value manipulator
Chris@16 47 template< typename RefT >
Chris@16 48 class add_value_manip
Chris@16 49 {
Chris@16 50 public:
Chris@16 51 //! Stored reference type
Chris@16 52 typedef RefT reference_type;
Chris@16 53 //! Attribute value type
Chris@16 54 typedef typename remove_cv< typename remove_reference< reference_type >::type >::type value_type;
Chris@16 55
Chris@16 56 private:
Chris@16 57 // The stored reference type is always an lvalue reference since apparently different compilers (GCC and MSVC) have different quirks when rvalue references are stored as members
Chris@16 58 typedef typename remove_reference< reference_type >::type& stored_reference_type;
Chris@16 59
Chris@16 60 private:
Chris@16 61 //! Attribute value
Chris@16 62 stored_reference_type m_value;
Chris@16 63 //! Attribute name
Chris@16 64 attribute_name m_name;
Chris@16 65
Chris@16 66 public:
Chris@16 67 //! Initializing constructor
Chris@16 68 add_value_manip(attribute_name const& name, reference_type value) : m_value(static_cast< stored_reference_type >(value)), m_name(name)
Chris@16 69 {
Chris@16 70 }
Chris@16 71
Chris@16 72 //! Returns attribute name
Chris@16 73 attribute_name get_name() const { return m_name; }
Chris@16 74 //! Returns attribute value
Chris@16 75 reference_type get_value() const { return static_cast< reference_type >(m_value); }
Chris@16 76 };
Chris@16 77
Chris@16 78 //! The operator attaches an attribute value to the log record
Chris@16 79 template< typename CharT, typename RefT >
Chris@16 80 inline basic_record_ostream< CharT >& operator<< (basic_record_ostream< CharT >& strm, add_value_manip< RefT > const& manip)
Chris@16 81 {
Chris@16 82 typedef typename aux::make_embedded_string_type< typename add_value_manip< RefT >::value_type >::type value_type;
Chris@16 83 attribute_value value(new attributes::attribute_value_impl< value_type >(manip.get_value()));
Chris@16 84 strm.get_record().attribute_values().insert(manip.get_name(), value);
Chris@16 85 return strm;
Chris@16 86 }
Chris@16 87
Chris@16 88 //! The function creates a manipulator that attaches an attribute value to a log record
Chris@16 89 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1600)
Chris@16 90
Chris@16 91 template< typename T >
Chris@16 92 inline add_value_manip< T&& > add_value(attribute_name const& name, T&& value)
Chris@16 93 {
Chris@16 94 return add_value_manip< T&& >(name, static_cast< T&& >(value));
Chris@16 95 }
Chris@16 96
Chris@16 97 //! \overload
Chris@16 98 template< typename DescriptorT, template< typename > class ActorT >
Chris@16 99 inline add_value_manip< typename DescriptorT::value_type&& >
Chris@16 100 add_value(expressions::attribute_keyword< DescriptorT, ActorT > const&, typename DescriptorT::value_type&& value)
Chris@16 101 {
Chris@16 102 typedef typename DescriptorT::value_type value_type;
Chris@16 103 return add_value_manip< value_type&& >(DescriptorT::get_name(), static_cast< value_type&& >(value));
Chris@16 104 }
Chris@16 105
Chris@16 106 //! \overload
Chris@16 107 template< typename DescriptorT, template< typename > class ActorT >
Chris@16 108 inline add_value_manip< typename DescriptorT::value_type& >
Chris@16 109 add_value(expressions::attribute_keyword< DescriptorT, ActorT > const&, typename DescriptorT::value_type& value)
Chris@16 110 {
Chris@16 111 return add_value_manip< typename DescriptorT::value_type& >(DescriptorT::get_name(), value);
Chris@16 112 }
Chris@16 113
Chris@16 114 #else // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1600)
Chris@16 115
Chris@16 116 template< typename T >
Chris@16 117 inline add_value_manip< T const& > add_value(attribute_name const& name, T const& value)
Chris@16 118 {
Chris@16 119 return add_value_manip< T const& >(name, value);
Chris@16 120 }
Chris@16 121
Chris@16 122 template< typename DescriptorT, template< typename > class ActorT >
Chris@16 123 inline add_value_manip< typename DescriptorT::value_type const& >
Chris@16 124 add_value(expressions::attribute_keyword< DescriptorT, ActorT > const&, typename DescriptorT::value_type const& value)
Chris@16 125 {
Chris@16 126 return add_value_manip< typename DescriptorT::value_type const& >(DescriptorT::get_name(), value);
Chris@16 127 }
Chris@16 128
Chris@16 129 #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1600)
Chris@16 130
Chris@16 131 BOOST_LOG_CLOSE_NAMESPACE // namespace log
Chris@16 132
Chris@16 133 } // namespace boost
Chris@16 134
Chris@16 135 #ifdef _MSC_VER
Chris@16 136 #pragma warning(pop)
Chris@16 137 #endif
Chris@16 138
Chris@16 139 #include <boost/log/detail/footer.hpp>
Chris@16 140
Chris@16 141 #endif // BOOST_LOG_UTILITY_MANIPULATORS_ADD_VALUE_HPP_INCLUDED_