BDE 4.14.0 Production release
|
Provide a default container for storing attribute name/value pairs.
This component provides a default implementation of the ball::AttributeContainer
protocol, ball::DefaultAttributeContainer
providing an unordered_set
-based container of ball::Attribute
values. Each attribute within the default attribute container holds a (case-sensitive) name and a value, which may be an int
, a 64-bit integer, 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".
ball::DefaultAttributeContainer
is const thread-safe, meaning that accessors may be invoked concurrently from different threads, but it is not safe to access or modify a ball::DefaultAttributeContainer
in one thread while another thread modifies the same object.
This section illustrates the intended use of this component.
A ball::DefaultAttributeContainer
initially has no attributes when created by the default constructor:
Let's now create some attributes and add them to the attribute map:
New attributes with a name that already exists in the map can be added, as long as they have a different value:
But attributes having the same name and value cannot be added:
Note that the attribute name is case-sensitive:
Existing attributes can be looked up by the hasValue
method:
Or removed by the removeAttribute
method:
Also, the ball::DefaultAttributeContainer
class provides an iterator:
Finally, we can provide a visitor functor and visit all attributes in the container. Note that this usage example uses lambdas and requires C++11. Lambdas can be replaced with named functions for C++03.