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)
9 * \author Andrey Semashev
12 * The header contains implementation of a constant attribute.
15 #ifndef BOOST_LOG_ATTRIBUTES_CONSTANT_HPP_INCLUDED_
16 #define BOOST_LOG_ATTRIBUTES_CONSTANT_HPP_INCLUDED_
18 #include <boost/move/core.hpp>
19 #include <boost/move/utility_core.hpp>
20 #include <boost/type_traits/remove_reference.hpp>
21 #include <boost/log/detail/config.hpp>
22 #include <boost/log/detail/embedded_string_type.hpp>
23 #include <boost/log/attributes/attribute.hpp>
24 #include <boost/log/attributes/attribute_cast.hpp>
25 #include <boost/log/attributes/attribute_value_impl.hpp>
26 #include <boost/log/detail/header.hpp>
28 #ifdef BOOST_HAS_PRAGMA_ONCE
34 BOOST_LOG_OPEN_NAMESPACE
36 namespace attributes {
39 * \brief A class of an attribute that holds a single constant value
41 * The constant is a simplest and one of the most frequently used types of attributes.
42 * It stores a constant value, which it eventually returns as its value each time
45 template< typename T >
50 //! Attribute value type
54 //! Factory implementation
55 class BOOST_SYMBOL_VISIBLE impl :
56 public attribute_value_impl< value_type >
59 typedef attribute_value_impl< value_type > base_type;
63 * Constructor with the stored value initialization
65 explicit impl(value_type const& value) : base_type(value) {}
67 * Constructor with the stored value initialization
69 explicit impl(BOOST_RV_REF(value_type) value) : base_type(boost::move(value)) {}
74 * Constructor with the stored value initialization
76 explicit constant(value_type const& value) : attribute(new impl(value)) {}
78 * Constructor with the stored value initialization
80 explicit constant(BOOST_RV_REF(value_type) value) : attribute(new impl(boost::move(value))) {}
82 * Constructor for casting support
84 explicit constant(cast_source const& source) : attribute(source.as< impl >())
89 * \return Reference to the contained value.
91 value_type const& get() const
93 return static_cast< impl* >(this->get_impl())->get();
98 * The function constructs a \c constant attribute containing the provided value.
99 * The function automatically converts C string arguments to \c std::basic_string objects.
101 template< typename T >
103 typename boost::log::aux::make_embedded_string_type<
104 typename remove_reference< T >::type
106 > make_constant(BOOST_FWD_REF(T) val)
108 typedef typename boost::log::aux::make_embedded_string_type<
109 typename remove_reference< T >::type
111 return constant< value_type >(boost::forward< T >(val));
114 } // namespace attributes
116 BOOST_LOG_CLOSE_NAMESPACE // namespace log
120 #include <boost/log/detail/footer.hpp>
122 #endif // BOOST_LOG_ATTRIBUTES_CONSTANT_HPP_INCLUDED_