comparison 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
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 /*
2 * Copyright Andrey Semashev 2007 - 2013.
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 add_value.hpp
9 * \author Andrey Semashev
10 * \date 26.11.2012
11 *
12 * This header contains the \c add_value manipulator.
13 */
14
15 #ifndef BOOST_LOG_UTILITY_MANIPULATORS_ADD_VALUE_HPP_INCLUDED_
16 #define BOOST_LOG_UTILITY_MANIPULATORS_ADD_VALUE_HPP_INCLUDED_
17
18 #include <boost/type_traits/remove_cv.hpp>
19 #include <boost/type_traits/remove_reference.hpp>
20 #include <boost/log/detail/config.hpp>
21 #include <boost/log/detail/embedded_string_type.hpp>
22 #include <boost/log/attributes/attribute_name.hpp>
23 #include <boost/log/attributes/attribute_value_impl.hpp>
24 #include <boost/log/expressions/keyword_fwd.hpp>
25 #include <boost/log/sources/record_ostream.hpp>
26 #include <boost/log/detail/header.hpp>
27
28 #ifdef BOOST_HAS_PRAGMA_ONCE
29 #pragma once
30 #endif
31
32 #ifdef _MSC_VER
33 #pragma warning(push)
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
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.
36 #pragma warning(disable: 4413)
37 // returning address of local variable or temporary
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.
39 #pragma warning(disable: 4172)
40 #endif
41
42 namespace boost {
43
44 BOOST_LOG_OPEN_NAMESPACE
45
46 //! Attribute value manipulator
47 template< typename RefT >
48 class add_value_manip
49 {
50 public:
51 //! Stored reference type
52 typedef RefT reference_type;
53 //! Attribute value type
54 typedef typename remove_cv< typename remove_reference< reference_type >::type >::type value_type;
55
56 private:
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
58 typedef typename remove_reference< reference_type >::type& stored_reference_type;
59
60 private:
61 //! Attribute value
62 stored_reference_type m_value;
63 //! Attribute name
64 attribute_name m_name;
65
66 public:
67 //! Initializing constructor
68 add_value_manip(attribute_name const& name, reference_type value) : m_value(static_cast< stored_reference_type >(value)), m_name(name)
69 {
70 }
71
72 //! Returns attribute name
73 attribute_name get_name() const { return m_name; }
74 //! Returns attribute value
75 reference_type get_value() const { return static_cast< reference_type >(m_value); }
76 };
77
78 //! The operator attaches an attribute value to the log record
79 template< typename CharT, typename RefT >
80 inline basic_record_ostream< CharT >& operator<< (basic_record_ostream< CharT >& strm, add_value_manip< RefT > const& manip)
81 {
82 typedef typename aux::make_embedded_string_type< typename add_value_manip< RefT >::value_type >::type value_type;
83 attribute_value value(new attributes::attribute_value_impl< value_type >(manip.get_value()));
84 strm.get_record().attribute_values().insert(manip.get_name(), value);
85 return strm;
86 }
87
88 //! The function creates a manipulator that attaches an attribute value to a log record
89 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1600)
90
91 template< typename T >
92 inline add_value_manip< T&& > add_value(attribute_name const& name, T&& value)
93 {
94 return add_value_manip< T&& >(name, static_cast< T&& >(value));
95 }
96
97 //! \overload
98 template< typename DescriptorT, template< typename > class ActorT >
99 inline add_value_manip< typename DescriptorT::value_type&& >
100 add_value(expressions::attribute_keyword< DescriptorT, ActorT > const&, typename DescriptorT::value_type&& value)
101 {
102 typedef typename DescriptorT::value_type value_type;
103 return add_value_manip< value_type&& >(DescriptorT::get_name(), static_cast< value_type&& >(value));
104 }
105
106 //! \overload
107 template< typename DescriptorT, template< typename > class ActorT >
108 inline add_value_manip< typename DescriptorT::value_type& >
109 add_value(expressions::attribute_keyword< DescriptorT, ActorT > const&, typename DescriptorT::value_type& value)
110 {
111 return add_value_manip< typename DescriptorT::value_type& >(DescriptorT::get_name(), value);
112 }
113
114 #else // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1600)
115
116 template< typename T >
117 inline add_value_manip< T const& > add_value(attribute_name const& name, T const& value)
118 {
119 return add_value_manip< T const& >(name, value);
120 }
121
122 template< typename DescriptorT, template< typename > class ActorT >
123 inline add_value_manip< typename DescriptorT::value_type const& >
124 add_value(expressions::attribute_keyword< DescriptorT, ActorT > const&, typename DescriptorT::value_type const& value)
125 {
126 return add_value_manip< typename DescriptorT::value_type const& >(DescriptorT::get_name(), value);
127 }
128
129 #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1600)
130
131 BOOST_LOG_CLOSE_NAMESPACE // namespace log
132
133 } // namespace boost
134
135 #ifdef _MSC_VER
136 #pragma warning(pop)
137 #endif
138
139 #include <boost/log/detail/footer.hpp>
140
141 #endif // BOOST_LOG_UTILITY_MANIPULATORS_ADD_VALUE_HPP_INCLUDED_