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)
8 * \file attribute_value_impl.hpp
9 * \author Andrey Semashev
12 * The header contains an implementation of a basic attribute value implementation class.
15 #ifndef BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_IMPL_HPP_INCLUDED_
16 #define BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_IMPL_HPP_INCLUDED_
18 #include <boost/type_index.hpp>
19 #include <boost/move/core.hpp>
20 #include <boost/move/utility_core.hpp>
21 #include <boost/type_traits/remove_cv.hpp>
22 #include <boost/type_traits/is_nothrow_move_constructible.hpp>
23 #include <boost/log/detail/config.hpp>
24 #include <boost/log/attributes/attribute_value.hpp>
25 #include <boost/log/utility/type_dispatch/type_dispatcher.hpp>
26 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
27 #include <boost/type_traits/remove_reference.hpp>
29 #include <boost/log/detail/header.hpp>
31 #ifdef BOOST_HAS_PRAGMA_ONCE
37 BOOST_LOG_OPEN_NAMESPACE
39 namespace attributes {
42 * \brief Basic attribute value implementation class
44 * This class can be used as a boilerplate for simple attribute values. The class implements all needed
45 * interfaces of attribute values and allows to store a single value of the type specified as a template parameter.
46 * The stored value can be dispatched with type dispatching mechanism.
48 template< typename T >
49 class attribute_value_impl :
50 public attribute_value::impl
58 const value_type m_value;
62 * Constructor with initialization of the stored value
64 explicit attribute_value_impl(value_type const& v) : m_value(v) {}
66 * Constructor with initialization of the stored value
68 explicit attribute_value_impl(BOOST_RV_REF(value_type) v) BOOST_NOEXCEPT_IF(boost::is_nothrow_move_constructible< value_type >::value) :
69 m_value(boost::move(v))
74 * Attribute value dispatching method.
76 * \param dispatcher The dispatcher that receives the stored value
78 * \return \c true if the value has been dispatched, \c false otherwise
80 bool dispatch(type_dispatcher& dispatcher) BOOST_OVERRIDE
82 type_dispatcher::callback< value_type > callback = dispatcher.get_callback< value_type >();
93 * \return The attribute value type
95 typeindex::type_index get_type() const BOOST_OVERRIDE { return typeindex::type_id< value_type >(); }
98 * \return Reference to the contained value.
100 value_type const& get() const { return m_value; }
104 * The function creates an attribute value from the specified object.
106 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
108 template< typename T >
109 inline attribute_value make_attribute_value(T&& v)
111 typedef typename remove_cv< typename remove_reference< T >::type >::type value_type;
112 return attribute_value(new attribute_value_impl< value_type >(boost::forward< T >(v)));
115 #else // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
117 template< typename T >
118 inline attribute_value make_attribute_value(T const& v)
120 typedef typename remove_cv< T >::type value_type;
121 return attribute_value(new attribute_value_impl< value_type >(v));
124 template< typename T >
125 inline attribute_value make_attribute_value(rv< T > const& v)
127 typedef typename remove_cv< T >::type value_type;
128 return attribute_value(new attribute_value_impl< value_type >(v));
131 #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
133 } // namespace attributes
135 BOOST_LOG_CLOSE_NAMESPACE // namespace log
139 #include <boost/log/detail/footer.hpp>
141 #endif // BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_IMPL_HPP_INCLUDED_