Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file attribute.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 15.04.2007
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains attribute interface definition.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_ATTRIBUTES_ATTRIBUTE_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_ATTRIBUTES_ATTRIBUTE_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <new>
|
Chris@16
|
19 #include <boost/move/core.hpp>
|
Chris@16
|
20 #include <boost/smart_ptr/intrusive_ptr.hpp>
|
Chris@16
|
21 #include <boost/smart_ptr/intrusive_ref_counter.hpp>
|
Chris@16
|
22 #include <boost/log/detail/config.hpp>
|
Chris@16
|
23 #include <boost/utility/explicit_operator_bool.hpp>
|
Chris@16
|
24 #include <boost/log/detail/header.hpp>
|
Chris@16
|
25
|
Chris@16
|
26 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
27 #pragma once
|
Chris@16
|
28 #endif
|
Chris@16
|
29
|
Chris@16
|
30 namespace boost {
|
Chris@16
|
31
|
Chris@16
|
32 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
33
|
Chris@16
|
34 #ifndef BOOST_LOG_DOXYGEN_PASS
|
Chris@16
|
35
|
Chris@16
|
36 class attribute_value;
|
Chris@16
|
37
|
Chris@16
|
38 namespace aux {
|
Chris@16
|
39
|
Chris@16
|
40 //! Reference proxy object to implement \c operator[]
|
Chris@16
|
41 class attribute_set_reference_proxy;
|
Chris@16
|
42
|
Chris@16
|
43 } // namespace aux
|
Chris@16
|
44
|
Chris@16
|
45 #endif // BOOST_LOG_DOXYGEN_PASS
|
Chris@16
|
46
|
Chris@16
|
47 /*!
|
Chris@16
|
48 * \brief A base class for an attribute value factory
|
Chris@16
|
49 *
|
Chris@16
|
50 * Every attribute is represented with a factory that is basically an attribute value generator.
|
Chris@16
|
51 * The sole purpose of an attribute is to return an actual value when requested. A simplest attribute
|
Chris@16
|
52 * can always return the same value that it stores internally, but more complex ones can
|
Chris@16
|
53 * perform a considerable amount of work to return a value, and the returned values may differ
|
Chris@16
|
54 * each time requested.
|
Chris@16
|
55 *
|
Chris@16
|
56 * A word about thread safety. An attribute should be prepared to be requested a value from
|
Chris@16
|
57 * multiple threads concurrently.
|
Chris@16
|
58 */
|
Chris@16
|
59 class attribute
|
Chris@16
|
60 {
|
Chris@16
|
61 BOOST_COPYABLE_AND_MOVABLE(attribute)
|
Chris@16
|
62
|
Chris@16
|
63 public:
|
Chris@16
|
64 /*!
|
Chris@16
|
65 * \brief A base class for an attribute value factory
|
Chris@16
|
66 *
|
Chris@16
|
67 * All attributes must derive their implementation from this class.
|
Chris@16
|
68 */
|
Chris@16
|
69 struct BOOST_LOG_NO_VTABLE BOOST_SYMBOL_VISIBLE impl :
|
Chris@16
|
70 public boost::intrusive_ref_counter< impl >
|
Chris@16
|
71 {
|
Chris@16
|
72 /*!
|
Chris@16
|
73 * \brief Virtual destructor
|
Chris@16
|
74 */
|
Chris@16
|
75 virtual ~impl() {}
|
Chris@16
|
76
|
Chris@16
|
77 /*!
|
Chris@16
|
78 * \return The actual attribute value. It shall not return empty values (exceptions
|
Chris@16
|
79 * shall be used to indicate errors).
|
Chris@16
|
80 */
|
Chris@16
|
81 virtual attribute_value get_value() = 0;
|
Chris@16
|
82
|
Chris@16
|
83 BOOST_LOG_API static void* operator new (std::size_t size);
|
Chris@16
|
84 BOOST_LOG_API static void operator delete (void* p, std::size_t size) BOOST_NOEXCEPT;
|
Chris@16
|
85 };
|
Chris@16
|
86
|
Chris@16
|
87 private:
|
Chris@16
|
88 //! Pointer to the attribute factory implementation
|
Chris@16
|
89 intrusive_ptr< impl > m_pImpl;
|
Chris@16
|
90
|
Chris@16
|
91 public:
|
Chris@16
|
92 /*!
|
Chris@16
|
93 * Default constructor. Creates an empty attribute value factory, which is not usable until
|
Chris@16
|
94 * \c set_impl is called.
|
Chris@16
|
95 */
|
Chris@16
|
96 BOOST_DEFAULTED_FUNCTION(attribute(), {})
|
Chris@16
|
97
|
Chris@16
|
98 /*!
|
Chris@16
|
99 * Copy constructor
|
Chris@16
|
100 */
|
Chris@16
|
101 attribute(attribute const& that) BOOST_NOEXCEPT : m_pImpl(that.m_pImpl) {}
|
Chris@16
|
102
|
Chris@16
|
103 /*!
|
Chris@16
|
104 * Move constructor
|
Chris@16
|
105 */
|
Chris@16
|
106 attribute(BOOST_RV_REF(attribute) that) BOOST_NOEXCEPT { m_pImpl.swap(that.m_pImpl); }
|
Chris@16
|
107
|
Chris@16
|
108 /*!
|
Chris@16
|
109 * Initializing constructor
|
Chris@16
|
110 *
|
Chris@16
|
111 * \param p Pointer to the implementation. Must not be \c NULL.
|
Chris@16
|
112 */
|
Chris@16
|
113 explicit attribute(intrusive_ptr< impl > p) BOOST_NOEXCEPT { m_pImpl.swap(p); }
|
Chris@16
|
114
|
Chris@16
|
115 /*!
|
Chris@16
|
116 * Copy assignment
|
Chris@16
|
117 */
|
Chris@16
|
118 attribute& operator= (BOOST_COPY_ASSIGN_REF(attribute) that) BOOST_NOEXCEPT
|
Chris@16
|
119 {
|
Chris@16
|
120 m_pImpl = that.m_pImpl;
|
Chris@16
|
121 return *this;
|
Chris@16
|
122 }
|
Chris@16
|
123
|
Chris@16
|
124 /*!
|
Chris@16
|
125 * Move assignment
|
Chris@16
|
126 */
|
Chris@16
|
127 attribute& operator= (BOOST_RV_REF(attribute) that) BOOST_NOEXCEPT
|
Chris@16
|
128 {
|
Chris@16
|
129 m_pImpl.swap(that.m_pImpl);
|
Chris@16
|
130 return *this;
|
Chris@16
|
131 }
|
Chris@16
|
132
|
Chris@16
|
133 #ifndef BOOST_LOG_DOXYGEN_PASS
|
Chris@16
|
134 attribute& operator= (aux::attribute_set_reference_proxy const& that) BOOST_NOEXCEPT;
|
Chris@16
|
135 #endif
|
Chris@16
|
136
|
Chris@16
|
137 /*!
|
Chris@16
|
138 * Verifies that the factory is not in empty state
|
Chris@16
|
139 */
|
Chris@101
|
140 BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
|
Chris@16
|
141
|
Chris@16
|
142 /*!
|
Chris@16
|
143 * Verifies that the factory is in empty state
|
Chris@16
|
144 */
|
Chris@16
|
145 bool operator! () const BOOST_NOEXCEPT { return !m_pImpl; }
|
Chris@16
|
146
|
Chris@16
|
147 /*!
|
Chris@16
|
148 * \return The actual attribute value. It shall not return empty values (exceptions
|
Chris@16
|
149 * shall be used to indicate errors).
|
Chris@16
|
150 */
|
Chris@16
|
151 attribute_value get_value() const;
|
Chris@16
|
152
|
Chris@16
|
153 /*!
|
Chris@16
|
154 * The method swaps two factories (i.e. their implementations).
|
Chris@16
|
155 */
|
Chris@16
|
156 void swap(attribute& that) BOOST_NOEXCEPT { m_pImpl.swap(that.m_pImpl); }
|
Chris@16
|
157
|
Chris@16
|
158 protected:
|
Chris@16
|
159 /*!
|
Chris@16
|
160 * \returns The pointer to the implementation
|
Chris@16
|
161 */
|
Chris@16
|
162 impl* get_impl() const BOOST_NOEXCEPT { return m_pImpl.get(); }
|
Chris@16
|
163 /*!
|
Chris@16
|
164 * Sets the pointer to the factory implementation.
|
Chris@16
|
165 *
|
Chris@16
|
166 * \param p Pointer to the implementation. Must not be \c NULL.
|
Chris@16
|
167 */
|
Chris@16
|
168 void set_impl(intrusive_ptr< impl > p) BOOST_NOEXCEPT { m_pImpl.swap(p); }
|
Chris@16
|
169
|
Chris@16
|
170 template< typename T >
|
Chris@16
|
171 friend T attribute_cast(attribute const&);
|
Chris@16
|
172 };
|
Chris@16
|
173
|
Chris@16
|
174 /*!
|
Chris@16
|
175 * The function swaps two attribute value factories
|
Chris@16
|
176 */
|
Chris@16
|
177 inline void swap(attribute& left, attribute& right) BOOST_NOEXCEPT
|
Chris@16
|
178 {
|
Chris@16
|
179 left.swap(right);
|
Chris@16
|
180 }
|
Chris@16
|
181
|
Chris@16
|
182 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
183
|
Chris@16
|
184 } // namespace boost
|
Chris@16
|
185
|
Chris@16
|
186 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
187 #if defined(BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_HPP_INCLUDED_)
|
Chris@16
|
188 #include <boost/log/detail/attribute_get_value_impl.hpp>
|
Chris@16
|
189 #endif
|
Chris@16
|
190
|
Chris@16
|
191 #endif // BOOST_LOG_ATTRIBUTES_ATTRIBUTE_HPP_INCLUDED_
|