BDE 4.14.0 Production release
|
Provide a registry for attribute collector functors.
This component provides a mechanism, ball::AttributeCollectorRegistry
, that allows clients to register ball::Attribute
collection functions, and to separately apply a visitor to all the attributes collected using those collection functions. A client can register a ball::Attribute
collection function by calling addCollector
and supplying a function matching the AttributeCollectorRegistry::Collector
signature. Clients can also apply a visitor to collected ball::Attribute
objects by calling collect
and supplying a function matching the ball::AttributeCollectorRegistry::Visitor
signature. This call to collect
will use the supplied Visitor
as the argument when calling each of the Collector
functors registered with addCollector
.
ball::AttributeCollectorRegistry
is fully thread-safe, meaning that all non-creator operations on an object can be safely invoked simultaneously from multiple threads.
This section illustrates intended use of this component.
In this example we will collect a set of application properties and perform some manipulation of the collected data. Note that this usage example uses lambdas and requires C++11. Lambdas can be replaced with named functions for C++03.
First, we define a few collector functions that will collect the application properties from various parts of an application and call the specified visitor functor for every collected attribute:
Then, we register collector functions with the attribute collector registry:
Next, we print every attribute gathered by all registered attribute collectors in the registry:
Finally, we remove one of the collectors and collect attributes again: