Provide a default container for storing attribute name/value pairs.
More...
Namespaces |
namespace | ball |
Detailed Description
- Outline
-
-
- Purpose:
- Provide a default container for storing attribute name/value pairs.
-
- Classes:
-
- See also:
- Component ball_attributecontainer
-
- Description:
- 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".
-
- Thread Safety:
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.
-
- Usage:
- This section illustrates the intended use of this component.
-
- Example 1: Basic Usage of ball::DefaultAttributeContainer:
- 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: assert(true == attributeContainer.hasValue(a1));
assert(true == attributeContainer.hasValue(a2));
assert(true == attributeContainer.hasValue(a3));
assert(true == attributeContainer.hasValue(a4));
assert(true == attributeContainer.hasValue(a5));
assert(true == attributeContainer.hasValue(a6));
Or removed by the removeAttribute
method: defaultattributecontainer.removeAttribute(a1);
assert(false == attributeContainer.hasValue(a1));
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.