Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/log/core/record_view.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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