Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:18

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   attribute_value_impl.hpp
0009  * \author Andrey Semashev
0010  * \date   24.06.2007
0011  *
0012  * The header contains an implementation of a basic attribute value implementation class.
0013  */
0014 
0015 #ifndef BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_IMPL_HPP_INCLUDED_
0016 #define BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_IMPL_HPP_INCLUDED_
0017 
0018 #include <boost/type_index.hpp>
0019 #include <boost/move/core.hpp>
0020 #include <boost/move/utility_core.hpp>
0021 #include <boost/type_traits/remove_cv.hpp>
0022 #include <boost/type_traits/is_nothrow_move_constructible.hpp>
0023 #include <boost/log/detail/config.hpp>
0024 #include <boost/log/attributes/attribute_value.hpp>
0025 #include <boost/log/utility/type_dispatch/type_dispatcher.hpp>
0026 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0027 #include <boost/type_traits/remove_reference.hpp>
0028 #endif
0029 #include <boost/log/detail/header.hpp>
0030 
0031 #ifdef BOOST_HAS_PRAGMA_ONCE
0032 #pragma once
0033 #endif
0034 
0035 namespace boost {
0036 
0037 BOOST_LOG_OPEN_NAMESPACE
0038 
0039 namespace attributes {
0040 
0041 /*!
0042  * \brief Basic attribute value implementation class
0043  *
0044  * This class can be used as a boilerplate for simple attribute values. The class implements all needed
0045  * interfaces of attribute values and allows to store a single value of the type specified as a template parameter.
0046  * The stored value can be dispatched with type dispatching mechanism.
0047  */
0048 template< typename T >
0049 class attribute_value_impl :
0050     public attribute_value::impl
0051 {
0052 public:
0053     //! Value type
0054     typedef T value_type;
0055 
0056 private:
0057     //! Attribute value
0058     const value_type m_value;
0059 
0060 public:
0061     /*!
0062      * Constructor with initialization of the stored value
0063      */
0064     explicit attribute_value_impl(value_type const& v) : m_value(v) {}
0065     /*!
0066      * Constructor with initialization of the stored value
0067      */
0068     explicit attribute_value_impl(BOOST_RV_REF(value_type) v) BOOST_NOEXCEPT_IF(boost::is_nothrow_move_constructible< value_type >::value) :
0069         m_value(boost::move(v))
0070     {
0071     }
0072 
0073     /*!
0074      * Attribute value dispatching method.
0075      *
0076      * \param dispatcher The dispatcher that receives the stored value
0077      *
0078      * \return \c true if the value has been dispatched, \c false otherwise
0079      */
0080     bool dispatch(type_dispatcher& dispatcher) BOOST_OVERRIDE
0081     {
0082         type_dispatcher::callback< value_type > callback = dispatcher.get_callback< value_type >();
0083         if (callback)
0084         {
0085             callback(m_value);
0086             return true;
0087         }
0088         else
0089             return false;
0090     }
0091 
0092     /*!
0093      * \return The attribute value type
0094      */
0095     typeindex::type_index get_type() const BOOST_OVERRIDE { return typeindex::type_id< value_type >(); }
0096 
0097     /*!
0098      * \return Reference to the contained value.
0099      */
0100     value_type const& get() const { return m_value; }
0101 };
0102 
0103 /*!
0104  * The function creates an attribute value from the specified object.
0105  */
0106 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0107 
0108 template< typename T >
0109 inline attribute_value make_attribute_value(T&& v)
0110 {
0111     typedef typename remove_cv< typename remove_reference< T >::type >::type value_type;
0112     return attribute_value(new attribute_value_impl< value_type >(boost::forward< T >(v)));
0113 }
0114 
0115 #else // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0116 
0117 template< typename T >
0118 inline attribute_value make_attribute_value(T const& v)
0119 {
0120     typedef typename remove_cv< T >::type value_type;
0121     return attribute_value(new attribute_value_impl< value_type >(v));
0122 }
0123 
0124 template< typename T >
0125 inline attribute_value make_attribute_value(rv< T > const& v)
0126 {
0127     typedef typename remove_cv< T >::type value_type;
0128     return attribute_value(new attribute_value_impl< value_type >(v));
0129 }
0130 
0131 #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0132 
0133 } // namespace attributes
0134 
0135 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0136 
0137 } // namespace boost
0138 
0139 #include <boost/log/detail/footer.hpp>
0140 
0141 #endif // BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_IMPL_HPP_INCLUDED_