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   constant.hpp
0009  * \author Andrey Semashev
0010  * \date   15.04.2007
0011  *
0012  * The header contains implementation of a constant attribute.
0013  */
0014 
0015 #ifndef BOOST_LOG_ATTRIBUTES_CONSTANT_HPP_INCLUDED_
0016 #define BOOST_LOG_ATTRIBUTES_CONSTANT_HPP_INCLUDED_
0017 
0018 #include <boost/move/core.hpp>
0019 #include <boost/move/utility_core.hpp>
0020 #include <boost/type_traits/remove_reference.hpp>
0021 #include <boost/type_traits/is_nothrow_move_constructible.hpp>
0022 #include <boost/log/detail/config.hpp>
0023 #include <boost/log/detail/embedded_string_type.hpp>
0024 #include <boost/log/attributes/attribute.hpp>
0025 #include <boost/log/attributes/attribute_cast.hpp>
0026 #include <boost/log/attributes/attribute_value_impl.hpp>
0027 #include <boost/log/detail/header.hpp>
0028 
0029 #ifdef BOOST_HAS_PRAGMA_ONCE
0030 #pragma once
0031 #endif
0032 
0033 namespace boost {
0034 
0035 BOOST_LOG_OPEN_NAMESPACE
0036 
0037 namespace attributes {
0038 
0039 /*!
0040  * \brief A class of an attribute that holds a single constant value
0041  *
0042  * The constant is a simplest and one of the most frequently used types of attributes.
0043  * It stores a constant value, which it eventually returns as its value each time
0044  * requested.
0045  */
0046 template< typename T >
0047 class constant :
0048     public attribute
0049 {
0050 public:
0051     //! Attribute value type
0052     typedef T value_type;
0053 
0054 protected:
0055     //! Factory implementation
0056     class BOOST_SYMBOL_VISIBLE impl :
0057         public attribute_value_impl< value_type >
0058     {
0059         //! Base type
0060         typedef attribute_value_impl< value_type > base_type;
0061 
0062     public:
0063         /*!
0064          * Constructor with the stored value initialization
0065          */
0066         explicit impl(value_type const& value) : base_type(value) {}
0067         /*!
0068          * Constructor with the stored value initialization
0069          */
0070         explicit impl(BOOST_RV_REF(value_type) value) BOOST_NOEXCEPT_IF(boost::is_nothrow_move_constructible< value_type >::value) :
0071             base_type(boost::move(value))
0072         {
0073         }
0074     };
0075 
0076 public:
0077     /*!
0078      * Constructor with the stored value initialization
0079      */
0080     explicit constant(value_type const& value) : attribute(new impl(value)) {}
0081     /*!
0082      * Constructor with the stored value initialization
0083      */
0084     explicit constant(BOOST_RV_REF(value_type) value) : attribute(new impl(boost::move(value))) {}
0085     /*!
0086      * Constructor for casting support
0087      */
0088     explicit constant(cast_source const& source) : attribute(source.as< impl >())
0089     {
0090     }
0091 
0092     /*!
0093      * \return Reference to the contained value.
0094      */
0095     value_type const& get() const
0096     {
0097         return static_cast< impl* >(this->get_impl())->get();
0098     }
0099 };
0100 
0101 /*!
0102  * The function constructs a \c constant attribute containing the provided value.
0103  * The function automatically converts C string arguments to \c std::basic_string objects.
0104  */
0105 template< typename T >
0106 inline constant<
0107     typename boost::log::aux::make_embedded_string_type<
0108         typename remove_reference< T >::type
0109     >::type
0110 > make_constant(BOOST_FWD_REF(T) val)
0111 {
0112     typedef typename boost::log::aux::make_embedded_string_type<
0113         typename remove_reference< T >::type
0114     >::type value_type;
0115     return constant< value_type >(boost::forward< T >(val));
0116 }
0117 
0118 } // namespace attributes
0119 
0120 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0121 
0122 } // namespace boost
0123 
0124 #include <boost/log/detail/footer.hpp>
0125 
0126 #endif // BOOST_LOG_ATTRIBUTES_CONSTANT_HPP_INCLUDED_