Container of service providers accessed by type and optional label. More...
#include <ProviderList.h>
Classes | |
struct | exception |
base exception class for ProviderList More... | |
struct | provider_deleted |
Exception thrown on when object is not available any more. More... | |
struct | provider_not_available |
Exception thrown on a request about an unregistered type. More... | |
struct | provider_wrong |
Exception thrown on a invalid type request. More... | |
Public Member Functions | |
template<typename T , typename SetupProc , typename... Args> | |
bool | custom_setup_instance (std::string label, SetupProc &&provSetup, Args &&...args) |
Construct and register an object of type T. More... | |
template<typename T , typename SetupProc , typename... Args> | |
bool | custom_setup (SetupProc &&provSetup, Args &&...args) |
Construct and register an object of type T with specified arguments. More... | |
template<typename T , typename... Args> | |
bool | setup_instance (std::string label, Args &&...args) |
template<typename T , typename... Args> | |
bool | setup (Args &&...args) |
Construct and register an object of type T with specified arguments. More... | |
template<typename T > | |
bool | acquire (std::unique_ptr< T > &&obj_ptr, std::string label="") |
Registers and gets ownership of the specified object. More... | |
template<typename T > | |
bool | erase (std::string label="") |
Drops the object with the specified type and label. More... | |
template<typename Prov , typename Alias > | |
bool | set_alias (std::string alias_label="", std::string prov_label="") |
Sets the Alias type as an alias of the Prov provider (with labels) More... | |
template<typename T > | |
bool | known (std::string label="") const |
Returns whether we have a slot for this object. More... | |
template<typename T > | |
bool | valid (std::string label="") const |
Returns whether the specified object is available. More... | |
template<typename T > | |
T const & | get (std::string label="") const |
Retrieve the object of type T stored with the specified label. More... | |
template<typename T > | |
T & | get (std::string label="") |
template<typename T > | |
T const * | getPointer (std::string label="") const |
Retrieve the object of type T stored with the specified label. More... | |
template<typename T > | |
T * | getPointer (std::string label="") |
Private Types | |
template<typename T > | |
using | smart_pointer_t = std::unique_ptr< T > |
type of smart pointer we use to store elements More... | |
using | pointer_t = smart_pointer_t< details::MovableClassWrapperBase > |
Type of objects contained in the list. More... | |
template<typename T > | |
using | concrete_type_t = details::MovableClassWrapper< std::decay_t< T >> |
Type of list element with explicit element type memory. More... | |
template<typename T > | |
using | concrete_pointer_t = smart_pointer_t< concrete_type_t< T >> |
Type of smart pointer to typed list element. More... | |
using | key_type = size_t |
type used for key in the internal registry More... | |
Private Member Functions | |
template<typename T > | |
concrete_type_t< T > const & | get_elem (std::string label="") const |
template<typename T > | |
concrete_type_t< T > & | get_elem (std::string label="") |
template<typename T > | |
auto | find (std::string label="") const |
template<typename T > | |
auto | find (std::string label="") |
Static Private Member Functions | |
template<typename T > | |
static std::string | type_name () |
Convert a type into a (ugly) type name. More... | |
template<typename T > | |
static std::string | type_name (T const *ptr) |
Convert a pointer to object into a (ugly) type name. More... | |
template<typename T > | |
static key_type | key (std::string label="") |
Extracts and returns the key out of a type and label. More... | |
Private Attributes | |
std::unordered_map< key_type, pointer_t > | data |
all our singletons More... | |
Container of service providers accessed by type and optional label.
This container is expected to contain elements that are service providers of different types. Each provider is accessed by its class type and an optional instance label to discriminate between providers of the same type.
The list owns the providers. A provider is created with setup()
(or setup_instance()
if a instance label is needed). This method relies on a class testing::ProvideSetupClass
to create and correctly set up the provider. For example, to set up the provider LArPropertiesStandard
:
provList.setup<LArPropertiesStandard>(pset);
assuming that LArPropertiesStandard
provider has a constructor with as only argument pset
(supposedly, a fhicl::ParameterSet
). If a custom setup is needed, the methods custom_setup_instance()
and custom_setup()
take as argument a setup function, which can do whatever it takes to perform the set up.
After a provider is set up, a reference to it can be obtained by get()
:
auto& larp = provList.get<LArPropertiesStandard>();
If no such class is available, an exception will be thrown. The presence of a provider can be checked beforehand with has()
.
setup()
construction method? A provider can specify its own setup by specialising the class testing::ProvideSetupClass
. A default implementation is provided, that constructs the provider with a parameter set.
Definition at line 160 of file ProviderList.h.
|
private |
Type of smart pointer to typed list element.
Definition at line 177 of file ProviderList.h.
|
private |
Type of list element with explicit element type memory.
Definition at line 174 of file ProviderList.h.
|
private |
type used for key in the internal registry
Definition at line 380 of file ProviderList.h.
Type of objects contained in the list.
Definition at line 170 of file ProviderList.h.
|
private |
type of smart pointer we use to store elements
Definition at line 167 of file ProviderList.h.
|
inline |
Registers and gets ownership of the specified object.
T | type of object being acquired |
obj_ptr | pointer to the object to be acquired |
label | name of the object instance |
The ProviderList takes ownership of the specified provider. If an object of type T is already registered, the pointer is left untouched and false
is returned.
Definition at line 268 of file ProviderList.h.
|
inline |
Construct and register an object of type T with specified arguments.
Definition at line 225 of file ProviderList.h.
|
inline |
Construct and register an object of type T.
T | type of the object to be constructed (caller specifies it) |
SetupProc | type of functor performing the actual setup |
Args | type of constructor arguments (compiler fills them in) |
label | name of this instance of object type T (can be empty) |
provSetup | functor performing the setup |
args | arguments to provSetup for the construction of T |
An object is instantiated and associates it with the specified instance label. It can then be accessed with a get<T>(label)
call.
The functor provSetup
is expected to return a unique pointer to the newly created provider, std::unique_ptr<T>
.
Definition at line 211 of file ProviderList.h.
|
inline |
Drops the object with the specified type and label.
T | type of object being acquired |
label | name of the object instance |
If present, the object is destroyed
Definition at line 290 of file ProviderList.h.
|
inlineprivate |
Returns an iterator pointing to the requested key, or data.end()
Definition at line 395 of file ProviderList.h.
|
inlineprivate |
Definition at line 399 of file ProviderList.h.
|
inline |
Retrieve the object of type T stored with the specified label.
T | type of the object to be retrieved |
label | optional label used when the object was inserted |
provider_not_available | no type T class was stored with label |
provider_deleted | the object that was stored is not present |
provider_wrong | the object is not compatible with the type T |
Definition at line 339 of file ProviderList.h.
|
inline |
Definition at line 343 of file ProviderList.h.
|
inlineprivate |
Definition at line 403 of file ProviderList.h.
|
inlineprivate |
Definition at line 420 of file ProviderList.h.
|
inline |
Retrieve the object of type T stored with the specified label.
T | type of the object to be retrieved |
label | optional label used when the object was inserted |
provider_not_available | no type T class was stored with label |
provider_deleted | the object that was stored is not present |
provider_wrong | the object is not compatible with the type T |
Definition at line 358 of file ProviderList.h.
|
inline |
Definition at line 362 of file ProviderList.h.
|
inlinestaticprivate |
Extracts and returns the key out of a type and label.
Definition at line 438 of file ProviderList.h.
|
inline |
Returns whether we have a slot for this object.
Definition at line 368 of file ProviderList.h.
|
inline |
Sets the Alias type as an alias of the Prov provider (with labels)
Definition at line 309 of file ProviderList.h.
|
inline |
Construct and register an object of type T with specified arguments.
Definition at line 252 of file ProviderList.h.
|
inline |
Definition at line 236 of file ProviderList.h.
|
inlinestaticprivate |
|
inlinestaticprivate |
Convert a pointer to object into a (ugly) type name.
Definition at line 390 of file ProviderList.h.
|
inline |
Returns whether the specified object is available.
Definition at line 373 of file ProviderList.h.
all our singletons
Definition at line 382 of file ProviderList.h.