STIR
6.2.0
|
This class can be used to store 'factories' and their corresponding keys. It is essentially a map, but with some extra embelishments. More...
#include "stir/FactoryRegistry.h"
Public Member Functions | |
FactoryRegistry () | |
Default constructor without defaults (see find_factory()) | |
FactoryRegistry (const Key &default_key, const Factory &default_factory) | |
constructor with default values which will be returned when no match is found (see find_factory()) | |
void | add_to_registry (const Key &key, Factory const &factory) |
Add a pair to the registry. More... | |
void | remove_from_registry (const Key &key) |
Remove a pair from the registry. | |
void | list_keys (std::ostream &s) const |
List all keys to an ostream, separated by newlines. | |
Factory const & | find_factory (const Key &key) const |
Find a factory corresponding to a key. More... | |
This class can be used to store 'factories' and their corresponding keys. It is essentially a map, but with some extra embelishments.
A factory is supposed to be an object which can create another object, although this is not really enfored by the implementation of FactoryRegistry.
Key,Factory,Compare must be suitable as defined for std::map. In addition, FactoryRegistry::list_keys() requires that operator<<(ostream&, const Key&) is defined.
|
inline |
Add a pair to the registry.
Adding the same key twice will overwrite the first value.
References stir::warning().
Referenced by stir::FactoryRegistry< Key, Factory, Compare >::FactoryRegistry().
|
inline |
Find a factory corresponding to a key.
If the key is not found, the behaviour depends on which constructor was used. If the (default) no-argument constructor is used, an error message is printed, and the program aborts. If the 2nd constructor with default values, the default_factory is returned.
References stir::error(), and stir::FactoryRegistry< Key, Factory, Compare >::list_keys().