BDE 4.14.0 Production release
|
Provide a representation of (literal) name/value pairs.
This component implements an unusual in-core value-semantic class, ball::Attribute
. Each instance of this type represents an attribute that consists of a (literal) name (held but not owned), and an associated value (owned) that can be an int
, long
, long long
, unsigned int
, unsigned long', unsigned long long
, bdlb::Guid
, or a bsl::string
.
This component participates in the implementation of "Rule-Based Logging". For more information on how to use that feature, please see the package level documentation and usage examples for "Rule-Based Logging".
IMPORTANT: The attribute name, whose type is const char *
, must therefore remain valid throughout the life time of the ball::Attribute
object and that of any other ball::Attribute
objects that are copied or assigned from the original object. It is recommended that only null-terminated C-string literals be used for names.
Attributes can be rendered as part of a log message and used for log post-processing and analysis. It is recommended to use the following naming conventions for attribute names:
_
), and dots(.
). Do not use any other special characters.Disregarding these conventions may prevent the log output from being correctly parsed by commonly used log processing software.
This section illustrates intended use of this component.
The following code creates four attributes having the same name, but different attribute value types.
The names of the attributes can be found by calling the name
method:
The value
method returns a non-modifiable reference to the bdlb::Variant
object that manages the value of the attribute:
Note that the name string that is passed to the constructor of ball::Attribute
must remain valid and unchanged after the ball::Attribute
object is created. In the next example, we create a temporary buffer to store the name string, and then use the buffer to create an attribute. Note that any subsequent changes to this temporary buffer will also modify the name of the attribute:
The ball::Attribute
class also provides a constructor that takes a value of type ball::Attribute::Value
:
Consider we have an event scheduler that operates on events referred to by event handle:
The event handler value can be logged using ball::Attribute
as follows: