]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/log/core/record.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / log / core / record.hpp
1 /*
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)
6 */
7 /*!
8 * \file record.hpp
9 * \author Andrey Semashev
10 * \date 09.03.2009
11 *
12 * This header contains a logging record class definition.
13 */
14
15 #ifndef BOOST_LOG_CORE_RECORD_HPP_INCLUDED_
16 #define BOOST_LOG_CORE_RECORD_HPP_INCLUDED_
17
18 #include <boost/move/core.hpp>
19 #include <boost/core/explicit_operator_bool.hpp>
20 #include <boost/log/detail/config.hpp>
21 #include <boost/log/attributes/attribute_value_set.hpp>
22 #include <boost/log/expressions/keyword_fwd.hpp>
23 #include <boost/log/core/record_view.hpp>
24 #include <boost/log/detail/header.hpp>
25
26 #ifdef BOOST_HAS_PRAGMA_ONCE
27 #pragma once
28 #endif
29
30 namespace boost {
31
32 BOOST_LOG_OPEN_NAMESPACE
33
34 class core;
35
36 /*!
37 * \brief Logging record class
38 *
39 * The logging record encapsulates all information related to a single logging statement,
40 * in particular, attribute values view and the log message string. The record can be updated before pushing
41 * for further processing to the logging core.
42 */
43 class record
44 {
45 BOOST_MOVABLE_BUT_NOT_COPYABLE(record)
46
47 friend class core;
48
49 #ifndef BOOST_LOG_DOXYGEN_PASS
50 private:
51 //! Private data
52 typedef record_view::public_data public_data;
53
54 private:
55 //! A pointer to the log record implementation
56 public_data* m_impl;
57
58 private:
59 // A private constructor, accessible from core
60 BOOST_CONSTEXPR explicit record(public_data* impl) BOOST_NOEXCEPT : m_impl(impl) {}
61
62 #endif // BOOST_LOG_DOXYGEN_PASS
63
64 public:
65 /*!
66 * Default constructor. Creates an empty record that is equivalent to the invalid record handle.
67 *
68 * \post <tt>!*this == true</tt>
69 */
70 BOOST_CONSTEXPR record() BOOST_NOEXCEPT : m_impl(NULL) {}
71
72 /*!
73 * Move constructor. Source record contents unspecified after the operation.
74 */
75 record(BOOST_RV_REF(record) that) BOOST_NOEXCEPT : m_impl(that.m_impl)
76 {
77 that.m_impl = NULL;
78 }
79
80 /*!
81 * Destructor. Destroys the record, releases any sinks and attribute values that were involved in processing this record.
82 */
83 ~record() BOOST_NOEXCEPT
84 {
85 reset();
86 }
87
88 /*!
89 * Move assignment. Source record contents unspecified after the operation.
90 */
91 record& operator= (BOOST_RV_REF(record) that) BOOST_NOEXCEPT
92 {
93 swap(static_cast< record& >(that));
94 return *this;
95 }
96
97 /*!
98 * \return A reference to the set of attribute values attached to this record
99 *
100 * \pre <tt>!!*this</tt>
101 */
102 attribute_value_set& attribute_values() BOOST_NOEXCEPT
103 {
104 return m_impl->m_attribute_values;
105 }
106
107 /*!
108 * \return A reference to the set of attribute values attached to this record
109 *
110 * \pre <tt>!!*this</tt>
111 */
112 attribute_value_set const& attribute_values() const BOOST_NOEXCEPT
113 {
114 return m_impl->m_attribute_values;
115 }
116
117 /*!
118 * Conversion to an unspecified boolean type
119 *
120 * \return \c true, if the <tt>*this</tt> identifies a log record, \c false, if the <tt>*this</tt> is not valid
121 */
122 BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
123
124 /*!
125 * Inverted conversion to an unspecified boolean type
126 *
127 * \return \c false, if the <tt>*this</tt> identifies a log record, \c true, if the <tt>*this</tt> is not valid
128 */
129 bool operator! () const BOOST_NOEXCEPT
130 {
131 return !m_impl;
132 }
133
134 /*!
135 * Swaps two handles
136 *
137 * \param that Another record to swap with
138 * <b>Throws:</b> Nothing
139 */
140 void swap(record& that) BOOST_NOEXCEPT
141 {
142 public_data* p = m_impl;
143 m_impl = that.m_impl;
144 that.m_impl = p;
145 }
146
147 /*!
148 * Resets the log record handle. If there are no other handles left, the log record is closed
149 * and all resources referenced by the record are released.
150 *
151 * \post <tt>!*this == true</tt>
152 */
153 void reset() BOOST_NOEXCEPT
154 {
155 if (m_impl)
156 {
157 public_data::destroy(m_impl);
158 m_impl = NULL;
159 }
160 }
161
162 /*!
163 * Attribute value lookup.
164 *
165 * \param name Attribute name.
166 * \return An \c attribute_value, non-empty if it is found, empty otherwise.
167 */
168 attribute_value_set::mapped_type operator[] (attribute_value_set::key_type name) const
169 {
170 return m_impl->m_attribute_values[name];
171 }
172
173 /*!
174 * Attribute value lookup.
175 *
176 * \param keyword Attribute keyword.
177 * \return A \c value_ref with extracted attribute value if it is found, empty \c value_ref otherwise.
178 */
179 template< typename DescriptorT, template< typename > class ActorT >
180 typename result_of::extract< typename expressions::attribute_keyword< DescriptorT, ActorT >::value_type, DescriptorT >::type
181 operator[] (expressions::attribute_keyword< DescriptorT, ActorT > const& keyword) const
182 {
183 return m_impl->m_attribute_values[keyword];
184 }
185
186 /*!
187 * The function ensures that the log record does not depend on any thread-specific data. Then the record contents
188 * are used to construct a \c record_view which is returned from the function. The record is no longer valid after the call.
189 *
190 * \pre <tt>!!*this</tt>
191 * \post <tt>!*this</tt>
192 * \returns The record view that contains all attribute values from the original record.
193 */
194 BOOST_LOG_API record_view lock();
195 };
196
197 /*!
198 * A free-standing swap function overload for \c record
199 */
200 inline void swap(record& left, record& right) BOOST_NOEXCEPT
201 {
202 left.swap(right);
203 }
204
205 BOOST_LOG_CLOSE_NAMESPACE // namespace log
206
207 } // namespace boost
208
209 #include <boost/log/detail/footer.hpp>
210
211 #endif // BOOST_LOG_CORE_RECORD_HPP_INCLUDED_