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 attribute.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 15.04.2007 Chris@16: * Chris@16: * The header contains attribute interface definition. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_ATTRIBUTES_ATTRIBUTE_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_ATTRIBUTES_ATTRIBUTE_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: 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: #ifndef BOOST_LOG_DOXYGEN_PASS Chris@16: Chris@16: class attribute_value; Chris@16: Chris@16: namespace aux { Chris@16: Chris@16: //! Reference proxy object to implement \c operator[] Chris@16: class attribute_set_reference_proxy; Chris@16: Chris@16: } // namespace aux Chris@16: Chris@16: #endif // BOOST_LOG_DOXYGEN_PASS Chris@16: Chris@16: /*! Chris@16: * \brief A base class for an attribute value factory Chris@16: * Chris@16: * Every attribute is represented with a factory that is basically an attribute value generator. Chris@16: * The sole purpose of an attribute is to return an actual value when requested. A simplest attribute Chris@16: * can always return the same value that it stores internally, but more complex ones can Chris@16: * perform a considerable amount of work to return a value, and the returned values may differ Chris@16: * each time requested. Chris@16: * Chris@16: * A word about thread safety. An attribute should be prepared to be requested a value from Chris@16: * multiple threads concurrently. Chris@16: */ Chris@16: class attribute Chris@16: { Chris@16: BOOST_COPYABLE_AND_MOVABLE(attribute) Chris@16: Chris@16: public: Chris@16: /*! Chris@16: * \brief A base class for an attribute value factory Chris@16: * Chris@16: * All attributes must derive their implementation from this class. Chris@16: */ Chris@16: struct BOOST_LOG_NO_VTABLE BOOST_SYMBOL_VISIBLE impl : Chris@16: public boost::intrusive_ref_counter< impl > Chris@16: { Chris@16: /*! Chris@16: * \brief Virtual destructor Chris@16: */ Chris@16: virtual ~impl() {} Chris@16: Chris@16: /*! Chris@16: * \return The actual attribute value. It shall not return empty values (exceptions Chris@16: * shall be used to indicate errors). Chris@16: */ Chris@16: virtual attribute_value get_value() = 0; Chris@16: Chris@16: BOOST_LOG_API static void* operator new (std::size_t size); Chris@16: BOOST_LOG_API static void operator delete (void* p, std::size_t size) BOOST_NOEXCEPT; Chris@16: }; Chris@16: Chris@16: private: Chris@16: //! Pointer to the attribute factory implementation Chris@16: intrusive_ptr< impl > m_pImpl; Chris@16: Chris@16: public: Chris@16: /*! Chris@16: * Default constructor. Creates an empty attribute value factory, which is not usable until Chris@16: * \c set_impl is called. Chris@16: */ Chris@16: BOOST_DEFAULTED_FUNCTION(attribute(), {}) Chris@16: Chris@16: /*! Chris@16: * Copy constructor Chris@16: */ Chris@16: attribute(attribute const& that) BOOST_NOEXCEPT : m_pImpl(that.m_pImpl) {} Chris@16: Chris@16: /*! Chris@16: * Move constructor Chris@16: */ Chris@16: attribute(BOOST_RV_REF(attribute) that) BOOST_NOEXCEPT { m_pImpl.swap(that.m_pImpl); } Chris@16: Chris@16: /*! Chris@16: * Initializing constructor Chris@16: * Chris@16: * \param p Pointer to the implementation. Must not be \c NULL. Chris@16: */ Chris@16: explicit attribute(intrusive_ptr< impl > p) BOOST_NOEXCEPT { m_pImpl.swap(p); } Chris@16: Chris@16: /*! Chris@16: * Copy assignment Chris@16: */ Chris@16: attribute& operator= (BOOST_COPY_ASSIGN_REF(attribute) that) BOOST_NOEXCEPT Chris@16: { Chris@16: m_pImpl = that.m_pImpl; Chris@16: return *this; Chris@16: } Chris@16: Chris@16: /*! Chris@16: * Move assignment Chris@16: */ Chris@16: attribute& operator= (BOOST_RV_REF(attribute) that) BOOST_NOEXCEPT Chris@16: { Chris@16: m_pImpl.swap(that.m_pImpl); Chris@16: return *this; Chris@16: } Chris@16: Chris@16: #ifndef BOOST_LOG_DOXYGEN_PASS Chris@16: attribute& operator= (aux::attribute_set_reference_proxy const& that) BOOST_NOEXCEPT; Chris@16: #endif Chris@16: Chris@16: /*! Chris@16: * Verifies that the factory is not in empty state Chris@16: */ Chris@101: BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT() Chris@16: Chris@16: /*! Chris@16: * Verifies that the factory is in empty state Chris@16: */ Chris@16: bool operator! () const BOOST_NOEXCEPT { return !m_pImpl; } Chris@16: Chris@16: /*! Chris@16: * \return The actual attribute value. It shall not return empty values (exceptions Chris@16: * shall be used to indicate errors). Chris@16: */ Chris@16: attribute_value get_value() const; Chris@16: Chris@16: /*! Chris@16: * The method swaps two factories (i.e. their implementations). Chris@16: */ Chris@16: void swap(attribute& that) BOOST_NOEXCEPT { m_pImpl.swap(that.m_pImpl); } Chris@16: Chris@16: protected: Chris@16: /*! Chris@16: * \returns The pointer to the implementation Chris@16: */ Chris@16: impl* get_impl() const BOOST_NOEXCEPT { return m_pImpl.get(); } Chris@16: /*! Chris@16: * Sets the pointer to the factory implementation. Chris@16: * Chris@16: * \param p Pointer to the implementation. Must not be \c NULL. Chris@16: */ Chris@16: void set_impl(intrusive_ptr< impl > p) BOOST_NOEXCEPT { m_pImpl.swap(p); } Chris@16: Chris@16: template< typename T > Chris@16: friend T attribute_cast(attribute const&); Chris@16: }; Chris@16: Chris@16: /*! Chris@16: * The function swaps two attribute value factories Chris@16: */ Chris@16: inline void swap(attribute& left, attribute& right) BOOST_NOEXCEPT Chris@16: { Chris@16: left.swap(right); Chris@16: } Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: #if defined(BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_HPP_INCLUDED_) Chris@16: #include Chris@16: #endif Chris@16: Chris@16: #endif // BOOST_LOG_ATTRIBUTES_ATTRIBUTE_HPP_INCLUDED_