2
* Copyright Andrey Semashev 2007 - 2013.
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)
9
* \author Andrey Semashev
12
* The header contains attribute interface definition.
15
#ifndef BOOST_LOG_ATTRIBUTES_ATTRIBUTE_HPP_INCLUDED_
16
#define BOOST_LOG_ATTRIBUTES_ATTRIBUTE_HPP_INCLUDED_
19
#include <boost/intrusive_ptr.hpp>
20
#include <boost/move/core.hpp>
21
#include <boost/log/detail/config.hpp>
22
#include <boost/log/utility/intrusive_ref_counter.hpp>
23
#include <boost/log/utility/explicit_operator_bool.hpp>
24
#include <boost/log/detail/header.hpp>
26
#ifdef BOOST_LOG_HAS_PRAGMA_ONCE
32
BOOST_LOG_OPEN_NAMESPACE
34
#ifndef BOOST_LOG_DOXYGEN_PASS
36
class attribute_value;
40
//! Reference proxy object to implement \c operator[]
41
class attribute_set_reference_proxy;
45
#endif // BOOST_LOG_DOXYGEN_PASS
48
* \brief A base class for an attribute value factory
50
* Every attribute is represented with a factory that is basically an attribute value generator.
51
* The sole purpose of an attribute is to return an actual value when requested. A simplest attribute
52
* can always return the same value that it stores internally, but more complex ones can
53
* perform a considerable amount of work to return a value, and the returned values may differ
54
* each time requested.
56
* A word about thread safety. An attribute should be prepared to be requested a value from
57
* multiple threads concurrently.
61
BOOST_COPYABLE_AND_MOVABLE(attribute)
65
* \brief A base class for an attribute value factory
67
* All attributes must derive their implementation from this class.
69
struct BOOST_LOG_NO_VTABLE BOOST_LOG_VISIBLE impl :
70
public intrusive_ref_counter
73
* \return The actual attribute value. It shall not return empty values (exceptions
74
* shall be used to indicate errors).
76
virtual attribute_value get_value() = 0;
78
BOOST_LOG_API static void* operator new (std::size_t size);
79
BOOST_LOG_API static void operator delete (void* p, std::size_t size) BOOST_NOEXCEPT;
83
//! Pointer to the attribute factory implementation
84
intrusive_ptr< impl > m_pImpl;
88
* Default constructor. Creates an empty attribute value factory, which is not usable until
89
* \c set_impl is called.
91
BOOST_LOG_DEFAULTED_FUNCTION(attribute(), {})
96
attribute(attribute const& that) BOOST_NOEXCEPT : m_pImpl(that.m_pImpl) {}
101
attribute(BOOST_RV_REF(attribute) that) BOOST_NOEXCEPT { m_pImpl.swap(that.m_pImpl); }
104
* Initializing constructor
106
* \param p Pointer to the implementation. Must not be \c NULL.
108
explicit attribute(intrusive_ptr< impl > p) BOOST_NOEXCEPT { m_pImpl.swap(p); }
113
attribute& operator= (BOOST_COPY_ASSIGN_REF(attribute) that) BOOST_NOEXCEPT
115
m_pImpl = that.m_pImpl;
122
attribute& operator= (BOOST_RV_REF(attribute) that) BOOST_NOEXCEPT
124
m_pImpl.swap(that.m_pImpl);
128
#ifndef BOOST_LOG_DOXYGEN_PASS
129
attribute& operator= (aux::attribute_set_reference_proxy const& that) BOOST_NOEXCEPT;
133
* Verifies that the factory is not in empty state
135
BOOST_LOG_EXPLICIT_OPERATOR_BOOL()
138
* Verifies that the factory is in empty state
140
bool operator! () const BOOST_NOEXCEPT { return !m_pImpl; }
143
* \return The actual attribute value. It shall not return empty values (exceptions
144
* shall be used to indicate errors).
146
attribute_value get_value() const;
149
* The method swaps two factories (i.e. their implementations).
151
void swap(attribute& that) BOOST_NOEXCEPT { m_pImpl.swap(that.m_pImpl); }
155
* \returns The pointer to the implementation
157
impl* get_impl() const BOOST_NOEXCEPT { return m_pImpl.get(); }
159
* Sets the pointer to the factory implementation.
161
* \param p Pointer to the implementation. Must not be \c NULL.
163
void set_impl(intrusive_ptr< impl > p) BOOST_NOEXCEPT { m_pImpl.swap(p); }
165
template< typename T >
166
friend T attribute_cast(attribute const&);
170
* The function swaps two attribute value factories
172
inline void swap(attribute& left, attribute& right) BOOST_NOEXCEPT
177
BOOST_LOG_CLOSE_NAMESPACE // namespace log
181
#include <boost/log/detail/footer.hpp>
182
#if defined(BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_HPP_INCLUDED_)
183
#include <boost/log/detail/attribute_get_value_impl.hpp>
186
#endif // BOOST_LOG_ATTRIBUTES_ATTRIBUTE_HPP_INCLUDED_