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   attribute.hpp
0009  * \author Andrey Semashev
0010  * \date   15.04.2007
0011  *
0012  * The header contains attribute interface definition.
0013  */
0014 
0015 #ifndef BOOST_LOG_ATTRIBUTES_ATTRIBUTE_HPP_INCLUDED_
0016 #define BOOST_LOG_ATTRIBUTES_ATTRIBUTE_HPP_INCLUDED_
0017 
0018 #include <new>
0019 #include <boost/move/core.hpp>
0020 #include <boost/smart_ptr/intrusive_ptr.hpp>
0021 #include <boost/smart_ptr/intrusive_ref_counter.hpp>
0022 #include <boost/core/explicit_operator_bool.hpp>
0023 #include <boost/log/detail/config.hpp>
0024 #include <boost/log/detail/header.hpp>
0025 
0026 #ifdef BOOST_HAS_PRAGMA_ONCE
0027 #pragma once
0028 #endif
0029 
0030 namespace boost {
0031 
0032 BOOST_LOG_OPEN_NAMESPACE
0033 
0034 #ifndef BOOST_LOG_DOXYGEN_PASS
0035 
0036 class attribute_value;
0037 
0038 namespace aux {
0039 
0040 //! Reference proxy object to implement \c operator[]
0041 class attribute_set_reference_proxy;
0042 
0043 } // namespace aux
0044 
0045 #endif // BOOST_LOG_DOXYGEN_PASS
0046 
0047 /*!
0048  * \brief A base class for an attribute value factory
0049  *
0050  * Every attribute is represented with a factory that is basically an attribute value generator.
0051  * The sole purpose of an attribute is to return an actual value when requested. A simplest attribute
0052  * can always return the same value that it stores internally, but more complex ones can
0053  * perform a considerable amount of work to return a value, and the returned values may differ
0054  * each time requested.
0055  *
0056  * A word about thread safety. An attribute should be prepared to be requested a value from
0057  * multiple threads concurrently.
0058  */
0059 class attribute
0060 {
0061     BOOST_COPYABLE_AND_MOVABLE(attribute)
0062 
0063 public:
0064     /*!
0065      * \brief A base class for an attribute value factory
0066      *
0067      * All attributes must derive their implementation from this class.
0068      */
0069     struct BOOST_LOG_NO_VTABLE BOOST_SYMBOL_VISIBLE impl :
0070         public boost::intrusive_ref_counter< impl >
0071     {
0072         /*!
0073          * \brief Virtual destructor
0074          */
0075         virtual ~impl() {}
0076 
0077         /*!
0078          * \return The actual attribute value. It shall not return empty values (exceptions
0079          *         shall be used to indicate errors).
0080          */
0081         virtual attribute_value get_value() = 0;
0082 
0083         BOOST_LOG_API static void* operator new (std::size_t size);
0084         BOOST_LOG_API static void operator delete (void* p, std::size_t size) BOOST_NOEXCEPT;
0085     };
0086 
0087 private:
0088     //! Pointer to the attribute factory implementation
0089     intrusive_ptr< impl > m_pImpl;
0090 
0091 public:
0092     /*!
0093      * Default constructor. Creates an empty attribute value factory, which is not usable until
0094      * \c set_impl is called.
0095      */
0096     BOOST_DEFAULTED_FUNCTION(attribute(), {})
0097 
0098     /*!
0099      * Copy constructor
0100      */
0101     attribute(attribute const& that) BOOST_NOEXCEPT : m_pImpl(that.m_pImpl) {}
0102 
0103     /*!
0104      * Move constructor
0105      */
0106     attribute(BOOST_RV_REF(attribute) that) BOOST_NOEXCEPT { m_pImpl.swap(that.m_pImpl); }
0107 
0108     /*!
0109      * Initializing constructor
0110      *
0111      * \param p Pointer to the implementation. Must not be \c NULL.
0112      */
0113     explicit attribute(intrusive_ptr< impl > p) BOOST_NOEXCEPT { m_pImpl.swap(p); }
0114 
0115     /*!
0116      * Copy assignment
0117      */
0118     attribute& operator= (BOOST_COPY_ASSIGN_REF(attribute) that) BOOST_NOEXCEPT
0119     {
0120         m_pImpl = that.m_pImpl;
0121         return *this;
0122     }
0123 
0124     /*!
0125      * Move assignment
0126      */
0127     attribute& operator= (BOOST_RV_REF(attribute) that) BOOST_NOEXCEPT
0128     {
0129         m_pImpl.swap(that.m_pImpl);
0130         return *this;
0131     }
0132 
0133 #ifndef BOOST_LOG_DOXYGEN_PASS
0134     attribute& operator= (aux::attribute_set_reference_proxy const& that) BOOST_NOEXCEPT;
0135 #endif
0136 
0137     /*!
0138      * Verifies that the factory is not in empty state
0139      */
0140     BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
0141 
0142     /*!
0143      * Verifies that the factory is in empty state
0144      */
0145     bool operator! () const BOOST_NOEXCEPT { return !m_pImpl; }
0146 
0147     /*!
0148      * \return The actual attribute value. It shall not return empty values (exceptions
0149      *         shall be used to indicate errors).
0150      */
0151     attribute_value get_value() const;
0152 
0153     /*!
0154      * The method swaps two factories (i.e. their implementations).
0155      */
0156     void swap(attribute& that) BOOST_NOEXCEPT { m_pImpl.swap(that.m_pImpl); }
0157 
0158 protected:
0159     /*!
0160      * \returns The pointer to the implementation
0161      */
0162     impl* get_impl() const BOOST_NOEXCEPT { return m_pImpl.get(); }
0163     /*!
0164      * Sets the pointer to the factory implementation.
0165      *
0166      * \param p Pointer to the implementation. Must not be \c NULL.
0167      */
0168     void set_impl(intrusive_ptr< impl > p) BOOST_NOEXCEPT { m_pImpl.swap(p); }
0169 
0170     template< typename T >
0171     friend T attribute_cast(attribute const&);
0172 };
0173 
0174 /*!
0175  * The function swaps two attribute value factories
0176  */
0177 inline void swap(attribute& left, attribute& right) BOOST_NOEXCEPT
0178 {
0179     left.swap(right);
0180 }
0181 
0182 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0183 
0184 } // namespace boost
0185 
0186 #include <boost/log/detail/footer.hpp>
0187 #if defined(BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_HPP_INCLUDED_)
0188 #include <boost/log/detail/attribute_get_value_impl.hpp>
0189 #endif
0190 
0191 #endif // BOOST_LOG_ATTRIBUTES_ATTRIBUTE_HPP_INCLUDED_