2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
8 * \file record_view.hpp
9 * \author Andrey Semashev
12 * This header contains a logging record view class definition.
15 #ifndef BOOST_LOG_CORE_RECORD_VIEW_HPP_INCLUDED_
16 #define BOOST_LOG_CORE_RECORD_VIEW_HPP_INCLUDED_
18 #include <boost/smart_ptr/intrusive_ptr.hpp>
19 #include <boost/move/core.hpp>
20 #include <boost/move/utility_core.hpp>
21 #include <boost/core/explicit_operator_bool.hpp>
22 #include <boost/log/detail/config.hpp>
23 #include <boost/log/attributes/attribute_value_set.hpp>
24 #include <boost/log/expressions/keyword_fwd.hpp>
25 #ifndef BOOST_LOG_NO_THREADS
26 #include <boost/detail/atomic_count.hpp>
27 #endif // BOOST_LOG_NO_THREADS
28 #include <boost/log/detail/header.hpp>
30 #ifdef BOOST_HAS_PRAGMA_ONCE
36 BOOST_LOG_OPEN_NAMESPACE
38 #ifndef BOOST_LOG_DOXYGEN_PASS
41 #endif // BOOST_LOG_DOXYGEN_PASS
44 * \brief Logging record view class
46 * The logging record encapsulates all information related to a single logging statement,
47 * in particular, attribute values view and the log message string. The view is immutable,
48 * it is implemented as a wrapper around a reference-counted implementation.
52 BOOST_COPYABLE_AND_MOVABLE(record_view)
57 #ifndef BOOST_LOG_DOXYGEN_PASS
61 friend struct private_data;
63 //! Publicly available record data
67 #ifndef BOOST_LOG_NO_THREADS
68 mutable boost::detail::atomic_count m_ref_counter;
70 mutable unsigned int m_ref_counter;
71 #endif // BOOST_LOG_NO_THREADS
73 //! Attribute values view
74 attribute_value_set m_attribute_values;
76 //! Constructor from the attribute value set
77 explicit public_data(BOOST_RV_REF(attribute_value_set) values) BOOST_NOEXCEPT :
79 m_attribute_values(boost::move(values))
84 BOOST_LOG_API static void destroy(const public_data* p) BOOST_NOEXCEPT;
89 BOOST_DELETED_FUNCTION(public_data(public_data const&))
90 BOOST_DELETED_FUNCTION(public_data& operator= (public_data const&))
92 friend void intrusive_ptr_add_ref(const public_data* p) BOOST_NOEXCEPT { ++p->m_ref_counter; }
93 friend void intrusive_ptr_release(const public_data* p) BOOST_NOEXCEPT { if (--p->m_ref_counter == 0) public_data::destroy(p); }
97 //! A pointer to the log record implementation
98 intrusive_ptr< public_data > m_impl;
101 // A private constructor, accessible from record
102 explicit record_view(public_data* impl) BOOST_NOEXCEPT : m_impl(impl, false) {}
104 #endif // BOOST_LOG_DOXYGEN_PASS
108 * Default constructor. Creates an empty record view that is equivalent to the invalid record handle.
110 * \post <tt>!*this == true</tt>
112 BOOST_CONSTEXPR record_view() BOOST_NOEXCEPT
113 #if !defined(BOOST_LOG_NO_CXX11_DEFAULTED_NOEXCEPT_FUNCTIONS) && !defined(BOOST_LOG_NO_CXX11_DEFAULTED_CONSTEXPR_CONSTRUCTORS)
122 record_view(record_view const& that) BOOST_NOEXCEPT : m_impl(that.m_impl) {}
125 * Move constructor. Source record contents unspecified after the operation.
127 record_view(BOOST_RV_REF(record_view) that) BOOST_NOEXCEPT
129 m_impl.swap(that.m_impl);
133 * Destructor. Destroys the record, releases any sinks and attribute values that were involved in processing this record.
135 ~record_view() BOOST_NOEXCEPT {}
140 record_view& operator= (BOOST_COPY_ASSIGN_REF(record_view) that) BOOST_NOEXCEPT
142 m_impl = that.m_impl;
147 * Move assignment. Source record contents unspecified after the operation.
149 record_view& operator= (BOOST_RV_REF(record_view) that) BOOST_NOEXCEPT
151 m_impl.swap(that.m_impl);
156 * \return A reference to the set of attribute values attached to this record
158 * \pre <tt>!!*this</tt>
160 attribute_value_set const& attribute_values() const BOOST_NOEXCEPT
162 return m_impl->m_attribute_values;
166 * Equality comparison
168 * \param that Comparand
169 * \return \c true if both <tt>*this</tt> and \a that identify the same log record or both do not
170 * identify any record, \c false otherwise.
172 bool operator== (record_view const& that) const BOOST_NOEXCEPT
174 return m_impl == that.m_impl;
178 * Inequality comparison
180 * \param that Comparand
181 * \return <tt>!(*this == that)</tt>
183 bool operator!= (record_view const& that) const BOOST_NOEXCEPT
185 return !operator== (that);
189 * Conversion to an unspecified boolean type
191 * \return \c true, if the <tt>*this</tt> identifies a log record, \c false, if the <tt>*this</tt> is not valid
193 BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
196 * Inverted conversion to an unspecified boolean type
198 * \return \c false, if the <tt>*this</tt> identifies a log record, \c true, if the <tt>*this</tt> is not valid
200 bool operator! () const BOOST_NOEXCEPT
208 * \param that Another record to swap with
209 * <b>Throws:</b> Nothing
211 void swap(record_view& that) BOOST_NOEXCEPT
213 m_impl.swap(that.m_impl);
217 * Resets the log record handle. If there are no other handles left, the log record is closed
218 * and all resources referenced by the record are released.
220 * \post <tt>!*this == true</tt>
222 void reset() BOOST_NOEXCEPT
228 * Attribute value lookup.
230 * \param name Attribute name.
231 * \return An \c attribute_value, non-empty if it is found, empty otherwise.
233 attribute_value_set::mapped_type operator[] (attribute_value_set::key_type name) const
235 return m_impl->m_attribute_values[name];
239 * Attribute value lookup.
241 * \param keyword Attribute keyword.
242 * \return A \c value_ref with extracted attribute value if it is found, empty \c value_ref otherwise.
244 template< typename DescriptorT, template< typename > class ActorT >
245 typename result_of::extract< typename expressions::attribute_keyword< DescriptorT, ActorT >::value_type, DescriptorT >::type
246 operator[] (expressions::attribute_keyword< DescriptorT, ActorT > const& keyword) const
248 return m_impl->m_attribute_values[keyword];
253 * A free-standing swap function overload for \c record_view
255 inline void swap(record_view& left, record_view& right) BOOST_NOEXCEPT
260 BOOST_LOG_CLOSE_NAMESPACE // namespace log
264 #include <boost/log/detail/footer.hpp>
266 #endif // BOOST_LOG_CORE_RECORD_VIEW_HPP_INCLUDED_