Chris@16: /* Chris@101: * Copyright Andrey Semashev 2007 - 2015. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: /*! Chris@16: * \file constant.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 15.04.2007 Chris@16: * Chris@16: * The header contains implementation of a constant attribute. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_ATTRIBUTES_CONSTANT_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_ATTRIBUTES_CONSTANT_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: BOOST_LOG_OPEN_NAMESPACE Chris@16: Chris@16: namespace attributes { Chris@16: Chris@16: /*! Chris@16: * \brief A class of an attribute that holds a single constant value Chris@16: * Chris@16: * The constant is a simplest and one of the most frequently used types of attributes. Chris@16: * It stores a constant value, which it eventually returns as its value each time Chris@16: * requested. Chris@16: */ Chris@16: template< typename T > Chris@16: class constant : Chris@16: public attribute Chris@16: { Chris@16: public: Chris@16: //! Attribute value type Chris@16: typedef T value_type; Chris@16: Chris@16: protected: Chris@16: //! Factory implementation Chris@16: class BOOST_SYMBOL_VISIBLE impl : Chris@16: public attribute_value_impl< value_type > Chris@16: { Chris@16: //! Base type Chris@16: typedef attribute_value_impl< value_type > base_type; Chris@16: Chris@16: public: Chris@16: /*! Chris@16: * Constructor with the stored value initialization Chris@16: */ Chris@16: explicit impl(value_type const& value) : base_type(value) {} Chris@16: /*! Chris@16: * Constructor with the stored value initialization Chris@16: */ Chris@16: explicit impl(BOOST_RV_REF(value_type) value) : base_type(boost::move(value)) {} Chris@16: }; Chris@16: Chris@16: public: Chris@16: /*! Chris@16: * Constructor with the stored value initialization Chris@16: */ Chris@16: explicit constant(value_type const& value) : attribute(new impl(value)) {} Chris@16: /*! Chris@16: * Constructor with the stored value initialization Chris@16: */ Chris@16: explicit constant(BOOST_RV_REF(value_type) value) : attribute(new impl(boost::move(value))) {} Chris@16: /*! Chris@16: * Constructor for casting support Chris@16: */ Chris@16: explicit constant(cast_source const& source) : attribute(source.as< impl >()) Chris@16: { Chris@16: } Chris@16: Chris@16: /*! Chris@16: * \return Reference to the contained value. Chris@16: */ Chris@16: value_type const& get() const Chris@16: { Chris@16: return static_cast< impl* >(this->get_impl())->get(); Chris@16: } Chris@16: }; Chris@16: Chris@16: /*! Chris@16: * The function constructs a \c constant attribute containing the provided value. Chris@16: * The function automatically converts C string arguments to \c std::basic_string objects. Chris@16: */ Chris@16: template< typename T > Chris@16: inline constant< Chris@16: typename boost::log::aux::make_embedded_string_type< Chris@16: typename remove_reference< T >::type Chris@16: >::type Chris@16: > make_constant(BOOST_FWD_REF(T) val) Chris@16: { Chris@16: typedef typename boost::log::aux::make_embedded_string_type< Chris@16: typename remove_reference< T >::type Chris@16: >::type value_type; Chris@16: return constant< value_type >(boost::forward< T >(val)); Chris@16: } Chris@16: Chris@16: } // namespace attributes Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_LOG_ATTRIBUTES_CONSTANT_HPP_INCLUDED_