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 attribute interface definition.
15 #ifndef BOOST_LOG_ATTRIBUTES_ATTRIBUTE_HPP_INCLUDED_
16 #define BOOST_LOG_ATTRIBUTES_ATTRIBUTE_HPP_INCLUDED_
19 #include <boost/move/core.hpp>
20 #include <boost/smart_ptr/intrusive_ptr.hpp>
21 #include <boost/smart_ptr/intrusive_ref_counter.hpp>
22 #include <boost/core/explicit_operator_bool.hpp>
23 #include <boost/log/detail/config.hpp>
24 #include <boost/log/detail/header.hpp>
26 #ifdef BOOST_HAS_PRAGMA_ONCE
32 BOOST_LOG_OPEN_NAMESPACE
34 #ifndef BOOST_LOG_DOXYGEN_PASS
36 class attribute_value;
40 //! Reference proxy object to implement \c operator[]
41 class attribute_set_reference_proxy;
45 #endif // BOOST_LOG_DOXYGEN_PASS
48 * \brief A base class for an attribute value factory
50 * Every attribute is represented with a factory that is basically an attribute value generator.
51 * The sole purpose of an attribute is to return an actual value when requested. A simplest attribute
52 * can always return the same value that it stores internally, but more complex ones can
53 * perform a considerable amount of work to return a value, and the returned values may differ
54 * each time requested.
56 * A word about thread safety. An attribute should be prepared to be requested a value from
57 * multiple threads concurrently.
61 BOOST_COPYABLE_AND_MOVABLE(attribute)
65 * \brief A base class for an attribute value factory
67 * All attributes must derive their implementation from this class.
69 struct BOOST_LOG_NO_VTABLE BOOST_SYMBOL_VISIBLE impl :
70 public boost::intrusive_ref_counter< impl >
73 * \brief Virtual destructor
78 * \return The actual attribute value. It shall not return empty values (exceptions
79 * shall be used to indicate errors).
81 virtual attribute_value get_value() = 0;
83 BOOST_LOG_API static void* operator new (std::size_t size);
84 BOOST_LOG_API static void operator delete (void* p, std::size_t size) BOOST_NOEXCEPT;
88 //! Pointer to the attribute factory implementation
89 intrusive_ptr< impl > m_pImpl;
93 * Default constructor. Creates an empty attribute value factory, which is not usable until
94 * \c set_impl is called.
96 BOOST_DEFAULTED_FUNCTION(attribute(), {})
101 attribute(attribute const& that) BOOST_NOEXCEPT : m_pImpl(that.m_pImpl) {}
106 attribute(BOOST_RV_REF(attribute) that) BOOST_NOEXCEPT { m_pImpl.swap(that.m_pImpl); }
109 * Initializing constructor
111 * \param p Pointer to the implementation. Must not be \c NULL.
113 explicit attribute(intrusive_ptr< impl > p) BOOST_NOEXCEPT { m_pImpl.swap(p); }
118 attribute& operator= (BOOST_COPY_ASSIGN_REF(attribute) that) BOOST_NOEXCEPT
120 m_pImpl = that.m_pImpl;
127 attribute& operator= (BOOST_RV_REF(attribute) that) BOOST_NOEXCEPT
129 m_pImpl.swap(that.m_pImpl);
133 #ifndef BOOST_LOG_DOXYGEN_PASS
134 attribute& operator= (aux::attribute_set_reference_proxy const& that) BOOST_NOEXCEPT;
138 * Verifies that the factory is not in empty state
140 BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
143 * Verifies that the factory is in empty state
145 bool operator! () const BOOST_NOEXCEPT { return !m_pImpl; }
148 * \return The actual attribute value. It shall not return empty values (exceptions
149 * shall be used to indicate errors).
151 attribute_value get_value() const;
154 * The method swaps two factories (i.e. their implementations).
156 void swap(attribute& that) BOOST_NOEXCEPT { m_pImpl.swap(that.m_pImpl); }
160 * \returns The pointer to the implementation
162 impl* get_impl() const BOOST_NOEXCEPT { return m_pImpl.get(); }
164 * Sets the pointer to the factory implementation.
166 * \param p Pointer to the implementation. Must not be \c NULL.
168 void set_impl(intrusive_ptr< impl > p) BOOST_NOEXCEPT { m_pImpl.swap(p); }
170 template< typename T >
171 friend T attribute_cast(attribute const&);
175 * The function swaps two attribute value factories
177 inline void swap(attribute& left, attribute& right) BOOST_NOEXCEPT
182 BOOST_LOG_CLOSE_NAMESPACE // namespace log
186 #include <boost/log/detail/footer.hpp>
187 #if defined(BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_HPP_INCLUDED_)
188 #include <boost/log/detail/attribute_get_value_impl.hpp>
191 #endif // BOOST_LOG_ATTRIBUTES_ATTRIBUTE_HPP_INCLUDED_