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.hpp
0009  * \author Andrey Semashev
0010  * \date   09.03.2009
0011  *
0012  * This header contains a logging record class definition.
0013  */
0014 
0015 #ifndef BOOST_LOG_CORE_RECORD_HPP_INCLUDED_
0016 #define BOOST_LOG_CORE_RECORD_HPP_INCLUDED_
0017 
0018 #include <boost/move/core.hpp>
0019 #include <boost/core/explicit_operator_bool.hpp>
0020 #include <boost/log/detail/config.hpp>
0021 #include <boost/log/attributes/attribute_value_set.hpp>
0022 #include <boost/log/expressions/keyword_fwd.hpp>
0023 #include <boost/log/core/record_view.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 class core;
0035 
0036 /*!
0037  * \brief Logging record class
0038  *
0039  * The logging record encapsulates all information related to a single logging statement,
0040  * in particular, attribute values view and the log message string. The record can be updated before pushing
0041  * for further processing to the logging core.
0042  */
0043 class record
0044 {
0045     BOOST_MOVABLE_BUT_NOT_COPYABLE(record)
0046 
0047     friend class core;
0048 
0049 #ifndef BOOST_LOG_DOXYGEN_PASS
0050 private:
0051     //! Private data
0052     typedef record_view::public_data public_data;
0053 
0054 private:
0055     //! A pointer to the log record implementation
0056     public_data* m_impl;
0057 
0058 private:
0059     //  A private constructor, accessible from core
0060     BOOST_CONSTEXPR explicit record(public_data* impl) BOOST_NOEXCEPT : m_impl(impl) {}
0061 
0062 #endif // BOOST_LOG_DOXYGEN_PASS
0063 
0064 public:
0065     /*!
0066      * Default constructor. Creates an empty record that is equivalent to the invalid record handle.
0067      *
0068      * \post <tt>!*this == true</tt>
0069      */
0070     BOOST_CONSTEXPR record() BOOST_NOEXCEPT : m_impl(NULL) {}
0071 
0072     /*!
0073      * Move constructor. Source record contents unspecified after the operation.
0074      */
0075     record(BOOST_RV_REF(record) that) BOOST_NOEXCEPT : m_impl(that.m_impl)
0076     {
0077         that.m_impl = NULL;
0078     }
0079 
0080     /*!
0081      * Destructor. Destroys the record, releases any sinks and attribute values that were involved in processing this record.
0082      */
0083     ~record() BOOST_NOEXCEPT
0084     {
0085         reset();
0086     }
0087 
0088     /*!
0089      * Move assignment. Source record contents unspecified after the operation.
0090      */
0091     record& operator= (BOOST_RV_REF(record) that) BOOST_NOEXCEPT
0092     {
0093         swap(static_cast< record& >(that));
0094         return *this;
0095     }
0096 
0097     /*!
0098      * \return A reference to the set of attribute values attached to this record
0099      *
0100      * \pre <tt>!!*this</tt>
0101      */
0102     attribute_value_set& attribute_values() BOOST_NOEXCEPT
0103     {
0104         return m_impl->m_attribute_values;
0105     }
0106 
0107     /*!
0108      * \return A reference to the set of attribute values attached to this record
0109      *
0110      * \pre <tt>!!*this</tt>
0111      */
0112     attribute_value_set const& attribute_values() const BOOST_NOEXCEPT
0113     {
0114         return m_impl->m_attribute_values;
0115     }
0116 
0117     /*!
0118      * Conversion to an unspecified boolean type
0119      *
0120      * \return \c true, if the <tt>*this</tt> identifies a log record, \c false, if the <tt>*this</tt> is not valid
0121      */
0122     BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
0123 
0124     /*!
0125      * Inverted conversion to an unspecified boolean type
0126      *
0127      * \return \c false, if the <tt>*this</tt> identifies a log record, \c true, if the <tt>*this</tt> is not valid
0128      */
0129     bool operator! () const BOOST_NOEXCEPT
0130     {
0131         return !m_impl;
0132     }
0133 
0134     /*!
0135      * Swaps two handles
0136      *
0137      * \param that Another record to swap with
0138      * <b>Throws:</b> Nothing
0139      */
0140     void swap(record& that) BOOST_NOEXCEPT
0141     {
0142         public_data* p = m_impl;
0143         m_impl = that.m_impl;
0144         that.m_impl = p;
0145     }
0146 
0147     /*!
0148      * Resets the log record handle. If there are no other handles left, the log record is closed
0149      * and all resources referenced by the record are released.
0150      *
0151      * \post <tt>!*this == true</tt>
0152      */
0153     void reset() BOOST_NOEXCEPT
0154     {
0155         if (m_impl)
0156         {
0157             public_data::destroy(m_impl);
0158             m_impl = NULL;
0159         }
0160     }
0161 
0162     /*!
0163      * Attribute value lookup.
0164      *
0165      * \param name Attribute name.
0166      * \return An \c attribute_value, non-empty if it is found, empty otherwise.
0167      */
0168     attribute_value_set::mapped_type operator[] (attribute_value_set::key_type name) const
0169     {
0170         return m_impl->m_attribute_values[name];
0171     }
0172 
0173     /*!
0174      * Attribute value lookup.
0175      *
0176      * \param keyword Attribute keyword.
0177      * \return A \c value_ref with extracted attribute value if it is found, empty \c value_ref otherwise.
0178      */
0179     template< typename DescriptorT, template< typename > class ActorT >
0180     typename result_of::extract< typename expressions::attribute_keyword< DescriptorT, ActorT >::value_type, DescriptorT >::type
0181     operator[] (expressions::attribute_keyword< DescriptorT, ActorT > const& keyword) const
0182     {
0183         return m_impl->m_attribute_values[keyword];
0184     }
0185 
0186     /*!
0187      * The function ensures that the log record does not depend on any thread-specific data. Then the record contents
0188      * are used to construct a \c record_view which is returned from the function. The record is no longer valid after the call.
0189      *
0190      * \pre <tt>!!*this</tt>
0191      * \post <tt>!*this</tt>
0192      * \returns The record view that contains all attribute values from the original record.
0193      */
0194     BOOST_LOG_API record_view lock();
0195 };
0196 
0197 /*!
0198  * A free-standing swap function overload for \c record
0199  */
0200 inline void swap(record& left, record& right) BOOST_NOEXCEPT
0201 {
0202     left.swap(right);
0203 }
0204 
0205 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0206 
0207 } // namespace boost
0208 
0209 #include <boost/log/detail/footer.hpp>
0210 
0211 #endif // BOOST_LOG_CORE_RECORD_HPP_INCLUDED_