Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:19

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   record_view.hpp
0009  * \author Andrey Semashev
0010  * \date   09.03.2009
0011  *
0012  * This header contains a logging record view class definition.
0013  */
0014 
0015 #ifndef BOOST_LOG_CORE_RECORD_VIEW_HPP_INCLUDED_
0016 #define BOOST_LOG_CORE_RECORD_VIEW_HPP_INCLUDED_
0017 
0018 #include <boost/smart_ptr/intrusive_ptr.hpp>
0019 #include <boost/move/core.hpp>
0020 #include <boost/move/utility_core.hpp>
0021 #include <boost/core/explicit_operator_bool.hpp>
0022 #include <boost/log/detail/config.hpp>
0023 #include <boost/log/attributes/attribute_value_set.hpp>
0024 #include <boost/log/expressions/keyword_fwd.hpp>
0025 #ifndef BOOST_LOG_NO_THREADS
0026 #include <boost/detail/atomic_count.hpp>
0027 #endif // BOOST_LOG_NO_THREADS
0028 #include <boost/log/detail/header.hpp>
0029 
0030 #ifdef BOOST_HAS_PRAGMA_ONCE
0031 #pragma once
0032 #endif
0033 
0034 namespace boost {
0035 
0036 BOOST_LOG_OPEN_NAMESPACE
0037 
0038 #ifndef BOOST_LOG_DOXYGEN_PASS
0039 class core;
0040 class record;
0041 #endif // BOOST_LOG_DOXYGEN_PASS
0042 
0043 /*!
0044  * \brief Logging record view class
0045  *
0046  * The logging record encapsulates all information related to a single logging statement,
0047  * in particular, attribute values view and the log message string. The view is immutable,
0048  * it is implemented as a wrapper around a reference-counted implementation.
0049  */
0050 class record_view
0051 {
0052     BOOST_COPYABLE_AND_MOVABLE(record_view)
0053 
0054     friend class core;
0055     friend class record;
0056 
0057 #ifndef BOOST_LOG_DOXYGEN_PASS
0058 private:
0059     //! Private data
0060     struct private_data;
0061     friend struct private_data;
0062 
0063     //! Publicly available record data
0064     struct public_data
0065     {
0066         //! Reference counter
0067 #ifndef BOOST_LOG_NO_THREADS
0068         mutable boost::detail::atomic_count m_ref_counter;
0069 #else
0070         mutable unsigned int m_ref_counter;
0071 #endif // BOOST_LOG_NO_THREADS
0072 
0073         //! Attribute values view
0074         attribute_value_set m_attribute_values;
0075 
0076         //! Constructor from the attribute value set
0077         explicit public_data(BOOST_RV_REF(attribute_value_set) values) BOOST_NOEXCEPT :
0078             m_ref_counter(1),
0079             m_attribute_values(boost::move(values))
0080         {
0081         }
0082 
0083         //! Destructor
0084         BOOST_LOG_API static void destroy(const public_data* p) BOOST_NOEXCEPT;
0085 
0086     protected:
0087         ~public_data() {}
0088 
0089         BOOST_DELETED_FUNCTION(public_data(public_data const&))
0090         BOOST_DELETED_FUNCTION(public_data& operator= (public_data const&))
0091 
0092         friend void intrusive_ptr_add_ref(const public_data* p) BOOST_NOEXCEPT { ++p->m_ref_counter; }
0093         friend void intrusive_ptr_release(const public_data* p) BOOST_NOEXCEPT { if (--p->m_ref_counter == 0) public_data::destroy(p); }
0094     };
0095 
0096 private:
0097     //! A pointer to the log record implementation
0098     intrusive_ptr< public_data > m_impl;
0099 
0100 private:
0101     //  A private constructor, accessible from record
0102     explicit record_view(public_data* impl) BOOST_NOEXCEPT : m_impl(impl, false) {}
0103 
0104 #endif // BOOST_LOG_DOXYGEN_PASS
0105 
0106 public:
0107     /*!
0108      * Default constructor. Creates an empty record view that is equivalent to the invalid record handle.
0109      *
0110      * \post <tt>!*this == true</tt>
0111      */
0112     BOOST_CONSTEXPR record_view() BOOST_NOEXCEPT
0113 #if !defined(BOOST_LOG_NO_CXX11_DEFAULTED_NOEXCEPT_FUNCTIONS) && !defined(BOOST_LOG_NO_CXX11_DEFAULTED_CONSTEXPR_CONSTRUCTORS)
0114         = default;
0115 #else
0116     {}
0117 #endif
0118 
0119     /*!
0120      * Copy constructor
0121      */
0122     record_view(record_view const& that) BOOST_NOEXCEPT : m_impl(that.m_impl) {}
0123 
0124     /*!
0125      * Move constructor. Source record contents unspecified after the operation.
0126      */
0127     record_view(BOOST_RV_REF(record_view) that) BOOST_NOEXCEPT
0128     {
0129         m_impl.swap(that.m_impl);
0130     }
0131 
0132     /*!
0133      * Destructor. Destroys the record, releases any sinks and attribute values that were involved in processing this record.
0134      */
0135     ~record_view() BOOST_NOEXCEPT {}
0136 
0137     /*!
0138      * Copy assignment
0139      */
0140     record_view& operator= (BOOST_COPY_ASSIGN_REF(record_view) that) BOOST_NOEXCEPT
0141     {
0142         m_impl = that.m_impl;
0143         return *this;
0144     }
0145 
0146     /*!
0147      * Move assignment. Source record contents unspecified after the operation.
0148      */
0149     record_view& operator= (BOOST_RV_REF(record_view) that) BOOST_NOEXCEPT
0150     {
0151         m_impl.swap(that.m_impl);
0152         return *this;
0153     }
0154 
0155     /*!
0156      * \return A reference to the set of attribute values attached to this record
0157      *
0158      * \pre <tt>!!*this</tt>
0159      */
0160     attribute_value_set const& attribute_values() const BOOST_NOEXCEPT
0161     {
0162         return m_impl->m_attribute_values;
0163     }
0164 
0165     /*!
0166      * Equality comparison
0167      *
0168      * \param that Comparand
0169      * \return \c true if both <tt>*this</tt> and \a that identify the same log record or both do not
0170      *         identify any record, \c false otherwise.
0171      */
0172     bool operator== (record_view const& that) const BOOST_NOEXCEPT
0173     {
0174         return m_impl == that.m_impl;
0175     }
0176 
0177     /*!
0178      * Inequality comparison
0179      *
0180      * \param that Comparand
0181      * \return <tt>!(*this == that)</tt>
0182      */
0183     bool operator!= (record_view const& that) const BOOST_NOEXCEPT
0184     {
0185         return !operator== (that);
0186     }
0187 
0188     /*!
0189      * Conversion to an unspecified boolean type
0190      *
0191      * \return \c true, if the <tt>*this</tt> identifies a log record, \c false, if the <tt>*this</tt> is not valid
0192      */
0193     BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
0194 
0195     /*!
0196      * Inverted conversion to an unspecified boolean type
0197      *
0198      * \return \c false, if the <tt>*this</tt> identifies a log record, \c true, if the <tt>*this</tt> is not valid
0199      */
0200     bool operator! () const BOOST_NOEXCEPT
0201     {
0202         return !m_impl;
0203     }
0204 
0205     /*!
0206      * Swaps two handles
0207      *
0208      * \param that Another record to swap with
0209      * <b>Throws:</b> Nothing
0210      */
0211     void swap(record_view& that) BOOST_NOEXCEPT
0212     {
0213         m_impl.swap(that.m_impl);
0214     }
0215 
0216     /*!
0217      * Resets the log record handle. If there are no other handles left, the log record is closed
0218      * and all resources referenced by the record are released.
0219      *
0220      * \post <tt>!*this == true</tt>
0221      */
0222     void reset() BOOST_NOEXCEPT
0223     {
0224         m_impl.reset();
0225     }
0226 
0227     /*!
0228      * Attribute value lookup.
0229      *
0230      * \param name Attribute name.
0231      * \return An \c attribute_value, non-empty if it is found, empty otherwise.
0232      */
0233     attribute_value_set::mapped_type operator[] (attribute_value_set::key_type name) const
0234     {
0235         return m_impl->m_attribute_values[name];
0236     }
0237 
0238     /*!
0239      * Attribute value lookup.
0240      *
0241      * \param keyword Attribute keyword.
0242      * \return A \c value_ref with extracted attribute value if it is found, empty \c value_ref otherwise.
0243      */
0244     template< typename DescriptorT, template< typename > class ActorT >
0245     typename result_of::extract< typename expressions::attribute_keyword< DescriptorT, ActorT >::value_type, DescriptorT >::type
0246     operator[] (expressions::attribute_keyword< DescriptorT, ActorT > const& keyword) const
0247     {
0248         return m_impl->m_attribute_values[keyword];
0249     }
0250 };
0251 
0252 /*!
0253  * A free-standing swap function overload for \c record_view
0254  */
0255 inline void swap(record_view& left, record_view& right) BOOST_NOEXCEPT
0256 {
0257     left.swap(right);
0258 }
0259 
0260 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0261 
0262 } // namespace boost
0263 
0264 #include <boost/log/detail/footer.hpp>
0265 
0266 #endif // BOOST_LOG_CORE_RECORD_VIEW_HPP_INCLUDED_