boost::log::attribute_value — A base class for an attribute value.
// In header: <boost/log/attributes/attribute.hpp> struct attribute_value { // construct/copy/destruct ~attribute_value(); // public member functions bool dispatch(type_dispatcher &); shared_ptr< attribute_value > detach_from_thread(); template<typename T> optional< T > get(); };
An attribute value is an object that contains a piece of data that represents an attribute state at the point of the value acquision. All major operations with log records, such as filtering and formatting, involve attribute values contained in a single view. Most likely an attribute value is implemented as a simple holder of some typed value. This holder implements attribute_value interface and provides type dispatching support in order to allow to extract the stored value.
Normally, attributes and their values shall be designed in order to exclude as much interference as reasonable. Such approach allows to have more than one attribute value simultaneously, which improves scalability and allows to implement generating attributes.
However, there are cases when this approach does not help to achieve the required level of independency of attribute values and attribute itself from each other at a reasonable performance tradeoff. For example, an attribute or its values may use thread-specific data, which is global and shared between all the instances of the attribute/value. Passing such an attribute value to another thread would be a disaster. To solve this the library defines an additional method for attribute values, namely detach_from_thread
. This method is called for all attribute values that are passed to another thread. The method is called only once per attribute value, on the first thread change. It is assumed that the value does not depend on any thread-specific data after this call.
attribute_value
public member functionsbool dispatch(type_dispatcher & dispatcher);
The method dispatches the value to the given object.
Parameters: |
|
||
Returns: | true if dispatcher was capable to consume the real attribute value type and false otherwise. |
shared_ptr< attribute_value > detach_from_thread();
The method is called when the attribute value is passed to another thread (e.g. in case of asynchronous logging). The value should ensure it properly owns all thread-specific data.
Returns: | An actual pointer to the attribute value. It may either point to this object or another. In the latter case the returned pointer replaces the pointer used by caller to invoke this method and is considered to be a functional equivalent to the previous pointer. |
template<typename T> optional< T > get();
An alternative to type dispatching. This is a simpler way to get the stored value in case if one knows its exact type.
Returns: | An optionally specified stored value. The returned value is present if the requested type matches the stored type, otherwise the returned value is absent. |