...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::log::attribute — A base class for an attribute value factory.
// In header: <boost/log/attributes/attribute.hpp> class attribute { public: // member classes/structs/unions // A base class for an attribute value factory. struct impl : public boost::intrusive_ref_counter< impl > { // construct/copy/destruct ~impl(); // public member functions virtual attribute_value get_value() = 0; // public static functions static void * operator new(std::size_t); static void operator delete(void *, std::size_t) noexcept; }; // construct/copy/destruct attribute(attribute const &) noexcept; attribute(attribute &&) noexcept; explicit attribute(intrusive_ptr< impl >) noexcept; attribute & operator=(attribute const &) noexcept; attribute & operator=(attribute &&) noexcept; // public member functions explicit operator bool() const noexcept; bool operator!() const noexcept; attribute_value get_value() const; void swap(attribute &) noexcept; // protected member functions impl * get_impl() const noexcept; void set_impl(intrusive_ptr< impl >) noexcept; // friend functions template<typename T> friend T attribute_cast(attribute const &); };
Every attribute is represented with a factory that is basically an attribute value generator. The sole purpose of an attribute is to return an actual value when requested. A simplest attribute can always return the same value that it stores internally, but more complex ones can perform a considerable amount of work to return a value, and the returned values may differ each time requested.
A word about thread safety. An attribute should be prepared to be requested a value from multiple threads concurrently.
attribute
public
construct/copy/destructattribute(attribute const & that) noexcept;
Default constructor. Creates an empty attribute value factory, which is not usable until set_impl
is called.
Copy constructor
attribute(attribute && that) noexcept;
Move constructor
explicit attribute(intrusive_ptr< impl > p) noexcept;
Initializing constructor
Parameters: |
|
attribute & operator=(attribute const & that) noexcept;
Copy assignment
attribute & operator=(attribute && that) noexcept;
Move assignment
attribute
public member functionsexplicit operator bool() const noexcept;
Verifies that the factory is not in empty state
bool operator!() const noexcept;
Verifies that the factory is in empty state
attribute_value get_value() const;
Returns: |
The actual attribute value. It shall not return empty values (exceptions shall be used to indicate errors). |
void swap(attribute & that) noexcept;
The method swaps two factories (i.e. their implementations).
attribute
friend functionstemplate<typename T> friend T attribute_cast(attribute const &);
The function casts one attribute factory to another