fire v0.19.0
Framework for sImulation and Reconstruction of Events
|
The special factory used to create processors. More...
#include <Processor.h>
Public Types | |
using | PrototypePtr = std::unique_ptr< Processor > |
The base pointer for processors. | |
using | PrototypeMaker = std::function< PrototypePtr(const config::Parameters &, Process &)> |
the signature of a function that can be used by this factory to dynamically create a new object. More... | |
Public Member Functions | |
template<typename DerivedType > | |
uint64_t | declare () |
register a new object to be constructible More... | |
PrototypePtr | make (const std::string &full_name, const config::Parameters &ps, Process &p) |
make a new object by name More... | |
Factory (Factory const &)=delete | |
delete the copy constructor | |
void | operator= (Factory const &)=delete |
delete the assignment operator | |
Static Public Member Functions | |
static Factory & | get () |
get the factory instance More... | |
Private Member Functions | |
Factory ()=default | |
private constructor to prevent creation | |
Static Private Member Functions | |
template<typename DerivedType > | |
static PrototypePtr | maker (const config::Parameters ¶meters, Process &process) |
make a DerivedType returning a PrototypePtr More... | |
Private Attributes | |
std::unordered_map< std::string, PrototypeMaker > | library_ |
library of possible objects to create | |
The special factory used to create processors.
we need a special factory because it needs to be able to create processors with two different construtor options
When "old-style" processors can be abandoned, this redundant code can be removed in favor of the templated factory:
and then adding the following line to the loop constructing Processors in the Process constructor:
using fire::Processor::Factory::PrototypeMaker = std::function<PrototypePtr(const config::Parameters&,Process&)> |
the signature of a function that can be used by this factory to dynamically create a new object.
This is merely here to make the definition of the Factory simpler.
|
inline |
register a new object to be constructible
We insert the new object into the library after checking that it hasn't been defined before.
DerivedType | type of processor to declare |
|
inlinestatic |
get the factory instance
Using a static function variable gaurantees that the factory is created as soon as it is needed and that it is deleted before the program completes.
|
inline |
make a new object by name
We look through the library to find the requested object. If found, we create one and return a pointer to the newly created object. If not found, we raise an exception.
Exception | if the input object name could not be found |
The arguments to the maker are determined at compiletime using the template parameters of Factory.
[in] | full_name | name of object to create, same name as passed to declare |
[in] | ps | Parameters to configure the Processor |
[in] | p | handle to current Process |
|
inlinestaticprivate |
make a DerivedType returning a PrototypePtr
We do a constexpr check on which type of processor it is. If it can be constructed from a Parameters alone, then it is a "new" type. Otherewise, it is a "legacy" type as defined in the framework namespace.
DerivedType | type of derived object we should create |
[in] | parameters | config::Parameters to configure Processor |
[in] | process | handle to current Process |